aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2016-07-16 12:36:02 -0400
committerPaul Gilbert2016-07-17 13:09:49 -0400
commit9b1efa3bf5696ea606b9374d216d4a1ecf52610b (patch)
treef747d0e110710a7002125b10a6101d55b7a1e929
parente1695101bc464fe1a4917f7cd25db38854c923e0 (diff)
downloadscummvm-rg350-9b1efa3bf5696ea606b9374d216d4a1ecf52610b.tar.gz
scummvm-rg350-9b1efa3bf5696ea606b9374d216d4a1ecf52610b.tar.bz2
scummvm-rg350-9b1efa3bf5696ea606b9374d216d4a1ecf52610b.zip
TITANIC: Added FMatrix methods
-rw-r--r--engines/titanic/star_control/dmatrix.h4
-rw-r--r--engines/titanic/star_control/dvector.cpp9
-rw-r--r--engines/titanic/star_control/dvector.h6
-rw-r--r--engines/titanic/star_control/fmatrix.cpp55
-rw-r--r--engines/titanic/star_control/fmatrix.h23
-rw-r--r--engines/titanic/star_control/fpoint.h9
-rw-r--r--engines/titanic/star_control/fvector.cpp22
-rw-r--r--engines/titanic/star_control/fvector.h22
-rw-r--r--engines/titanic/star_control/star_control_sub21.cpp118
-rw-r--r--engines/titanic/star_control/star_control_sub6.cpp10
-rw-r--r--engines/titanic/star_control/star_control_sub6.h12
11 files changed, 152 insertions, 138 deletions
diff --git a/engines/titanic/star_control/dmatrix.h b/engines/titanic/star_control/dmatrix.h
index 8c5eeeb584..565df80cd1 100644
--- a/engines/titanic/star_control/dmatrix.h
+++ b/engines/titanic/star_control/dmatrix.h
@@ -27,6 +27,10 @@
namespace Titanic {
+/**
+ * Double based matrix class.
+ * @remarks TODO: See if it can be merged with FMatrix
+ */
class DMatrix {
private:
DVector _row1;
diff --git a/engines/titanic/star_control/dvector.cpp b/engines/titanic/star_control/dvector.cpp
index 8e071cf0ab..e4c5b15cb0 100644
--- a/engines/titanic/star_control/dvector.cpp
+++ b/engines/titanic/star_control/dvector.cpp
@@ -21,8 +21,17 @@
*/
#include "titanic/star_control/dvector.h"
+#include "common/algorithm.h"
namespace Titanic {
+void DVector::fn3() {
+ double hyp = sqrt(_x * _x + _y * _y + _z * _z);
+ assert(hyp);
+
+ _x *= 1.0 / hyp;
+ _y *= 1.0 / hyp;
+ _z *= 1.0 / hyp;
+}
} // End of namespace Titanic
diff --git a/engines/titanic/star_control/dvector.h b/engines/titanic/star_control/dvector.h
index 32d2bdd229..7aca407c1c 100644
--- a/engines/titanic/star_control/dvector.h
+++ b/engines/titanic/star_control/dvector.h
@@ -25,12 +25,18 @@
namespace Titanic {
+/**
+ * Double based vector class.
+ * @remarks TODO: See if it can be merged with FVector
+ */
class DVector {
public:
double _x, _y, _z;
public:
DVector() : _x(0), _y(0), _z(0) {}
DVector(double x, double y, double z) : _x(x), _y(y), _z(z) {}
+
+ void fn3();
};
} // End of namespace Titanic
diff --git a/engines/titanic/star_control/fmatrix.cpp b/engines/titanic/star_control/fmatrix.cpp
index 52fc2bfd86..c53892d0fe 100644
--- a/engines/titanic/star_control/fmatrix.cpp
+++ b/engines/titanic/star_control/fmatrix.cpp
@@ -72,4 +72,59 @@ void FMatrix::set(FVector *row1, FVector *row2, FVector *row3) {
_row3 = *row3;
}
+void FMatrix::fn1(FVector *v) {
+ _row3._x = v->_x;
+
+ FVector tempVector;
+ tempVector.fn1(v);
+
+ _row2._x = tempVector._x;
+ _row2._y = tempVector._y;
+ _row2._z = tempVector._z;
+
+ _row3.multiply(v, &_row2);
+ _row1._x = _row2._x;
+ _row1._y = _row2._y;
+ _row1._z = _row2._z;
+ _row1.fn3();
+
+ _row3.multiply(&tempVector, &_row1);
+ _row2._x = _row1._x;
+ _row2._y = _row1._y;
+ _row2._z = _row1._z;
+ _row2.fn3();
+}
+
+void FMatrix::fn2(FMatrix *m) {
+ double x1 = _row1._y * m->_row2._x + _row1._z * m->_row3._x + _row1._x * m->_row1._x;
+ double y1 = _row1._x * m->_row1._y + m->_row2._y * _row1._y + m->_row3._y * _row1._z;
+ double z1 = _row1._x * m->_row1._z + _row1._y * m->_row2._z + _row1._z * m->_row3._z;
+ double x2 = m->_row1._x * _row2._x + m->_row3._x * _row2._z + m->_row2._x * _row2._y;
+ double y2 = m->_row3._y * _row2._z + m->_row1._y * _row2._x + m->_row2._y * _row2._y;
+ double z2 = _row2._z * m->_row3._z + _row2._x * m->_row1._z + _row2._y * m->_row2._z;
+ double x3 = m->_row1._x * _row3._x + _row3._z * m->_row3._x + _row3._y * m->_row2._x;
+ double y3 = _row3._y * m->_row2._y + _row3._z * m->_row3._y + _row3._x * m->_row1._y;
+ double z3 = _row3._x * m->_row1._z + _row3._y * m->_row2._z + _row3._z * m->_row3._z;
+
+ _row1 = FVector(x1, y1, z1);
+ _row2 = FVector(x2, y2, z2);
+ _row3 = FVector(x3, y3, z3);
+}
+
+void FMatrix::fn3(FMatrix *m) {
+ double x1 = _row2._x * m->_row1._y + m->_row1._z * _row3._x + _row1._x * m->_row1._x;
+ double y1 = m->_row1._x * _row1._y + _row3._y * m->_row1._z + _row2._y * m->_row1._y;
+ double z1 = m->_row1._x * _row1._z + m->_row1._y * _row2._z + m->_row1._z * _row3._z;
+ double x2 = _row1._x * m->_row2._x + _row2._x * m->_row2._y + _row3._x * m->_row2._z;
+ double y2 = _row3._y * m->_row2._z + _row1._y * m->_row2._x + _row2._y * m->_row2._y;
+ double z2 = m->_row2._z * _row3._z + m->_row2._x * _row1._z + m->_row2._y * _row2._z;
+ double x3 = _row1._x * m->_row3._x + m->_row3._z * _row3._x + m->_row3._y * _row2._x;
+ double y3 = m->_row3._y * _row2._y + m->_row3._z * _row3._y + m->_row3._x * _row1._y;
+ double 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);
+}
+
} // End of namespace Titanic
diff --git a/engines/titanic/star_control/fmatrix.h b/engines/titanic/star_control/fmatrix.h
index e98b160f01..391e117472 100644
--- a/engines/titanic/star_control/fmatrix.h
+++ b/engines/titanic/star_control/fmatrix.h
@@ -30,6 +30,10 @@ namespace Titanic {
class DMatrix;
+/**
+ * Floating point matrix class.
+ * @remarks TODO: See if it can be merged with DMatrix
+ */
class FMatrix {
private:
FVector _row1;
@@ -63,6 +67,25 @@ public:
* Sets the data for the matrix
*/
void set(FVector *row1, FVector *row2, FVector *row3);
+
+ void fn1(FVector *v);
+
+ void fn2(FMatrix *m);
+ void fn3(FMatrix *m);
+
+ /**
+ * Returns true if the passed matrix equals this one
+ */
+ bool operator==(const FMatrix &src) {
+ return _row1 == src._row1 && _row2 == src._row2 && _row3 == src._row3;
+ }
+
+ /**
+ * Returns true if the passed matrix does not equal this one
+ */
+ bool operator!=(const FMatrix &src) {
+ return !operator==(src);
+ }
};
} // End of namespace Titanic
diff --git a/engines/titanic/star_control/fpoint.h b/engines/titanic/star_control/fpoint.h
index 5329ecb9e3..f2cef18ea5 100644
--- a/engines/titanic/star_control/fpoint.h
+++ b/engines/titanic/star_control/fpoint.h
@@ -25,12 +25,15 @@
namespace Titanic {
-class FVector {
+/**
+ * Floating point Point class
+ */
+class FPoint {
public:
double _x, _y;
public:
- FVector() : _x(0), _y(0) {}
- FVector(double x, double y) : _x(x), _y(y) {}
+ FPoint() : _x(0), _y(0) {}
+ FPoint(double x, double y) : _x(x), _y(y) {}
};
} // End of namespace Titanic
diff --git a/engines/titanic/star_control/fvector.cpp b/engines/titanic/star_control/fvector.cpp
index 39d303c4dc..a7520bf508 100644
--- a/engines/titanic/star_control/fvector.cpp
+++ b/engines/titanic/star_control/fvector.cpp
@@ -21,8 +21,30 @@
*/
#include "titanic/star_control/fvector.h"
+#include "common/algorithm.h"
namespace Titanic {
+void FVector::fn1(FVector *v) {
+ v->_x = (ABS(_x - _y) < 0.00001 && ABS(_y - _z) < 0.00001 &&
+ ABS(_x - _z) < 0.00001) ? -_x : _x;
+ v->_y = _y;
+ v->_z = _z;
+}
+
+void FVector::multiply(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);
+}
+
+void FVector::fn3() {
+ double hyp = sqrt(_x * _x + _y * _y + _z * _z);
+ assert(hyp);
+
+ _x *= 1.0 / hyp;
+ _y *= 1.0 / hyp;
+ _z *= 1.0 / hyp;
+}
} // End of namespace Titanic
diff --git a/engines/titanic/star_control/fvector.h b/engines/titanic/star_control/fvector.h
index 86e6e384ac..75ad2f8fe0 100644
--- a/engines/titanic/star_control/fvector.h
+++ b/engines/titanic/star_control/fvector.h
@@ -25,12 +25,34 @@
namespace Titanic {
+/**
+ * Floating point vector class.
+ * @remarks TODO: See if it can be merged with DVector
+ */
class FVector {
public:
double _x, _y, _z;
public:
FVector() : _x(0), _y(0), _z(0) {}
FVector(double x, double y, double z) : _x(x), _y(y), _z(z) {}
+
+ void fn1(FVector *v);
+ void multiply(FVector *dest, const FVector *src);
+ void fn3();
+
+ /**
+ * Returns true if the passed vector equals this one
+ */
+ bool operator==(const FVector &src) const {
+ return _x != src._x || _y != src._y || _z != src._z;
+ }
+
+ /**
+ * Returns true if the passed vector does not equal this one
+ */
+ bool operator!=(const FVector &src) const {
+ return !operator==(src);
+ }
};
} // End of namespace Titanic
diff --git a/engines/titanic/star_control/star_control_sub21.cpp b/engines/titanic/star_control/star_control_sub21.cpp
index 958ee3813e..b606d15b41 100644
--- a/engines/titanic/star_control/star_control_sub21.cpp
+++ b/engines/titanic/star_control/star_control_sub21.cpp
@@ -20,125 +20,9 @@
*
*/
-#include "titanic/star_control/star_control_sub20.h"
+#include "titanic/star_control/star_control_sub21.h"
#include "common/textconsole.h"
namespace Titanic {
-CStarControlSub20::CStarControlSub20(void *src) {
- _lockCounter = 0;
- _dataP = nullptr;
-
- if (src) {
- copyFrom1(src);
- } else {
- _field4 = 0.0;
- _field8 = 0.0;
- _fieldC = 20.0;
- _field10 = 0.0;
- _field14 = 50000.0;
- _field18 = 1.0;
- _field1C = 1.0;
- _field20 = 0.0;
- }
-}
-
-CStarControlSub20::~CStarControlSub20() {
- clear();
-}
-
-void CStarControlSub20::copyFrom1(void *src) {
- error("TODO: CStarControlSub20::copyFrom1");
-}
-
-void CStarControlSub20::copyFrom2(void *src) {
- error("TODO: CStarControlSub20::copyFrom2");
-}
-
-void CStarControlSub20::proc4() {
- if (!isLocked() && _field4 < _field14) {
- _field8 += _field4;
- if (_fieldC == _field8)
- _field4 -= _field8;
- else
- _field4 += _field8;
- }
-}
-
-void CStarControlSub20::proc5() {
- if (!isLocked()) {
- _field8 -= _fieldC;
- if (_field8 == _field4)
- _field4 += _field8;
- else
- _field4 -= _field8;
-
- if (_field8 < 0.0)
- _field8 = 0.0;
- }
-}
-
-void CStarControlSub20::proc6() {
- if (!isLocked())
- _field4 = _field14;
-}
-
-void CStarControlSub20::proc7() {
- if (!isLocked()) {
- _field4 = 0.0;
- _field8 = 0.0;
- }
-}
-
-void CStarControlSub20::proc11(CErrorCode *errorCode, void *v2, void *v3) {
- if (_field4 > 0.0) {
- warning("TODO: CStarControlSub20::proc11");
- }
-}
-
-void CStarControlSub20::setData(void *data) {
- clear();
- _dataP = data;
-}
-
-void CStarControlSub20::clear() {
- if (_dataP) {
- delete _dataP;
- _dataP = nullptr;
- }
-}
-
-void CStarControlSub20::load(SimpleFile *file, int val) {
- if (!val) {
- _field4 = file->readFloat();
- _field8 = file->readFloat();
- _fieldC = file->readFloat();
- _field10 = file->readFloat();
- _field14 = file->readFloat();
- _field18 = file->readFloat();
- _field1C = file->readFloat();
- _field20 = file->readFloat();
- }
-}
-
-void CStarControlSub20::save(SimpleFile *file, int indent) {
- file->writeFloatLine(_field4, indent);
- file->writeFloatLine(_field8, indent);
- file->writeFloatLine(_fieldC, indent);
- file->writeFloatLine(_field10, indent);
- file->writeFloatLine(_field14, indent);
- file->writeFloatLine(_field18, indent);
- file->writeFloatLine(_field1C, indent);
- file->writeFloatLine(_field20, indent);
-}
-
-void CStarControlSub20::incLockCount() {
- ++_lockCounter;
-}
-
-void CStarControlSub20::decLockCount() {
- if (_lockCounter > 0)
- --_lockCounter;
-}
-
} // End of namespace Titanic
diff --git a/engines/titanic/star_control/star_control_sub6.cpp b/engines/titanic/star_control/star_control_sub6.cpp
index c4161813f4..dfa23d65b6 100644
--- a/engines/titanic/star_control/star_control_sub6.cpp
+++ b/engines/titanic/star_control/star_control_sub6.cpp
@@ -29,15 +29,7 @@ CStarControlSub6::CStarControlSub6() {
}
void CStarControlSub6::clear() {
- _field0 = 0x3F800000;
- _field4 = 0;
- _field8 = 0;
- _fieldC = 0;
- _field10 = 0x3F800000;
- _field14 = 0;
- _field18 = 0;
- _field1C = 0;
- _field20 = 0x3F800000;
+ _matrix.clear();
_field24 = 0;
_field28 = 0;
_field2C = 0;
diff --git a/engines/titanic/star_control/star_control_sub6.h b/engines/titanic/star_control/star_control_sub6.h
index 3531c76d1b..0c477ee345 100644
--- a/engines/titanic/star_control/star_control_sub6.h
+++ b/engines/titanic/star_control/star_control_sub6.h
@@ -23,19 +23,13 @@
#ifndef TITANIC_STAR_CONTROL_SUB6_H
#define TITANIC_STAR_CONTROL_SUB6_H
+#include "titanic/star_control/fmatrix.h"
+
namespace Titanic {
class CStarControlSub6 {
private:
- int _field0;
- int _field4;
- int _field8;
- int _fieldC;
- int _field10;
- int _field14;
- int _field18;
- int _field1C;
- int _field20;
+ FMatrix _matrix;
int _field24;
int _field28;
int _field2C;