added wrappers around math functions

This commit is contained in:
aap
2019-07-10 17:18:26 +02:00
parent 80e0409d6a
commit 4a36d64f15
31 changed files with 204 additions and 191 deletions

View File

@ -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;

View File

@ -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) {

View File

@ -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();

View File

@ -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){

View File

@ -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;
}

12
src/math/maths.h Normal file
View File

@ -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); }