40 return fabs(a - b) < tolerance;
50 inline float Min(
float a,
float b)
52 if ( a <= b )
return a;
56 inline float Min(
float a,
float b,
float c)
58 return Min(
Min(a, b), c );
61 inline float Min(
float a,
float b,
float c,
float d)
66 inline float Min(
float a,
float b,
float c,
float d,
float e)
72 inline float Max(
float a,
float b)
74 if ( a >= b )
return a;
78 inline float Max(
float a,
float b,
float c)
83 inline float Max(
float a,
float b,
float c,
float d)
88 inline float Max(
float a,
float b,
float c,
float d,
float e)
96 if ( a < 0.0f )
return 0.0f;
97 if ( a > 1.0f )
return 1.0f;
102 inline void Swap(
int &a,
int &b)
110 inline void Swap(
float &a,
float &b)
120 inline float Mod(
float a,
float m)
122 return a - (
static_cast<int>(a / m) ) * m;
128 return static_cast<float>(rand()) / static_cast<float>(RAND_MAX);
134 return x && !(x & (x - 1));
140 double logbase2 = log(static_cast<float>(x)) /
Math::LOG_2;
141 return static_cast<int>(pow(2, ceil(logbase2)) + 0.5);
150 return PI*2.0f + angle;
156 inline bool TestAngle(
float angle,
float min,
float max)
163 return ( angle <= max || angle >= min );
165 return ( angle >= min && angle <= max );
171 float aa =
static_cast<float>(a) *
DEG_TO_RAD;
172 float bb =
static_cast<float>(b) *
DEG_TO_RAD;
174 return aa + p * (bb - aa);
186 if ( a+
PI*2.0f-g < g-a ) a +=
PI*2.0f;
190 if ( g+
PI*2.0f-a < a-g ) g +=
PI*2.0f;
207 if ( fabs(value) <= dead )
213 if ( value > 0.0f )
return (value-dead)/(1.0f-dead);
214 else return (value+dead)/(1.0f-dead);
220 inline float Smooth(
float actual,
float hope,
float time)
222 float future = actual + (hope-actual)*time;
226 if ( future > hope ) future = hope;
230 if ( future < hope ) future = hope;
250 inline float Bounce(
float progress,
float middle = 0.3f,
float bounce = 0.4f)
252 if ( progress < middle )
254 progress = progress/middle;
255 return 0.5f+sinf(progress*
PI-
PI/2.0f)/2.0f;
259 progress = (progress-middle)/(1.0f-middle);
260 return (1.0f-bounce/2.0f)+sinf((0.5f+progress*2.0f)*
PI)*(bounce/2.0f);
bool TestAngle(float angle, float min, float max)
Test if a angle is between two terminals.
Definition: func.h:156
const float DEG_TO_RAD
Degrees to radians multiplier.
Definition: const.h:47
const float TOLERANCE
Tolerance level – minimum accepted float value.
Definition: const.h:33
bool IsZero(float a, float tolerance=Math::TOLERANCE)
Compares a to zero within tolerance.
Definition: func.h:44
float Max(float a, float b)
Maximum.
Definition: func.h:72
float NormAngle(float angle)
Returns a normalized angle, that is in other words between 0 and 2 * PI.
Definition: func.h:146
float Direction(float a, float g)
Calculates the angle to rotate the angle a to the angle g.
Definition: func.h:179
float Mod(float a, float m)
Returns the modulo of a floating point number.
Definition: func.h:120
float Smooth(float actual, float hope, float time)
Gently advances a desired value from its current value.
Definition: func.h:220
const float PI
PI.
Definition: const.h:44
float Norm(float a)
Returns the normalized value (0 .. 1)
Definition: func.h:94
bool IsPowerOfTwo(unsigned int x)
Returns whether x is an even power of 2.
Definition: func.h:132
float Rand()
Returns a random value between 0 and 1.
Definition: func.h:126
bool IsEqual(float a, float b, float tolerance=Math::TOLERANCE)
Compares a and b within tolerance.
Definition: func.h:38
float Bounce(float progress, float middle=0.3f, float bounce=0.4f)
Bounces any movement.
Definition: func.h:250
const float LOG_2
Natural logarithm of 2.
Definition: const.h:52
void Swap(int &a, int &b)
Swaps two integers.
Definition: func.h:102
float Min(float a, float b)
Minimum.
Definition: func.h:50
Constants used in math functions.
float Neutral(float value, float dead)
Managing the dead zone of a joystick.
Definition: func.h:205
int NextPowerOfTwo(int x)
Returns the next nearest power of two to x.
Definition: func.h:138
float PropAngle(int a, int b, float p)
Calculates a value (radians) proportional between a and b (degrees)
Definition: func.h:169