hal_gfx_math.h
Go to the documentation of this file.
1 
2 
3 /** @addtogroup GRAPHICS_SDK Graphics
4  * @{
5  */
6 
7 /** @defgroup HAL_GFX_MATH Hal gfx math
8  * @brief GPU base math interfaces.
9  * @{
10  */
11 
12 #ifndef HAL_GFX_MATH_H__
13 #define HAL_GFX_MATH_H__
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 /**
20  * @defgroup HAL_GFX_MATH_MACRO Defines
21  * @{
22  */
23 #define HAL_GFX_E 2.71828182845904523536f /**< e */
24 #define HAL_GFX_LOG2E 1.44269504088896340736f /**< log2(e) */
25 #define HAL_GFX_LOG10E 0.434294481903251827651f /**< log10(e) */
26 #define HAL_GFX_LN2 0.693147180559945309417f /**< ln(2) */
27 #define HAL_GFX_LN10 2.30258509299404568402f /**< ln(10) */
28 #define HAL_GFX_PI 3.14159265358979323846f /**< pi */
29 #define HAL_GFX_PI_2 1.57079632679489661923f /**< pi/2 */
30 #define HAL_GFX_PI_4 0.785398163397448309616f /**< pi/4 */
31 #define HAL_GFX_1_PI 0.318309886183790671538f /**< 1/pi */
32 #define HAL_GFX_2_PI 0.636619772367581343076f /**< 2/pi */
33 #define HAL_GFX_2_SQRTPI 1.12837916709551257390f /**< 2/sqrt(pi) */
34 #define HAL_GFX_SQRT2 1.41421356237309504880f /**< sqrt(2) */
35 #define HAL_GFX_SQRT1_2 0.707106781186547524401f /**< 1/sqrt(2) */
36 
37 #define hal_gfx_min2(a,b) (((a)<(b))?( a):(b)) /**< Find the minimum of two values */
38 #define hal_gfx_max2(a,b) (((a)>(b))?( a):(b)) /**< Find the maximum of two values */
39 #define hal_gfx_clamp(val, min, max) hal_gfx_min2((max), hal_gfx_max2((min), (val))) /**< Clamp value. */
40 #define hal_gfx_abs(a) (((a)< 0 )?(-(a)):(a)) /**< Calculate the absolute value of int. */
41 #define hal_gfx_absf(a) (((a)< 0.f )?(-(a)):(a)) /**< Calculate the absolute value of float. */
42 #define hal_gfx_floats_equal(x, y) (hal_gfx_absf((x) - (y)) <= 0.00001f * hal_gfx_min2(hal_gfx_absf(x), hal_gfx_absf(y))) /**< Compare two floats. */
43 #define hal_gfx_float_is_zero(x) (hal_gfx_absf(x) <= 0.00001f) /**< Checks if value x is zero. */
44 #define hal_gfx_deg_to_rad(d) (0.0174532925199f * (d)) /**< Convert degrees to radians. */
45 #define hal_gfx_rad_to_deg(r) (57.295779513f * (r)) /**< onvert radians to degries. */
46 #define hal_gfx_i2fx(a) ((a)*0x10000) /**< Convert integer to 16.16 fixed point. */
47 #define hal_gfx_floor(f) ((int)(f) - ( (int)(f) > (f) )) /**< Floor function. */
48 #define hal_gfx_ceil(f) ((int)(f) + ( (int)(f) < (f) )) /**< Ceiling function. */
49 /** @} */
50 
51 /**
52  * @defgroup HAL_GFX_MATH_FUNCTION Functions
53  * @{
54  */
55 /**
56  *****************************************************************************************
57  * @brief Fast sine approximation of a given angle
58  *
59  * @param[in] angle_degrees: Angle in degrees
60  *
61  * @return return Sine of the given angle
62  *****************************************************************************************
63  */
64 float hal_gfx_sin(float angle_degrees);
65 
66 /**
67  *****************************************************************************************
68  * @brief Fast cosine approximation of a given angle
69  *
70  * @param[in] angle_degrees: Angle in degrees
71  *
72  * @return Cosine of the given angle
73  *****************************************************************************************
74  */
75 float hal_gfx_cos(float angle_degrees);
76 
77 /**
78  *****************************************************************************************
79  * @brief Fast tangent approximation of a given angle
80  *
81  * @param[in] angle_degrees: Angle in degrees
82  *
83  * @return Tangent of the given angle
84  *****************************************************************************************
85  */
86 float hal_gfx_tan(float angle_degrees);
87 
88 /**
89  *****************************************************************************************
90  * @brief A rough approximation of x raised to the power of y. USE WITH CAUTION!
91  *
92  * @param[in] x: base value. Must be non negative.
93  * @param[in] y: power value
94  *
95  * @return The result of raising x to the power y
96  *****************************************************************************************
97  */
98 float hal_gfx_pow(float x, float y);
99 
100 /**
101  *****************************************************************************************
102  * @brief A rough approximation of the square root of x. USE WITH CAUTION!
103  *
104  * @param[in] x: X value. Must be non negative
105  *
106  * @return The square root of x
107  *****************************************************************************************
108  */
109 float hal_gfx_sqrt(float x);
110 
111 /**
112  *****************************************************************************************
113  * @brief A floating-point approximation of the inverse tangent of x
114  *
115  * @param[in] x: X value
116  *
117  * @return Inverse tangent (angle) of x in degrees
118  *****************************************************************************************
119  */
120 float hal_gfx_atan(float x);
121 
122 /**
123  *****************************************************************************************
124  * @brief Convert float to 16.16 fixed point
125  *
126  * @param[in] f: Value to be converted
127  *
128  * @return 16.16 fixed point value
129  *****************************************************************************************
130  */
131 int hal_gfx_f2fx(float f);
132 /** @} */
133 #ifdef __cplusplus
134 }
135 #endif
136 
137 #endif
138 /** @} */
139 /** @} */
hal_gfx_cos
float hal_gfx_cos(float angle_degrees)
Fast cosine approximation of a given angle.
hal_gfx_sqrt
float hal_gfx_sqrt(float x)
A rough approximation of the square root of x. USE WITH CAUTION!
hal_gfx_tan
float hal_gfx_tan(float angle_degrees)
Fast tangent approximation of a given angle.
hal_gfx_atan
float hal_gfx_atan(float x)
A floating-point approximation of the inverse tangent of x.
hal_gfx_sin
float hal_gfx_sin(float angle_degrees)
Fast sine approximation of a given angle.
hal_gfx_f2fx
int hal_gfx_f2fx(float f)
Convert float to 16.16 fixed point.
hal_gfx_pow
float hal_gfx_pow(float x, float y)
A rough approximation of x raised to the power of y. USE WITH CAUTION!