diff options
author | Sergeanur <s.anureev@yandex.ua> | 2020-09-14 19:48:49 +0200 |
---|---|---|
committer | Sergeanur <s.anureev@yandex.ua> | 2020-09-14 20:07:31 +0200 |
commit | 38ec1bd50de234faf476daa15ea41778a860ca0b (patch) | |
tree | fedfb6fcbdd34f2dd576e6e6b1e6b2a76871b5a1 /src/math/Matrix.h | |
parent | Fixes from miami (diff) | |
download | re3-38ec1bd50de234faf476daa15ea41778a860ca0b.tar re3-38ec1bd50de234faf476daa15ea41778a860ca0b.tar.gz re3-38ec1bd50de234faf476daa15ea41778a860ca0b.tar.bz2 re3-38ec1bd50de234faf476daa15ea41778a860ca0b.tar.lz re3-38ec1bd50de234faf476daa15ea41778a860ca0b.tar.xz re3-38ec1bd50de234faf476daa15ea41778a860ca0b.tar.zst re3-38ec1bd50de234faf476daa15ea41778a860ca0b.zip |
Diffstat (limited to 'src/math/Matrix.h')
-rw-r--r-- | src/math/Matrix.h | 257 |
1 files changed, 27 insertions, 230 deletions
diff --git a/src/math/Matrix.h b/src/math/Matrix.h index e2d6b0e0..d8f6388d 100644 --- a/src/math/Matrix.h +++ b/src/math/Matrix.h @@ -7,104 +7,30 @@ public: RwMatrix *m_attachment; bool m_hasRwMatrix; // are we the owner? - CMatrix(void){ - m_attachment = nil; - m_hasRwMatrix = false; - } - CMatrix(CMatrix const &m){ - m_attachment = nil; - m_hasRwMatrix = false; - *this = m; - } - CMatrix(RwMatrix *matrix, bool owner = false){ - m_attachment = nil; - Attach(matrix, owner); - } + CMatrix(void); + CMatrix(CMatrix const &m); + CMatrix(RwMatrix *matrix, bool owner = false); CMatrix(float scale){ m_attachment = nil; m_hasRwMatrix = false; SetScale(scale); } - ~CMatrix(void){ - if(m_hasRwMatrix && m_attachment) - RwMatrixDestroy(m_attachment); - } - void Attach(RwMatrix *matrix, bool owner = false){ -#ifdef FIX_BUGS - if(m_attachment && m_hasRwMatrix) -#else - if(m_hasRwMatrix && m_attachment) -#endif - RwMatrixDestroy(m_attachment); - m_attachment = matrix; - m_hasRwMatrix = owner; - Update(); - } - void AttachRW(RwMatrix *matrix, bool owner = false){ - if(m_hasRwMatrix && m_attachment) - RwMatrixDestroy(m_attachment); - m_attachment = matrix; - m_hasRwMatrix = owner; - UpdateRW(); - } - void Detach(void){ - if(m_hasRwMatrix && m_attachment) - RwMatrixDestroy(m_attachment); - m_attachment = nil; - } - void Update(void){ - m_matrix = *m_attachment; - } - void UpdateRW(void){ - if(m_attachment){ - *m_attachment = m_matrix; - RwMatrixUpdate(m_attachment); - } - } - void operator=(CMatrix const &rhs){ - m_matrix = rhs.m_matrix; - if(m_attachment) - UpdateRW(); - } - CMatrix& operator+=(CMatrix const &rhs){ - m_matrix.right.x += rhs.m_matrix.right.x; - m_matrix.up.x += rhs.m_matrix.up.x; - m_matrix.at.x += rhs.m_matrix.at.x; - m_matrix.right.y += rhs.m_matrix.right.y; - m_matrix.up.y += rhs.m_matrix.up.y; - m_matrix.at.y += rhs.m_matrix.at.y; - m_matrix.right.z += rhs.m_matrix.right.z; - m_matrix.up.z += rhs.m_matrix.up.z; - m_matrix.at.z += rhs.m_matrix.at.z; - m_matrix.pos.x += rhs.m_matrix.pos.x; - m_matrix.pos.y += rhs.m_matrix.pos.y; - m_matrix.pos.z += rhs.m_matrix.pos.z; - return *this; - } - CMatrix& operator*=(CMatrix const &rhs); + ~CMatrix(void); + void Attach(RwMatrix *matrix, bool owner = false); + void AttachRW(RwMatrix *matrix, bool owner = false); + void Detach(void); + void Update(void); + void UpdateRW(void); + void operator=(CMatrix const &rhs); + 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; } - 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(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; @@ -113,23 +39,7 @@ public: } 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; - m_matrix.right.z = 0.0f; - - m_matrix.up.x = 0.0f; - m_matrix.up.y = s; - m_matrix.up.z = 0.0f; - - m_matrix.at.x = 0.0f; - m_matrix.at.y = 0.0f; - m_matrix.at.z = s; - - m_matrix.pos.x = 0.0f; - m_matrix.pos.y = 0.0f; - m_matrix.pos.z = 0.0f; - } + void SetScale(float s); void Scale(float scale) { float *pFloatMatrix = (float*)&m_matrix; @@ -143,66 +53,9 @@ public: } - void SetRotateXOnly(float angle){ - float c = Cos(angle); - float s = Sin(angle); - - 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 = c; - m_matrix.up.z = s; - - m_matrix.at.x = 0.0f; - m_matrix.at.y = -s; - m_matrix.at.z = c; - } - void SetRotateX(float angle){ - SetRotateXOnly(angle); - m_matrix.pos.x = 0.0f; - m_matrix.pos.y = 0.0f; - m_matrix.pos.z = 0.0f; - } - void SetRotateYOnly(float angle){ - float c = Cos(angle); - float s = Sin(angle); - - m_matrix.right.x = c; - m_matrix.right.y = 0.0f; - m_matrix.right.z = -s; - - m_matrix.up.x = 0.0f; - m_matrix.up.y = 1.0f; - m_matrix.up.z = 0.0f; - - m_matrix.at.x = s; - m_matrix.at.y = 0.0f; - m_matrix.at.z = c; - } - void SetRotateY(float angle){ - SetRotateYOnly(angle); - m_matrix.pos.x = 0.0f; - m_matrix.pos.y = 0.0f; - m_matrix.pos.z = 0.0f; - } - void SetRotateZOnly(float angle){ - float c = Cos(angle); - float s = Sin(angle); - - m_matrix.right.x = c; - m_matrix.right.y = s; - m_matrix.right.z = 0.0f; - - m_matrix.up.x = -s; - m_matrix.up.y = c; - m_matrix.up.z = 0.0f; - - m_matrix.at.x = 0.0f; - m_matrix.at.y = 0.0f; - m_matrix.at.z = 1.0f; - } + void SetRotateXOnly(float angle); + void SetRotateYOnly(float angle); + void SetRotateZOnly(float angle); void SetRotateZOnlyScaled(float angle, float scale) { float c = Cos(angle); float s = Sin(angle); @@ -219,12 +72,9 @@ public: m_matrix.at.y = 0.0f; m_matrix.at.z = scale; } - void SetRotateZ(float angle){ - SetRotateZOnly(angle); - m_matrix.pos.x = 0.0f; - m_matrix.pos.y = 0.0f; - m_matrix.pos.z = 0.0f; - } + void SetRotateX(float angle); + void SetRotateY(float angle); + void SetRotateZ(float angle); void SetRotate(float xAngle, float yAngle, float zAngle); void Rotate(float x, float y, float z); void RotateX(float x); @@ -232,34 +82,9 @@ public: void RotateZ(float z); void Reorthogonalise(void); - void CopyOnlyMatrix(CMatrix *other){ - m_matrix = other->m_matrix; - } - void SetUnity(void) { - 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 = 0.0f; - m_matrix.pos.y = 0.0f; - m_matrix.pos.z = 0.0f; - } - void ResetOrientation(void) { - 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; - } + void CopyOnlyMatrix(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; @@ -268,11 +93,12 @@ public: void SetTranslateOnly(const CVector& pos) { SetTranslateOnly(pos.x, pos.y, pos.z); } + void CheckIntegrity(){} }; CMatrix &Invert(const CMatrix &src, CMatrix &dst); -CVector operator*(const CMatrix &mat, const CVector &vec); +CMatrix Invert(const CMatrix &matrix); CMatrix operator*(const CMatrix &m1, const CMatrix &m2); inline CVector MultiplyInverse(const CMatrix &mat, const CVector &vec) { @@ -283,15 +109,6 @@ inline CVector MultiplyInverse(const CMatrix &mat, const CVector &vec) mat.m_matrix.at.x * v.x + mat.m_matrix.at.y * v.y + mat.m_matrix.at.z * v.z); } -const CVector Multiply3x3(const CMatrix &mat, const CVector &vec); -const CVector Multiply3x3(const CVector &vec, const CMatrix &mat); - -inline CMatrix -Invert(const CMatrix &matrix) -{ - CMatrix inv; - return Invert(matrix, inv); -} class CCompressedMatrixNotAligned @@ -304,28 +121,8 @@ class CCompressedMatrixNotAligned int8 m_upY; int8 m_upZ; 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(); - } - 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.Reorthogonalise(); - } + void CompressFromFullMatrix(CMatrix &other); + void DecompressIntoFullMatrix(CMatrix &other); }; class CCompressedMatrix : public CCompressedMatrixNotAligned |