summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2007-03-03 11:59:53 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2007-03-03 11:59:53 +0000
commitf9980c8854a94863b24be459d800ba57fd92037f (patch)
tree8a245c5a9b6a863f5a449d4e1deb34a14e1d1db4 /src/utils
parentcdf81ef8e5b25fd8751a92c6ff394c01daedbb88 (diff)
downloadmanaserv-f9980c8854a94863b24be459d800ba57fd92037f.tar.gz
manaserv-f9980c8854a94863b24be459d800ba57fd92037f.tar.bz2
manaserv-f9980c8854a94863b24be459d800ba57fd92037f.tar.xz
manaserv-f9980c8854a94863b24be459d800ba57fd92037f.zip
Use M_PI_2 instead of acos(0.0f) and FLT_MAX instead of 1.0E40f (which exceeded
the maximum float value). Some cosmetics (whitespace and declaring variables where they are used).
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/mathutils.cpp37
-rw-r--r--src/utils/mathutils.h8
2 files changed, 23 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);
}
}
diff --git a/src/utils/mathutils.h b/src/utils/mathutils.h
index 3d90b022..31f48805 100644
--- a/src/utils/mathutils.h
+++ b/src/utils/mathutils.h
@@ -27,8 +27,16 @@ namespace utils
{
namespace math
{
+ /**
+ * A very fast function to calculate the approximate inverse square
+ * root of a floating point value.
+ */
float fastInvSqrt(float x);
+ /**
+ * A helper function that uses the fastInvSqrt for getting the
+ * normal squareroot.
+ */
float fastSqrt(float x);
float cachedSin(int angle);