From 4bd42373ce7867d499169c1fa7ee8825b5a54e15 Mon Sep 17 00:00:00 2001 From: David Fioramonti Date: Mon, 14 Aug 2017 17:17:05 -0700 Subject: TITANIC: star control, fmatrix refactoring renamed fn2->MatRProd and fn3->MatLProd. They do post (R) and pre (L) multiplication. --- engines/titanic/star_control/fmatrix.cpp | 4 ++-- engines/titanic/star_control/fmatrix.h | 15 +++++++++++++-- engines/titanic/star_control/viewport.cpp | 4 ++-- 3 files changed, 17 insertions(+), 6 deletions(-) (limited to 'engines/titanic') diff --git a/engines/titanic/star_control/fmatrix.cpp b/engines/titanic/star_control/fmatrix.cpp index 23a2ce2203..21b2e4e385 100644 --- a/engines/titanic/star_control/fmatrix.cpp +++ b/engines/titanic/star_control/fmatrix.cpp @@ -104,7 +104,7 @@ void FMatrix::set(const FVector &v) { _row2.normalize(); } -void FMatrix::fn2(const FMatrix &m) { +void FMatrix::matRProd(const FMatrix &m) { float x1 = _row1._y * m._row2._x + _row1._z * m._row3._x + _row1._x * m._row1._x; float y1 = _row1._x * m._row1._y + m._row2._y * _row1._y + m._row3._y * _row1._z; float z1 = _row1._x * m._row1._z + _row1._y * m._row2._z + _row1._z * m._row3._z; @@ -120,7 +120,7 @@ void FMatrix::fn2(const FMatrix &m) { _row3 = FVector(x3, y3, z3); } -void FMatrix::fn3(const FMatrix &m) { +void FMatrix::matLProd(const FMatrix &m) { float x1 = _row2._x * m._row1._y + m._row1._z * _row3._x + _row1._x * m._row1._x; float y1 = m._row1._x * _row1._y + _row3._y * m._row1._z + _row2._y * m._row1._y; float z1 = m._row1._x * _row1._z + m._row1._y * _row2._z + m._row1._z * _row3._z; diff --git a/engines/titanic/star_control/fmatrix.h b/engines/titanic/star_control/fmatrix.h index 95bb91cf73..e783a2342c 100644 --- a/engines/titanic/star_control/fmatrix.h +++ b/engines/titanic/star_control/fmatrix.h @@ -85,8 +85,19 @@ public: */ void set(const FVector &v); - void fn2(const FMatrix &m); - void fn3(const FMatrix &m); + /** + * Changes this matrix, A, to be C, where C=Am. + * Matrix m multiplies this matrix (A) on its Right. + * Matrix m is said to premultiply A (previous this matrix). + */ + void matRProd(const FMatrix &m); + + /** + * Changes this matrix, A, to be C, where C=mA. + * Matrix m multiplies this matrix (A) on its Left. + * m is said to postmultiply A (previous this matrix). + */ + void matLProd(const FMatrix &m); /** * Returns true if the passed matrix equals this one diff --git a/engines/titanic/star_control/viewport.cpp b/engines/titanic/star_control/viewport.cpp index c3625b85c4..39d2c5f201 100644 --- a/engines/titanic/star_control/viewport.cpp +++ b/engines/titanic/star_control/viewport.cpp @@ -156,7 +156,7 @@ void CViewport::fn12() { FPose s2(s1, m3); m1.copyFrom(s2); - _orientation.fn2(m1); + _orientation.matRProd(m1); _flag = false; } @@ -181,7 +181,7 @@ void CViewport::reposition(double factor) { } void CViewport::fn15(const FMatrix &matrix) { - _orientation.fn3(matrix); + _orientation.matLProd(matrix); _flag = false; } -- cgit v1.2.3 From 40b09ffd5414d3117a0e85b0cf3b3539ca015df4 Mon Sep 17 00:00:00 2001 From: David Fioramonti Date: Tue, 15 Aug 2017 14:43:03 -0700 Subject: TITANIC: fmatrix refactor, common code for matrix product Changed the left and right matrix product to use the matrix product function with the matrix order reversed. --- engines/titanic/star_control/fmatrix.cpp | 59 ++++++++++++++++++-------------- engines/titanic/star_control/fmatrix.h | 21 ++++++++---- 2 files changed, 48 insertions(+), 32 deletions(-) (limited to 'engines/titanic') diff --git a/engines/titanic/star_control/fmatrix.cpp b/engines/titanic/star_control/fmatrix.cpp index 21b2e4e385..04f9c889da 100644 --- a/engines/titanic/star_control/fmatrix.cpp +++ b/engines/titanic/star_control/fmatrix.cpp @@ -29,6 +29,12 @@ FMatrix::FMatrix() : _row1(1.0, 0.0, 0.0), _row2(0.0, 1.0, 0.0), _row3(0.0, 0.0, 1.0) { } +FMatrix::FMatrix(const FVector &row1, const FVector &row2, const FVector &row3) { + _row1 = row1; + _row2 = row2; + _row3 = row3; +} + FMatrix::FMatrix(const DAffine &src) { copyFrom(src); } @@ -81,6 +87,13 @@ void FMatrix::identity() { _row3 = FVector(0.0, 0.0, 1.0); } +void FMatrix::set(const FMatrix &m) { + _row1 = m._row1; + _row2 = m._row2; + _row3 = m._row3; +} + + void FMatrix::set(const FVector &row1, const FVector &row2, const FVector &row3) { _row1 = row1; _row2 = row2; @@ -104,36 +117,30 @@ void FMatrix::set(const FVector &v) { _row2.normalize(); } -void FMatrix::matRProd(const FMatrix &m) { - float x1 = _row1._y * m._row2._x + _row1._z * m._row3._x + _row1._x * m._row1._x; - float y1 = _row1._x * m._row1._y + m._row2._y * _row1._y + m._row3._y * _row1._z; - float z1 = _row1._x * m._row1._z + _row1._y * m._row2._z + _row1._z * m._row3._z; - float x2 = m._row1._x * _row2._x + m._row3._x * _row2._z + m._row2._x * _row2._y; - float y2 = m._row3._y * _row2._z + m._row1._y * _row2._x + m._row2._y * _row2._y; - float z2 = _row2._z * m._row3._z + _row2._x * m._row1._z + _row2._y * m._row2._z; - float x3 = m._row1._x * _row3._x + _row3._z * m._row3._x + _row3._y * m._row2._x; - float y3 = _row3._y * m._row2._y + _row3._z * m._row3._y + _row3._x * m._row1._y; - float z3 = _row3._x * m._row1._z + _row3._y * m._row2._z + _row3._z * m._row3._z; +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; +} - _row1 = FVector(x1, y1, z1); - _row2 = FVector(x2, y2, z2); - _row3 = FVector(x3, y3, z3); +void FMatrix::matRProd(const FMatrix &m) { + FMatrix C = FMatrix(); + FMatrix A = FMatrix(_row1,_row2,_row3); + matProd(A,m,C); + this->set(C); } void FMatrix::matLProd(const FMatrix &m) { - float x1 = _row2._x * m._row1._y + m._row1._z * _row3._x + _row1._x * m._row1._x; - float y1 = m._row1._x * _row1._y + _row3._y * m._row1._z + _row2._y * m._row1._y; - float z1 = m._row1._x * _row1._z + m._row1._y * _row2._z + m._row1._z * _row3._z; - float x2 = _row1._x * m._row2._x + _row2._x * m._row2._y + _row3._x * m._row2._z; - float y2 = _row3._y * m._row2._z + _row1._y * m._row2._x + _row2._y * m._row2._y; - float z2 = m._row2._z * _row3._z + m._row2._x * _row1._z + m._row2._y * _row2._z; - float x3 = _row1._x * m._row3._x + m._row3._z * _row3._x + m._row3._y * _row2._x; - float y3 = m._row3._y * _row2._y + m._row3._z * _row3._y + m._row3._x * _row1._y; - float z3 = m._row3._x * _row1._z + m._row3._y * _row2._z + m._row3._z * _row3._z; - - _row1 = FVector(x1, y1, z1); - _row2 = FVector(x2, y2, z2); - _row3 = FVector(x3, y3, z3); + FMatrix C = FMatrix(); + FMatrix A = FMatrix(_row1,_row2,_row3); + matProd(m,A,C); + this->set(C); } } // End of namespace Titanic diff --git a/engines/titanic/star_control/fmatrix.h b/engines/titanic/star_control/fmatrix.h index e783a2342c..3970ac8eb2 100644 --- a/engines/titanic/star_control/fmatrix.h +++ b/engines/titanic/star_control/fmatrix.h @@ -47,6 +47,7 @@ public: FVector _row3; public: FMatrix(); + FMatrix(const FVector &, const FVector &, const FVector &); FMatrix(const DAffine &src); FMatrix(const FMatrix &src); @@ -70,6 +71,11 @@ public: */ void identity(); + /** + * Sets the data for the matrix + */ + void set(const FMatrix &m); + /** * Sets the data for the matrix */ @@ -86,16 +92,19 @@ public: void set(const FVector &v); /** - * Changes this matrix, A, to be C, where C=Am. - * Matrix m multiplies this matrix (A) on its Right. - * Matrix m is said to premultiply A (previous this matrix). + * 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). */ void matRProd(const FMatrix &m); /** - * Changes this matrix, A, to be C, where C=mA. - * Matrix m multiplies this matrix (A) on its Left. - * m is said to postmultiply A (previous this matrix). + * Changes this matrix, A, to be C, where C=mA. Matrix m multiplies this matrix (A) on its Left. + * m is said to postmultiply A (the previous this matrix). */ void matLProd(const FMatrix &m); -- cgit v1.2.3 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/titanic') 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