00001
00002
00003
00004
00005 #ifndef __MATHSSTRUCT_H_
00006 #define __MATHSSTRUCT_H_
00007
00009
00010 const float PI = 3.14159265358979323846f;
00011
00012 #define DEGTORAD(x) ( ((x) * PI) / 180.0 )
00013 #define RADTODEG(x) ( ((x) * 180.0) / PI )
00014
00015 #define SQR(x) ( (x) * (x) )
00016
00017
00018 #define LIMIT_RANGE(low, value, high) { if (value < low) value = low; else if(value > high) value = high; }
00019
00020 __forceinline void SWAP(float &x, float &y) { float temp; temp = x; x = y; y = temp; }
00021
00023
00024
00025
00026 const float EPSILON = 0.005f;
00027 const int FLOAT_DECIMAL_TOLERANCE = 3;
00028
00029 #define ZERO_CLAMP(x) ( (EPSILON > fabs(x))?0.0f:(x) ) // set float to 0 if within tolerance
00030
00031 #define FLOAT_EQ(x,v) ( ((v) - EPSILON) < (x) && (x) < ((v) + EPSILON) ) // float equality test
00032
00034
00035 __forceinline float ROUND(const float value, const int accuracy)
00036 {
00037 double integer, fraction;
00038
00039 fraction = modf(value, &integer);
00040
00041 return(float(integer + (float(int(fraction*pow(10,accuracy)))) / pow(10, accuracy) ) );
00042 }
00043
00044
00046
00047 #endif // __MATHSSTRUCT_H_