Go to the documentation of this file.00001 #ifndef GIM_MATH_H_INCLUDED
00002 #define GIM_MATH_H_INCLUDED
00003
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "LinearMath/btScalar.h"
00036
00037
00038
00039 #define GREAL btScalar
00040 #define GREAL2 double
00041 #define GINT int
00042 #define GUINT unsigned int
00043 #define GSHORT short
00044 #define GUSHORT unsigned short
00045 #define GINT64 long long
00046 #define GUINT64 unsigned long long
00047
00048
00049
00050 #define G_PI 3.14159265358979f
00051 #define G_HALF_PI 1.5707963f
00052
00053 #define G_TWO_PI 6.28318530f
00054
00055 #define G_ROOT3 1.73205f
00056 #define G_ROOT2 1.41421f
00057 #define G_UINT_INFINITY 0xffffffff //!< A very very high value
00058 #define G_REAL_INFINITY FLT_MAX
00059 #define G_SIGN_BITMASK 0x80000000
00060 #define G_EPSILON SIMD_EPSILON
00061
00062
00063
00064 enum GIM_SCALAR_TYPES
00065 {
00066 G_STYPE_REAL =0,
00067 G_STYPE_REAL2,
00068 G_STYPE_SHORT,
00069 G_STYPE_USHORT,
00070 G_STYPE_INT,
00071 G_STYPE_UINT,
00072 G_STYPE_INT64,
00073 G_STYPE_UINT64
00074 };
00075
00076
00077
00078 #define G_DEGTORAD(X) ((X)*3.1415926f/180.0f)
00079 #define G_RADTODEG(X) ((X)*180.0f/3.1415926f)
00080
00082 #define GIM_IR(x) ((GUINT&)(x))
00083
00085 #define GIM_SIR(x) ((GINT&)(x))
00086
00088 #define GIM_AIR(x) (GIM_IR(x)&0x7fffffff)
00089
00091 #define GIM_FR(x) ((GREAL&)(x))
00092
00093 #define GIM_MAX(a,b) (a<b?b:a)
00094 #define GIM_MIN(a,b) (a>b?b:a)
00095
00096 #define GIM_MAX3(a,b,c) GIM_MAX(a,GIM_MAX(b,c))
00097 #define GIM_MIN3(a,b,c) GIM_MIN(a,GIM_MIN(b,c))
00098
00099 #define GIM_IS_ZERO(value) (value < G_EPSILON && value > -G_EPSILON)
00100
00101 #define GIM_IS_NEGATIVE(value) (value <= -G_EPSILON)
00102
00103 #define GIM_IS_POSISITVE(value) (value >= G_EPSILON)
00104
00105 #define GIM_NEAR_EQUAL(v1,v2) GIM_IS_ZERO((v1-v2))
00106
00108 #define GIM_CLAMP(number,minval,maxval) (number<minval?minval:(number>maxval?maxval:number))
00109
00110 #define GIM_GREATER(x, y) btFabs(x) > (y)
00111
00113 #define GIM_SWAP_NUMBERS(a,b){ \
00114 a = a+b; \
00115 b = a-b; \
00116 a = a-b; \
00117 }\
00118
00119 #define GIM_INV_SQRT(va,isva)\
00120 {\
00121 if(va<=0.0000001f)\
00122 {\
00123 isva = G_REAL_INFINITY;\
00124 }\
00125 else\
00126 {\
00127 GREAL _x = va * 0.5f;\
00128 GUINT _y = 0x5f3759df - ( GIM_IR(va) >> 1);\
00129 isva = GIM_FR(_y);\
00130 isva = isva * ( 1.5f - ( _x * isva * isva ) );\
00131 }\
00132 }\
00133
00134 #define GIM_SQRT(va,sva)\
00135 {\
00136 GIM_INV_SQRT(va,sva);\
00137 sva = 1.0f/sva;\
00138 }\
00139
00140
00141 inline GREAL gim_inv_sqrt(GREAL f)
00142 {
00143 GREAL r;
00144 GIM_INV_SQRT(f,r);
00145 return r;
00146 }
00147
00148 inline GREAL gim_sqrt(GREAL f)
00149 {
00150 GREAL r;
00151 GIM_SQRT(f,r);
00152 return r;
00153 }
00154
00155
00156
00157 #endif // GIM_MATH_H_INCLUDED