00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00020
00021
00023
00024
00026
00027 #ifndef MATHFUNCS_H
00028 #define MATHFUNCS_H
00029
00030 #include <cstdlib>
00031 #include <cmath>
00033
00034
00036 inline int GetPow2(int Exp)
00037 {
00038 return (1 << Exp);
00039 }
00040
00042 inline int GetBiggerPow2(int Value)
00043 {
00044 if (Value < 1) return 0;
00045 int i = 1;
00046
00047 while (Value >> i)
00048 {
00049 i++;
00050 }
00051
00052 return GetPow2(i);
00053 }
00054
00056 inline float lerp(float Value1, float Value2, float a)
00057 {
00058 return(Value1*(1.0f-a)+Value2*a);
00059 }
00060
00062 inline float frnd(float low, float high)
00063 {
00064 if(low > high)
00065 {
00066 float Temp = high;
00067 high = low;
00068 low = Temp;
00069 }
00070
00071 float rnd = low + (high - low) * ( (long)rand() ) / RAND_MAX;
00072
00073 if(rnd < high)
00074 {
00075 return rnd;
00076 }
00077 else
00078 {
00079 return low;
00080 }
00081 }
00082
00084 inline int sgn(float arg)
00085 {
00086 return (arg < 0.0f) ? -1 : 1;
00087 }
00088
00089
00090 inline float manhattan(float x1, float y1, float x2, float y2)
00091 {
00092 return std::fabs(x1-x2) + std::fabs(y1-y2);
00093 }
00094
00095 #endif
00096