Gateware Libraries  R6.5A
Beta Build
GMathDefines.h
1 #ifndef GMATHDEFINES_H
2 #define GMATHDEFINES_H
3 
15 #define G_PI 3.14159265358979323846
16 #define G_PI_R 0.318309886183790671538
17 
18 #define G_EPSILON_F 1.192092896e-07F
19 #define G_EPSILON_D 2.2204460492503131e-016
20 
21 #define G_ABS(num) ( ( (num) > 0 ) ? (num) : (-(num)) ) //RETURN THE ABSOLUTE VALUE OF THE INPUT NUMBER
22 #define G_LARGER(A, B) ( ( (A) > (B) ) ? (A) : (B) ) //RETURN THE LARGER INPUT NUMBER
23 #define G_SMALLER(A, B) ( ( (A) < (B) ) ? (A) : (B) ) //RETURN THE SMALLER INPUT NUMBER
24 #define G_ABS_LARGER(A, B) ( ( G_ABS(A) > G_ABS(B) ) ? G_ABS(A) : G_ABS(B) )
25 
26 #define G_DEVIATION_EXACT 0
27 #define G_DEVIATION_PRECISE_F G_EPSILON_F
28 #define G_DEVIATION_STANDARD_F G_EPSILON_F * 10
29 #define G_DEVIATION_LOOSE_F G_EPSILON_F * 100
30 
31 #define G_DEVIATION_PRECISE_D G_EPSILON_D
32 #define G_DEVIATION_STANDARD_D G_EPSILON_D * 10
33 #define G_DEVIATION_LOOSE_D G_EPSILON_D * 100
34 
35 #define G_FIRST_COMPARISON_F(num1 , num2) ( G_ABS( (num1) - (num2) ) <= ( G_EPSILON_F ) ) //FIRST CHECK IF TWO INPUT FLOATS' DIFF ARE LESS THAN EPSILON
36 #define G_SECOND_COMPARISON_F(num1 , num2) ( G_ABS( (num1) - (num2) ) <= ( G_DEVIATION_STANDARD_F * G_ABS_LARGER(num1, num2)) ) //SECOND CHECK IF TWO INPUT FLOATS' DIFF ARE LESS THAN EPSILON MULTIPLY THE LARGER INPUT FLOAT
37 #define G_COMPARISON_STANDARD_F(num1 , num2) ( G_FIRST_COMPARISON_F( (num1), (num2) ) ? true : G_SECOND_COMPARISON_F( (num1) , (num2) ) )
38 #define G_COMPARISON_F(num1, num2, deviation) ( G_FIRST_COMPARISON_F( (num1), (num2) ) ? true : ( G_ABS( (num1) - (num2) ) <= ( deviation * G_ABS_LARGER(num1, num2)) ) )
39 
40 #define G_FIRST_COMPARISON_D(num1 , num2) ( G_ABS( (num1) - (num2) ) <= ( G_EPSILON_D ) ) //FIRST CHECK IF TWO INPUT FLOATS' DIFF ARE LESS THAN EPSILON
41 #define G_SECOND_COMPARISON_D(num1 , num2) ( G_ABS( (num1) - (num2) ) <= ( G_DEVIATION_STANDARD_D * G_ABS_LARGER(num1, num2)) ) //SECOND CHECK IF TWO INPUT FLOATS' DIFF ARE LESS THAN EPSILON MULTIPLY THE LARGER INPUT FLOAT
42 #define G_COMPARISON_STANDARD_D(num1 , num2) ( G_FIRST_COMPARISON_D( (num1), (num2) ) ? true : G_SECOND_COMPARISON_D( (num1) , (num2) ) )
43 #define G_COMPARISON_D(num1 , num2, deviation) ( G_FIRST_COMPARISON_D( (num1), (num2) ) ? true :( G_ABS( (num1) - (num2) ) <= ( deviation * (G_ABS_LARGER(num1, num2))) ) )
44 
45 #define G_LERP(start , end, ratio) ( start + ratio * (end - start) ) //LINEAR INTERPOLATE TWO POINT WITH THE RATIO
46 #define G_CLAMP(num , top, bottom) ((((num) > (top)) ? (top) : (num)) < (bottom)) ? (bottom) : (num) //CLAMP THE NUMBER BETWEEN THE TOP NUMBER AND THE BOTTOM NUMBER
47 
48 #define G_DEGREE_TO_RADIAN(degree) ( (degree) * ( (G_PI) / (180.0) ) )
49 #define G_RADIAN_TO_DEGREE(radian) ( (radian) * ( (180.0) / (G_PI) ) )
50 
51 
53 namespace GW
54 {
55 
57  namespace MATH
58  {
59  // Ensure identical binary padding for structures on all platforms.
60 #pragma pack(push, 1)
61 
63 
67  struct GVECTORF
69  {
70  union
71  {
72  struct
73  {
74  float x;
75  float y;
76  float z;
77  float w;
78  };
79  float data[4];
80  };
81  };
82 
84  struct GVECTORD
85  {
86  union
87  {
88  struct
89  {
90  double x;
91  double y;
92  double z;
93  double w;
94  };
95  double data[4];
96  };
97  };
99  struct GMATRIXF
100  {
101  union
102  {
103  struct
104  {
105  GVECTORF row1;
106  GVECTORF row2;
107  GVECTORF row3;
108  GVECTORF row4;
109  };
110 
111  float data[16];
112  };
113  };
114 
116  struct GMATRIXD
117  {
118  union
119  {
120  struct
121  {
122  GVECTORD row1;
123  GVECTORD row2;
124  GVECTORD row3;
125  GVECTORD row4;
126  };
127  double data[16];
128  };
129  };
130 
133  {
134  union
135  {
136  struct
137  {
138  float x;
139  float y;
140  float z;
141  float w;
142  };
143  float data[4];
144  };
145  };
146 
149  {
150  union
151  {
152  struct
153  {
154  double x;
155  double y;
156  double z;
157  double w;
158  };
159  double data[4];
160  };
161  };
162 
163 #pragma pack(pop)
164 
165  static const GVECTORF GIdentityVectorF{ 0,0,0,1 };
166  static const GVECTORD GIdentityVectorD{ 0,0,0,1 };
167  static const GVECTORF GZeroVectorF{ 0,0,0,0 };
168  static const GVECTORD GZeroVectorD{ 0,0,0,0 };
169 
170  static const GMATRIXF GIdentityMatrixF{ 1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1 };
171  static const GMATRIXD GIdentityMatrixD{ 1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1 };
172  static const GMATRIXF GZeroMatrixF{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
173  static const GMATRIXD GZeroMatrixD{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
174 
175  static const GQUATERNIONF GIdentityQuaternionF{ 0,0,0,1 };
176  static const GQUATERNIOND GIdentityQuaternionD{ 0,0,0,1 };
177  static const GQUATERNIONF GZeroQuaternionF{ 0,0,0,0 };
178  static const GQUATERNIOND GZeroQuaternionD{ 0,0,0,0 };
179 
180  } // end MATH namespace
181 } // end GW namespace
182 
183 
184 
185 
186 #endif
Vector with 4 double elements.
Definition: GMathDefines.h:84
Quaternion with 4 float elements.
Definition: GMathDefines.h:132
Matrix with 4 double vectors which represent for each row.
Definition: GMathDefines.h:116
To hold all math structs and variables.
Definition: GMathDefines.h:68
Quaternion with 4 double elements.
Definition: GMathDefines.h:148
The core namespace to which all Gateware interfaces/structures/defines must belong.
Definition: GAudio.h:20
Matrix with 4 float vectors which represent for each row.
Definition: GMathDefines.h:99