diff options
author | Sergeanur <s.anureev@yandex.ua> | 2021-01-18 20:06:59 +0100 |
---|---|---|
committer | Sergeanur <s.anureev@yandex.ua> | 2021-01-18 20:06:59 +0100 |
commit | 91093305d65305722e380c0087c71469363a8396 (patch) | |
tree | b589257deee2ecccf0617601da97c82fbb8385f5 /src/math/Matrix.h | |
parent | sync milessdk with re3mss (diff) | |
download | re3-91093305d65305722e380c0087c71469363a8396.tar re3-91093305d65305722e380c0087c71469363a8396.tar.gz re3-91093305d65305722e380c0087c71469363a8396.tar.bz2 re3-91093305d65305722e380c0087c71469363a8396.tar.lz re3-91093305d65305722e380c0087c71469363a8396.tar.xz re3-91093305d65305722e380c0087c71469363a8396.tar.zst re3-91093305d65305722e380c0087c71469363a8396.zip |
Diffstat (limited to 'src/math/Matrix.h')
-rw-r--r-- | src/math/Matrix.h | 66 |
1 files changed, 39 insertions, 27 deletions
diff --git a/src/math/Matrix.h b/src/math/Matrix.h index d8f6388d..fdbd0b60 100644 --- a/src/math/Matrix.h +++ b/src/math/Matrix.h @@ -1,9 +1,22 @@ #pragma once +#include "VuVector.h" + class CMatrix { public: - RwMatrix m_matrix; + union + { + float f[4][4]; + struct + { + CVuVector right; + CVuVector forward; + CVuVector up; + CVuVector pos; + }; + }; + RwMatrix *m_attachment; bool m_hasRwMatrix; // are we the owner? @@ -25,31 +38,30 @@ public: CMatrix &operator+=(CMatrix const &rhs); CMatrix &operator*=(CMatrix const &rhs); - 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 pos; } + CVector &GetRight(void) { return right; } + CVector &GetForward(void) { return forward; } + CVector &GetUp(void) { return up; } void SetTranslate(float x, float y, float 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; + pos.x += x; + pos.y += y; + pos.z += z; } void Translate(const CVector &trans){ Translate(trans.x, trans.y, trans.z); } void SetScale(float s); void Scale(float scale) { - float *pFloatMatrix = (float*)&m_matrix; for (int i = 0; i < 3; i++) #ifdef FIX_BUGS // BUGFIX from VC for (int j = 0; j < 3; j++) #else for (int j = 0; j < 4; j++) #endif - pFloatMatrix[i * 4 + j] *= scale; + f[i][j] *= scale; } @@ -60,17 +72,17 @@ public: float c = Cos(angle); float s = Sin(angle); - m_matrix.right.x = c * scale; - m_matrix.right.y = s * scale; - m_matrix.right.z = 0.0f; + right.x = c * scale; + right.y = s * scale; + right.z = 0.0f; - m_matrix.up.x = -s * scale; - m_matrix.up.y = c * scale; - m_matrix.up.z = 0.0f; + forward.x = -s * scale; + forward.y = c * scale; + forward.z = 0.0f; - m_matrix.at.x = 0.0f; - m_matrix.at.y = 0.0f; - m_matrix.at.z = scale; + up.x = 0.0f; + up.y = 0.0f; + up.z = scale; } void SetRotateX(float angle); void SetRotateY(float angle); @@ -82,13 +94,13 @@ public: void RotateZ(float z); void Reorthogonalise(void); - void CopyOnlyMatrix(CMatrix *other); + void CopyOnlyMatrix(const CMatrix &other); void SetUnity(void); void ResetOrientation(void); void SetTranslateOnly(float x, float y, float z) { - m_matrix.pos.x = x; - m_matrix.pos.y = y; - m_matrix.pos.z = z; + pos.x = x; + pos.y = y; + pos.z = z; } void SetTranslateOnly(const CVector& pos) { SetTranslateOnly(pos.x, pos.y, pos.z); @@ -102,11 +114,11 @@ CMatrix Invert(const CMatrix &matrix); CMatrix operator*(const CMatrix &m1, const CMatrix &m2); inline CVector MultiplyInverse(const CMatrix &mat, const CVector &vec) { - CVector v(vec.x - mat.m_matrix.pos.x, vec.y - mat.m_matrix.pos.y, vec.z - mat.m_matrix.pos.z); + CVector v(vec.x - mat.pos.x, vec.y - mat.pos.y, vec.z - mat.pos.z); return CVector( - mat.m_matrix.right.x * v.x + mat.m_matrix.right.y * v.y + mat.m_matrix.right.z * v.z, - mat.m_matrix.up.x * v.x + mat.m_matrix.up.y * v.y + mat.m_matrix.up.z * v.z, - mat.m_matrix.at.x * v.x + mat.m_matrix.at.y * v.y + mat.m_matrix.at.z * v.z); + mat.right.x * v.x + mat.right.y * v.y + mat.right.z * v.z, + mat.forward.x * v.x + mat.forward.y * v.y + mat.forward.z * v.z, + mat.up.x * v.x + mat.up.y * v.y + mat.up.z * v.z); } |