From 0f02c878efc8664309ead9daecd6355792ebd689 Mon Sep 17 00:00:00 2001 From: marauder2k7 Date: Sat, 27 Jul 2024 23:06:59 +0100 Subject: [PATCH] Update mMatrix.h setColumn setRow isIdentity only a few functions left --- Engine/source/math/mMatrix.h | 84 ++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/Engine/source/math/mMatrix.h b/Engine/source/math/mMatrix.h index 9c53fa1c2..bdd167aee 100644 --- a/Engine/source/math/mMatrix.h +++ b/Engine/source/math/mMatrix.h @@ -672,9 +672,17 @@ public: Matrix& scale(const Point3F& s); Matrix& scale(DATA_TYPE s) { return scale(Point3F(s, s, s)); } + void setColumn(S32 col, const Point4F& cptr); + void setColumn(S32 col, const Point3F& cptr); + + void setRow(S32 row, const Point4F& cptr); + void setRow(S32 row, const Point3F& cptr); + // ------ Getters ------ bool isAffine() const; + bool isIdentity() const; Point3F getScale() const; + EulerF toEuler() const; Point3F getPosition() const; @@ -781,6 +789,26 @@ inline Matrix& Matrix::scale(const return (*this); } +template +inline bool Matrix::isIdentity() const { + for (U32 i = 0; i < rows; i++) { + for (U32 j = 0; j < cols; j++) { + if (j == i) { + if((*this)(i, j) != static_cast(1)) { + return false; + } + } + else { + if((*this)(i, j) != static_cast(0)) { + return false; + } + } + } + } + + return true; +} + template inline Point3F Matrix::getScale() const { @@ -842,6 +870,34 @@ inline void Matrix::getColumn(S32 col, Point3F* cptr) con cptr->z = 0.0f; } +template +inline void Matrix::setColumn(S32 col, const Point4F &cptr) { + if(rows >= 2) + { + (*this)(0, col) = cptr.x; + (*this)(1, col) = cptr.y; + } + + if(rows >= 3) + (*this)(2, col) = cptr.z; + + if(rows >= 4) + (*this)(3, col) = cptr.w; +} + +template +inline void Matrix::setColumn(S32 col, const Point3F &cptr) { + if(rows >= 2) + { + (*this)(0, col) = cptr.x; + (*this)(1, col) = cptr.y; + } + + if(rows >= 3) + (*this)(2, col) = cptr.z; + +} + template inline void Matrix::getRow(S32 row, Point4F* cptr) const { @@ -877,6 +933,34 @@ inline void Matrix::getRow(S32 row, Point3F* cptr) const cptr->z = 0.0f; } +template +inline void Matrix::setRow(S32 row, const Point4F& cptr) { + if(cols >= 2) + { + (*this)(row, 0) = cptr.x; + (*this)(row, 1) = cptr.y; + } + + if(cols >= 3) + (*this)(row, 2) = cptr.z; + + if(cols >= 4) + (*this)(row, 3) = cptr.w; +} + +template +inline void Matrix::setRow(S32 row, const Point3F& cptr) { + if(cols >= 2) + { + (*this)(row, 0) = cptr.x; + (*this)(row, 1) = cptr.y; + } + + if(cols >= 3) + (*this)(row, 2) = cptr.z; + +} + //-------------------------------------------- // INLINE FUNCTIONS END //--------------------------------------------