aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic
diff options
context:
space:
mode:
authorDavid Fioramonti2017-08-15 14:43:03 -0700
committerDavid Fioramonti2017-08-15 14:44:08 -0700
commit40b09ffd5414d3117a0e85b0cf3b3539ca015df4 (patch)
tree841daac198454c575e92a768d810a76e577c8851 /engines/titanic
parent4bd42373ce7867d499169c1fa7ee8825b5a54e15 (diff)
downloadscummvm-rg350-40b09ffd5414d3117a0e85b0cf3b3539ca015df4.tar.gz
scummvm-rg350-40b09ffd5414d3117a0e85b0cf3b3539ca015df4.tar.bz2
scummvm-rg350-40b09ffd5414d3117a0e85b0cf3b3539ca015df4.zip
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.
Diffstat (limited to 'engines/titanic')
-rw-r--r--engines/titanic/star_control/fmatrix.cpp59
-rw-r--r--engines/titanic/star_control/fmatrix.h21
2 files changed, 48 insertions, 32 deletions
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);
@@ -73,6 +74,11 @@ public:
/**
* Sets the data for the matrix
*/
+ void set(const FMatrix &m);
+
+ /**
+ * Sets the data for the matrix
+ */
void set(const FVector &row1, const FVector &row2, const FVector &row3);
/**
@@ -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);