diff options
-rw-r--r-- | engines/titanic/star_control/fmatrix.cpp | 14 | ||||
-rw-r--r-- | engines/titanic/star_control/fmatrix.h | 5 | ||||
-rw-r--r-- | engines/titanic/star_control/fvector.cpp | 18 | ||||
-rw-r--r-- | engines/titanic/star_control/fvector.h | 18 | ||||
-rw-r--r-- | engines/titanic/star_control/star_control_sub13.cpp | 2 | ||||
-rw-r--r-- | engines/titanic/star_control/star_control_sub23.cpp | 4 | ||||
-rw-r--r-- | engines/titanic/star_control/star_control_sub6.cpp | 4 | ||||
-rw-r--r-- | engines/titanic/star_control/star_control_sub6.h | 4 | ||||
-rw-r--r-- | engines/titanic/star_control/star_view.cpp | 8 |
9 files changed, 50 insertions, 27 deletions
diff --git a/engines/titanic/star_control/fmatrix.cpp b/engines/titanic/star_control/fmatrix.cpp index f3cf19c85f..e0c270ba7d 100644 --- a/engines/titanic/star_control/fmatrix.cpp +++ b/engines/titanic/star_control/fmatrix.cpp @@ -67,6 +67,12 @@ void FMatrix::save(SimpleFile *file, int indent) { } void FMatrix::clear() { + _row1.clear(); + _row2.clear(); + _row3.clear(); +} + +void FMatrix::identity() { _row1 = FVector(1.0, 0.0, 0.0); _row2 = FVector(0.0, 1.0, 0.0); _row3 = FVector(0.0, 0.0, 1.0); @@ -88,17 +94,17 @@ void FMatrix::fn1(const FVector &v) { _row2._y = tempVector._y; _row2._z = tempVector._z; - _row3.multiply(&tempVector, &_row2); + _row3.crossProduct(&tempVector, &_row2); _row1._x = _row2._x; _row1._y = _row2._y; _row1._z = _row2._z; - _row1.fn3(); + _row1.normalize(); - _row3.multiply(&tempVector, &_row1); + _row3.crossProduct(&tempVector, &_row1); _row2._x = _row1._x; _row2._y = _row1._y; _row2._z = _row1._z; - _row2.fn3(); + _row2.normalize(); } void FMatrix::fn2(const FMatrix &m) { diff --git a/engines/titanic/star_control/fmatrix.h b/engines/titanic/star_control/fmatrix.h index b0dc709ad7..282338c082 100644 --- a/engines/titanic/star_control/fmatrix.h +++ b/engines/titanic/star_control/fmatrix.h @@ -65,6 +65,11 @@ public: void clear(); /** + * Sets up an identity matrix + */ + void identity(); + + /** * Sets the data for the matrix */ void set(FVector *row1, FVector *row2, FVector *row3); diff --git a/engines/titanic/star_control/fvector.cpp b/engines/titanic/star_control/fvector.cpp index de33bcf2a0..b0667c532b 100644 --- a/engines/titanic/star_control/fvector.cpp +++ b/engines/titanic/star_control/fvector.cpp @@ -34,13 +34,13 @@ void FVector::fn1(FVector *v) { v->_z = _z; } -void FVector::multiply(FVector *dest, const FVector *src) { +void FVector::crossProduct(FVector *dest, const FVector *src) { dest->_x = (src->_z * _y) - (_z * src->_y); dest->_y = (src->_x * _z) - (_x * src->_z); dest->_z = (src->_y * _x) - (_y * src->_x); } -double FVector::fn3() { +double FVector::normalize() { double hyp = sqrt(_x * _x + _y * _y + _z * _z); assert(hyp); @@ -50,6 +50,13 @@ double FVector::fn3() { return hyp; } +void FVector::addAndNormalize(FVector *dest, const FVector *v1, const FVector *v2) { + FVector tempVector(v1->_x + v2->_x, v1->_y + v2->_y, v1->_z + v2->_z); + tempVector.normalize(); + + *dest = tempVector; +} + double FVector::getDistance(const FVector *src) const { double xd = src->_x - _x; double yd = src->_y - _y; @@ -58,13 +65,6 @@ double FVector::getDistance(const FVector *src) const { return sqrt(xd * xd + yd * yd + zd * zd); } -void FVector::fn4(FVector *dest, const FVector *v1, const FVector *v2) { - FVector tempVector(v1->_x + v2->_x, v1->_y + v2->_y, v1->_z + v2->_z); - tempVector.fn3(); - - *dest = tempVector; -} - void FVector::fn5(FVector *dest, const CStarControlSub6 *sub6) const { error("TODO: FVector::fn5"); } diff --git a/engines/titanic/star_control/fvector.h b/engines/titanic/star_control/fvector.h index 71336eb9a9..83f0039aaa 100644 --- a/engines/titanic/star_control/fvector.h +++ b/engines/titanic/star_control/fvector.h @@ -48,15 +48,27 @@ public: } void fn1(FVector *v); - void multiply(FVector *dest, const FVector *src); - double fn3(); + + /** + * Calculates the cross-product between this matrix and a passed one + */ + void crossProduct(FVector *dest, const FVector *src); + + /** + * Normalizes the vector so the length from origin equals 1.0 + */ + double normalize(); + + /** + * Adds two vectors together and then normalizes the result + */ + static void addAndNormalize(FVector *dest, const FVector *v1, const FVector *v2); /** * Returns the distance between a specified point and this one */ double getDistance(const FVector *src) const; - static void fn4(FVector *dest, const FVector *v1, const FVector *v2); void fn5(FVector *dest, const CStarControlSub6 *sub6) const; /** diff --git a/engines/titanic/star_control/star_control_sub13.cpp b/engines/titanic/star_control/star_control_sub13.cpp index 5e33eebdc5..cd7f0bb5d6 100644 --- a/engines/titanic/star_control/star_control_sub13.cpp +++ b/engines/titanic/star_control/star_control_sub13.cpp @@ -156,7 +156,7 @@ void CStarControlSub13::set1C(double v) { } void CStarControlSub13::fn12() { - _matrix.clear(); + _matrix.identity(); CStarControlSub6 m1(0, g_vm->getRandomNumber(359)); CStarControlSub6 m2(1, g_vm->getRandomNumber(359)); diff --git a/engines/titanic/star_control/star_control_sub23.cpp b/engines/titanic/star_control/star_control_sub23.cpp index 40dbb8d06f..5d09475b85 100644 --- a/engines/titanic/star_control/star_control_sub23.cpp +++ b/engines/titanic/star_control/star_control_sub23.cpp @@ -47,7 +47,7 @@ void CStarControlSub23::proc2(FVector &v1, FVector &v2, FMatrix &m1, FMatrix &m2 _row1 = v1; _row2 = v2; _row3 = _row2 - _row1; - _field24 = _row3.fn3(); + _field24 = _row3.normalize(); _field58 = 0; _field8 = 0; @@ -74,7 +74,7 @@ void CStarControlSub23::proc4(FVector &v1, FVector &v2, FMatrix &m) { _row2 = v2; FVector vector = _row2 - _row1; _row3 = vector; - _field24 = _row3.fn3(); + _field24 = _row3.normalize(); _field8 = 0; _field34 = 0; diff --git a/engines/titanic/star_control/star_control_sub6.cpp b/engines/titanic/star_control/star_control_sub6.cpp index b1dd9e43e3..f0ec68e86e 100644 --- a/engines/titanic/star_control/star_control_sub6.cpp +++ b/engines/titanic/star_control/star_control_sub6.cpp @@ -47,8 +47,8 @@ void CStarControlSub6::deinit() { _static = nullptr; } -void CStarControlSub6::clear() { - FMatrix::clear(); +void CStarControlSub6::identity() { + FMatrix::identity(); _vector.clear(); } diff --git a/engines/titanic/star_control/star_control_sub6.h b/engines/titanic/star_control/star_control_sub6.h index 572ac4a4f1..d63868027a 100644 --- a/engines/titanic/star_control/star_control_sub6.h +++ b/engines/titanic/star_control/star_control_sub6.h @@ -41,9 +41,9 @@ public: CStarControlSub6(const CStarControlSub6 *src); /** - * Clear the item + * Sets an identity matrix */ - void clear(); + void identity(); /** * Sets up a passed instance from the specified two other ones diff --git a/engines/titanic/star_control/star_view.cpp b/engines/titanic/star_control/star_view.cpp index f320bba99d..540d2c7666 100644 --- a/engines/titanic/star_control/star_view.cpp +++ b/engines/titanic/star_control/star_view.cpp @@ -450,7 +450,7 @@ void CStarView::randomizeVectors1(FVector &v1, FVector &v2) { v2._x = vx; v2._y = vy; v2._z = -v1._z; - v2.fn3(); + v2.normalize(); } void CStarView::randomizeVectors2(FVector &v1, FVector &v2) { @@ -462,7 +462,7 @@ void CStarView::randomizeVectors2(FVector &v1, FVector &v2) { v2._x = -v1._x; v2._y = -v1._y; v2._z = -v1._z; - v2.fn3(); + v2.normalize(); } void CStarView::randomizeVectors3(FVector &v1, FVector &v2) { @@ -474,7 +474,7 @@ void CStarView::randomizeVectors3(FVector &v1, FVector &v2) { v2._x = -v1._x; v2._y = -v1._y; v2._z = -v1._z; - v2.fn3(); + v2.normalize(); } void CStarView::randomizeVectors4(FVector &v1, FVector &v2) { @@ -486,7 +486,7 @@ void CStarView::randomizeVectors4(FVector &v1, FVector &v2) { v2._x = -v1._x; v2._y = -v1._y; v2._z = -v1._z; - v2.fn3(); + v2.normalize(); } void CStarView::resizeSurface(CScreenManager *scrManager, int width, int height, CVideoSurface **surface) { |