diff options
author | Paul Gilbert | 2017-03-24 21:19:38 -0400 |
---|---|---|
committer | Paul Gilbert | 2017-03-24 21:19:38 -0400 |
commit | 6ecc83325dbd9665e7f8605f85112b8cb5c33528 (patch) | |
tree | 932439379b5980bece552eba38beb5e332a5e39a /engines | |
parent | c9f9582994d94b1efa6108fdb7ea4a768dd80acc (diff) | |
download | scummvm-rg350-6ecc83325dbd9665e7f8605f85112b8cb5c33528.tar.gz scummvm-rg350-6ecc83325dbd9665e7f8605f85112b8cb5c33528.tar.bz2 scummvm-rg350-6ecc83325dbd9665e7f8605f85112b8cb5c33528.zip |
TITANIC: Finished DMatrix class
Diffstat (limited to 'engines')
-rw-r--r-- | engines/titanic/star_control/dmatrix.cpp | 133 | ||||
-rw-r--r-- | engines/titanic/star_control/dmatrix.h | 2 | ||||
-rw-r--r-- | engines/titanic/star_control/dvector.cpp | 4 | ||||
-rw-r--r-- | engines/titanic/star_control/star_control_sub12.cpp | 4 |
4 files changed, 130 insertions, 13 deletions
diff --git a/engines/titanic/star_control/dmatrix.cpp b/engines/titanic/star_control/dmatrix.cpp index 86ccd3d866..32614ac063 100644 --- a/engines/titanic/star_control/dmatrix.cpp +++ b/engines/titanic/star_control/dmatrix.cpp @@ -109,20 +109,137 @@ void DMatrix::setRotationMatrix(Axis axis, double amount) { } } -void DMatrix::fn1(DMatrix &m) { - // TODO +DMatrix DMatrix::fn1() const { + double val1 = _row1._x * _row3._z * _row2._y; + double val2 = 0.0; + double val3 = val1; + + if (val1 < 0.0) { + val2 = val3; + val1 = 0.0; + } + + double val4 = _row3._x * _row1._y * _row2._z; + if (val4 < 0.0) + val2 = val2 + val4; + else + val1 = val1 + val4; + + double val5 = _row3._y * _row1._z * _row2._x; + if (val5 < 0.0) + val2 = val2 + val5; + else + val1 = val1 + val5; + + if (-(_row3._x * _row2._y * _row1._z) < 0.0) + val2 = val2 - _row3._x * _row2._y * _row1._z; + else + val1 = val1 - _row3._x * _row2._y * _row1._z; + if (-(_row1._y * _row3._z * _row2._x) < 0.0) + val2 = val2 - _row1._y * _row3._z * _row2._x; + else + val1 = val1 - _row1._y * _row3._z * _row2._x; + + val3 = _row3._y * _row2._z; + double val6 = -(_row1._x * val3); + if (val6 < 0.0) + val2 = val2 + val6; + else + val1 = val1 + val6; + + double val7 = val2 + val1; + assert(!(val7 == 0.0 || fabs(val7 / (val1 - val2)) < 1.0e-10)); + + double val8 = val1; + double val9 = 1.0 / val7; + + DMatrix m; + m._row1._x = (val8 - val3) * val9; + m._row2._x = -((_row3._z * _row2._x - _row3._x * _row2._z) * val9); + m._row3._x = (_row3._y * _row2._x - _row3._x * _row2._y) * val9; + m._row1._y = -((_row1._y * _row3._z - _row3._y * _row1._z) * val9); + m._row2._y = (_row1._x * _row3._z - _row3._x * _row1._z) * val9; + m._row3._y = -((_row1._x * _row3._y - _row3._x * _row1._y) * val9); + m._row1._z = (_row1._y * _row2._z - _row2._y * _row1._z) * val9; + m._row2._z = -((_row1._x * _row2._z - _row1._z * _row2._x) * val9); + m._row3._z = (_row1._x * _row2._y - _row1._y * _row2._x) * val9; + + m._row4._x = -(m._row1._x * _row4._x + _row4._z * m._row2._x + + _row4._y * m._row3._x); + m._row4._z = -(_row4._y * m._row3._y + _row4._z * m._row2._y + + _row4._x * m._row1._y); + m._row4._y = -(_row4._y * m._row3._z + _row4._x * m._row1._z + + _row4._z * m._row2._z); + return m; } void DMatrix::fn3(CStarControlSub26 *sub26) { - double v = sub26->fn1(); - v = (v < 0.0) ? 0.0 : 2.0 / v; - - error("TODO: DMatrix::fn3 %d", (int)v); + double v3, v4, v5, v6, v7, v8, v9, v10; + double v11, v12, v13, v14, v15, v16, v17, v18, v19, v20; + + v3 = sub26->fn1(); + if (v3 <= 0.0) + v20 = 0.0; + else + v20 = 2.0 / v3; + v4 = v20 * sub26->_sub._v1; + v5 = v20 * sub26->_sub._v2; + v6 = v20 * sub26->_sub._v3; + v7 = v4 * sub26->_sub._v1; + v8 = v4; + v9 = v5; + v10 = v5 * sub26->_sub._v1; + v11 = v5 * sub26->_sub._v2; + v12 = v6; + v13 = v8 * sub26->_field0; + v14 = v12 + v11; + v15 = v6 * sub26->_sub._v2; + v16 = v6 * sub26->_field0; + v17 = v11 + v7; + v18 = v6 * sub26->_sub._v1; + v19 = v9 * sub26->_field0; + _row1._x = 1.0 - v14; + _row1._y = v10 + v16; + _row1._z = v18 - v19; + _row2._x = v10 - v16; + _row2._y = 1.0 - (v12 + v7); + _row2._z = v15 + v13; + _row3._x = v18 + v19; + _row3._y = v15 - v13; + _row3._z = 1.0 - v17; + _row4._x = 0.0; + _row4._y = 0.0; + _row4._z = 0.0; } DMatrix DMatrix::fn4(const DMatrix &m) { - // TODO - return DMatrix(); + DMatrix dm, dest; + dm._row1._x = m._row3._x * _row1._z + m._row2._x * _row1._y + + m._row1._x * _row1._x; + dm._row1._y = _row1._x * m._row1._y + m._row3._y * _row1._z + + m._row2._y * _row1._y; + dm._row1._z = _row1._x * m._row1._z + m._row3._z * _row1._z + + m._row2._z * _row1._y; + dm._row2._x = m._row1._x * _row2._x + _row2._y * m._row2._x + + _row2._z * m._row3._x; + dm._row2._y = _row2._y * m._row2._y + _row2._z * m._row3._y + + m._row1._y * _row2._x; + dm._row2._z = m._row1._z * _row2._x + _row2._y * m._row2._z + + _row2._z * m._row3._z; + dm._row3._x = m._row1._x * _row3._x + _row3._y * m._row2._x + + _row3._z * m._row3._x; + dm._row3._y = _row3._y * m._row2._y + _row3._z * m._row3._y + + m._row1._y * _row3._x; + dm._row3._z = m._row2._z * _row3._y + m._row3._z * _row3._z + + m._row1._z * _row3._x; + dm._row4._x = m._row1._x * dm._row4._x + _row4._y * m._row2._x + + _row4._z * m._row3._x + m._row4._x; + dm._row4._z = _row4._z * m._row3._y + _row4._y * m._row2._y + + dm._row4._x * m._row1._y + m._row4._y; + dm._row4._z = _row4._y * m._row2._z + dm._row4._x * m._row1._z + + _row4._z * m._row3._z + m._row4._z; + + return dest; } } // End of namespace Titanic diff --git a/engines/titanic/star_control/dmatrix.h b/engines/titanic/star_control/dmatrix.h index 793abadffd..cc14c5ebbf 100644 --- a/engines/titanic/star_control/dmatrix.h +++ b/engines/titanic/star_control/dmatrix.h @@ -57,7 +57,7 @@ public: */ void setRotationMatrix(Axis axis, double amount); - void fn1(DMatrix &m); + DMatrix fn1() const; void fn3(CStarControlSub26 *sub26); DMatrix fn4(const DMatrix &m); diff --git a/engines/titanic/star_control/dvector.cpp b/engines/titanic/star_control/dvector.cpp index 17409c6811..080b45e5b8 100644 --- a/engines/titanic/star_control/dvector.cpp +++ b/engines/titanic/star_control/dvector.cpp @@ -86,13 +86,13 @@ void DVector::fn4(const DVector &v, DMatrix &m) { matrix1.setRotationMatrix(X_AXIS, vector1._y * FACTOR); matrix2.setRotationMatrix(Y_AXIS, -(vector1._z * FACTOR)); matrix3 = matrix1.fn4(matrix2); - matrix3.fn1(matrix4); + matrix4 = matrix3.fn1(); vector1 = v.fn3(); matrix1.setRotationMatrix(X_AXIS, vector1._y * FACTOR); matrix2.setRotationMatrix(Y_AXIS, -(vector1._z * FACTOR)); matrix3 = matrix1.fn4(matrix2); - matrix1.fn1(matrix4); + matrix4 = matrix1.fn1(); m = matrix4.fn4(matrix3); } diff --git a/engines/titanic/star_control/star_control_sub12.cpp b/engines/titanic/star_control/star_control_sub12.cpp index 6b2f78c309..e236403e1f 100644 --- a/engines/titanic/star_control/star_control_sub12.cpp +++ b/engines/titanic/star_control/star_control_sub12.cpp @@ -326,7 +326,7 @@ void CStarControlSub12::setViewportPosition(const FPoint &angles) { diffV = tempV1; m1 = diffV.fn5(); m1 = m1.fn4(subX); - m1.fn1(subX); + subX = m1.fn1(); subX = subX.fn4(subY); FMatrix m3 = _sub13.getMatrix(); @@ -510,7 +510,7 @@ void CStarControlSub12::fn3(CStarControlSub13 *sub13, const FVector &v) { m1 = tempV1.fn5(); m1 = m1.fn4(m2); - m1.fn1(m2); + m2 = m1.fn1(); DVector tempV2 = _sub13._position; DMatrix m4; |