From c1f3ce8cceb675a9c76b4dc4e7cdfb18b17c4f2f Mon Sep 17 00:00:00 2001 From: aap Date: Sun, 7 Jul 2019 18:36:55 +0200 Subject: implemented CDoor --- src/math/Matrix.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/math') diff --git a/src/math/Matrix.h b/src/math/Matrix.h index 6e1001cb..5cc7d12f 100644 --- a/src/math/Matrix.h +++ b/src/math/Matrix.h @@ -306,6 +306,15 @@ Multiply3x3(const CMatrix &mat, const CVector &vec) mat.m_matrix.right.z * vec.x + mat.m_matrix.up.z * vec.y + mat.m_matrix.at.z * vec.z); } +inline CVector +Multiply3x3(const CVector &vec, const CMatrix &mat) +{ + return CVector( + mat.m_matrix.right.x * vec.x + mat.m_matrix.right.y * vec.y + mat.m_matrix.right.z * vec.z, + mat.m_matrix.up.x * vec.x + mat.m_matrix.up.y * vec.y + mat.m_matrix.up.z * vec.z, + mat.m_matrix.at.x * vec.x + mat.m_matrix.at.y * vec.y + mat.m_matrix.at.z * vec.z); +} + class CCompressedMatrixNotAligned { CVector m_vecPos; -- cgit v1.2.3 From edf5ac2626ce17b74037281aa3c9730902b4b1d4 Mon Sep 17 00:00:00 2001 From: aap Date: Mon, 8 Jul 2019 17:07:34 +0200 Subject: little changes; one more function of CAutomobile --- src/math/Matrix.h | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'src/math') diff --git a/src/math/Matrix.h b/src/math/Matrix.h index 5cc7d12f..eda75e4a 100644 --- a/src/math/Matrix.h +++ b/src/math/Matrix.h @@ -78,10 +78,10 @@ public: return *this; } - CVector *GetPosition(void){ return (CVector*)&m_matrix.pos; } - CVector *GetRight(void) { return (CVector*)&m_matrix.right; } - CVector *GetForward(void) { return (CVector*)&m_matrix.up; } - CVector *GetUp(void) { return (CVector*)&m_matrix.at; } + CVector &GetPosition(void){ return *(CVector*)&m_matrix.pos; } + CVector &GetRight(void) { return *(CVector*)&m_matrix.right; } + CVector &GetForward(void) { return *(CVector*)&m_matrix.up; } + CVector &GetUp(void) { return *(CVector*)&m_matrix.at; } void SetScale(float s){ m_matrix.right.x = s; m_matrix.right.y = 0.0f; @@ -190,9 +190,9 @@ public: m_matrix.pos.z = 0.0f; } void Reorthogonalise(void){ - CVector &r = *GetRight(); - CVector &f = *GetForward(); - CVector &u = *GetUp(); + CVector &r = GetRight(); + CVector &f = GetForward(); + CVector &u = GetUp(); u = CrossProduct(r, f); u.Normalise(); r = CrossProduct(f, u); @@ -327,24 +327,24 @@ class CCompressedMatrixNotAligned public: void CompressFromFullMatrix(CMatrix &other) { - m_rightX = 127.0f * other.GetRight()->x; - m_rightY = 127.0f * other.GetRight()->y; - m_rightZ = 127.0f * other.GetRight()->z; - m_upX = 127.0f * other.GetForward()->x; - m_upY = 127.0f * other.GetForward()->y; - m_upZ = 127.0f * other.GetForward()->z; - m_vecPos = *other.GetPosition(); + m_rightX = 127.0f * other.GetRight().x; + m_rightY = 127.0f * other.GetRight().y; + m_rightZ = 127.0f * other.GetRight().z; + m_upX = 127.0f * other.GetForward().x; + m_upY = 127.0f * other.GetForward().y; + m_upZ = 127.0f * other.GetForward().z; + m_vecPos = other.GetPosition(); } void DecompressIntoFullMatrix(CMatrix &other) { - other.GetRight()->x = m_rightX / 127.0f; - other.GetRight()->y = m_rightY / 127.0f; - other.GetRight()->z = m_rightZ / 127.0f; - other.GetForward()->x = m_upX / 127.0f; - other.GetForward()->y = m_upY / 127.0f; - other.GetForward()->z = m_upZ / 127.0f; - *other.GetUp() = CrossProduct(*other.GetRight(), *other.GetForward()); - *other.GetPosition() = m_vecPos; + other.GetRight().x = m_rightX / 127.0f; + other.GetRight().y = m_rightY / 127.0f; + other.GetRight().z = m_rightZ / 127.0f; + other.GetForward().x = m_upX / 127.0f; + other.GetForward().y = m_upY / 127.0f; + other.GetForward().z = m_upZ / 127.0f; + other.GetUp() = CrossProduct(other.GetRight(), other.GetForward()); + other.GetPosition() = m_vecPos; other.Reorthogonalise(); } -}; \ No newline at end of file +}; -- cgit v1.2.3 From 2ae112fdf6b90bb4435dba34bcc2a23604e1e158 Mon Sep 17 00:00:00 2001 From: aap Date: Mon, 8 Jul 2019 21:37:47 +0200 Subject: more CAutomobile --- src/math/Matrix.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/math') diff --git a/src/math/Matrix.h b/src/math/Matrix.h index eda75e4a..b7d6c207 100644 --- a/src/math/Matrix.h +++ b/src/math/Matrix.h @@ -82,6 +82,32 @@ public: CVector &GetRight(void) { return *(CVector*)&m_matrix.right; } CVector &GetForward(void) { return *(CVector*)&m_matrix.up; } CVector &GetUp(void) { return *(CVector*)&m_matrix.at; } + + void SetTranslate(float x, float y, float z){ + m_matrix.right.x = 1.0f; + m_matrix.right.y = 0.0f; + m_matrix.right.z = 0.0f; + + m_matrix.up.x = 0.0f; + m_matrix.up.y = 1.0f; + m_matrix.up.z = 0.0f; + + m_matrix.at.x = 0.0f; + m_matrix.at.y = 0.0f; + m_matrix.at.z = 1.0f; + + m_matrix.pos.x = x; + m_matrix.pos.y = y; + m_matrix.pos.z = z; + } + void SetTranslate(const CVector &trans){ SetTranslate(trans.x, trans.y, trans.z); } + void Translate(float x, float y, float z){ + m_matrix.pos.x += x; + m_matrix.pos.y += y; + m_matrix.pos.z += z; + } + void Translate(const CVector &trans){ Translate(trans.x, trans.y, trans.z); } + void SetScale(float s){ m_matrix.right.x = s; m_matrix.right.y = 0.0f; @@ -99,6 +125,7 @@ public: m_matrix.pos.y = 0.0f; m_matrix.pos.z = 0.0f; } + void SetRotateXOnly(float angle){ float c = cos(angle); float s = sin(angle); -- cgit v1.2.3 From 4a36d64f15f898854bb8a76be86ac9a8c536b291 Mon Sep 17 00:00:00 2001 From: aap Date: Wed, 10 Jul 2019 17:18:26 +0200 Subject: added wrappers around math functions --- src/math/Matrix.h | 24 ++++++++++++------------ src/math/Quaternion.h | 2 +- src/math/Vector.h | 6 +++--- src/math/Vector2D.h | 2 +- src/math/math.cpp | 6 +++--- src/math/maths.h | 12 ++++++++++++ 6 files changed, 32 insertions(+), 20 deletions(-) create mode 100644 src/math/maths.h (limited to 'src/math') 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); } -- cgit v1.2.3 From 90e093cd47fb2af10617b1d404fc65ca813782ec Mon Sep 17 00:00:00 2001 From: aap Date: Wed, 10 Jul 2019 17:34:11 +0200 Subject: and of course the last commit didnt fix everything --- src/math/Vector.h | 2 +- src/math/Vector2D.h | 2 +- src/math/math.cpp | 2 +- src/math/maths.h | 8 ++++++-- 4 files changed, 9 insertions(+), 5 deletions(-) (limited to 'src/math') diff --git a/src/math/Vector.h b/src/math/Vector.h index 9a1dde7a..de8092eb 100644 --- a/src/math/Vector.h +++ b/src/math/Vector.h @@ -30,7 +30,7 @@ public: void Normalise(void) { float sq = MagnitudeSqr(); if(sq > 0.0f){ - float invsqrt = 1.0f/sqrt(sq); // CMaths::RecipSqrt + float invsqrt = 1.0f/Sqrt(sq); // CMaths::RecipSqrt x *= invsqrt; y *= invsqrt; z *= invsqrt; diff --git a/src/math/Vector2D.h b/src/math/Vector2D.h index d0580545..e6b04c14 100644 --- a/src/math/Vector2D.h +++ b/src/math/Vector2D.h @@ -13,7 +13,7 @@ public: void Normalise(void){ float sq = MagnitudeSqr(); if(sq > 0.0f){ - float invsqrt = 1.0f/sqrt(sq); + float invsqrt = 1.0f/Sqrt(sq); x *= invsqrt; y *= invsqrt; }else diff --git a/src/math/math.cpp b/src/math/math.cpp index b4ba9c98..c1199fcc 100644 --- a/src/math/math.cpp +++ b/src/math/math.cpp @@ -14,7 +14,7 @@ CQuaternion::Slerp(const CQuaternion &q1, const CQuaternion &q2, float theta, fl if(theta > PI/2){ theta = PI - theta; w1 = Sin((1.0f - t) * theta) * invSin; - w2 = -sin(t * theta) * invSin; + w2 = -Sin(t * theta) * invSin; }else{ w1 = Sin((1.0f - t) * theta) * invSin; w2 = Sin(t * theta) * invSin; diff --git a/src/math/maths.h b/src/math/maths.h index 49e39631..a1c3f109 100644 --- a/src/math/maths.h +++ b/src/math/maths.h @@ -4,9 +4,13 @@ // in gta they are in CMaths but that makes the code rather noisy inline float Sin(float x) { return sinf(x); } +inline float Asin(float x) { return asinf(x); } inline float Cos(float x) { return cosf(x); } +inline float Acos(float x) { return acosf(x); } +inline float Tan(float x) { return tanf(x); } +inline float Atan(float x) { return atanf(x); } +inline float Atan2(float y, float x) { return atan2f(y, 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 RecipSqrt(float x) { return 1.0f/Sqrt(x); } inline float Pow(float x, float y) { return powf(x, y); } -- cgit v1.2.3