diff options
author | Paul Gilbert | 2017-08-15 21:28:46 -0400 |
---|---|---|
committer | GitHub | 2017-08-15 21:28:46 -0400 |
commit | 66024fdd2b9519560718cbc8a4ace3959279243a (patch) | |
tree | ec637517e84a55747fcc63a302e179ddce500d13 /engines/titanic/star_control | |
parent | 867a37618b95a1cadeb3a0adf84a4cee31d52699 (diff) | |
parent | 781c679c7f8e761e35c3d72ac27e16350c55964a (diff) | |
download | scummvm-rg350-66024fdd2b9519560718cbc8a4ace3959279243a.tar.gz scummvm-rg350-66024fdd2b9519560718cbc8a4ace3959279243a.tar.bz2 scummvm-rg350-66024fdd2b9519560718cbc8a4ace3959279243a.zip |
Merge pull request #991 from dafioram/daffine_refactor
TITANIC: DAffine refactor
Diffstat (limited to 'engines/titanic/star_control')
-rw-r--r-- | engines/titanic/star_control/daffine.cpp | 39 | ||||
-rw-r--r-- | engines/titanic/star_control/daffine.h | 25 | ||||
-rw-r--r-- | engines/titanic/star_control/dvector.cpp | 9 | ||||
-rw-r--r-- | engines/titanic/star_control/dvector.h | 3 |
4 files changed, 58 insertions, 18 deletions
diff --git a/engines/titanic/star_control/daffine.cpp b/engines/titanic/star_control/daffine.cpp index a7bed770c7..6dfee29b32 100644 --- a/engines/titanic/star_control/daffine.cpp +++ b/engines/titanic/star_control/daffine.cpp @@ -29,7 +29,7 @@ namespace Titanic { DAffine *DAffine::_static; DAffine::DAffine() : - _col1(0.0, 0.0, 0.0), _col2(0.0, 0.0, 0.0), _col3(0.0, 0.0, 0.0) { + _col1(0.0, 0.0, 0.0), _col2(0.0, 0.0, 0.0), _col3(0.0, 0.0, 0.0), _col4(0.0, 0.0, 0.0) { } DAffine::DAffine(int mode, const DVector &src) { @@ -55,8 +55,8 @@ DAffine::DAffine(int mode, const DVector &src) { } } -DAffine::DAffine(Axis axis, double amount) { - setRotationMatrix(axis, amount); +DAffine::DAffine(Axis axis, double angleDeg) { + setRotationMatrix(axis, angleDeg); } DAffine::DAffine(const FMatrix &src) { @@ -65,6 +65,7 @@ DAffine::DAffine(const FMatrix &src) { _col3 = src._row3; } +//TODO: What is _static for? void DAffine::init() { _static = nullptr; } @@ -74,10 +75,27 @@ void DAffine::deinit() { _static = nullptr; } -void DAffine::setRotationMatrix(Axis axis, double amount) { - const double FACTOR = 0.0174532925199433; - double sinVal = sin(amount * FACTOR); - double cosVal = cos(amount * FACTOR); +void DAffine::clear() { + _col1._x = 0.0; + _col1._y = 0.0; + _col1._z = 0.0; + _col2._x = 0.0; + _col2._y = 0.0; + _col2._z = 0.0; + _col3._x = 0.0; + _col3._y = 0.0; + _col3._z = 0.0; + _col4._x = 0.0; + _col4._y = 0.0; + _col4._z = 0.0; +} + +// Source: https://en.wikipedia.org/wiki/Rotation_matrix +void DAffine::setRotationMatrix(Axis axis, double angleDeg) { + clear(); + + double sinVal = sin(angleDeg * Deg2Rad); + double cosVal = cos(angleDeg * Deg2Rad); switch (axis) { case X_AXIS: @@ -90,9 +108,9 @@ void DAffine::setRotationMatrix(Axis axis, double amount) { case Y_AXIS: _col1._x = cosVal; - _col1._z = sinVal; + _col1._z = -sinVal; _col2._y = 1.0; - _col3._x = -sinVal; + _col3._x = sinVal; _col3._z = cosVal; break; @@ -109,6 +127,7 @@ void DAffine::setRotationMatrix(Axis axis, double amount) { } } +//TODO: Check math and provide source DAffine DAffine::inverseTransform() const { double val1 = _col1._x * _col3._z * _col2._y; double val2 = 0.0; @@ -174,6 +193,7 @@ DAffine DAffine::inverseTransform() const { return m; } +//TODO: Check math and provide source void DAffine::loadTransform(const CMatrixTransform &src) { double total = src.fn1(); double factor = (total <= 0.0) ? 0.0 : 2.0 / total; @@ -201,6 +221,7 @@ void DAffine::loadTransform(const CMatrixTransform &src) { _col4._z = 0; } +//TODO: Check math and provide source DAffine DAffine::compose(const DAffine &m) { DAffine dm; dm._col1._x = m._col3._x * _col1._z + m._col2._x * _col1._y diff --git a/engines/titanic/star_control/daffine.h b/engines/titanic/star_control/daffine.h index 50f8b9580b..631b6003f0 100644 --- a/engines/titanic/star_control/daffine.h +++ b/engines/titanic/star_control/daffine.h @@ -50,19 +50,38 @@ public: static void deinit(); public: DAffine(); + //TODO: consider making mode an enum since that is more helpful when it is used in code DAffine(int mode, const DVector &src); - DAffine(Axis axis, double amount); + DAffine(Axis axis, double angleDeg); DAffine(const FMatrix &src); /** - * Sets up a matrix for rotating on a given axis by a given amount + * Sets all elements to zero */ - void setRotationMatrix(Axis axis, double amount); + void clear(); + /** + * Sets up an affine matrix for rotating on a given axis by an amount in degrees + */ + void setRotationMatrix(Axis axis, double angleDeg); + + /** + * Return the Inverse of this Daffine + */ DAffine inverseTransform() const; + /** + * Change this Daffine to have its first three columns be some mapping from src matrix + * and the 4rth column to be (three) zeros. The mapping is not as simple as replacing + * matching row/colmn indices + */ void loadTransform(const CMatrixTransform &src); + /** + * Do the affine product between this Daffine on the right + * and the m Daffine matrix on the left. This product is NOT the same + * as multiplying two matrices of dimensions 3x4. + */ DAffine compose(const DAffine &m); }; diff --git a/engines/titanic/star_control/dvector.cpp b/engines/titanic/star_control/dvector.cpp index 1f873b5764..c7481a2b49 100644 --- a/engines/titanic/star_control/dvector.cpp +++ b/engines/titanic/star_control/dvector.cpp @@ -26,9 +26,6 @@ namespace Titanic { -const double Rad2Deg = 180.0 / M_PI; -const double Deg2Rad = 1.0 / Rad2Deg; - double DVector::normalize() { double hyp = sqrt(_x * _x + _y * _y + _z * _z); assert(hyp); @@ -89,13 +86,13 @@ DAffine DVector::getFrameTransform(const DVector &v) { DVector vector1 = getAnglesAsVect(); matrix1.setRotationMatrix(X_AXIS, vector1._y * Rad2Deg); - matrix2.setRotationMatrix(Y_AXIS, -(vector1._z * Rad2Deg)); + matrix2.setRotationMatrix(Y_AXIS, vector1._z * Rad2Deg); matrix3 = matrix1.compose(matrix2); matrix4 = matrix3.inverseTransform(); vector1 = v.getAnglesAsVect(); matrix1.setRotationMatrix(X_AXIS, vector1._y * Rad2Deg); - matrix2.setRotationMatrix(Y_AXIS, -(vector1._z * Rad2Deg)); + matrix2.setRotationMatrix(Y_AXIS, vector1._z * Rad2Deg); matrix3 = matrix1.compose(matrix2); return matrix4.compose(matrix3); @@ -105,7 +102,7 @@ DAffine DVector::rotXY() const { DVector v1 = getAnglesAsVect(); DAffine m1, m2; m1.setRotationMatrix(X_AXIS, v1._y * Rad2Deg); - m2.setRotationMatrix(Y_AXIS, -(v1._z * Rad2Deg)); + m2.setRotationMatrix(Y_AXIS, v1._z * Rad2Deg); return m1.compose(m2); } diff --git a/engines/titanic/star_control/dvector.h b/engines/titanic/star_control/dvector.h index eda69f9b81..bff271dd6f 100644 --- a/engines/titanic/star_control/dvector.h +++ b/engines/titanic/star_control/dvector.h @@ -27,6 +27,9 @@ namespace Titanic { +const double Rad2Deg = 180.0 / M_PI; +const double Deg2Rad = 1.0 / Rad2Deg; + class DAffine; /** |