summaryrefslogtreecommitdiffstats
path: root/src/math
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/math/Matrix.h24
-rw-r--r--src/math/Quaternion.h2
-rw-r--r--src/math/Vector.h6
-rw-r--r--src/math/Vector2D.h2
-rw-r--r--src/math/math.cpp6
-rw-r--r--src/math/maths.h12
6 files changed, 32 insertions, 20 deletions
diff --git a/src/math/Matrix.h b/src/math/Matrix.h
index b7d6c207..2c0108c1 100644
--- a/src/math/Matrix.h
+++ b/src/math/Matrix.h
@@ -127,8 +127,8 @@ public:
}
void SetRotateXOnly(float angle){
- float c = cos(angle);
- float s = sin(angle);
+ float c = Cos(angle);
+ float s = Sin(angle);
m_matrix.right.x = 1.0f;
m_matrix.right.y = 0.0f;
@@ -149,8 +149,8 @@ public:
m_matrix.pos.z = 0.0f;
}
void SetRotateYOnly(float angle){
- float c = cos(angle);
- float s = sin(angle);
+ float c = Cos(angle);
+ float s = Sin(angle);
m_matrix.right.x = c;
m_matrix.right.y = 0.0f;
@@ -171,8 +171,8 @@ public:
m_matrix.pos.z = 0.0f;
}
void SetRotateZOnly(float angle){
- float c = cos(angle);
- float s = sin(angle);
+ float c = Cos(angle);
+ float s = Sin(angle);
m_matrix.right.x = c;
m_matrix.right.y = s;
@@ -193,12 +193,12 @@ public:
m_matrix.pos.z = 0.0f;
}
void SetRotate(float xAngle, float yAngle, float zAngle) {
- float cX = cos(xAngle);
- float sX = sin(xAngle);
- float cY = cos(yAngle);
- float sY = sin(yAngle);
- float cZ = cos(zAngle);
- float sZ = sin(zAngle);
+ float cX = Cos(xAngle);
+ float sX = Sin(xAngle);
+ float cY = Cos(yAngle);
+ float sY = Sin(yAngle);
+ float cZ = Cos(zAngle);
+ float sZ = Sin(zAngle);
m_matrix.right.x = cZ * cY - (sZ * sX) * sY;
m_matrix.right.y = (cZ * sX) * sY + sZ * cY;
diff --git a/src/math/Quaternion.h b/src/math/Quaternion.h
index 702fc72f..fb37dc10 100644
--- a/src/math/Quaternion.h
+++ b/src/math/Quaternion.h
@@ -8,7 +8,7 @@ public:
CQuaternion(void) {}
CQuaternion(float x, float y, float z, float w) : x(x), y(y), z(z), w(w) {}
- float Magnitude(void) const { return sqrt(x*x + y*y + z*z + w*w); }
+ float Magnitude(void) const { return Sqrt(x*x + y*y + z*z + w*w); }
float MagnitudeSqr(void) const { return x*x + y*y + z*z + w*w; }
const CQuaternion &operator+=(CQuaternion const &right) {
diff --git a/src/math/Vector.h b/src/math/Vector.h
index b49f00f2..9a1dde7a 100644
--- a/src/math/Vector.h
+++ b/src/math/Vector.h
@@ -22,10 +22,10 @@ public:
return *((RwV3d*)this);
}
#endif
- float Heading(void) const { return atan2(-x, y); }
- float Magnitude(void) const { return sqrt(x*x + y*y + z*z); }
+ float Heading(void) const { return Atan2(-x, y); }
+ float Magnitude(void) const { return Sqrt(x*x + y*y + z*z); }
float MagnitudeSqr(void) const { return x*x + y*y + z*z; }
- float Magnitude2D(void) const { return sqrt(x*x + y*y); }
+ float Magnitude2D(void) const { return Sqrt(x*x + y*y); }
float MagnitudeSqr2D(void) const { return x*x + y*y; }
void Normalise(void) {
float sq = MagnitudeSqr();
diff --git a/src/math/Vector2D.h b/src/math/Vector2D.h
index fa32bd9b..d0580545 100644
--- a/src/math/Vector2D.h
+++ b/src/math/Vector2D.h
@@ -7,7 +7,7 @@ public:
CVector2D(void) {}
CVector2D(float x, float y) : x(x), y(y) {}
CVector2D(const CVector &v) : x(v.x), y(v.y) {}
- float Magnitude(void) const { return sqrt(x*x + y*y); }
+ float Magnitude(void) const { return Sqrt(x*x + y*y); }
float MagnitudeSqr(void) const { return x*x + y*y; }
void Normalise(void){
diff --git a/src/math/math.cpp b/src/math/math.cpp
index b76db4ae..b4ba9c98 100644
--- a/src/math/math.cpp
+++ b/src/math/math.cpp
@@ -13,11 +13,11 @@ CQuaternion::Slerp(const CQuaternion &q1, const CQuaternion &q2, float theta, fl
float w1, w2;
if(theta > PI/2){
theta = PI - theta;
- w1 = sin((1.0f - t) * theta) * invSin;
+ w1 = Sin((1.0f - t) * theta) * invSin;
w2 = -sin(t * theta) * invSin;
}else{
- w1 = sin((1.0f - t) * theta) * invSin;
- w2 = sin(t * theta) * invSin;
+ w1 = Sin((1.0f - t) * theta) * invSin;
+ w2 = Sin(t * theta) * invSin;
}
*this = w1*q1 + w2*q2;
}
diff --git a/src/math/maths.h b/src/math/maths.h
new file mode 100644
index 00000000..49e39631
--- /dev/null
+++ b/src/math/maths.h
@@ -0,0 +1,12 @@
+#pragma once
+
+// wrapper around float versions of functions
+// in gta they are in CMaths but that makes the code rather noisy
+
+inline float Sin(float x) { return sinf(x); }
+inline float Cos(float x) { return cosf(x); }
+inline float Abs(float x) { return fabs(x); }
+inline float Sqrt(float x) { return sqrtf(x); }
+inline float Atan2(float y, float x) { return atan2f(y, x); }
+inline float RecipSqrt(float x) { return 1.0f/sqrtf(x); }
+inline float Pow(float x, float y) { return powf(x, y); }