diff options
Diffstat (limited to 'engines/titanic')
-rw-r--r-- | engines/titanic/star_control/fpose.cpp | 29 | ||||
-rw-r--r-- | engines/titanic/star_control/fpose.h | 9 | ||||
-rw-r--r-- | engines/titanic/star_control/fvector.h | 4 | ||||
-rw-r--r-- | engines/titanic/star_control/matrix_transform.cpp | 55 | ||||
-rw-r--r-- | engines/titanic/star_control/matrix_transform.h | 10 | ||||
-rw-r--r-- | engines/titanic/star_control/orientation_changer.cpp | 4 | ||||
-rw-r--r-- | engines/titanic/star_control/star_camera.cpp | 20 |
7 files changed, 89 insertions, 42 deletions
diff --git a/engines/titanic/star_control/fpose.cpp b/engines/titanic/star_control/fpose.cpp index a076cbb288..54cfebd186 100644 --- a/engines/titanic/star_control/fpose.cpp +++ b/engines/titanic/star_control/fpose.cpp @@ -21,6 +21,7 @@ */ #include "titanic/star_control/fpose.h" +#include "titanic/star_control/matrix_transform.h" namespace Titanic { @@ -183,6 +184,34 @@ FPose FPose::inverseTransform() const { return result; } +//TODO: Check math and provide source +void FPose::loadTransform(const CMatrixTransform &src) { + double total = src.fn1(); + double factor = (total <= 0.0) ? 0.0 : 2.0 / total; + FVector temp1V = src._vector * factor; + FVector temp2V = temp1V * src._vector; + + double val1 = temp1V._y * src._vector._x; + double val2 = temp1V._z * src._vector._x; + double val3 = temp1V._z * src._vector._y; + double val4 = temp1V._x * src._field0; + double val5 = temp1V._y * src._field0; + double val6 = temp1V._z * src._field0; + + _row1._x = 1.0 - (temp2V._z + temp2V._y); + _row1._y = val1 + val6; + _row1._z = val2 - val5; + _row2._x = val1 - val6; + _row2._y = 1.0 - (temp2V._z + temp2V._x); + _row2._z = val3 + val4; + _row3._x = val2 + val5; + _row3._y = val3 - val4; + _row3._z = 1.0 - (temp2V._y + temp2V._x); + _vector._x = 0; + _vector._y = 0; + _vector._z = 0; +} + FPose FPose::compose2(const FPose &m) { FPose dm; dm._row1 = _row1.MatProdRowVect(m); diff --git a/engines/titanic/star_control/fpose.h b/engines/titanic/star_control/fpose.h index 7a1dc7e5e1..d3c43fa439 100644 --- a/engines/titanic/star_control/fpose.h +++ b/engines/titanic/star_control/fpose.h @@ -27,6 +27,8 @@ namespace Titanic { +class CMatrixTransform; + /* * This class combines a position and orientation in 3D space * TODO: Merge with DAffine @@ -69,6 +71,13 @@ public: void copyFrom(const FMatrix &src); /** + * 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); + + /** * The inverse of rotation and the position vector */ FPose inverseTransform() const; diff --git a/engines/titanic/star_control/fvector.h b/engines/titanic/star_control/fvector.h index 201d19e33a..9bf6a55cce 100644 --- a/engines/titanic/star_control/fvector.h +++ b/engines/titanic/star_control/fvector.h @@ -152,6 +152,10 @@ public: return FVector(_x * right, _y * right, _z * right); } + const FVector operator*(const FVector &right) const { + return FVector(_x * right._x, _y * right._y, _z * right._z); + } + void operator+=(const FVector &delta) { _x += delta._x; _y += delta._y; diff --git a/engines/titanic/star_control/matrix_transform.cpp b/engines/titanic/star_control/matrix_transform.cpp index 4f1324d310..e9f04c97bd 100644 --- a/engines/titanic/star_control/matrix_transform.cpp +++ b/engines/titanic/star_control/matrix_transform.cpp @@ -21,7 +21,8 @@ */ #include "titanic/star_control/matrix_transform.h" -#include "titanic/star_control/daffine.h" +//#include "titanic/star_control/daffine.h" +#include "titanic/star_control/fpose.h" #include "common/textconsole.h" namespace Titanic { @@ -55,47 +56,47 @@ CMatrixTransform CMatrixTransform::resize(double factor) const { return dest; } -void CMatrixTransform::fn4(const DAffine &m) { - double total = m._col1._x + m._col3._z + m._col2._y + 1.0; +void CMatrixTransform::fn4(const FMatrix &m) { + double total = m._row1._x + m._row3._z + m._row2._y + 1.0; if (total <= 0.00001) { - total = m._col3._z; + total = m._row3._z; - if (m._col1._x <= m._col3._z) { - if (m._col2._y > total) - total = m._col2._y; - } else if (m._col1._x > total) { - total = m._col1._x; + if (m._row1._x <= m._row3._z) { + if (m._row2._y > total) + total = m._row2._y; + } else if (m._row1._x > total) { + total = m._row1._x; } - if (total == m._col1._x) { - double val1 = sqrt(m._col1._x - -1.0 - m._col2._y - m._col3._z); + if (total == m._row1._x) { + double val1 = sqrt(m._row1._x - -1.0 - m._row2._y - m._row3._z); double val2 = 0.5 / val1; _vector._x = val1 * 0.5; - _field0 = (m._col2._z - m._col3._y) * val2; - _vector._y = (m._col2._x + m._col1._y) * val2; - _vector._z = (m._col3._x + m._col1._z) * val2; - } else if (total == m._col2._y) { - double val1 = sqrt(m._col2._y - -1.0 - m._col3._z - m._col1._x); + _field0 = (m._row2._z - m._row3._y) * val2; + _vector._y = (m._row2._x + m._row1._y) * val2; + _vector._z = (m._row3._x + m._row1._z) * val2; + } else if (total == m._row2._y) { + double val1 = sqrt(m._row2._y - -1.0 - m._row3._z - m._row1._x); double val2 = 0.5 / val1; _vector._y = val1 * 0.5; - _field0 = (m._col3._x - m._col1._z) * val2; - _vector._z = (m._col3._y + m._col2._z) * val2; - _vector._x = (m._col2._x + m._col1._y) * val2; - } else if (total == m._col3._z) { - double val1 = sqrt(m._col3._z - -1.0 - m._col1._x - m._col2._y); + _field0 = (m._row3._x - m._row1._z) * val2; + _vector._z = (m._row3._y + m._row2._z) * val2; + _vector._x = (m._row2._x + m._row1._y) * val2; + } else if (total == m._row3._z) { + double val1 = sqrt(m._row3._z - -1.0 - m._row1._x - m._row2._y); double val2 = 0.5 / val1; _vector._z = val1 * 0.5; - _field0 = (m._col1._y - m._col2._x) * val2; - _vector._x = (m._col3._x + m._col1._z) * val2; - _vector._y = (m._col3._y + m._col2._z) * val2; + _field0 = (m._row1._y - m._row2._x) * val2; + _vector._x = (m._row3._x + m._row1._z) * val2; + _vector._y = (m._row3._y + m._row2._z) * val2; } } else { double val1 = 0.5 / sqrt(total); _field0 = sqrt(total) * 0.5; - _vector._x = (m._col2._z - m._col3._y) * val1; - _vector._y = (m._col3._x - m._col1._z) * val1; - _vector._z = (m._col1._y - m._col2._x) * val1; + _vector._x = (m._row2._z - m._row3._y) * val1; + _vector._y = (m._row3._x - m._row1._z) * val1; + _vector._z = (m._row1._y - m._row2._x) * val1; } } diff --git a/engines/titanic/star_control/matrix_transform.h b/engines/titanic/star_control/matrix_transform.h index 92d4fbff22..2043e8de76 100644 --- a/engines/titanic/star_control/matrix_transform.h +++ b/engines/titanic/star_control/matrix_transform.h @@ -23,11 +23,12 @@ #ifndef TITANIC_MATRIX_TRANSFORM_H #define TITANIC_MATRIX_TRANSFORM_H -#include "titanic/star_control/dvector.h" +//#include "titanic/star_control/dvector.h" +#include "titanic/star_control/fvector.h" namespace Titanic { -class Daffine; +class FMatrix; class CMatrixTransform { private: @@ -35,7 +36,8 @@ private: CMatrixTransform resize(double factor) const; public: double _field0; - DVector _vector; + //DVector _vector; + FVector _vector; public: CMatrixTransform() : _field0(1.0) {} @@ -50,7 +52,7 @@ public: void copyFrom(const CMatrixTransform &src); double fn1() const; - void fn4(const DAffine &m); + void fn4(const FMatrix &m); CMatrixTransform fn5(double percent, const CMatrixTransform &src); }; diff --git a/engines/titanic/star_control/orientation_changer.cpp b/engines/titanic/star_control/orientation_changer.cpp index a0c5c73fbe..e6d52df212 100644 --- a/engines/titanic/star_control/orientation_changer.cpp +++ b/engines/titanic/star_control/orientation_changer.cpp @@ -22,6 +22,7 @@ #include "titanic/star_control/orientation_changer.h" #include "titanic/star_control/daffine.h" +#include "titanic/star_control/fpose.h" namespace Titanic { @@ -41,7 +42,8 @@ FMatrix COrientationChanger::getOrientation(double percent) { } else { CMatrixTransform tfm = _sub1.fn5(percent, _sub2); - DAffine m1; + //DAffine m1; + FPose m1; m1.loadTransform(tfm); return m1; } diff --git a/engines/titanic/star_control/star_camera.cpp b/engines/titanic/star_control/star_camera.cpp index 38ce492ce5..88c943e685 100644 --- a/engines/titanic/star_control/star_camera.cpp +++ b/engines/titanic/star_control/star_camera.cpp @@ -518,15 +518,15 @@ bool CStarCamera::lockMarker2(CViewport *viewport, const FVector &secondStarPosi _isInLockingProcess = true; FVector firstStarPosition = _lockedStarsPos._row1; - DAffine m2(0, firstStarPosition); // Identity matrix and col4 as the 1st stars position + //DAffine m2(0, firstStarPosition); // Identity matrix and col4 as the 1st stars position FPose m3(0, firstStarPosition); // Identity matrix and row4 as the 1st stars position FVector starDelta = secondStarPosition - firstStarPosition; - DAffine m1 = starDelta.formRotXY(); + //DAffine m1 = starDelta.formRotXY(); FPose m10 = starDelta.formRotXY2(); FPose m11; fposeProd(m10,m3,m11); - m1 = m1.compose(m2); - m2 = m1.inverseTransform(); + //m1 = m1.compose(m2); + //m2 = m1.inverseTransform(); float A[16]={m11._row1._x,m11._row1._y,m11._row1._z, 0.0, m11._row2._x,m11._row2._y,m11._row2._z, 0.0, @@ -543,11 +543,11 @@ bool CStarCamera::lockMarker2(CViewport *viewport, const FVector &secondStarPosi m10._vector._z=B[14]; FVector oldPos = _viewport._position; - DAffine m5; - m5._col1 = viewport->_position; - m5._col2 = FVector(0.0, 0.0, 0.0); - m5._col3 = FVector(0.0, 0.0, 0.0); - m5._col4 = FVector(0.0, 0.0, 0.0); + //DAffine m5; + //m5._col1 = viewport->_position; + //m5._col2 = FVector(0.0, 0.0, 0.0); + //m5._col3 = FVector(0.0, 0.0, 0.0); + //m5._col4 = FVector(0.0, 0.0, 0.0); FPose m4; m4._row1 = viewport->_position; @@ -583,7 +583,7 @@ bool CStarCamera::lockMarker2(CViewport *viewport, const FVector &secondStarPosi m4._vector = tempV3; - FVector viewPosition = oldPos.MatProdColVect(m2); + //FVector viewPosition = oldPos.MatProdColVect(m2); FVector viewPosition2 = oldPos.MatProdRowVect(m10); //m4 = m4.compose2(m2); //fposeProd(m4,m10,m3); |