From e9ab6fcead6f2aaeb5a21e72a3a2e54eca661b9e Mon Sep 17 00:00:00 2001 From: David Fioramonti Date: Mon, 14 Aug 2017 18:22:00 -0700 Subject: TITANIC: fmatrix refactor, matrix product now non-member function The matrix product doesn't change anything about the class so it doesn't need to be a member function. This way other functions can do multiplication of matrices. --- engines/titanic/star_control/fmatrix.cpp | 27 +++++++++++++++------------ engines/titanic/star_control/fmatrix.h | 12 +++++++----- 2 files changed, 22 insertions(+), 17 deletions(-) (limited to 'engines') diff --git a/engines/titanic/star_control/fmatrix.cpp b/engines/titanic/star_control/fmatrix.cpp index 04f9c889da..724b5975d4 100644 --- a/engines/titanic/star_control/fmatrix.cpp +++ b/engines/titanic/star_control/fmatrix.cpp @@ -25,6 +25,21 @@ namespace Titanic { +//Non-member functions +void matProd(const FMatrix &a, const FMatrix &m, FMatrix &C) { + C._row1._x = a._row1._y * m._row2._x + a._row1._z * m._row3._x + a._row1._x * m._row1._x; + C._row1._y = a._row1._x * m._row1._y + m._row2._y * a._row1._y + m._row3._y * a._row1._z; + C._row1._z = a._row1._x * m._row1._z + a._row1._y * m._row2._z + a._row1._z * m._row3._z; + C._row2._x = m._row1._x * a._row2._x + m._row3._x * a._row2._z + m._row2._x * a._row2._y; + C._row2._y = m._row3._y * a._row2._z + m._row1._y * a._row2._x + m._row2._y * a._row2._y; + C._row2._z = a._row2._z * m._row3._z + a._row2._x * m._row1._z + a._row2._y * m._row2._z; + C._row3._x = m._row1._x * a._row3._x + a._row3._z * m._row3._x + a._row3._y * m._row2._x; + C._row3._y = a._row3._y * m._row2._y + a._row3._z * m._row3._y + a._row3._x * m._row1._y; + C._row3._z = a._row3._x * m._row1._z + a._row3._y * m._row2._z + a._row3._z * m._row3._z; +} + +//member functions + FMatrix::FMatrix() : _row1(1.0, 0.0, 0.0), _row2(0.0, 1.0, 0.0), _row3(0.0, 0.0, 1.0) { } @@ -117,18 +132,6 @@ void FMatrix::set(const FVector &v) { _row2.normalize(); } -void FMatrix::matProd(const FMatrix &a, const FMatrix &m, FMatrix &C) { - C._row1._x = a._row1._y * m._row2._x + a._row1._z * m._row3._x + a._row1._x * m._row1._x; - C._row1._y = a._row1._x * m._row1._y + m._row2._y * a._row1._y + m._row3._y * a._row1._z; - C._row1._z = a._row1._x * m._row1._z + a._row1._y * m._row2._z + a._row1._z * m._row3._z; - C._row2._x = m._row1._x * a._row2._x + m._row3._x * a._row2._z + m._row2._x * a._row2._y; - C._row2._y = m._row3._y * a._row2._z + m._row1._y * a._row2._x + m._row2._y * a._row2._y; - C._row2._z = a._row2._z * m._row3._z + a._row2._x * m._row1._z + a._row2._y * m._row2._z; - C._row3._x = m._row1._x * a._row3._x + a._row3._z * m._row3._x + a._row3._y * m._row2._x; - C._row3._y = a._row3._y * m._row2._y + a._row3._z * m._row3._y + a._row3._x * m._row1._y; - C._row3._z = a._row3._x * m._row1._z + a._row3._y * m._row2._z + a._row3._z * m._row3._z; -} - void FMatrix::matRProd(const FMatrix &m) { FMatrix C = FMatrix(); FMatrix A = FMatrix(_row1,_row2,_row3); diff --git a/engines/titanic/star_control/fmatrix.h b/engines/titanic/star_control/fmatrix.h index 3970ac8eb2..f477500bad 100644 --- a/engines/titanic/star_control/fmatrix.h +++ b/engines/titanic/star_control/fmatrix.h @@ -91,11 +91,6 @@ public: */ void set(const FVector &v); - /** - * Puts the matrix product between a and m in C, C = am - */ - void matProd(const FMatrix &a, const FMatrix &m, FMatrix &C); - /** * Changes this matrix, A, to be C, where C=Am. Matrix m multiplies this matrix (A) on its Right. * m is said to premultiply A (the previous this matrix). @@ -132,6 +127,13 @@ public: } }; +/** +* Puts the matrix product between a and m in C, C = am +* Called by MatLProd and MatLProd +* Caller must preallocate output matrix +*/ +void matProd(const FMatrix &a, const FMatrix &m, FMatrix &C); + } // End of namespace Titanic #endif /* TITANIC_FMATRIX_H */ -- cgit v1.2.3