From c61d36b799ea9f8b24e3525d8db99510a2e303fc Mon Sep 17 00:00:00 2001 From: marauder2k7 Date: Sun, 28 Jul 2024 19:36:07 +0100 Subject: [PATCH] closest backup closest working example, no errors or warnings from compile, matrices arent correct though yet. --- Engine/source/math/mMatrix.h | 52 +++++++++++++++---- .../math/util/matrixSetDelegateMethods.h | 25 ++++++++- 2 files changed, 67 insertions(+), 10 deletions(-) diff --git a/Engine/source/math/mMatrix.h b/Engine/source/math/mMatrix.h index 503ede5a0..29e39c276 100644 --- a/Engine/source/math/mMatrix.h +++ b/Engine/source/math/mMatrix.h @@ -796,15 +796,8 @@ public: } } - void invertTo(Matrix* matrix) { - Matrix invMatrix = this->inverse(); - - for (U32 i = 0; i < rows; ++i) { - for (U32 j = 0; j < cols; ++j) { - (*matrix)(j, i) = invMatrix(i, j); - } - } - } + void invertTo(Matrix* matrix) const; + void invertTo(Matrix* matrix); void dumpMatrix(const char* caption = NULL) const; // Static identity matrix @@ -1157,6 +1150,47 @@ inline VectorF Matrix::getUpVector() const return vec; } +template +inline void Matrix::invertTo(Matrix* matrix) const +{ + Matrix invMatrix; + for (U32 i = 0; i < rows; ++i) { + for (U32 j = 0; j < cols; ++j) { + invMatrix(i, j) = (*this)(i, j); + } + } + + invMatrix.inverse(); + + for (U32 i = 0; i < rows; ++i) { + for (U32 j = 0; j < cols; ++j) { + (*matrix)(j, i) = invMatrix(i, j); + } + } + + (*matrix)(3, 0) = (*this)(3, 0); + (*matrix)(3, 1) = (*this)(3, 1); + (*matrix)(3, 2) = (*this)(3, 2); + (*matrix)(3, 3) = (*this)(3, 3); +} + +template +inline void Matrix::invertTo(Matrix* matrix) +{ + Matrix invMatrix = this->inverse(); + + for (U32 i = 0; i < rows; ++i) { + for (U32 j = 0; j < cols; ++j) { + (*matrix)(i, j) = invMatrix(i, j); + } + } + + (*matrix)(3, 0) = (*this)(3, 0); + (*matrix)(3, 1) = (*this)(3, 1); + (*matrix)(3, 2) = (*this)(3, 2); + (*matrix)(3, 3) = (*this)(3, 3); +} + template inline void Matrix::setRow(S32 row, const Point4F& cptr) { if(cols >= 2) diff --git a/Engine/source/math/util/matrixSetDelegateMethods.h b/Engine/source/math/util/matrixSetDelegateMethods.h index f5d237472..c2b375814 100644 --- a/Engine/source/math/util/matrixSetDelegateMethods.h +++ b/Engine/source/math/util/matrixSetDelegateMethods.h @@ -22,7 +22,7 @@ #ifndef _MATRIXSETDELEGATES_H_ #define _MATRIXSETDELEGATES_H_ - // Access to the direct value +#ifndef USE_TEMPLATE_MATRIX #define MATRIX_SET_GET_VALUE_FN(xfm) _transform_##xfm #define MATRIX_SET_GET_VALUE(xfm) inline const MatrixF &MATRIX_SET_GET_VALUE_FN(xfm)() { return mTransform[xfm]; } #define MATRIX_SET_BIND_VALUE(xfm) mEvalDelegate[xfm].bind(this, &MatrixSet::MATRIX_SET_GET_VALUE_FN(xfm)) @@ -44,5 +44,28 @@ return mTransform[matC]; \ } +#else + // Access to the direct value +#define MATRIX_SET_GET_VALUE_FN(xfm) _transform_##xfm +#define MATRIX_SET_GET_VALUE(xfm) inline const MatrixF &MATRIX_SET_GET_VALUE_FN(xfm)() { return mTransform[xfm]; } +#define MATRIX_SET_BIND_VALUE(xfm) mEvalDelegate[xfm].bind(this, &MatrixSet::MATRIX_SET_GET_VALUE_FN(xfm)) +#define MATRIX_SET_IS_INVERSE_OF_FN(inv_xfm, src_xfm) _##inv_xfm##_is_inverse_of_##src_xfm +#define MATRIX_SET_IS_INVERSE_OF(inv_xfm, src_xfm) inline const MatrixF &MATRIX_SET_IS_INVERSE_OF_FN(inv_xfm, src_xfm)() \ + { \ + mEvalDelegate[src_xfm]().invertTo(&mTransform[inv_xfm]); \ + MATRIX_SET_BIND_VALUE(inv_xfm); \ + return mTransform[inv_xfm]; \ + } + + +#define MATRIX_SET_MULT_ASSIGN_FN(matA, matB, matC) _##matC##_is_##matA##_x_##matB +#define MATRIX_SET_MULT_ASSIGN(matA, matB, matC) inline const MatrixF &MATRIX_SET_MULT_ASSIGN_FN(matA, matB, matC)() \ + { \ + mTransform[matC].mul(mEvalDelegate[matA](),mEvalDelegate[matB]()); \ + MATRIX_SET_BIND_VALUE(matC); \ + return mTransform[matC]; \ + } + +#endif #endif // _MATRIXSETDELEGATES_H_