diff options
Diffstat (limited to 'src/utils/mathutils.cpp')
-rw-r--r-- | src/utils/mathutils.cpp | 37 |
1 files changed, 15 insertions, 22 deletions
diff --git a/src/utils/mathutils.cpp b/src/utils/mathutils.cpp index 0a46ff2c..407bba7f 100644 --- a/src/utils/mathutils.cpp +++ b/src/utils/mathutils.cpp @@ -23,6 +23,7 @@ #include "mathutils.h"
#include <cmath>
+#include <float.h>
#define MATH_UTILS_MAX_ANGLE 360
@@ -30,9 +31,7 @@ float sinList[MATH_UTILS_MAX_ANGLE]; float cosList[MATH_UTILS_MAX_ANGLE];
float tanList[MATH_UTILS_MAX_ANGLE];
-/**
- * fastInvSqrt:
- *
+/*
* A very fast function to calculate the approximate inverse square root of a
* floating point value. For an explanation of the inverse squareroot function
* read:
@@ -47,46 +46,40 @@ float tanList[MATH_UTILS_MAX_ANGLE]; */
float utils::math::fastInvSqrt(float x)
{
- float xhalf = 0.5f*x;
- int i = *(int*)&x;
- i = 0x5f375a86- (i>>1);
- x = *(float*)&i;
- x = x*(1.5f-xhalf*x*x);
+ float xhalf = 0.5f * x;
+ int i = *(int*) &x;
+ i = 0x5f375a86 - (i >> 1);
+ x = *(float*) &i;
+ x = x * (1.5f-xhalf * x * x);
return x;
}
-/**
- * fastSqrt:
- *
- * A helper function that uses the fastInvSqrt for getting the
- * normal squareroot.
- */
float utils::math::fastSqrt(float x)
{
- return 1.0f/utils::math::fastInvSqrt(x);
+ return 1.0f / utils::math::fastInvSqrt(x);
}
void utils::math::init()
{
// Constant for calculating an angle in radians out of an angle in degrees
- const float radianAngleRatio = acos(0.0f) / 90.0f; // pi/2 / 90[deg]
+ const float radianAngleRatio = M_PI_2 / 90.0f; // pi/2 / 90[deg]
- for(int i = 0; i < MATH_UTILS_MAX_ANGLE; i++)
+ for (int i = 0; i < MATH_UTILS_MAX_ANGLE; i++)
{
- sinList[i] = sin(radianAngleRatio * (float)i);
- cosList[i] = cos(radianAngleRatio * (float)i);
+ sinList[i] = sin(radianAngleRatio * (float) i);
+ cosList[i] = cos(radianAngleRatio * (float) i);
if (i == 90)
{
- tanList[i] = 1.0E40f; //approximately infinity
+ tanList[i] = FLT_MAX; // approximately infinity
continue;
}
if (i == 270)
{
- tanList[i] = -1.0E40f; //approximately infinity
+ tanList[i] = -FLT_MAX; // approximately infinity
continue;
}
- tanList[i] = tan(radianAngleRatio * (float)i);
+ tanList[i] = tan(radianAngleRatio * (float) i);
}
}
|