diff options
Diffstat (limited to 'engines/titanic')
50 files changed, 1731 insertions, 491 deletions
diff --git a/engines/titanic/module.mk b/engines/titanic/module.mk index aaa2a99671..cdb3a64b3c 100644 --- a/engines/titanic/module.mk +++ b/engines/titanic/module.mk @@ -436,10 +436,10 @@ MODULE_OBJS := \ star_control/dvector.o \ star_control/fmatrix.o \ star_control/fpoint.o \ + star_control/frange.o \ star_control/frect.o \ star_control/fvector.o \ star_control/star_control_sub2.o \ - star_control/star_control_sub4.o \ star_control/star_control_sub5.o \ star_control/star_control_sub6.o \ star_control/star_control_sub7.o \ @@ -457,6 +457,7 @@ MODULE_OBJS := \ star_control/star_field.o \ star_control/star_points1.o \ star_control/star_points2.o \ + star_control/star_ref.o \ star_control/star_view.o \ star_control/surface_area.o \ star_control/surface_fader_base.o \ diff --git a/engines/titanic/star_control/base_star.cpp b/engines/titanic/star_control/base_star.cpp index a32263a926..ffe5fd05b4 100644 --- a/engines/titanic/star_control/base_star.cpp +++ b/engines/titanic/star_control/base_star.cpp @@ -22,6 +22,7 @@ #include "titanic/star_control/base_star.h" #include "titanic/star_control/star_control_sub12.h" +#include "titanic/star_control/star_ref.h" #include "titanic/titanic.h" namespace Titanic { @@ -44,6 +45,15 @@ void CBaseStarEntry::load(Common::SeekableReadStream &s) { _data[idx] = s.readUint32LE(); } +bool CBaseStarEntry::operator==(const CBaseStarEntry &s) const { + return _field0 == s._field0 && _field1 == s._field1 + && _field2 == s._field2 && _field3 == s._field3 + && _value == s._value && _position == s._position + && _data[0] == s._data[0] && _data[1] == s._data[1] + && _data[2] == s._data[2] && _data[3] == s._data[3] + && _data[4] == s._data[4]; +} + /*------------------------------------------------------------------------*/ CBaseStar::CBaseStar() : _minVal(0.0), _maxVal(1.0), _range(0.0), @@ -57,11 +67,11 @@ void CBaseStar::clear() { void CBaseStar::initialize() { _minVal = 9.9999998e10; _maxVal = -9.9999998e10; - _sub4.initialize(); + _minMax.reset(); for (uint idx = 0; idx < _data.size(); ++idx) { const CBaseStarEntry *entry = getDataPtr(idx); - _sub4.checkEntry(entry->_position); + _minMax.expand(entry->_position); if (entry->_value < _minVal) _minVal = entry->_value; @@ -191,13 +201,17 @@ void CBaseStar::draw4(CSurfaceArea *surfaceArea, CStarControlSub12 *sub12, CStar // TODO } -void CBaseStar::baseFn1(int v1, int v2, int v3, int v4) { - // TODO +int CBaseStar::baseFn1(CSurfaceArea *surfaceArea, CStarControlSub12 *sub12, + const Common::Point &pt) { + CStarRef1 ref(this, pt); + ref.process(surfaceArea, sub12); + return ref._index; } int CBaseStar::baseFn2(CSurfaceArea *surfaceArea, CStarControlSub12 *sub12) { - // TODO - return 0; + CStarRef3 ref(this); + ref.process(surfaceArea, sub12); + return ref._index; } } // End of namespace Titanic diff --git a/engines/titanic/star_control/base_star.h b/engines/titanic/star_control/base_star.h index 1450b25bb3..8fc36ba6c7 100644 --- a/engines/titanic/star_control/base_star.h +++ b/engines/titanic/star_control/base_star.h @@ -24,7 +24,7 @@ #define TITANIC_STAR_CONTROL_SUB3_H #include "titanic/support/simple_file.h" -#include "titanic/star_control/star_control_sub4.h" +#include "titanic/star_control/frange.h" #include "titanic/star_control/star_control_sub5.h" #include "titanic/star_control/surface_area.h" @@ -44,7 +44,23 @@ struct CBaseStarEntry { uint _data[5]; CBaseStarEntry(); + + /** + * Loads the data for a star + */ void load(Common::SeekableReadStream &s); + + bool operator==(const CBaseStarEntry &s) const; +}; + +struct CStarPosition : public Common::Point { + int _index1; + int _index2; + CStarPosition() : _index1(0), _index2(0) {} + + bool operator==(const CStarPosition &sp) const { + return x == sp.x && y == sp.y && _index1 == sp._index1 && _index2 == sp._index2; + } }; class CBaseStar { @@ -55,7 +71,7 @@ private: void draw4(CSurfaceArea *surfaceArea, CStarControlSub12 *sub12, CStarControlSub5 *sub5); protected: Common::Array<CBaseStarEntry> _data; - CStarControlSub4 _sub4; + FRange _minMax; double _minVal; double _maxVal; double _range; @@ -76,9 +92,6 @@ protected: * Reset the data for an entry */ void resetEntry(CBaseStarEntry &entry); - - void baseFn1(int v1, int v2, int v3, int v4); - int baseFn2(CSurfaceArea *surfaceArea, CStarControlSub12 *sub12); public: CBaseStar(); virtual ~CBaseStar() {} @@ -94,7 +107,7 @@ public: * Selects a star */ virtual bool selectStar(CSurfaceArea *surfaceArea, CStarControlSub12 *sub12, - int flags, const Common::Point &pt) { return false; } + const Common::Point &pt, void *handler = nullptr) { return false; } /** * Adds a new star, or removes one if already present at the given co-ordinates @@ -126,6 +139,11 @@ public: * Get a pointer to a data entry */ const CBaseStarEntry *getDataPtr(int index) const; + + int baseFn1(CSurfaceArea *surfaceArea, CStarControlSub12 *sub12, + const Common::Point &pt); + + int baseFn2(CSurfaceArea *surfaceArea, CStarControlSub12 *sub12); }; } // End of namespace Titanic diff --git a/engines/titanic/star_control/dmatrix.cpp b/engines/titanic/star_control/dmatrix.cpp index 70008054b6..940b34833f 100644 --- a/engines/titanic/star_control/dmatrix.cpp +++ b/engines/titanic/star_control/dmatrix.cpp @@ -29,25 +29,40 @@ namespace Titanic { DMatrix *DMatrix::_static; DMatrix::DMatrix() : - _row1(1.0, 0.0, 0.0), _row2(0.0, 1.0, 0.0), _row3(0.0, 0.0, 1.0) { + _row1(1.875, 0.0, 0.0), _row2(0.0, 1.875, 0.0), _row3(0.0, 0.0, 1.875) { } -DMatrix::DMatrix(int mode, const FMatrix *src) { - assert(!mode); - - _row1._x = 1.0; - _row2._y = 1.0; - _row3._z = 1.0; - _frow1._x = src->_row1._x; - _frow1._y = src->_row1._y; - _frow1._z = src->_row1._z; - _frow2._x = src->_row2._x; - _frow2._y = src->_row2._y; - _frow2._z = src->_row2._z; +DMatrix::DMatrix(int mode, const DVector &src) { + switch (mode) { + case 0: + _row1._x = 1.0; + _row2._y = 1.0; + _row3._z = 1.0; + _row4 = src; + break; + + case 1: + _row1._x = src._x; + _row2._y = src._y; + _row3._z = src._z; + break; + + default: + _row1._x = 1.0; + _row2._y = 1.0; + _row3._z = 1.0; + break; + } } -DMatrix::DMatrix(int mode, double val) { - set(mode, val); +DMatrix::DMatrix(Axis axis, double amount) { + setRotationMatrix(axis, amount); +} + +DMatrix::DMatrix(const FMatrix &src) { + _row1 = src._row1; + _row2 = src._row2; + _row3 = src._row3; } void DMatrix::init() { @@ -59,13 +74,13 @@ void DMatrix::deinit() { _static = nullptr; } -void DMatrix::set(int mode, double amount) { +void DMatrix::setRotationMatrix(Axis axis, double amount) { const double FACTOR = 0.0174532925199433; double sinVal = sin(amount * FACTOR); double cosVal = cos(amount * FACTOR); - switch (mode) { - case 0: + switch (axis) { + case X_AXIS: _row1._x = 1.0; _row2._y = cosVal; _row2._z = sinVal; @@ -73,7 +88,7 @@ void DMatrix::set(int mode, double amount) { _row3._z = cosVal; break; - case 1: + case Y_AXIS: _row1._x = cosVal; _row1._z = sinVal; _row2._y = 1.0; @@ -81,7 +96,7 @@ void DMatrix::set(int mode, double amount) { _row3._z = cosVal; break; - case 2: + case Z_AXIS: _row1._x = cosVal; _row1._y = sinVal; _row2._x = -sinVal; @@ -94,6 +109,10 @@ void DMatrix::set(int mode, double amount) { } } +void DMatrix::fn1(DMatrix &m) { + // TODO +} + void DMatrix::fn3(CStarControlSub26 *sub26) { double v = sub26->fn1(); v = (v < 0.0) ? 0.0 : 2.0 / v; @@ -101,4 +120,9 @@ void DMatrix::fn3(CStarControlSub26 *sub26) { error("TODO: DMatrix::fn3 %d", (int)v); } +const DMatrix *DMatrix::fn4(DMatrix &dest, const DMatrix &m1, const DMatrix &m2) { + // TODO + return nullptr; +} + } // End of namespace Titanic diff --git a/engines/titanic/star_control/dmatrix.h b/engines/titanic/star_control/dmatrix.h index 14f6bb0331..c3490770fb 100644 --- a/engines/titanic/star_control/dmatrix.h +++ b/engines/titanic/star_control/dmatrix.h @@ -42,22 +42,25 @@ public: DVector _row1; DVector _row2; DVector _row3; - FVector _frow1; - FVector _frow2; + DVector _row4; public: static void init(); static void deinit(); public: DMatrix(); - DMatrix(int mode, const FMatrix *src); - DMatrix(int mode, double val); + DMatrix(int mode, const DVector &src); + DMatrix(Axis axis, double amount); + DMatrix(const FMatrix &src); /** - * Sets up data for the matrix + * Sets up a matrix for rotating on a given axis by a given amount */ - void set(int mode, double amount); + void setRotationMatrix(Axis axis, double amount); + void fn1(DMatrix &m); void fn3(CStarControlSub26 *sub26); + + const DMatrix *fn4(DMatrix &dest, const DMatrix &m1, const DMatrix &m2); }; } // End of namespace Titanic diff --git a/engines/titanic/star_control/dvector.cpp b/engines/titanic/star_control/dvector.cpp index e4c5b15cb0..dc1376537e 100644 --- a/engines/titanic/star_control/dvector.cpp +++ b/engines/titanic/star_control/dvector.cpp @@ -25,7 +25,7 @@ namespace Titanic { -void DVector::fn3() { +void DVector::normalize() { double hyp = sqrt(_x * _x + _y * _y + _z * _z); assert(hyp); @@ -34,4 +34,29 @@ void DVector::fn3() { _z *= 1.0 / hyp; } +double DVector::getDistance(const DVector &src) { + return sqrt((src._x - _x) * (src._x - _x) + (src._y - _y) * (src._y - _y) + (src._z - _z) * (src._z - _z)); +} + +void DVector::fn1(DVector &dest, const DMatrix &m) { + // TODO +} + +void DVector::fn2(double val) { + // TODO +} + +void DVector::fn3(DVector &dest) { + // TODO +} + +const DMatrix *DVector::fn4(const DVector &v, DMatrix &m) { + // TODO + return nullptr; +} + +void DVector::fn5(DMatrix &dest) { + // TODO +} + } // End of namespace Titanic diff --git a/engines/titanic/star_control/dvector.h b/engines/titanic/star_control/dvector.h index 7aca407c1c..a216be15fe 100644 --- a/engines/titanic/star_control/dvector.h +++ b/engines/titanic/star_control/dvector.h @@ -23,8 +23,12 @@ #ifndef TITANIC_DVECTOR_H #define TITANIC_DVECTOR_H +#include "titanic/star_control/fvector.h" + namespace Titanic { +class DMatrix; + /** * Double based vector class. * @remarks TODO: See if it can be merged with FVector @@ -35,8 +39,20 @@ public: public: DVector() : _x(0), _y(0), _z(0) {} DVector(double x, double y, double z) : _x(x), _y(y), _z(z) {} + DVector(const FVector &v) : _x(v._x), _y(v._y), _z(v._z) {} + + void normalize(); + + /** + * Returns the distance between this vector and the passed one + */ + double getDistance(const DVector &src); - void fn3(); + void fn1(DVector &dest, const DMatrix &m); + void fn2(double val); + void fn3(DVector &dest); + const DMatrix *fn4(const DVector &v, DMatrix &m); + void fn5(DMatrix &dest); }; } // End of namespace Titanic diff --git a/engines/titanic/star_control/fmatrix.cpp b/engines/titanic/star_control/fmatrix.cpp index af15477d04..02da11576c 100644 --- a/engines/titanic/star_control/fmatrix.cpp +++ b/engines/titanic/star_control/fmatrix.cpp @@ -28,17 +28,17 @@ FMatrix::FMatrix() : _row1(1.0, 0.0, 0.0), _row2(0.0, 1.0, 0.0), _row3(0.0, 0.0, 1.0) { } -FMatrix::FMatrix(DMatrix *src) { +FMatrix::FMatrix(const DMatrix &src) { copyFrom(src); } -FMatrix::FMatrix(FMatrix *src) { - _row1 = src->_row1; - _row2 = src->_row2; - _row3 = src->_row3; +FMatrix::FMatrix(const FMatrix &src) { + _row1 = src._row1; + _row2 = src._row2; + _row3 = src._row3; } -void FMatrix::copyFrom(const DMatrix *src) { +void FMatrix::copyFrom(const DMatrix &src) { // TODO } @@ -67,19 +67,25 @@ 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); } -void FMatrix::set(FVector *row1, FVector *row2, FVector *row3) { - _row1 = *row1; - _row2 = *row2; - _row3 = *row3; +void FMatrix::set(const FVector &row1, const FVector &row2, const FVector &row3) { + _row1 = row1; + _row2 = row2; + _row3 = row3; } -void FMatrix::fn1(const FVector *v) { - _row3._x = v->_x; +void FMatrix::fn1(const FVector &v) { + _row3._x = v._x; FVector tempVector; _row3.fn1(&tempVector); @@ -88,45 +94,45 @@ 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(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; +void FMatrix::fn2(const 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; +void FMatrix::fn3(const 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); diff --git a/engines/titanic/star_control/fmatrix.h b/engines/titanic/star_control/fmatrix.h index d7c4acfbdc..6fa847f950 100644 --- a/engines/titanic/star_control/fmatrix.h +++ b/engines/titanic/star_control/fmatrix.h @@ -39,15 +39,15 @@ private: /** * Copys data from a given source */ - void copyFrom(const DMatrix *src); + void copyFrom(const DMatrix &src); public: FVector _row1; FVector _row2; FVector _row3; public: FMatrix(); - FMatrix(DMatrix *src); - FMatrix(FMatrix *src); + FMatrix(const DMatrix &src); + FMatrix(const FMatrix &src); /** * Load the data for the class from file @@ -65,14 +65,18 @@ public: void clear(); /** - * Sets the data for the matrix + * Sets up an identity matrix */ - void set(FVector *row1, FVector *row2, FVector *row3); + void identity(); - void fn1(const FVector *v); + /** + * Sets the data for the matrix + */ + void set(const FVector &row1, const FVector &row2, const FVector &row3); - void fn2(FMatrix *m); - void fn3(FMatrix *m); + void fn1(const FVector &v); + void fn2(const FMatrix &m); + void fn3(const FMatrix &m); /** * Returns true if the passed matrix equals this one @@ -91,4 +95,4 @@ public: } // End of namespace Titanic -#endif /* TITANIC_MATRIX3_H */ +#endif /* TITANIC_FMATRIX_H */ diff --git a/engines/titanic/star_control/star_control_sub4.cpp b/engines/titanic/star_control/frange.cpp index 6ce0795c25..e70976d6cd 100644 --- a/engines/titanic/star_control/star_control_sub4.cpp +++ b/engines/titanic/star_control/frange.cpp @@ -21,19 +21,19 @@ */ #include "common/algorithm.h" -#include "titanic/star_control/star_control_sub4.h" +#include "titanic/star_control/frange.h" namespace Titanic { -CStarControlSub4::CStarControlSub4() { +FRange::FRange() { } -void CStarControlSub4::initialize() { +void FRange::reset() { _min._x = _min._y = _min._z = 9.9999994e27; _max._x = _max._y = _max._z = -9.9999994e27; } -void CStarControlSub4::checkEntry(const FVector &v) { +void FRange::expand(const FVector &v) { _min._x = MIN(_min._x, v._x); _min._y = MIN(_min._y, v._y); _min._z = MIN(_min._z, v._z); diff --git a/engines/titanic/star_control/star_control_sub4.h b/engines/titanic/star_control/frange.h index 43c8ab5f79..f36aa2c538 100644 --- a/engines/titanic/star_control/star_control_sub4.h +++ b/engines/titanic/star_control/frange.h @@ -20,25 +20,31 @@ * */ -#ifndef TITANIC_STAR_CONTROL_SUB4_H -#define TITANIC_STAR_CONTROL_SUB4_H +#ifndef TITANIC_FRANGE_H +#define TITANIC_FRANGE_H #include "titanic/star_control/fvector.h" namespace Titanic { -class CStarControlSub4 { +class FRange { private: FVector _min; FVector _max; public: - CStarControlSub4(); + FRange(); - void initialize(); + /** + * Resets the minimum & maximum vector values + */ + void reset(); - void checkEntry(const FVector &v); + /** + * Expands the minimum & maximum as necessary to encompass the passed vector/ + */ + void expand(const FVector &v); }; } // End of namespace Titanic -#endif /* TITANIC_STAR_CONTROL_SUB4_H */ +#endif /* TITANIC_FRANGE_H */ diff --git a/engines/titanic/star_control/fvector.cpp b/engines/titanic/star_control/fvector.cpp index aa99e8b4d1..92c17a09b4 100644 --- a/engines/titanic/star_control/fvector.cpp +++ b/engines/titanic/star_control/fvector.cpp @@ -34,19 +34,27 @@ 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); } -void FVector::fn3() { +double FVector::normalize() { double hyp = sqrt(_x * _x + _y * _y + _z * _z); assert(hyp); _x *= 1.0 / hyp; _y *= 1.0 / hyp; _z *= 1.0 / hyp; + 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 { @@ -57,14 +65,7 @@ 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 { +FVector FVector::fn5(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 e19419bf20..4582072f50 100644 --- a/engines/titanic/star_control/fvector.h +++ b/engines/titanic/star_control/fvector.h @@ -27,6 +27,8 @@ namespace Titanic { +enum Axis { X_AXIS, Y_AXIS, Z_AXIS }; + class CStarControlSub6; /** @@ -48,16 +50,28 @@ public: } void fn1(FVector *v); - void multiply(FVector *dest, const FVector *src); - void 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; + FVector fn5(const CStarControlSub6 *sub6) const; /** * Returns true if the passed vector equals this one diff --git a/engines/titanic/star_control/star_control_sub12.cpp b/engines/titanic/star_control/star_control_sub12.cpp index 79061301d3..4e6a6bc0f2 100644 --- a/engines/titanic/star_control/star_control_sub12.cpp +++ b/engines/titanic/star_control/star_control_sub12.cpp @@ -29,9 +29,8 @@ namespace Titanic { FMatrix *CStarControlSub12::_matrix1; FMatrix *CStarControlSub12::_matrix2; -CStarControlSub12::CStarControlSub12(void *val1, const CStar20Data *data) : - _currentIndex(-1), _handlerP(nullptr), _field108(0), - _sub13(val1) { +CStarControlSub12::CStarControlSub12(const CStar20Data *data) : + _currentIndex(-1), _handlerP(nullptr), _field108(0) { setupHandler(data); } @@ -55,7 +54,7 @@ CStarControlSub12::~CStarControlSub12() { deleteHandler(); } -void CStarControlSub12::proc2(const void *src) { +void CStarControlSub12::proc2(const CStarControlSub13 *src) { _sub13.copyFrom(src); } @@ -114,12 +113,11 @@ void CStarControlSub12::proc13(CStarControlSub13 *dest) { *dest = _sub13; } -void CStarControlSub12::proc14(int v) { - FMatrix matrix; - _sub13.getMatrix(&matrix); +void CStarControlSub12::proc14(FVector &v) { + FMatrix matrix = _sub13.getMatrix(); FVector vector = _sub13._position; - _handlerP->proc9(&vector, v, &matrix); + _handlerP->proc9(vector, v, matrix); } void CStarControlSub12::proc15(CErrorCode *errorCode) { @@ -128,12 +126,12 @@ void CStarControlSub12::proc15(CErrorCode *errorCode) { if (!_matrix2) _matrix2 = new FMatrix(); - _sub13.getMatrix(_matrix1); + *_matrix1 = _sub13.getMatrix(); *_matrix2 = *_matrix1; FVector v1 = _sub13._position; FVector v2 = _sub13._position; - _handlerP->proc11(*errorCode, v2, _matrix2); + _handlerP->proc11(*errorCode, v2, *_matrix2); if (v1 != v2) { _sub13.setPosition(v2); @@ -141,7 +139,7 @@ void CStarControlSub12::proc15(CErrorCode *errorCode) { } if (_matrix1 != _matrix2) { - _sub13.setMatrix(_matrix2); + _sub13.setMatrix(*_matrix2); } } @@ -161,12 +159,12 @@ void CStarControlSub12::proc19() { _handlerP->proc7(); } -void CStarControlSub12::proc20(double v) { +void CStarControlSub12::proc20(double factor) { if (!isLocked()) - _sub13.fn14(v); + _sub13.reposition(factor); } -void CStarControlSub12::proc21(CStarControlSub6 &sub6) { +void CStarControlSub12::proc21(const CStarControlSub6 *sub6) { if (!isLocked()) { _sub13.setPosition(sub6); set108(); @@ -217,8 +215,103 @@ FVector CStarControlSub12::proc31(int index, const FVector &v) { return _sub13.fn18(index, v); } -void CStarControlSub12::setViewportPosition(const FPoint &pt) { - // TODO +void CStarControlSub12::setViewportPosition(const FPoint &angles) { + if (isLocked()) + return; + + if (_currentIndex == -1) { + CStarControlSub6 subX(X_AXIS, angles._x); + CStarControlSub6 subY(Y_AXIS, angles._y); + CStarControlSub6 sub(&subX, &subY); + subY.copyFrom(&sub); + proc22(subY); + } else if (_currentIndex == 0) { + FVector row1 = _matrix._row1; + CStarControlSub6 subX(X_AXIS, angles._x); + CStarControlSub6 subY(Y_AXIS, angles._y); + CStarControlSub6 sub(&subX, &subY); + subX.copyFrom(&sub); + + FMatrix m1 = _sub13.getMatrix(); + FVector tempV1 = _sub13._position; + FVector tempV2, tempV3, tempV4, tempV5, tempV6; + tempV2._y = m1._row1._y * 100000.0; + tempV2._z = m1._row1._z * 100000.0; + tempV3._x = m1._row1._x * 100000.0 + tempV1._x; + tempV4._x = tempV3._x; + tempV3._y = tempV2._y + tempV1._y; + tempV4._y = tempV3._y; + tempV3._z = tempV2._z + tempV1._z; + tempV4._z = tempV3._z; + tempV2._x = m1._row2._x * 100000.0; + tempV2._y = m1._row2._y * 100000.0; + tempV2._z = m1._row2._z * 100000.0; + tempV2._x = m1._row3._x * 100000.0; + tempV2._y = m1._row3._y * 100000.0; + tempV2._z = m1._row3._z * 100000.0; + tempV2._x = tempV2._x + tempV1._x; + tempV2._y = tempV2._y + tempV1._y; + tempV2._z = tempV2._z + tempV1._z; + tempV3._x = tempV2._x + tempV1._x; + tempV3._y = tempV2._y + tempV1._y; + tempV5._x = tempV2._x; + tempV5._y = tempV2._y; + tempV3._z = tempV2._z + tempV1._z; + tempV5._z = tempV2._z; + tempV6._x = tempV3._x; + tempV6._y = tempV3._y; + tempV6._z = tempV3._z; + tempV1._x = tempV1._x - row1._x; + tempV1._y = tempV1._y - row1._y; + tempV1._z = tempV1._z - row1._z; + tempV4._x = tempV3._x - row1._x; + tempV4._y = tempV4._y - row1._y; + tempV4._z = tempV4._z - row1._z; + tempV5._x = tempV2._x - row1._x; + + tempV5._y = tempV5._y - row1._y; + tempV5._z = tempV5._z - row1._z; + tempV6._x = tempV3._x - row1._x; + tempV6._y = tempV6._y - row1._y; + tempV6._z = tempV6._z - row1._z; + + FVector modV1 = tempV1.fn5(&subX); + FVector modV2 = tempV4.fn5(&subX); + FVector modV3 = tempV5.fn5(&subX); + FVector modV4 = tempV6.fn5(&subX); + tempV1 = modV1; + tempV4 = modV2; + tempV5 = modV3; + tempV4 = modV4; + + tempV2._x = tempV4._x - tempV1._x; + tempV2._y = tempV4._y - tempV1._y; + tempV2._z = tempV4._z - tempV1._z; + tempV4._x = tempV2._x; + tempV4._y = tempV2._y; + tempV2._x = tempV5._x - tempV1._x; + tempV4._z = tempV2._z; + tempV5._x = tempV2._x; + tempV2._y = tempV5._y - tempV1._y; + tempV5._y = tempV2._y; + tempV2._z = tempV5._z - tempV1._z; + tempV5._z = tempV2._z; + tempV2._x = tempV6._x - tempV1._x; + tempV2._y = tempV6._y - tempV1._y; + tempV2._z = tempV6._z - tempV1._z; + tempV6 = tempV2; + + tempV4.normalize(); + tempV5.normalize(); + tempV6.normalize(); + tempV1 += row1; + + m1.set(tempV4, tempV5, tempV6); + _sub13.setMatrix(m1); + _sub13.setPosition(tempV1); + } else if (_currentIndex == 1) { + // TODO + } } bool CStarControlSub12::setArrayVector(const FVector &v) { diff --git a/engines/titanic/star_control/star_control_sub12.h b/engines/titanic/star_control/star_control_sub12.h index 5fac6bf11a..b1a25682d7 100644 --- a/engines/titanic/star_control/star_control_sub12.h +++ b/engines/titanic/star_control/star_control_sub12.h @@ -39,7 +39,7 @@ private: static FMatrix *_matrix2; private: int _currentIndex; - FVector _array[3]; + FMatrix _matrix; CStarControlSub20 *_handlerP; CStarControlSub13 _sub13; int _field108; @@ -62,11 +62,11 @@ public: static void init(); static void deinit(); public: - CStarControlSub12(void *val1, const CStar20Data *data); + CStarControlSub12(const CStar20Data *data); CStarControlSub12(CStarControlSub13 *src); virtual ~CStarControlSub12(); - virtual void proc2(const void *src); + virtual void proc2(const CStarControlSub13 *src); virtual void proc3(const CStar20Data *src); virtual void setPosition(const FVector &v); virtual void proc5(const FVector &v); @@ -78,14 +78,14 @@ public: virtual void proc11(); virtual void proc12(StarMode mode, double v2); virtual void proc13(CStarControlSub13 *dest); - virtual void proc14(int v); + virtual void proc14(FVector &v); virtual void proc15(CErrorCode *errorCode); virtual void proc16(); virtual void proc17(); virtual void proc18(); virtual void proc19(); - virtual void proc20(double v); - virtual void proc21(CStarControlSub6 &sub6); + virtual void proc20(double factor); + virtual void proc21(const CStarControlSub6 *sub6); virtual void proc22(FMatrix &m); virtual CStarControlSub6 proc23(); virtual CStarControlSub6 proc24(); @@ -100,7 +100,7 @@ public: /** * Sets the viewport position within the starfield */ - virtual void setViewportPosition(const FPoint &pt); + virtual void setViewportPosition(const FPoint &angles); virtual int getCurrentIndex() const { return _currentIndex; } virtual bool setArrayVector(const FVector &v); diff --git a/engines/titanic/star_control/star_control_sub13.cpp b/engines/titanic/star_control/star_control_sub13.cpp index d70ad55f4a..6512d12232 100644 --- a/engines/titanic/star_control/star_control_sub13.cpp +++ b/engines/titanic/star_control/star_control_sub13.cpp @@ -21,29 +21,27 @@ */ #include "titanic/star_control/star_control_sub13.h" +#include "titanic/titanic.h" namespace Titanic { -CStarControlSub13::CStarControlSub13(void *src) : - _fieldC0(0), _fieldC4(0), _fieldC8(0.0), _fieldCC(0.0), _fieldD0(0.0) { - if (src) { - setup(src); - } else { - _fieldC = 0; - _field10 = 0x44480000; - _field14 = 0x461C4000; - _field18 = 0x41A00000; - _field1C = 0x41A00000; - _width = 600; - _height = 340; - _field24 = 0; - } - - _fieldD4 = 0; +CStarControlSub13::CStarControlSub13() { + _fieldC = 0; + _field10 = 800.0; + _field14 = 10000.0; + _field18 = 20.0; + _field1C = 20.0; + _width = 600; + _height = 340; + _field24 = 0; + _fieldC0 = _fieldC4 = _fieldC8 = 0.0; + _fieldCC = _fieldD0 = 0.0; + _flag = false; + Common::fill(&_valArray[0], &_valArray[5], 0.0); } CStarControlSub13::CStarControlSub13(CStarControlSub13 *src) : - _matrix(&src->_matrix), _sub1(&src->_sub1), _sub2(&src->_sub2) { + _matrix(src->_matrix), _sub1(&src->_sub1), _sub2(&src->_sub2) { _position = src->_position; _fieldC = src->_fieldC; _field10 = src->_field10; @@ -60,26 +58,17 @@ CStarControlSub13::CStarControlSub13(CStarControlSub13 *src) : _fieldC8 = src->_fieldC8; _field24 = src->_field24; - _valArray[0] = src->_valArray[0]; - _valArray[2] = src->_valArray[2]; - _valArray[3] = src->_valArray[3]; - _fieldD4 = 0; -} - -void CStarControlSub13::setup(void *ptr) { - // TODO + Common::copy(&src->_valArray[0], &src->_valArray[4], &_valArray[0]); + _flag = false; } -void CStarControlSub13::copyFrom(const void *src) { - if (!src) - return; -/* - _field0 = src->_field0; - _field4 = src->_field4; - _field8 = src->_field8; - _fieldC = src->_field18; - _field10 = src->_field1C; - */ +void CStarControlSub13::copyFrom(const CStarControlSub13 *src) { + if (src) { + // TODO: Not really certain src is a CStarControlSub13 + _position = src->_position; + _fieldC = src->_field18; + _field10 = src->_field1C; + } } void CStarControlSub13::load(SimpleFile *file, int param) { @@ -101,7 +90,7 @@ void CStarControlSub13::load(SimpleFile *file, int param) { _valArray[idx] = file->readFloat(); _matrix.load(file, param); - _fieldD4 = 0; + _flag = false; } void CStarControlSub13::save(SimpleFile *file, int indent) { @@ -123,53 +112,62 @@ void CStarControlSub13::save(SimpleFile *file, int indent) { void CStarControlSub13::setPosition(const FVector &v) { _position = v; - _fieldD4 = 0; + _flag = false; } -void CStarControlSub13::setPosition(const CStarControlSub6 &sub6) { - FVector vector; - _position.fn5(&vector, &sub6); - _position = sub6._row1; - _fieldD4 = 0; +void CStarControlSub13::setPosition(const CStarControlSub6 *sub6) { + _position.fn5(sub6); + _position = sub6->_row1; + _flag = false; } void CStarControlSub13::setMatrix(const FMatrix &m) { _matrix = m; - _fieldD4 = 0; + _flag = false; } void CStarControlSub13::fn11(const FVector &v) { - _matrix.fn1(&v); - _fieldD4 = 0; + _matrix.fn1(v); + _flag = false; } -void CStarControlSub13::setC(int v) { +void CStarControlSub13::setC(double v) { _fieldC = v; - _fieldD4 = 0; + _flag = false; } -void CStarControlSub13::set10(int v) { +void CStarControlSub13::set10(double v) { _field10 = v; - _fieldD4 = 0; + _flag = false; } -void CStarControlSub13::set14(int v) { +void CStarControlSub13::set14(double v) { _field10 = v; } -void CStarControlSub13::set18(int v) { +void CStarControlSub13::set18(double v) { _field18 = v; - _fieldD4 = 0; + _flag = false; } -void CStarControlSub13::set1C(int v) { +void CStarControlSub13::set1C(double v) { _field1C = v; - _fieldD4 = 0; + _flag = false; } void CStarControlSub13::fn12() { - _matrix.clear(); - error("TODO: CStarControlSub13::fn12"); + _matrix.identity(); + + CStarControlSub6 m1(X_AXIS, g_vm->getRandomNumber(359)); + CStarControlSub6 m2(Y_AXIS, g_vm->getRandomNumber(359)); + CStarControlSub6 m3(Z_AXIS, g_vm->getRandomNumber(359)); + + CStarControlSub6 s1(&m1, &m2); + CStarControlSub6 s2(&s1, &m3); + + m1.copyFrom(s2); + _matrix.fn2(m1); + _flag = false; } void CStarControlSub13::fn13(StarMode mode, double v2) { @@ -185,52 +183,95 @@ void CStarControlSub13::fn13(StarMode mode, double v2) { _field24 = v2 ? 2 : 0; } -void CStarControlSub13::fn14(double v) { - error("TODO: CStarControlSub13::fn14"); +void CStarControlSub13::reposition(double factor) { + _position._x = _matrix._row3._x * factor + _position._x; + _position._y = _matrix._row3._y * factor + _position._y; + _position._z = _matrix._row3._z * factor + _position._z; + _flag = false; } -void CStarControlSub13::fn15(FMatrix &matrix) { - _matrix.fn3(&matrix); - _fieldD4 = 0; +void CStarControlSub13::fn15(const FMatrix &matrix) { + _matrix.fn3(matrix); + _flag = false; } CStarControlSub6 CStarControlSub13::getSub1() { - if (!_fieldD4) + if (!_flag) reset(); return _sub1; } CStarControlSub6 CStarControlSub13::getSub2() { - if (!_fieldD4) + if (!_flag) reset(); return _sub2; } void CStarControlSub13::fn16(int index, const FVector &src, FVector &dest) { - error("TODO: CStarControlSub13::fn16"); + CStarControlSub6 temp = getSub1(); + + dest._x = temp._row3._x * src._z + temp._row2._x * src._y + + src._x * temp._row1._x + temp._vector._x; + dest._y = temp._row3._y * src._z + temp._row2._y * src._y + + src._x * temp._row1._y + temp._vector._y; + dest._z = temp._row3._z * src._z + temp._row2._z * src._y + + src._x * temp._row1._z + temp._vector._z; } -FVector CStarControlSub13::fn17(int index, const FVector &v) { - error("TODO: CStarControlSub13::fn17"); +FVector CStarControlSub13::fn17(int index, const FVector &src) { + FVector dest; + CStarControlSub6 sub6 = getSub1(); + FVector tv = src.fn5(&sub6); + + dest._x = (_valArray[index] + tv._x) + * _fieldC8 / (_fieldCC * tv._z); + dest._y = (tv._y * _fieldC8) / (_fieldD0 * tv._z); + dest._z = tv._z; + return dest; } -FVector CStarControlSub13::fn18(int index, const FVector &v) { - error("TODO: CStarControlSub13::fn17"); +FVector CStarControlSub13::fn18(int index, const FVector &src) { + FVector dest; + CStarControlSub6 sub6 = getSub2(); + FVector tv = src.fn5(&sub6); + + dest._x = (_valArray[index] + tv._x) + * _fieldC8 / (_fieldCC * tv._z); + dest._y = (tv._y * _fieldC8) / (_fieldD0 * tv._z); + dest._z = tv._z; + return dest; } void CStarControlSub13::fn19(double *v1, double *v2, double *v3, double *v4) { - error("TODO: CStarControlSub13::fn19"); + *v1 = _fieldC8 / _fieldCC; + *v2 = _fieldC8 / _fieldD0; + *v3 = _valArray[3]; + *v4 = _valArray[4]; } void CStarControlSub13::reset() { - //const double FACTOR = 3.1415927 * 0.0055555557; - error("TODO: CStarControlSub13::reset"); + const double FACTOR = 2 * M_PI / 360.0; + + _sub2.copyFrom(_matrix); + _sub2._vector._x = _position._x; + _sub2._vector._y = _position._y; + _sub2._vector._z = _position._z; + _sub2.fn4(&_sub1); + + double widthV = (double)_width * 0.5; + double heightV = (double)_height * 0.5; + _fieldC0 = widthV; + _fieldC4 = heightV; + _fieldC8 = MIN(widthV, heightV); + _fieldCC = tan(_field18 * FACTOR); + _fieldD0 = tan(_field1C * FACTOR); + _flag = true; } -void CStarControlSub13::getMatrix(FMatrix *matrix) { - *matrix = _matrix; +const FMatrix &CStarControlSub13::getMatrix() const { + return _matrix; } } // End of namespace Titanic diff --git a/engines/titanic/star_control/star_control_sub13.h b/engines/titanic/star_control/star_control_sub13.h index 047df987d2..80b2e55c4b 100644 --- a/engines/titanic/star_control/star_control_sub13.h +++ b/engines/titanic/star_control/star_control_sub13.h @@ -42,10 +42,8 @@ private: CStarControlSub6 _sub2; double _fieldC0; double _fieldC4; - int _fieldD4; + bool _flag; private: - void setup(void *ptr); - void reset(); public: FVector _position; @@ -57,10 +55,13 @@ public: double _fieldCC; double _fieldD0; public: - CStarControlSub13(void *ptr); + CStarControlSub13(); CStarControlSub13(CStarControlSub13 *src); - void copyFrom(const void *src); + /** + * Copys the data from another instance + */ + void copyFrom(const CStarControlSub13 *src); /** * Load the data for the class from file @@ -80,7 +81,7 @@ public: /** * Sets the position */ - void setPosition(const CStarControlSub6 &sub6); + void setPosition(const CStarControlSub6 *sub6); /** * Sets the matrix @@ -90,25 +91,25 @@ public: void fn11(const FVector &v); void fn12(); void fn13(StarMode mode, double v2); - void fn14(double v); - void fn15(FMatrix &matrix); + void reposition(double factor); + void fn15(const FMatrix &matrix); CStarControlSub6 getSub1(); CStarControlSub6 getSub2(); void fn16(int index, const FVector &src, FVector &dest); - FVector fn17(int index, const FVector &v); - FVector fn18(int index, const FVector &v); + FVector fn17(int index, const FVector &src); + FVector fn18(int index, const FVector &src); void fn19(double *v1, double *v2, double *v3, double *v4); /** - * Makes a copy of the instance's matrix into the passed matrix + * Returns the instance's matrix */ - void getMatrix(FMatrix *matrix); + const FMatrix &getMatrix() const; - void setC(int v); - void set10(int v); - void set14(int v); - void set18(int v); - void set1C(int v); + void setC(double v); + void set10(double v); + void set14(double v); + void set18(double v); + void set1C(double v); }; } // End of namespace Titanic diff --git a/engines/titanic/star_control/star_control_sub2.cpp b/engines/titanic/star_control/star_control_sub2.cpp index cf7190fb34..ebeb9bf239 100644 --- a/engines/titanic/star_control/star_control_sub2.cpp +++ b/engines/titanic/star_control/star_control_sub2.cpp @@ -21,9 +21,15 @@ */ #include "titanic/star_control/star_control_sub2.h" +#include "titanic/star_control/star_control_sub12.h" namespace Titanic { +bool CStarControlSub2::setup() { + loadData("STARFIELD/132"); + return true; +} + bool CStarControlSub2::loadYale(int v1) { clear(); error("Original loadYale not supported"); @@ -31,19 +37,20 @@ bool CStarControlSub2::loadYale(int v1) { } bool CStarControlSub2::selectStar(CSurfaceArea *surfaceArea, - CStarControlSub12 *sub12, int flags, const Common::Point &pt) { - // TODO - return true; + CStarControlSub12 *sub12, const Common::Point &pt, void *handler) { + int index = baseFn1(surfaceArea, sub12, pt); + if (index == -1) { + return false; + } else if (!handler) { + sub12->proc14(_data[index]._position); + return true; + } else { + error("no handler ever passed in original"); + } } bool CStarControlSub2::loadStar() { - // TODO - return true; -} - -bool CStarControlSub2::setup() { - // TODO - return true; + error("loadStar not supported"); } } // End of namespace Titanic diff --git a/engines/titanic/star_control/star_control_sub2.h b/engines/titanic/star_control/star_control_sub2.h index 9de2da4583..bcf7397fe1 100644 --- a/engines/titanic/star_control/star_control_sub2.h +++ b/engines/titanic/star_control/star_control_sub2.h @@ -37,7 +37,7 @@ public: * Selects a star */ virtual bool selectStar(CSurfaceArea *surfaceArea, CStarControlSub12 *sub12, - int flags, const Common::Point &pt); + const Common::Point &pt, void *handler = nullptr); virtual bool loadStar(); diff --git a/engines/titanic/star_control/star_control_sub20.cpp b/engines/titanic/star_control/star_control_sub20.cpp index cc1029896a..ca60cc9948 100644 --- a/engines/titanic/star_control/star_control_sub20.cpp +++ b/engines/titanic/star_control/star_control_sub20.cpp @@ -32,7 +32,7 @@ CStarControlSub20::CStarControlSub20(const CStar20Data *src) { if (src) { copyFrom(src); } else { - _field0 = 0.0; + _size = 0.0; _field4 = 0.0; _field8 = 20.0; _fieldC = 0.0; @@ -56,22 +56,22 @@ void CStarControlSub20::copyTo(CStar20Data *dest) { } void CStarControlSub20::proc4() { - if (!isLocked() && _field0 < _field10) { - _field4 += _field0; + if (!isLocked() && _size < _field10) { + _field4 += _size; if (_field8 == _field4) - _field0 -= _field4; + _size -= _field4; else - _field0 += _field4; + _size += _field4; } } void CStarControlSub20::proc5() { if (!isLocked()) { _field4 -= _field8; - if (_field4 == _field0) - _field0 += _field4; + if (_field4 == _size) + _size += _field4; else - _field0 -= _field4; + _size -= _field4; if (_field4 < 0.0) _field4 = 0.0; @@ -80,19 +80,23 @@ void CStarControlSub20::proc5() { void CStarControlSub20::proc6() { if (!isLocked()) - _field0 = _field10; + _size = _field10; } void CStarControlSub20::proc7() { if (!isLocked()) { - _field0 = 0.0; + _size = 0.0; _field4 = 0.0; } } void CStarControlSub20::proc11(CErrorCode &errorCode, FVector &v, const FMatrix &m) { - if (_field0 > 0.0) { - warning("TODO: CStarControlSub20::proc11"); + if (_size > 0.0) { + v._x += m._row3._x * _size; + v._y += m._row3._y * _size; + v._z += m._row3._z * _size; + + errorCode.set(); } } @@ -110,7 +114,7 @@ void CStarControlSub20::clear() { void CStarControlSub20::load(SimpleFile *file, int val) { if (!val) { - _field0 = file->readFloat(); + _size = file->readFloat(); _field4 = file->readFloat(); _field8 = file->readFloat(); _fieldC = file->readFloat(); @@ -122,7 +126,7 @@ void CStarControlSub20::load(SimpleFile *file, int val) { } void CStarControlSub20::save(SimpleFile *file, int indent) { - file->writeFloatLine(_field0, indent); + file->writeFloatLine(_size, indent); file->writeFloatLine(_field4, indent); file->writeFloatLine(_field8, indent); file->writeFloatLine(_fieldC, indent); diff --git a/engines/titanic/star_control/star_control_sub20.h b/engines/titanic/star_control/star_control_sub20.h index 9dbabbb7f1..49b63d5d5d 100644 --- a/engines/titanic/star_control/star_control_sub20.h +++ b/engines/titanic/star_control/star_control_sub20.h @@ -30,7 +30,7 @@ namespace Titanic { struct CStar20Data { - double _field0; + double _size; double _field4; double _field8; double _fieldC; @@ -54,9 +54,9 @@ public: virtual void proc5(); virtual void proc6(); virtual void proc7(); - virtual void proc8() {} - virtual void proc9(FVector *v, int v2, FMatrix *matrix) {} - virtual void proc10() {} + virtual void proc8(FVector &v1, FVector &v2, FMatrix &m1, FMatrix &m2) {} + virtual void proc9(FVector &v1, FVector &v2, FMatrix &matrix) {} + virtual void proc10(const FVector &v1, const FVector &v2, const FVector &v3, const FMatrix &m) {} virtual void proc11(CErrorCode &errorCode, FVector &v, const FMatrix &m); /** diff --git a/engines/titanic/star_control/star_control_sub21.cpp b/engines/titanic/star_control/star_control_sub21.cpp index 41d24d55c0..1e676b7703 100644 --- a/engines/titanic/star_control/star_control_sub21.cpp +++ b/engines/titanic/star_control/star_control_sub21.cpp @@ -21,15 +21,51 @@ */ #include "titanic/star_control/star_control_sub21.h" +#include "titanic/star_control/dmatrix.h" +#include "titanic/star_control/dvector.h" #include "common/textconsole.h" namespace Titanic { CStarControlSub21::CStarControlSub21(const CStar20Data *src) : CStarControlSub20(src) { -#if 0 - _sub24() -#endif +} + +void CStarControlSub21::proc9(FVector &v1, FVector &v2, FMatrix &matrix) { + if (isLocked()) + decLockCount(); + + _sub24.proc4(v1, v2, matrix); +} + +void CStarControlSub21::proc10(const FVector &v1, const FVector &v2, const FVector &v3, const FMatrix &m) { + if (isLocked()) + decLockCount(); + + DVector vector1 = v1; + DVector vector2 = v2; + DMatrix matrix1, matrix2 = m, matrix3; + vector2.fn4(vector1, matrix1); + const DMatrix *matrixP = matrix1.fn4(matrix3, matrix1, matrix2); + + FMatrix matrix4 = *matrixP; + _sub24.proc3(m, matrix4); + incLockCount(); +} + +void CStarControlSub21::proc11(CErrorCode &errorCode, FVector &v, const FMatrix &m) { + if (_sub24.get8()) { + int val = _sub24.proc5(errorCode, v, m); + if (val == 1) + incLockCount(); + if (val == 2) { + proc7(); + error("TODO: _dataP"); + } + } else if (_size != 0.0) { + // TODO + error("TODO"); + } } } // End of namespace Titanic diff --git a/engines/titanic/star_control/star_control_sub21.h b/engines/titanic/star_control/star_control_sub21.h index 3f47a1a3e1..66ce535993 100644 --- a/engines/titanic/star_control/star_control_sub21.h +++ b/engines/titanic/star_control/star_control_sub21.h @@ -30,11 +30,14 @@ namespace Titanic { class CStarControlSub21 : public CStarControlSub20 { private: -#if 0 CStarControlSub24 _sub24; -#endif public: CStarControlSub21(const CStar20Data *src); + virtual ~CStarControlSub21() {} + + virtual void proc9(FVector &v1, FVector &v2, FMatrix &matrix); + virtual void proc10(const FVector &v1, const FVector &v2, const FVector &v3, const FMatrix &m); + virtual void proc11(CErrorCode &errorCode, FVector &v, const FMatrix &m); }; } // End of namespace Titanic diff --git a/engines/titanic/star_control/star_control_sub22.cpp b/engines/titanic/star_control/star_control_sub22.cpp index 05a1cec87d..b76d96e47a 100644 --- a/engines/titanic/star_control/star_control_sub22.cpp +++ b/engines/titanic/star_control/star_control_sub22.cpp @@ -27,9 +27,18 @@ namespace Titanic { CStarControlSub22::CStarControlSub22(const CStar20Data *src) : CStarControlSub20(src) { -#if 0 - _sub27() -#endif +} + +void CStarControlSub22::proc8(FVector &v1, FVector &v2, FMatrix &m1, FMatrix &m2) { + if (isLocked()) + decLockCount(); + + _sub27.proc2(v1, v2, m1, m2); + incLockCount(); +} + +void CStarControlSub22::proc11(CErrorCode &errorCode, FVector &v, const FMatrix &m) { + // TODO } } // End of namespace Titanic diff --git a/engines/titanic/star_control/star_control_sub22.h b/engines/titanic/star_control/star_control_sub22.h index 4d353aa074..61f60b10f1 100644 --- a/engines/titanic/star_control/star_control_sub22.h +++ b/engines/titanic/star_control/star_control_sub22.h @@ -30,11 +30,13 @@ namespace Titanic { class CStarControlSub22 : public CStarControlSub20 { private: -#if 0 CStarControlSub27 _sub27; -#endif public: CStarControlSub22(const CStar20Data *src); + virtual ~CStarControlSub22() {} + + virtual void proc8(FVector &v1, FVector &v2, FMatrix &m1, FMatrix &m2); + virtual void proc11(CErrorCode &errorCode, FVector &v, const FMatrix &m); }; } // End of namespace Titanic diff --git a/engines/titanic/star_control/star_control_sub23.cpp b/engines/titanic/star_control/star_control_sub23.cpp index b009cbc35b..4587fd3e27 100644 --- a/engines/titanic/star_control/star_control_sub23.cpp +++ b/engines/titanic/star_control/star_control_sub23.cpp @@ -25,4 +25,89 @@ namespace Titanic { +CStarControlSub23::CStarControlSub23() : _row1(0.0, 1000000.0, 0.0) { + _field4 = 0; + _field8 = 0; + _field24 = 0.0; + _field34 = 0; + _field38 = 0; + _field3C = 0; + _field40 = 0; + _field44 = 0; + _field48 = 0; + _field4C = 0; + _field54 = 0; + _field58 = 0; + _field5C = 0; + _field60 = 0; + _field64 = 0; +} + +void CStarControlSub23::proc2(FVector &v1, FVector &v2, FMatrix &m1, FMatrix &m2) { + _row1 = v1; + _row2 = v2; + _row3 = _row2 - _row1; + _field24 = _row3.normalize(); + + _field58 = 0; + _field8 = 0; + _field34 = 0; + _field5C = 1.875; + _field40 = -1; + _field44 = -1; + _field48 = -1; + _field4C = 0; +} + +void CStarControlSub23::proc3(const FMatrix &m1, const FMatrix &m2) { + _row1.clear(); + _row2.clear(); + _field58 = 0; + _field24 = 0.0; + _field8 = 0; + _field34 = 0; + _field5C = 1.875; +} + +void CStarControlSub23::proc4(FVector &v1, FVector &v2, FMatrix &m) { + _row1 = v1; + _row2 = v2; + FVector vector = _row2 - _row1; + _row3 = vector; + _field24 = _row3.normalize(); + + _field8 = 0; + _field34 = 0; + _field40 = -1; + _field44 = -1; + _field48 = -1; + _field4C = -1; + _field58 = 0; + _field5C = 1.875; +} + +void CStarControlSub23::proc6(int val1, int val2, float val) { + _field44 = val1; + _field4C = val1 + 62; + _field38 = val / (double)(val1 + val2 * 2); + _field40 = 31; + _field48 = 31; + _field3C = (double)val2 * _field38; + + if (_powers.empty()) + _powers.resize(32); + + // Calculate the powers table + double exponent = 0.0, total = 0.0; + for (int idx = 31; idx >= 0; --idx) { + _powers[idx] = pow(4.0, exponent); + total += _powers[idx]; + exponent += 0.03125; + } + + for (int idx = 0; idx < 32; ++idx) { + _powers[idx] = _powers[idx] * _field3C / total; + } +} + } // End of namespace Titanic diff --git a/engines/titanic/star_control/star_control_sub23.h b/engines/titanic/star_control/star_control_sub23.h index 136401e329..9e90e021a2 100644 --- a/engines/titanic/star_control/star_control_sub23.h +++ b/engines/titanic/star_control/star_control_sub23.h @@ -23,9 +23,45 @@ #ifndef TITANIC_STAR_CONTROL_SUB23_H #define TITANIC_STAR_CONTROL_SUB23_H +#include "titanic/star_control/error_code.h" +#include "titanic/star_control/fmatrix.h" +#include "titanic/star_control/fvector.h" +#include "titanic/star_control/star_control_sub25.h" + namespace Titanic { class CStarControlSub23 { +protected: + int _field4; + int _field8; + FVector _row1, _row2; + double _field24; + FVector _row3; + int _field34; + double _field38; + int _field3C; + int _field40; + int _field44; + int _field48; + int _field4C; + Common::Array<double> _powers; + int _field54; + int _field58; + double _field5C; + double _field60; + double _field64; + CStarControlSub25 _sub25; +public: + CStarControlSub23(); + virtual ~CStarControlSub23() {} + + virtual void proc2(FVector &v1, FVector &v2, FMatrix &m1, FMatrix &m2); + virtual void proc3(const FMatrix &m1, const FMatrix &m2); + virtual void proc4(FVector &v1, FVector &v2, FMatrix &m); + virtual int proc5(CErrorCode &errorCode, FVector &v, const FMatrix &m) { return 2; } + virtual void proc6(int val1, int val2, float val); + + int get8() const { return _field8; } }; } // End of namespace Titanic diff --git a/engines/titanic/star_control/star_control_sub24.cpp b/engines/titanic/star_control/star_control_sub24.cpp index 6f17eb7193..27f29b41ca 100644 --- a/engines/titanic/star_control/star_control_sub24.cpp +++ b/engines/titanic/star_control/star_control_sub24.cpp @@ -25,5 +25,19 @@ namespace Titanic { +void CStarControlSub24::proc3(const FMatrix &m1, const FMatrix &m2) { + +} + +void CStarControlSub24::proc4(FVector &v1, FVector &v2, FMatrix &m) { + CStarControlSub23::proc4(v1, v2, m); + + // TODO +} + +int CStarControlSub24::proc5(CErrorCode &errorCode, FVector &v, const FMatrix &m) { + // TODO + return 0; +} } // End of namespace Titanic diff --git a/engines/titanic/star_control/star_control_sub24.h b/engines/titanic/star_control/star_control_sub24.h index e0970fc1de..34b9cf4eac 100644 --- a/engines/titanic/star_control/star_control_sub24.h +++ b/engines/titanic/star_control/star_control_sub24.h @@ -28,6 +28,12 @@ namespace Titanic { class CStarControlSub24 : public CStarControlSub23 { +public: + virtual ~CStarControlSub24() {} + + virtual void proc3(const FMatrix &m1, const FMatrix &m2); + virtual void proc4(FVector &v1, FVector &v2, FMatrix &m); + virtual int proc5(CErrorCode &errorCode, FVector &v, const FMatrix &m); }; } // End of namespace Titanic diff --git a/engines/titanic/star_control/star_control_sub25.cpp b/engines/titanic/star_control/star_control_sub25.cpp index f91c75af6a..73c72e6a77 100644 --- a/engines/titanic/star_control/star_control_sub25.cpp +++ b/engines/titanic/star_control/star_control_sub25.cpp @@ -25,4 +25,10 @@ namespace Titanic { +void CStarControlSub25::fn1(const FMatrix &m1, const FMatrix &m2) { + _matrix1 = m1; + _matrix2 = m2; + +} + } // End of namespace Titanic diff --git a/engines/titanic/star_control/star_control_sub25.h b/engines/titanic/star_control/star_control_sub25.h index b61569c49d..85692cf62d 100644 --- a/engines/titanic/star_control/star_control_sub25.h +++ b/engines/titanic/star_control/star_control_sub25.h @@ -35,7 +35,7 @@ public: CStarControlSub26 _sub1; CStarControlSub26 _sub2; public: - + void fn1(const FMatrix &m1, const FMatrix &m2); }; } // End of namespace Titanic diff --git a/engines/titanic/star_control/star_control_sub26.cpp b/engines/titanic/star_control/star_control_sub26.cpp index 89ff93c347..546a3e9fae 100644 --- a/engines/titanic/star_control/star_control_sub26.cpp +++ b/engines/titanic/star_control/star_control_sub26.cpp @@ -30,5 +30,16 @@ double CStarControlSub26::fn1() const { _sub._v3 * _sub._v3 + _field0 * _field0; } +void CStarControlSub26::setup(double val1, double val2, double val3, double val4) { + _field0 = val1; + _sub._v1 = val2; + _sub._v2 = val3; + _sub._v3 = val4; +} + +void CStarControlSub26::copyFrom(const CStarControlSub26 *src) { + _field0 = src->_field0; + _sub = src->_sub; +} } // End of namespace Titanic diff --git a/engines/titanic/star_control/star_control_sub26.h b/engines/titanic/star_control/star_control_sub26.h index 4054a2ba6e..9023da906c 100644 --- a/engines/titanic/star_control/star_control_sub26.h +++ b/engines/titanic/star_control/star_control_sub26.h @@ -39,7 +39,18 @@ public: public: CStarControlSub26() : _field0(1.0) {} + /** + * Sets the field values + */ + void setup(double val1, double val2, double val3, double val4); + + /** + * Copies from another instance + */ + void copyFrom(const CStarControlSub26 *src); + double fn1() const; + }; } // End of namespace Titanic diff --git a/engines/titanic/star_control/star_control_sub27.cpp b/engines/titanic/star_control/star_control_sub27.cpp index 6f17eb7193..706e947a05 100644 --- a/engines/titanic/star_control/star_control_sub27.cpp +++ b/engines/titanic/star_control/star_control_sub27.cpp @@ -20,10 +20,40 @@ * */ -#include "titanic/star_control/star_control_sub24.h" +#include "titanic/star_control/star_control_sub27.h" #include "common/textconsole.h" namespace Titanic { +void CStarControlSub27::proc2(FVector &v1, FVector &v2, FMatrix &m1, FMatrix &m2) { + CStarControlSub23::proc2(v1, v2, m1, m2); + + int v24 = _field24; + if (_field24 > 0.0) { + _field8 = 1; + _field34 = 1; + proc6(120, 4, _field24); + } + + if (m1 != m2) { + _sub25.fn1(m1, m2); + _field58 = 0; + _field5C = 0.0; + + if (_field4C == 0) { + _field60 = -1.5881868e-23; + _field64 = 1.4499999; + _field8 = 1; + } else { + _field60 = 1.0 / (double)v24; + _field8 = 1; + } + } +} + +int CStarControlSub27::proc5(CErrorCode &errorCode, FVector &v, const FMatrix &m) { + // TODO + return 0; +} } // End of namespace Titanic diff --git a/engines/titanic/star_control/star_control_sub27.h b/engines/titanic/star_control/star_control_sub27.h index 01782b69ca..801591294e 100644 --- a/engines/titanic/star_control/star_control_sub27.h +++ b/engines/titanic/star_control/star_control_sub27.h @@ -28,6 +28,11 @@ namespace Titanic { class CStarControlSub27 : public CStarControlSub23 { +public: + virtual ~CStarControlSub27() {} + + virtual void proc2(FVector &v1, FVector &v2, FMatrix &m1, FMatrix &m2); + virtual int proc5(CErrorCode &errorCode, FVector &v, const FMatrix &m); }; } // End of namespace Titanic diff --git a/engines/titanic/star_control/star_control_sub5.cpp b/engines/titanic/star_control/star_control_sub5.cpp index 5023a59383..8c332975c6 100644 --- a/engines/titanic/star_control/star_control_sub5.cpp +++ b/engines/titanic/star_control/star_control_sub5.cpp @@ -26,6 +26,8 @@ namespace Titanic { +#define MKTAG_BE(a3,a2,a1,a0) ((uint32)((a3) | ((a2) << 8) | ((a1) << 16) | ((a0) << 24))) + void CStarControlSub5::SubEntry::clear() { _data1.clear(); _data2.clear(); @@ -37,7 +39,7 @@ bool CStarControlSub5::SineTable::setup() { if (_data.empty()) { _data.resize(1024); for (int idx = 0; idx < 1024; ++idx) - _data[idx] = sin((double)idx * 6.283185307179586 * 0.001953125); + _data[idx] = sin((double)idx * 2 * M_PI / 512.0); } return true; @@ -63,7 +65,7 @@ bool CStarControlSub5::setup() { bool CStarControlSub5::setup2(int val1, int val2) { // TODO: Original set an explicit random seed here. Could be // problematic if following random values need to be deterministic - const double FACTOR = 3.1415927 * 0.0055555557; + const double FACTOR = 2 * M_PI / 360.0; const int VALUES1[] = { 0x800, 0xC00, 0x1000, 0x1400, 0x1800 }; const int VALUES2[] = { 0xF95BCD, 0xA505A0, 0xFFAD43, 0x98F4EB, 0xF3EFA5, 0, @@ -76,9 +78,9 @@ bool CStarControlSub5::setup2(int val1, int val2) { for (int idx = 0; idx < 256; ++idx) { if (idx == 0) { e->_field0 = 0x4C8; - e->_field4 = 0x40; - e->_field5 = 0x40; - e->_field6 = 0x40; + e->_pixel1 = 0x40; + e->_pixel2 = 0x40; + e->_pixel3 = 0x40; e->_field8 = g_vm->getRandomNumber(3) + 3; e->_fieldC = g_vm->getRandomNumber(255); e->_field10 = FACTOR * 7.0; @@ -86,9 +88,9 @@ bool CStarControlSub5::setup2(int val1, int val2) { ++e; e->_field0 = 0x574; - e->_field4 = 0x7f; - e->_field5 = 0; - e->_field6 = 0; + e->_pixel1 = 0x7f; + e->_pixel2 = 0; + e->_pixel3 = 0; e->_field8 = g_vm->getRandomNumber(3) + 3; e->_fieldC = g_vm->getRandomNumber(255); e->_field10 = FACTOR * 3.0; @@ -96,9 +98,9 @@ bool CStarControlSub5::setup2(int val1, int val2) { ++e; e->_field0 = 0x603; - e->_field4 = 0; - e->_field5 = 0; - e->_field6 = 0xff; + e->_pixel1 = 0; + e->_pixel2 = 0; + e->_pixel3 = 0xff; e->_field8 = g_vm->getRandomNumber(3) + 3; e->_fieldC = g_vm->getRandomNumber(255); e->_field10 = 0; @@ -106,9 +108,9 @@ bool CStarControlSub5::setup2(int val1, int val2) { ++e; e->_field0 = 0x712; - e->_field4 = 0xff; - e->_field5 = 0; - e->_field6 = 0; + e->_pixel1 = 0xff; + e->_pixel2 = 0; + e->_pixel3 = 0; e->_field8 = g_vm->getRandomNumber(3) + 3; e->_fieldC = g_vm->getRandomNumber(255); e->_field10 = FACTOR * 2.0; @@ -116,9 +118,9 @@ bool CStarControlSub5::setup2(int val1, int val2) { ++e; e->_field0 = 0xe7f; - e->_field4 = 0xe6; - e->_field5 = 0xbe; - e->_field6 = 0; + e->_pixel1 = 0xe6; + e->_pixel2 = 0xbe; + e->_pixel3 = 0; e->_field8 = g_vm->getRandomNumber(3) + 3; e->_fieldC = g_vm->getRandomNumber(255); e->_field10 = FACTOR * 1.0; @@ -126,9 +128,9 @@ bool CStarControlSub5::setup2(int val1, int val2) { ++e; e->_field0 = 0x173f; - e->_field4 = 0xf0; - e->_field5 = 0xf0; - e->_field6 = 0xe6; + e->_pixel1 = 0xf0; + e->_pixel2 = 0xf0; + e->_pixel3 = 0xe6; e->_field8 = g_vm->getRandomNumber(3) + 3; e->_fieldC = g_vm->getRandomNumber(255); e->_field10 = FACTOR * 3.0; @@ -136,9 +138,9 @@ bool CStarControlSub5::setup2(int val1, int val2) { ++e; e->_field0 = 0x2ab8; - e->_field4 = 0x28; - e->_field5 = 0x32; - e->_field6 = 0x28; + e->_pixel1 = 0x28; + e->_pixel2 = 0x32; + e->_pixel3 = 0x28; e->_field8 = g_vm->getRandomNumber(3) + 3; e->_fieldC = g_vm->getRandomNumber(255); e->_field10 = FACTOR * 1.0; @@ -146,9 +148,9 @@ bool CStarControlSub5::setup2(int val1, int val2) { ++e; e->_field0 = 0x40ac; - e->_field4 = 0x0; - e->_field5 = 0xbe; - e->_field6 = 0xf0; + e->_pixel1 = 0x0; + e->_pixel2 = 0xbe; + e->_pixel3 = 0xf0; e->_field8 = g_vm->getRandomNumber(3) + 3; e->_fieldC = g_vm->getRandomNumber(255); e->_field10 = FACTOR * 2.0; @@ -156,27 +158,27 @@ bool CStarControlSub5::setup2(int val1, int val2) { ++e; e->_field0 = 0x539c; - e->_field4 = 0x20; - e->_field5 = 0x20; - e->_field6 = 0x20; + e->_pixel1 = 0x20; + e->_pixel2 = 0x20; + e->_pixel3 = 0x20; e->_field8 = g_vm->getRandomNumber(3) + 3; e->_fieldC = g_vm->getRandomNumber(255); e->_field10 = FACTOR * 17.0; - e->_field14 = 0.00390625; + e->_field14 = 1 / 256.0; } else { for (int ctr = 0; ctr < 5; ++ctr) { e->_field0 = static_cast<int>(g_vm->getRandomFloat() * 1350.0 - 675.0) + VALUES1[idx]; int val = VALUES2[g_vm->getRandomNumber(15)]; - e->_field4 = val & 0xff; - e->_field5 = (val >> 8) & 0xff; - e->_field6 = (val >> 16) & 0xff; + e->_pixel1 = val & 0xff; + e->_pixel2 = (val >> 8) & 0xff; + e->_pixel3 = (val >> 16) & 0xff; e->_field8 = g_vm->getRandomNumber(3) + 3; e->_fieldC = g_vm->getRandomNumber(255); e->_field10 = FACTOR * (double)g_vm->getRandomNumber(15); - e->_field14 = ((double)g_vm->getRandomNumber(0xffffffff) - * 50.0 * 0.000015259022) * 0.00390625; + e->_field14 = ((double)g_vm->getRandomNumber(0xfffffffe) + * 50.0 / 65536.0) / 256.0; } } } @@ -194,13 +196,23 @@ void CStarControlSub5::proc2(CStarControlSub6 *sub6, FVector *vector, double v1, const int VALUES[] = { 0, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4 }; double val1 = sub12->proc25(); int val2 = sub12->proc27(); + if (!_flag) + return; + + int f1, f3, size2, size1; + double f2, f4, f5, f6, f7, f8, f9; + double f10, f11, f12, f13, f14, f15, f16, f17, f18, f19; + double f20, f21, f22, f23, f24, f25, f26, f27, f28; + double f34, f35, f36, f37, f38, f39, f40; + double f41, f42, f43, f44, f45, f46; + FVector tempV; if (v3 >= 6.0e9) { int count, start; if (vector->_x != 0.0 && (vector->_y != 0.0 || vector->_z != 0.0)) { - // TODO: Non-sensical randSeed((int)vector->_x); + // WORKAROUND: Ignoring non-sensical randSeed((int)vector->_x); count = VALUES[g_vm->getRandomNumber(15)]; - start = g_vm->getRandomNumber(255); + start = 5 * g_vm->getRandomNumber(255); } else { count = 9; start = 0; @@ -208,45 +220,280 @@ void CStarControlSub5::proc2(CStarControlSub6 *sub6, FVector *vector, double v1, Entry *entryP = &_entries[start]; for (; count > 0; --count, ++entryP) { - //eax=sineIndex1, ecx=sineIndex2, - int sineIndex1 = (entryP->_field8 * _multiplier) & 0x1ff; - int sineIndex2 = (entryP->_fieldC * _multiplier + entryP->_fieldC) & 0x1ff; - - double t1 = _sineTable[sineIndex2]; - double t2 = sin(_sineTable[sineIndex1] * entryP->_field10); - double t3 = cos(_sineTable[sineIndex1] * entryP->_field10); - double t4 = _sineTable[sineIndex2 + 512]; - double t5 = t3 * t4; - t3 = t3 * t1; - double t6 = entryP->_field14 * t5; - double t7 = t2 * entryP->_field14; - double t8 = entryP->_field14 * t3; - double t9 = -(t2 * t4 * entryP->_field14); - double t10 = t3 * entryP->_field14; - double t11 = -(t2 * t1 * entryP->_field14); - t4 = -(t1 * entryP->_field14); - t1 = t4 * entryP->_field14; - - _sub1._row1._x = t6; - _sub1._row1._y = t2 * entryP->_field14; - _sub1._row1._z = entryP->_field14 * t3; - _sub1._row2._x = -(t2 * t4 * entryP->_field14); - _sub1._row2._y = t3 * entryP->_field14; - _sub1._row2._z = -(t2 * t1 * entryP->_field14); - _sub1._row3._x = -(t1 * entryP->_field14); - _sub1._row3._z = t4 * entryP->_field14; - - double t12 = entryP->_field0; - _sub1._vector._x = t12 * t5 + vector->_x; - _sub1._vector._y = t12 * t2 + vector->_y; - _sub1._vector._z = t12 * t3 + vector->_z; - - // TODO - warning("TODO: %f %f %f %f %f %f %d", t7, t8, t9, t10, t11, val1, val2); + f1 = _multiplier * entryP->_field8; + f2 = entryP->_field14; + f3 = (f1 + entryP->_fieldC) & 0x1FF; + f4 = _sineTable[f1 & 0x1FF] * entryP->_field10; + f5 = _sineTable[f3]; + f6 = cos(f4); + f7 = sin(f4); + f8 = _sineTable[f3 + 128]; + f9 = f7; + f10 = f6 * f8; + f11 = f6; + f12 = f6 * f5; + f13 = f2 * f10; + f14 = f8 * f2; + f15 = f9 * f2; + f16 = f2 * f12; + f17 = -(f7 * f8 * f2); + f18 = f11 * f2; + f19 = -(f9 * f5 * f2); + f20 = -(f5 * f2); + f21 = f14; + _sub1._row1._x = f13; + _sub1._row1._y = f15; + _sub1._row1._z = f16; + _sub1._row2._x = f17; + _sub1._row2._y = f18; + _sub1._row2._z = f19; + _sub1._row3._x = f20; + _sub1._row3._z = f14; + + f22 = (double)entryP->_field0; + _sub1._vector._x = f22 * f10 + vector->_x; + _sub1._vector._y = f9 * f22 + vector->_y; + _sub1._vector._z = f22 * f12 + vector->_z; + _sub2._row1._x = sub6->_row1._x * f13 + f16 * sub6->_row3._x + f15 * sub6->_row2._x; + _sub2._row1._y = f15 * sub6->_row2._y + f16 * sub6->_row3._y + f13 * sub6->_row1._y; + _sub2._row1._z = f16 * sub6->_row3._z + f13 * sub6->_row1._z + f15 * sub6->_row2._z; + _sub2._row2._x = sub6->_row1._x * f17 + f19 * sub6->_row3._x + f18 * sub6->_row2._x; + _sub2._row2._y = f18 * sub6->_row2._y + f17 * sub6->_row1._y + f19 * sub6->_row3._y; + _sub2._row2._z = f18 * sub6->_row2._z + f19 * sub6->_row3._z + f17 * sub6->_row1._z; + _sub2._row3._x = sub6->_row1._x * f20 + f21 * sub6->_row3._x; + _sub2._row3._y = f20 * sub6->_row1._y + f21 * sub6->_row3._y; + _sub2._row3._z = f20 * sub6->_row1._z + f21 * sub6->_row3._z; + + f23 = _sub1._vector._y; + f24 = _sub1._vector._z; + f25 = _sub1._vector._x; + f26 = _sub1._vector._z; + f27 = _sub1._vector._x; + + f28 = _sub1._vector._y; + _sub2._vector._x = sub6->_row1._x * _sub1._vector._x + + sub6->_row3._x * _sub1._vector._z + + sub6->_row2._x * f28 + + sub6->_vector._x; + _sub2._vector._y = f23 * sub6->_row2._y + + f24 * sub6->_row3._y + + f25 * sub6->_row1._y + + sub6->_vector._y; + _sub2._vector._z = f26 * sub6->_row3._z + + f27 * sub6->_row1._z + + f28 * sub6->_row2._z + + sub6->_vector._z; + + size2 = (int)_array[1]._data2.size(); + size1 = (int)_array[1]._data1.size(); + + if (size2 > 0) { + for (int ctr2 = 0; ctr2 < size2; ++ctr2) { + FVector &currVector = _array[1]._data2[ctr2]; + GridEntry &gridEntry = _grid[ctr2]; + + f34 = currVector._x; + f35 = currVector._y; + f36 = f35 * _sub2._row2._x; + f37 = currVector._z; + f38 = f37 * _sub2._row3._x + f36; + f39 = f38 + f34 * _sub2._row1._x; + f40 = f39 + _sub2._vector._x; + + gridEntry._x = f40; + gridEntry._y = f37 * _sub2._row3._y + + f35 * _sub2._row2._y + + f34 * _sub2._row1._y + + _sub2._vector._y; + gridEntry._z = f37 * _sub2._row3._z + + f35 * _sub2._row2._z + + f34 * _sub2._row1._z + + _sub2._vector._z; + } + } + + if (val2 <= 0) { + surfaceArea->setMode(SA_NONE); + surfaceArea->_pixel = MKTAG_BE(entryP->_pixel1, entryP->_pixel2, + entryP->_pixel3, 0); + surfaceArea->setColorFromPixel(); + + for (int ctr2 = 0; ctr2 < size2; ++ctr2) { + GridEntry &gridEntry = _grid[ctr2]; + sub12->proc28(2, gridEntry, tempV); + gridEntry._position._x = tempV._x; + gridEntry._position._y = tempV._y + v2; + } + + for (int ctr2 = 0; ctr2 < size1; ++ctr2) { + Data1 &d1 = _array[1]._data1[ctr2]; + GridEntry &grid1 = _grid[d1._index1]; + GridEntry &grid2 = _grid[d1._index2]; + + if (grid1._z > val1 && grid2._z > val1) { + surfaceArea->fn1(FRect(grid1._position._x, grid1._position._y, + grid2._position._x, grid2._position._y)); + } + } + } else { + surfaceArea->setMode(SA_NONE); + surfaceArea->_pixel = entryP->_pixel1; + surfaceArea->setColorFromPixel(); + + for (int ctr2 = 0; ctr2 < size2; ++ctr2) { + GridEntry &gridEntry = _grid[ctr2]; + sub12->proc28(0, gridEntry, tempV); + gridEntry._position._x = tempV._x + v1; + gridEntry._position._y = tempV._y + v2; + } + + for (int ctr2 = 0; ctr2 < size1; ++ctr2) { + Data1 &d1 = _array[1]._data1[ctr2]; + GridEntry &grid1 = _grid[d1._index1]; + GridEntry &grid2 = _grid[d1._index2]; + + if (grid1._z > val1 && grid2._z > val1) { + surfaceArea->fn1(FRect(grid1._position._x, grid1._position._y, + grid2._position._x, grid2._position._y)); + } + } + + surfaceArea->_pixel = entryP->_pixel3; + surfaceArea->setColorFromPixel(); + surfaceArea->setMode(SA_MODE2); + + for (int ctr2 = 0; ctr2 < size2; ++ctr2) { + GridEntry &gridEntry = _grid[ctr2]; + sub12->proc28(1, gridEntry, tempV); + gridEntry._position._x = tempV._x + v1; + gridEntry._position._y = tempV._y + v2; + } + + for (int ctr2 = 0; ctr2 < size1; ++ctr2) { + Data1 &d1 = _array[1]._data1[ctr2]; + GridEntry &grid1 = _grid[d1._index1]; + GridEntry &grid2 = _grid[d1._index2]; + + if (grid1._z > val1 && grid2._z > val1) { + surfaceArea->fn1(FRect(grid1._position._x, grid1._position._y, + grid2._position._x, grid2._position._y)); + } + } + } + } + } + + uint pixel1 = 0x81EEF5, pixel2 = 0xF5, pixel3 = 0x810000; + int arrIndex = 0; + + if (v3 >= 200000000.0) { + if (v3 >= 900000000.0) { + if (v3 >= 6000000000.0) { + arrIndex = 3; + if (v3 >= 1.0e10) + arrIndex = 4; + } else { + arrIndex = 2; + } + } else { + arrIndex = 1; } + } else { + arrIndex = 0; } - // TODO + SubEntry &entry = _array[arrIndex]; + + for (uint ctr = 0; ctr < entry._data2.size(); ++ctr) { + GridEntry &gridEntry = _grid[ctr]; + const FVector &d2v = entry._data2[ctr]; + FVector newV = d2v + *vector; + + f41 = sub6->_row1._x; + f42 = sub6->_row3._x; + f43 = sub6->_row2._x; + f44 = f43 * newV._y; + f45 = f41 * newV._x + f42 * newV._z + f44; + f46 = f45 + sub6->_vector._x; + + gridEntry._x = f46; + gridEntry._y = newV._y * sub6->_row2._y + + newV._z * sub6->_row3._y + + newV._x * sub6->_row1._y + + sub6->_vector._y; + gridEntry._z = newV._z * sub6->_row3._z + + newV._y * sub6->_row2._z + + newV._x * sub6->_row1._z + + sub6->_vector._z; + } + + if (val2 <= 0) { + surfaceArea->setMode(SA_NONE); + surfaceArea->_pixel = pixel1; + surfaceArea->setColorFromPixel(); + + for (uint ctr = 0; ctr < entry._data2.size(); ++ctr) { + GridEntry &gridEntry = _grid[ctr]; + sub12->proc28(2, gridEntry, tempV); + gridEntry._position._x = tempV._x + v1; + gridEntry._position._y = tempV._y + v2; + } + + for (uint ctr = 0; ctr < entry._data1.size(); ++ctr) { + Data1 &d1 = entry._data1[ctr]; + GridEntry &grid1 = _grid[d1._index1]; + GridEntry &grid2 = _grid[d1._index2]; + + if (grid2._z > val1 && grid1._z > val1) { + surfaceArea->fn1(FRect(grid1._position._x, grid1._position._y, + grid2._position._x, grid2._position._y)); + } + } + } else { + surfaceArea->setMode(SA_NONE); + surfaceArea->_pixel = pixel2; + surfaceArea->setColorFromPixel(); + + for (uint ctr = 0; ctr < entry._data2.size(); ++ctr) { + GridEntry &gridEntry = _grid[ctr]; + sub12->proc28(2, gridEntry, tempV); + gridEntry._position._x = tempV._x + v1; + gridEntry._position._y = tempV._y + v2; + } + + for (uint ctr = 0; ctr < entry._data1.size(); ++ctr) { + Data1 &d1 = entry._data1[ctr]; + GridEntry &grid1 = _grid[d1._index1]; + GridEntry &grid2 = _grid[d1._index2]; + + if (grid2._z > val1 && grid1._z > val1) { + surfaceArea->fn1(FRect(grid1._position._x, grid1._position._y, + grid2._position._x, grid2._position._y)); + } + } + + surfaceArea->_pixel = pixel3; + surfaceArea->setColorFromPixel(); + surfaceArea->setMode(SA_MODE2); + + for (uint ctr = 0; ctr < entry._data2.size(); ++ctr) { + GridEntry &gridEntry = _grid[ctr]; + sub12->proc28(2, gridEntry, tempV); + gridEntry._position._x = tempV._x + v1; + gridEntry._position._y = tempV._y + v2; + } + + for (uint ctr = 0; ctr < entry._data1.size(); ++ctr) { + Data1 &d1 = entry._data1[ctr]; + GridEntry &grid1 = _grid[d1._index1]; + GridEntry &grid2 = _grid[d1._index2]; + + if (grid2._z > val1 && grid1._z > val1) { + surfaceArea->fn1(FRect(grid1._position._x, grid1._position._y, + grid2._position._x, grid2._position._y)); + } + } + } } void CStarControlSub5::proc3(CErrorCode *errorCode) { @@ -259,40 +506,85 @@ void CStarControlSub5::fn1() { } bool CStarControlSub5::setupEntry(int width, int height, int index, double val) { - /* if (width < 2 || height < 3) return false; SubEntry &entry = _array[index]; entry.clear(); - int height2 = height - 2; - int height1 = height - 1; - entry._data1.resize((2 * height - 3) * width); - entry._data2.resize(width * height2 + 2); - entry._data2[0] = FVector(0.0, val, 0.0); + const double FACTOR = 2 * M_PI / 360.0; + int d1Count, d2Count, size3, height1; + int ctr, ctr2, idx, offset, f11; + double vx, vy, f5, f6, f7, f8, f9, f10; + + d1Count = width * (2 * height - 3); + d2Count = (height - 2) * width + 2; + entry._data1.resize(d1Count); + entry._data2.resize(d2Count); + + height1 = height - 1; + entry._data2[0]._y = val; + + vy = 180.0 / (double)height1; + vx = 360.0 / (double)width; + + for (ctr = height - 2, idx = 0; ctr > 0; --ctr, vy *= 2) { + f5 = 0.0; + f6 = cos(vy * FACTOR); + f7 = sin(vy * FACTOR); - index = 1; - double vy = 180.0 / (double)height1; - double vx = 360.0 / (double)width; - const double FACTOR = 3.1415927 * 0.0055555557; + if (width > 0) { + f8 = f6 * val; - if (height1 > 1) { - double yAmount = vy; - int width12 = width * 12; - for (int yCtr = height1 - 1; yCtr > 0; --yCtr, yAmount += vy) { - double sineVal = sin(yAmount * FACTOR); + for (int xp = width; xp > 0; --xp, ++idx, f5 += vx) { + f9 = f5 * FACTOR; + f10 = cos(f9) * f7 * val; + FVector &tempV = entry._data2[idx]; + tempV._x = sin(f9) * f7 * val; + tempV._y = f8; + tempV._z = f10; + } + } + } + entry._data2[idx] = FVector(0.0, -1.0, 0.0); + + size3 = width * (height - 3) + 1; + offset = 0; + Data1 *data1P = &entry._data1[0]; + for (ctr = 0; ctr < width; ++ctr, ++size3) { + data1P->_index1 = 0; + data1P->_index2 = size3 - width * (height - 3); + ++data1P; + + data1P->_index1 = d2Count - 1; + data1P->_index2 = size3; + ++data1P; + } - | 0.0 * FACTOR | - | cos(yAmount * FACTOR) * val | - | 0.0 | - |yAmount| + f11 = 1; + for (ctr = 1; ctr < height1; ++ctr, f11 += width) { + data1P = &entry._data1[offset]; + + for (ctr2 = 0; ctr2 < width; ++ctr2) { + data1P->_index1 = ctr2 + f11; + if (ctr2 == width - 1) + data1P->_index2 = f11; + else + data1P->_index2 = ctr2 + f11 + 1; + + ++offset; + ++data1P; + + if (ctr < height - 2) { + data1P->_index1 = ctr2 + f11; + ++offset; + data1P->_index2 = width + ctr2 + f11; + ++data1P; + } } } - // TODO - */ return true; } diff --git a/engines/titanic/star_control/star_control_sub5.h b/engines/titanic/star_control/star_control_sub5.h index 32094f5227..b5e5bb1b6a 100644 --- a/engines/titanic/star_control/star_control_sub5.h +++ b/engines/titanic/star_control/star_control_sub5.h @@ -33,8 +33,14 @@ namespace Titanic { class CStarControlSub12; class CStarControlSub5 { + struct Data1 { + int _index1; + int _index2; + Data1() : _index1(0), _index2(0) {} + }; + struct SubEntry { - Common::Array<FPoint> _data1; + Common::Array<Data1> _data1; Common::Array<FVector> _data2; ~SubEntry() { clear(); } @@ -46,28 +52,23 @@ class CStarControlSub5 { struct Entry { int _field0; - byte _field4; - byte _field5; - byte _field6; + byte _pixel1; + byte _pixel2; + byte _pixel3; int _field8; int _fieldC; double _field10; double _field14; - Entry() : _field0(0), _field4(0), _field5(0), _field6(0), _field8(0), + Entry() : _field0(0), _pixel1(0), _pixel2(0), _pixel3(0), _field8(0), _fieldC(0), _field10(0), _field14(0) {} }; - struct GridEntry { - int _field0; - int _field4; - int _field8; - int _fieldC; - int _field10; + struct GridEntry : public FVector { + FPoint _position; int _field14; - GridEntry() : _field0(0), _field4(0), _field8(0), _fieldC(0), - _field10(0), _field14(0) {} + GridEntry() : FVector(), _field14(0) {} }; /** diff --git a/engines/titanic/star_control/star_control_sub6.cpp b/engines/titanic/star_control/star_control_sub6.cpp index 27e2a491f8..0ced3df9fe 100644 --- a/engines/titanic/star_control/star_control_sub6.cpp +++ b/engines/titanic/star_control/star_control_sub6.cpp @@ -30,14 +30,56 @@ CStarControlSub6::CStarControlSub6() { clear(); } -CStarControlSub6::CStarControlSub6(int mode, double val) { - set(mode, val); +CStarControlSub6::CStarControlSub6(Axis axis, double amount) { + setRotationMatrix(axis, amount); } CStarControlSub6::CStarControlSub6(const CStarControlSub6 *src) { copyFrom(src); } +CStarControlSub6::CStarControlSub6(const CStarControlSub6 *s1, const CStarControlSub6 *s2) { + _row1._x = s2->_row1._x * s1->_row1._x + + s1->_row1._z * s2->_row3._x + + s1->_row1._y * s2->_row2._x; + _row1._y = s1->_row1._x * s2->_row1._y + + s2->_row3._y * s1->_row1._z + + s2->_row2._y * s1->_row1._y; + _row1._z = s1->_row1._x * s2->_row1._z + + s2->_row3._z * s1->_row1._z + + s2->_row2._z * s1->_row1._y; + _row2._x = s2->_row1._x * s1->_row2._x + + s1->_row2._y * s2->_row2._x + + s1->_row2._z * s2->_row3._x; + _row2._y = s1->_row2._y * s2->_row2._y + + s1->_row2._z * s2->_row3._y + + s2->_row1._y * s1->_row2._x; + _row2._z = s2->_row1._z * s1->_row2._x + + s1->_row2._y * s2->_row2._z + + s1->_row2._z * s2->_row3._z; + _row3._x = s2->_row1._x * s1->_row3._x + + s1->_row3._y * s2->_row2._x + + s1->_row3._z * s2->_row3._x; + _row3._y = s1->_row3._z * s2->_row3._y + + s1->_row3._y * s2->_row2._y + + s2->_row1._y * s1->_row3._x; + _row3._z = s2->_row3._z * s1->_row3._z + + s2->_row2._z * s1->_row3._y + + s2->_row1._z * s1->_row3._x; + _vector._x = s2->_row1._x * s1->_vector._x + + s1->_vector._y * s2->_row2._x + + s1->_vector._z * s2->_row3._x + + s2->_vector._x; + _vector._y = s1->_vector._z * s2->_row3._y + + s1->_vector._y * s2->_row2._y + + s1->_vector._x * s2->_row1._y + + s2->_vector._y; + _vector._z = s1->_vector._y * s2->_row2._z + + s1->_vector._z * s2->_row3._z + + s1->_vector._x * s2->_row1._z + + s2->_vector._z; +} + void CStarControlSub6::init() { _static = nullptr; } @@ -47,18 +89,18 @@ void CStarControlSub6::deinit() { _static = nullptr; } -void CStarControlSub6::clear() { - FMatrix::clear(); +void CStarControlSub6::identity() { + FMatrix::identity(); _vector.clear(); } -void CStarControlSub6::set(int mode, double amount) { - const double ROTATION = 3.1415927 * 0.0055555557; +void CStarControlSub6::setRotationMatrix(Axis axis, double amount) { + const double ROTATION = 2 * M_PI / 360.0; double sinVal = sin(amount * ROTATION); double cosVal = cos(amount * ROTATION); - switch (mode) { - case 0: + switch (axis) { + case X_AXIS: _row1._x = 1.0; _row1._y = 0.0; _row1._z = 0.0; @@ -70,7 +112,7 @@ void CStarControlSub6::set(int mode, double amount) { _row3._z = cosVal; break; - case 1: + case Y_AXIS: _row1._x = cosVal; _row1._y = 0.0; _row1._z = sinVal; @@ -82,7 +124,7 @@ void CStarControlSub6::set(int mode, double amount) { _row3._z = sinVal; break; - case 2: + case Z_AXIS: _row1._x = cosVal; _row1._y = sinVal; _row1._z = 0.0; @@ -108,52 +150,73 @@ void CStarControlSub6::copyFrom(const CStarControlSub6 *src) { _vector = src->_vector; } -void CStarControlSub6::setup(CStarControlSub6 *dest, const CStarControlSub6 *s2, const CStarControlSub6 *s3) { - CStarControlSub6 &d = *dest; - - d._row1._x = s3->_row1._x * s2->_row1._x - + s2->_row1._z * s3->_row3._x - + s2->_row1._y * s3->_row2._x; - d._row1._y = s2->_row1._x * s3->_row1._y - + s3->_row3._y * s2->_row1._z - + s3->_row2._y * s2->_row1._y; - d._row1._z = s2->_row1._x * s3->_row1._z - + s3->_row3._z * s2->_row1._z - + s3->_row2._z * s2->_row1._y; - d._row2._x = s3->_row1._x * s2->_row2._x - + s2->_row2._y * s3->_row2._x - + s2->_row2._z * s3->_row3._x; - d._row2._y = s2->_row2._y * s3->_row2._y - + s2->_row2._z * s3->_row3._y - + s3->_row1._y * s2->_row2._x; - d._row2._z = s3->_row1._z * s2->_row2._x - + s2->_row2._y * s3->_row2._z - + s2->_row2._z * s3->_row3._z; - d._row3._x = s3->_row1._x * s2->_row3._x - + s2->_row3._y * s3->_row2._x - + s2->_row3._z * s3->_row3._x; - d._row3._y = s2->_row3._z * s3->_row3._y - + s2->_row3._y * s3->_row2._y - + s3->_row1._y * s2->_row3._x; - d._row3._z = s3->_row3._z * s2->_row3._z - + s3->_row2._z * s2->_row3._y - + s3->_row1._z * s2->_row3._x; - d._vector._x = s3->_row1._x * s2->_vector._x - + s2->_vector._y * s3->_row2._x - + s2->_vector._z * s3->_row3._x - + s3->_vector._x; - d._vector._y = s2->_vector._z * s3->_row3._y - + s2->_vector._y * s3->_row2._y - + s2->_vector._x * s3->_row1._y - + s3->_vector._y; - d._vector._z = s2->_vector._y * s3->_row2._z - + s2->_vector._z * s3->_row3._z - + s2->_vector._x * s3->_row1._z - + s3->_vector._z; +void CStarControlSub6::copyFrom(const FMatrix &src) { + _row1 = src._row1; + _row2 = src._row2; + _row3 = src._row3; } -void CStarControlSub6::fn1(CStarControlSub6 *sub6) { - // TODO +void CStarControlSub6::fn4(CStarControlSub6 *sub6) { + double v2, v3, v6, v7, v8, v9, v10, v11; + double v12, v13, v14, v15, v16, v17, v18; + + v16 = _row3._z * _row2._y; + v2 = _row1._x * v16; + v3 = 0.0; + v18 = v2; + if (v2 < 0.0) { + v3 = v18; + v2 = 0.0; + } + v6 = _row3._x * _row1._y * _row2._z; + if (v6 < 0.0) + v3 = v3 + v6; + else + v2 = v2 + v6; + v7 = _row3._y * _row1._z * _row2._x; + if (v7 < 0.0) + v3 = v3 + v7; + else + v2 = v2 + v7; + if (-(_row3._x * _row1._z * _row2._y) < 0.0) + v3 = v3 - _row3._x * _row1._z * _row2._y; + else + v2 = v2 - _row3._x * _row1._z * _row2._y; + if (-(_row1._y * _row2._x * _row3._z) < 0.0) + v3 = v3 - _row1._y * _row2._x * _row3._z; + else + v2 = v2 - _row1._y * _row2._x * _row3._z; + v17 = _row2._z * _row3._y; + if (-(_row1._x * v17) < 0.0) + v3 = v3 - _row1._x * v17; + else + v2 = v2 - _row1._x * v17; + v18 = v3 + v2; + assert(!(v18 == 0.0 || fabs(v18 / (v2 - v3)) < 1.0e-10)); + + v8 = 1.0 / v18; + v18 = v8; + sub6->_row1._x = (v16 - v17) * v8; + sub6->_row2._x = -(_row2._x * _row3._z - _row3._x * _row2._z) * v8; + sub6->_row3._x = (_row3._y * _row2._x - _row3._x * _row2._y) * v8; + sub6->_row1._y = -(_row1._y * _row3._z - _row3._y * _row1._z) * v8; + sub6->_row2._y = (_row1._x * _row3._z - _row3._x * _row1._z) * v8; + sub6->_row3._y = -(_row1._x * _row3._y - _row3._x * _row1._y) * v8; + sub6->_row1._z = (_row1._y * _row2._z - _row1._z * _row2._y) * v8; + sub6->_row2._z = -(_row1._x * _row2._z - _row1._z * _row2._x) * v8; + v9 = sub6->_row1._x; + v10 = sub6->_row2._y; + v11 = sub6->_row3._y; + v12 = sub6->_row1._z; + v13 = sub6->_row2._z; + sub6->_row3._z = (_row1._x * _row2._y - _row1._y * _row2._x) * v18; + v14 = v9; + v15 = sub6->_row3._z; + sub6->_vector._x = -(v14 * _vector._x + + _vector._y * sub6->_row2._x + + _vector._z * sub6->_row3._x); + sub6->_vector._y = -(_vector._x * sub6->_row1._y + v10 * _vector._y + v11 * _vector._z); + sub6->_vector._z = -(v12 * _vector._x + v13 * _vector._y + v15 * _vector._z); } } // End of namespace Titanic diff --git a/engines/titanic/star_control/star_control_sub6.h b/engines/titanic/star_control/star_control_sub6.h index 16304b8540..91def29973 100644 --- a/engines/titanic/star_control/star_control_sub6.h +++ b/engines/titanic/star_control/star_control_sub6.h @@ -37,27 +37,28 @@ public: FVector _vector; public: CStarControlSub6(); - CStarControlSub6(int mode, double amount); + CStarControlSub6(Axis axis, double amount); CStarControlSub6(const CStarControlSub6 *src); + CStarControlSub6(const CStarControlSub6 *s1, const CStarControlSub6 *s2); /** - * Clear the item + * Sets an identity matrix */ - void clear(); + void identity(); /** - * Sets up a passed instance from the specified two other ones + * Sets a rotation matrix for the given axis for the given amount */ - static void setup(CStarControlSub6 *dest, const CStarControlSub6 *s2, const CStarControlSub6 *s3); + void setRotationMatrix(Axis axis, double val); + + void copyFrom(const CStarControlSub6 *src); /** - * Sets the default data + * Copy from the specified matrix */ - void set(int mode, double val); - - void copyFrom(const CStarControlSub6 *src); + void copyFrom(const FMatrix &src); - void fn1(CStarControlSub6 *sub6); + void fn4(CStarControlSub6 *sub6); }; } // End of namespace Titanic diff --git a/engines/titanic/star_control/star_control_sub7.cpp b/engines/titanic/star_control/star_control_sub7.cpp index 4b694810ad..8386e7305f 100644 --- a/engines/titanic/star_control/star_control_sub7.cpp +++ b/engines/titanic/star_control/star_control_sub7.cpp @@ -21,18 +21,62 @@ */ #include "titanic/star_control/star_control_sub7.h" +#include "titanic/star_control/star_control_sub12.h" namespace Titanic { void CStarControlSub7::draw(CSurfaceArea *surfaceArea, CStarControlSub12 *sub12, CStarControlSub5 *sub5) { - // TODO + if (_data.empty()) + return; + + CStarControlSub6 sub6 = sub12->proc23(); + double threshold = sub12->proc25(); + FPoint center((double)surfaceArea->_width * 0.5, + surfaceArea->_height * 0.5); + FVector newV; + + uint savedPixel = surfaceArea->_pixel; + surfaceArea->_pixel = 0xffff; + surfaceArea->setColorFromPixel(); + + for (uint idx = 0; idx < _data.size(); ++idx) { + const CBaseStarEntry &star = _data[idx]; + + newV._x = sub6._row1._x * star._position._x + sub6._row3._x * star._position._z + + sub6._row2._x * star._position._y + sub6._vector._x; + newV._y = sub6._row1._y * star._position._x + sub6._row3._y * star._position._z + + sub6._row2._y * star._position._x + sub6._vector._y; + newV._z = sub6._row1._z * star._position._x + sub6._row3._z * star._position._z + + sub6._row2._z * star._position._y + sub6._vector._z; + + if (newV._z > threshold) { + FVector vTemp; + sub12->proc28(2, newV, vTemp); + + FRect r1(center._x + vTemp._x, center._y + vTemp._y, + center._x + vTemp._x + 4.0, center._y + vTemp._y + 4.0); + surfaceArea->fn1(r1); + + FRect r2(r1.right, r1.bottom, r1.right + 4.0, r1.top); + surfaceArea->fn1(r2); + + FRect r3(r2.right, r1.top, r1.right, r1.top - 4.0); + surfaceArea->fn1(r3); + + FRect r4(r1.right, r1.top - 4.0, r1.left, r1.top); + surfaceArea->fn1(r4); + } + } + + surfaceArea->_pixel = savedPixel; + surfaceArea->setColorFromPixel(); } bool CStarControlSub7::addStar(const CBaseStarEntry *entry) { // iterate through the existing stars for (uint idx = 0; idx < _data.size(); ++idx) { CBaseStarEntry &star = _data[idx]; - if (star._position == entry->_position) { + if (star == *entry) { // Found a matching star at the exact same position, so remove it instead _data.remove_at(idx); return true; diff --git a/engines/titanic/star_control/star_control_sub8.cpp b/engines/titanic/star_control/star_control_sub8.cpp index 50c90d2bc1..bf29b053c5 100644 --- a/engines/titanic/star_control/star_control_sub8.cpp +++ b/engines/titanic/star_control/star_control_sub8.cpp @@ -24,36 +24,102 @@ #include "titanic/star_control/star_control_sub7.h" #include "titanic/star_control/star_control_sub12.h" #include "titanic/star_control/star_field.h" +#include "titanic/star_control/star_ref.h" namespace Titanic { -CStarControlSub8::CStarControlSub8() : _field8(-1), _fieldC(-1) { -#if 0 - _field4(0), _field8(-1) -#endif -} - -bool MouseButtonDown(const Common::Point &pt) { - // TODO - return true; -} - -int CStarControlSub8::findStar(const Common::Point &pt) { - // TODO - return -1; +CStarControlSub8::CStarControlSub8() : _field8(-1), _entryIndex(-1) { } void CStarControlSub8::selectStar(int index, CVideoSurface *surface, CStarField *starField, CStarControlSub7 *sub7) { - // TODO + if (_entryIndex >= 0) { + if (_entryIndex == _field8) { + if (_field8 != 2) { + if (_positions[index] != _positions[_entryIndex + 1]) { + surface->lock(); + + CSurfaceArea surfaceArea(surface); + fn4(index, &surfaceArea); + surface->unlock(); + + ++_entryIndex; + CStarPosition &newP = _positions[_entryIndex + 1]; + newP = _positions[index]; + + const CBaseStarEntry *starP = starField->getDataPtr(_positions[index]._index1); + sub7->addStar(starP); + } + } + } else if (_entryIndex == _field8 + 1) { + if (_positions[index] == _positions[_entryIndex + 1]) { + surface->lock(); + CSurfaceArea surfaceArea(surface); + fn6(&surfaceArea); + surface->unlock(); + + --_entryIndex; + const CBaseStarEntry *starP = starField->getDataPtr(_positions[index]._index1); + sub7->addStar(starP); + } else { + surface->lock(); + CSurfaceArea surfaceArea(surface); + fn6(&surfaceArea); + fn4(index, &surfaceArea); + surface->unlock(); + + const CBaseStarEntry *starP; + starP = starField->getDataPtr(_positions[_entryIndex]._index1); + sub7->addStar(starP); + starP = starField->getDataPtr(_positions[index]._index1); + sub7->addStar(starP); + + CStarPosition &newP = _positions[_entryIndex + 1]; + newP = _positions[index]; + } + } + } else { + surface->lock(); + CSurfaceArea surfaceArea(surface); + fn4(index, &surfaceArea); + surface->unlock(); + + ++_entryIndex; + CStarPosition &newP = _positions[_entryIndex + 1]; + newP = _positions[index]; + + const CBaseStarEntry *starP = starField->getDataPtr(_positions[index]._index1); + sub7->addStar(starP); + } } -void CStarControlSub8::fn1(CStarField *starField, CSurfaceArea *surfaceArea, CStarControlSub12 *sub12) { - // TODO +bool CStarControlSub8::fn1(CStarField *starField, CSurfaceArea *surfaceArea, CStarControlSub12 *sub12) { + int count = starField->baseFn2(surfaceArea, sub12); + + if (count > 0) { + allocate(count); + CStarRef2 starRef(starField, &_positions); + starRef.process(surfaceArea, sub12); + return true; + } else { + clear(); + return false; + } } void CStarControlSub8::fn2(CVideoSurface *surface, CStarField *starField, CStarControlSub7 *sub7) { - // TODO + if (_field8 <= -1) { + if (_entryIndex > -1) { + fn5(_entryIndex, surface, starField, sub7); + --_entryIndex; + } + } else { + --_field8; + if (_entryIndex - _field8 > 1) { + fn5(_entryIndex, surface, starField, sub7); + --_entryIndex; + } + } } void CStarControlSub8::fn3() { @@ -62,15 +128,97 @@ void CStarControlSub8::fn3() { } FPoint CStarControlSub8::getPosition() const { - return (_fieldC >= 0 && _fieldC <= 2) ? _data[_fieldC]._position : FPoint(); + return (_entryIndex >= 0 && _entryIndex <= 2) ? + FPoint(_entries[_entryIndex]) : FPoint(); } void CStarControlSub8::draw(CSurfaceArea *surfaceArea) { - // TODO + if (!_positions.empty()) { + uint savedPixel = surfaceArea->_pixel; + surfaceArea->_pixel = 0xff; + surfaceArea->setColorFromPixel(); + SurfaceAreaMode savedMode = surfaceArea->setMode(SA_NONE); + + for (int idx = 0; idx < _entryIndex; ++idx) { + const CStarPosition &src = _entries[idx]; + double xp = src.x, yp = src.y; + + surfaceArea->fn1(FRect(xp - 8.0, yp, xp - 4.0, yp)); + surfaceArea->fn1(FRect(xp + 4.0, yp, xp + 8.0, yp)); + surfaceArea->fn1(FRect(xp, yp - 8.0, xp, yp - 4.0)); + surfaceArea->fn1(FRect(xp, yp + 4.0, xp, yp + 8.0)); + } + + surfaceArea->_pixel = savedPixel; + surfaceArea->setColorFromPixel(); + surfaceArea->setMode(savedMode); + } +} + +void CStarControlSub8::allocate(int count) { + if (!_positions.empty()) { + if ((int)_positions.size() == count) + return; + + clear(); + } + + _positions.resize(count); } void CStarControlSub8::clear() { - // TODO + _positions.clear(); + _field8 = _entryIndex = -1; +} + +int CStarControlSub8::indexOf(const Common::Point &pt) const { + Common::Rect r(pt.x - 2, pt.y - 2, pt.x + 2, pt.y + 2); + + for (int idx = 0; idx < (int)_positions.size(); ++idx) { + if (r.contains(_positions[idx])) + return idx; + } + + return -1; +} + +void CStarControlSub8::fn4(int index, CSurfaceArea *surfaceArea) { + if (index >= 0 && index < (int)_positions.size()) { + const CStarPosition &pt = _positions[index]; + fn7(pt, surfaceArea); + } +} + +void CStarControlSub8::fn5(int index, CVideoSurface *surface, CStarField *starField, CStarControlSub7 *sub7) { + surface->lock(); + CSurfaceArea surfaceArea(surface); + fn7(_positions[index + 1], &surfaceArea); + surface->unlock(); + + const CBaseStarEntry *starP = starField->getDataPtr(_positions[index + 1]._index1); + sub7->addStar(starP); +} + +void CStarControlSub8::fn6(CSurfaceArea *surfaceArea) { + const CStarPosition &pt = _positions[_entryIndex]; + fn7(pt, surfaceArea); +} + +void CStarControlSub8::fn7(const FPoint &pt, CSurfaceArea *surfaceArea) { + uint savedPixel = surfaceArea->_pixel; + surfaceArea->_pixel = 255; + surfaceArea->setColorFromPixel(); + SurfaceAreaMode savedMode = surfaceArea->setMode(SA_MODE3); + + + surfaceArea->fn1(FRect(pt._x - 8.0, pt._y, pt._x - 4.0, pt._y)); + surfaceArea->fn1(FRect(pt._x - -4.0, pt._y, pt._x + 8.0, pt._y)); + surfaceArea->fn1(FRect(pt._x, pt._y - 8.0, pt._x, pt._y - 4.0)); + surfaceArea->fn1(FRect(pt._x, pt._y + 4.0, pt._x, pt._y + 8.0)); + + surfaceArea->_pixel = savedPixel; + surfaceArea->setColorFromPixel(); + surfaceArea->setMode(savedMode); } } // End of namespace Titanic diff --git a/engines/titanic/star_control/star_control_sub8.h b/engines/titanic/star_control/star_control_sub8.h index f7f8ba4fb5..4939179481 100644 --- a/engines/titanic/star_control/star_control_sub8.h +++ b/engines/titanic/star_control/star_control_sub8.h @@ -23,6 +23,9 @@ #ifndef TITANIC_STAR_CONTROL_SUB8_H #define TITANIC_STAR_CONTROL_SUB8_H +#include "common/array.h" +#include "common/rect.h" +#include "titanic/star_control/base_star.h" #include "titanic/star_control/surface_area.h" #include "titanic/star_control/fpoint.h" #include "titanic/support/simple_file.h" @@ -35,19 +38,20 @@ class CStarControlSub7; class CStarControlSub12; class CStarControlSub8 { - struct StructEntry { - FPoint _position; - int _field8; - int _fieldC; - - StructEntry() : _field8(0), _fieldC(0) {} - }; private: -#if 0 - int _field0; - int _field4; -#endif - StructEntry _data[3]; + Common::Array<CStarPosition> _positions; + int _entryIndex; + CStarPosition _entries[3]; +private: + /** + * Allocates space in the _rects array + */ + void allocate(int count); + + /** + * Clears any current data + */ + void clear(); public: int _field8; int _fieldC; @@ -65,19 +69,24 @@ public: */ void save(SimpleFile *file, int indent) {} - int findStar(const Common::Point &pt); - void selectStar(int starNum, CVideoSurface *surface, CStarField *starField, CStarControlSub7 *sub7); void draw(CSurfaceArea *surfaceArea); - void fn1(CStarField *starField, CSurfaceArea *surfaceArea, CStarControlSub12 *sub12); + bool fn1(CStarField *starField, CSurfaceArea *surfaceArea, CStarControlSub12 *sub12); void fn2(CVideoSurface *surface, CStarField *starField, CStarControlSub7 *sub7); void fn3(); + void fn4(int index, CSurfaceArea *surfaceArea); + void fn5(int index, CVideoSurface *surface, CStarField *starField, CStarControlSub7 *sub7); + void fn6(CSurfaceArea *surfaceArea); + void fn7(const FPoint &pt, CSurfaceArea *surfaceArea); FPoint getPosition() const; - void clear(); + /** + * Returns the index of an entry in the rects list a given point falls within + */ + int indexOf(const Common::Point &pt) const; }; } // End of namespace Titanic diff --git a/engines/titanic/star_control/star_field.cpp b/engines/titanic/star_control/star_field.cpp index 3a09be3e8a..5c22e5e308 100644 --- a/engines/titanic/star_control/star_field.cpp +++ b/engines/titanic/star_control/star_field.cpp @@ -230,9 +230,9 @@ bool CStarField::mouseButtonDown(CVideoSurface *surface, CStarControlSub12 *sub1 int flags, const Common::Point &pt) { if (_mode == MODE_STARFIELD) { CSurfaceArea surfaceArea(surface); - return selectStar(&surfaceArea, sub12, 0, pt); + return selectStar(&surfaceArea, sub12, pt); } else { - int starNum = _sub8.findStar(pt); + int starNum = _sub8.indexOf(pt); if (starNum >= 0) { _sub8.selectStar(starNum, surface, this, &_sub7); return true; diff --git a/engines/titanic/star_control/star_points1.cpp b/engines/titanic/star_control/star_points1.cpp index c72795f11d..ab5da111ac 100644 --- a/engines/titanic/star_control/star_points1.cpp +++ b/engines/titanic/star_control/star_points1.cpp @@ -27,7 +27,7 @@ namespace Titanic { #define ARRAY_COUNT 876 -const double FACTOR = 3.1415927 * 0.0055555557; +const double FACTOR = 2 * M_PI / 360.0; CStarPoints1::CStarPoints1() { } diff --git a/engines/titanic/star_control/star_points2.cpp b/engines/titanic/star_control/star_points2.cpp index 9c4cfe8cf5..7a3e873e90 100644 --- a/engines/titanic/star_control/star_points2.cpp +++ b/engines/titanic/star_control/star_points2.cpp @@ -27,7 +27,7 @@ namespace Titanic { #define ARRAY_COUNT 80 -const double FACTOR = 3.1415927 * 0.0055555557; +const double FACTOR = 2 * M_PI / 360.0; bool CStarPoints2::initialize() { // Get a reference to the starfield points resource @@ -47,7 +47,7 @@ bool CStarPoints2::initialize() { v1 = stream->readSint32LE(); v2 = stream->readSint32LE(); v1 *= 0.015 * FACTOR; - v2 *= 0.0099999998 * FACTOR; + v2 *= FACTOR / 100.0; entry._x = cos(v1) * 3000000.0 * cos(v2); entry._y = sin(v1) * 3000000.0 * cos(v2); diff --git a/engines/titanic/star_control/star_ref.cpp b/engines/titanic/star_control/star_ref.cpp new file mode 100644 index 0000000000..7f36ae7473 --- /dev/null +++ b/engines/titanic/star_control/star_ref.cpp @@ -0,0 +1,63 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "titanic/star_control/star_ref.h" + +namespace Titanic { + +void CBaseStarRef::process(CSurfaceArea *surface, CStarControlSub12 *sub12) { + // TODO +} + +/*------------------------------------------------------------------------*/ + +bool CStarRef1::check(const Common::Point &pt, int index) { + Common::Rect r(pt.x - 2, pt.y - 2, pt.x + 2, pt.y + 2); + if (r.contains(_position)) { + _index = index; + return false; + } else { + return true; + } +} + +/*------------------------------------------------------------------------*/ + +bool CStarRef2::check(const Common::Point &pt, int index) { + if (_index >= (int)_positions->size()) + return false; + + CStarPosition &sp = (*_positions)[index]; + sp.x = pt.x; + sp.y = pt.y; + sp._index1 = sp._index2 = index; + return true; +} + +/*------------------------------------------------------------------------*/ + +bool CStarRef3::check(const Common::Point &pt, int index) { + ++_index; + return true; +} + +} // End of namespace Titanic diff --git a/engines/titanic/star_control/star_ref.h b/engines/titanic/star_control/star_ref.h new file mode 100644 index 0000000000..c6fec90fbc --- /dev/null +++ b/engines/titanic/star_control/star_ref.h @@ -0,0 +1,84 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include "common/rect.h" +#include "titanic/star_control/base_star.h" +#include "titanic/star_control/star_control_sub12.h" +#include "titanic/star_control/surface_area.h" + +#ifndef TITANIC_STAR_REF_H +#define TITANIC_STAR_REF_H + +namespace Titanic { + +class CBaseStarRef { +protected: + CBaseStar *_star; +public: + CBaseStarRef(CBaseStar *star) : _star(star) {} + CBaseStarRef() : _star(nullptr) {} + virtual ~CBaseStarRef() {} + + void process(CSurfaceArea *surface, CStarControlSub12 *sub12); + + virtual bool check(const Common::Point &pt, int index) { return false; } +}; + +class CStarRef1 : public CBaseStarRef { +private: + Common::Point _position; +public: + int _index; +public: + CStarRef1(CBaseStar *star, const Common::Point &pt) : + CBaseStarRef(star), _index(-1) {} + virtual ~CStarRef1() {} + + virtual bool check(const Common::Point &pt, int index); +}; + +class CStarRef2 : public CBaseStarRef { +private: + Common::Array<CStarPosition> *_positions; +public: + int _index; +public: + CStarRef2(CBaseStar *star, Common::Array<CStarPosition> *positions) : + CBaseStarRef(star), _positions(positions), _index(0) {} + virtual ~CStarRef2() {} + + virtual bool check(const Common::Point &pt, int index); +}; + +class CStarRef3 : public CBaseStarRef { +public: + int _index; +public: + CStarRef3(CBaseStar *star) :CBaseStarRef(star), _index(0) {} + virtual ~CStarRef3() {} + + virtual bool check(const Common::Point &pt, int index); +}; + +} // End of namespace Titanic + +#endif /* TITANIC_STAR_REF_H */ diff --git a/engines/titanic/star_control/star_view.cpp b/engines/titanic/star_control/star_view.cpp index 23e9325a64..34fd371bac 100644 --- a/engines/titanic/star_control/star_view.cpp +++ b/engines/titanic/star_control/star_view.cpp @@ -30,8 +30,8 @@ namespace Titanic { -CStarView::CStarView() : _sub12(nullptr, nullptr), _sub13((void *)nullptr), - _owner(nullptr), _starField(nullptr), _videoSurface(nullptr), _field118(0), +CStarView::CStarView() : _sub12((const CStar20Data *)nullptr), _owner(nullptr), + _starField(nullptr), _videoSurface(nullptr), _field118(0), _videoSurface2(nullptr), _homePhotoMask(nullptr), _field218(false), _showingPhoto(false) { CStar20Data data = { 0, 0, 100000.0, 0, 20.0, 1.0, 1.0, 1.0 }; @@ -177,7 +177,7 @@ bool CStarView::KeyCharMsg(int key, CErrorCode *errorCode) { case Common::KEYCODE_z: case Common::KEYCODE_c: if (v == -1) { - sub6.set(key == Common::KEYCODE_z ? MODE_PHOTO : MODE_STARFIELD, 1.0); + sub6.setRotationMatrix(key == Common::KEYCODE_z ? Y_AXIS : X_AXIS, 1.0); _sub12.proc22(sub6); _sub12.proc15(errorCode); return true; @@ -210,7 +210,7 @@ bool CStarView::KeyCharMsg(int key, CErrorCode *errorCode) { case Common::KEYCODE_x: if (v == -1) { - sub6.set(MODE_PHOTO, -1.0); + sub6.setRotationMatrix(Y_AXIS, -1.0); _sub12.proc22(sub6); _sub12.proc15(errorCode); return true; @@ -219,7 +219,7 @@ bool CStarView::KeyCharMsg(int key, CErrorCode *errorCode) { case Common::KEYCODE_QUOTE: if (v == -1) { - sub6.set(MODE_STARFIELD, -1.0); + sub6.setRotationMatrix(X_AXIS, -1.0); _sub12.proc22(sub6); _sub12.proc15(errorCode); return true; @@ -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) { diff --git a/engines/titanic/star_control/surface_area.cpp b/engines/titanic/star_control/surface_area.cpp index 9b46cf03b7..4cfc4f84d2 100644 --- a/engines/titanic/star_control/surface_area.cpp +++ b/engines/titanic/star_control/surface_area.cpp @@ -28,11 +28,14 @@ CSurfaceArea::CSurfaceArea(CVideoSurface *surface) { _width = surface->getWidth(); _height = surface->getHeight(); _pitch = surface->getPitch(); + _field0 = 0; + _colorMask = _color = 0; + _mode = SA_NONE; // Original supported other pixel depths _bpp = surface->getPixelDepth(); - assert(_bpp == 2); _pixelsPtr = surface->getPixels(); + assert(_bpp == 2 && _pixelsPtr); initialize(); } diff --git a/engines/titanic/titanic.h b/engines/titanic/titanic.h index fdc9402d89..6bc999cd40 100644 --- a/engines/titanic/titanic.h +++ b/engines/titanic/titanic.h @@ -166,7 +166,7 @@ public: /** * Returns a random floating point number between 0.0 to 65535.0 */ - double getRandomFloat() { return getRandomNumber(0xffffffff) * 0.000015259022; } + double getRandomFloat() { return getRandomNumber(0xfffffffe) * 0.000015259022; } /** * Support method that generates a savegame name |