aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Gilbert2017-03-23 19:49:05 -0400
committerPaul Gilbert2017-03-23 19:49:05 -0400
commit6da793a8dd4539294a6bc0347cd57c1fd0580044 (patch)
treee03ea575e3e8288ff4efe23112388107e8b86045
parentb0b0971b3ec3f1771def057c1e7d2560dd2709c4 (diff)
downloadscummvm-rg350-6da793a8dd4539294a6bc0347cd57c1fd0580044.tar.gz
scummvm-rg350-6da793a8dd4539294a6bc0347cd57c1fd0580044.tar.bz2
scummvm-rg350-6da793a8dd4539294a6bc0347cd57c1fd0580044.zip
TITANIC: Finished CStarControlSub26 class
-rw-r--r--engines/titanic/star_control/star_control_sub25.cpp4
-rw-r--r--engines/titanic/star_control/star_control_sub26.cpp114
-rw-r--r--engines/titanic/star_control/star_control_sub26.h6
3 files changed, 118 insertions, 6 deletions
diff --git a/engines/titanic/star_control/star_control_sub25.cpp b/engines/titanic/star_control/star_control_sub25.cpp
index a8e13473f2..0bd5a860e8 100644
--- a/engines/titanic/star_control/star_control_sub25.cpp
+++ b/engines/titanic/star_control/star_control_sub25.cpp
@@ -29,6 +29,10 @@ void CStarControlSub25::fn1(const FMatrix &m1, const FMatrix &m2) {
_matrix1 = m1;
_matrix2 = m2;
+ DMatrix matrix = _matrix2;
+ _sub1.fn4(matrix);
+ matrix = _matrix2;
+ _sub2.fn4(matrix);
}
void CStarControlSub25::fn2(double val, FMatrix &m) {
diff --git a/engines/titanic/star_control/star_control_sub26.cpp b/engines/titanic/star_control/star_control_sub26.cpp
index 91dd1576f9..198e2f9074 100644
--- a/engines/titanic/star_control/star_control_sub26.cpp
+++ b/engines/titanic/star_control/star_control_sub26.cpp
@@ -25,11 +25,6 @@
namespace Titanic {
-double CStarControlSub26::fn1() const {
- return _sub._v1 * _sub._v1 + _sub._v2 * _sub._v2 +
- _sub._v3 * _sub._v3 + _field0 * _field0;
-}
-
void CStarControlSub26::setup(double val1, double val2, double val3, double val4) {
_field0 = val1;
_sub._v1 = val2;
@@ -42,8 +37,115 @@ void CStarControlSub26::copyFrom(const CStarControlSub26 *src) {
_sub = src->_sub;
}
+double CStarControlSub26::fn1() const {
+ return _sub._v1 * _sub._v1 + _sub._v2 * _sub._v2 +
+ _sub._v3 * _sub._v3 + _field0 * _field0;
+}
+
+double CStarControlSub26::fn2(const CStarControlSub26 *src) {
+ return _field0 * src->_field0 + _sub._v1 * src->_sub._v1
+ + _sub._v2 * src->_sub._v2 + _sub._v3 * src->_sub._v3;
+}
+
+const CStarControlSub26 *CStarControlSub26::fn3(const CStarControlSub26 *src, double val) {
+ CStarControlSub26::setup(_field0 * val, _sub._v1 * val, _sub._v2 * val, _sub._v3 * val);
+ return src;
+}
+
+void CStarControlSub26::fn4(const DMatrix &m) {
+ double total = m._row1._x + m._row3._z + m._row2._y + 1.0;
+
+ if (total <= 0.00001) {
+ total = m._row3._z;
+
+ if (m._row1._x <= m._row3._z) {
+ if (m._row2._y > total)
+ total = m._row2._y;
+ } else if (m._row1._x > total) {
+ total = m._row1._x;
+ }
+
+ if (total == m._row1._x) {
+ double val1 = sqrt(m._row1._x - -1.0 - m._row2._y - m._row3._z);
+ double val2 = 0.5 / val1;
+ _sub._v1 = val1 * 0.5;
+ _field0 = (m._row2._z - m._row3._y) * val2;
+ _sub._v2 = (m._row2._x + m._row1._y) * val2;
+ _sub._v3 = (m._row3._x + m._row1._z) * val2;
+ } else if (total == m._row2._y) {
+ double val1 = sqrt(m._row2._y - -1.0 - m._row3._z - m._row1._x);
+ double val2 = 0.5 / val1;
+ _sub._v2 = val1 * 0.5;
+ _field0 = (m._row3._x - m._row1._z) * val2;
+ _sub._v3 = (m._row3._y + m._row2._z) * val2;
+ _sub._v1 = (m._row2._x + m._row1._y) * val2;
+ } else if (total == m._row3._z) {
+ double val1 = sqrt(m._row3._z - -1.0 - m._row1._x - m._row2._y);
+ double val2 = 0.5 / val1;
+ _sub._v3 = val1 * 0.5;
+ _field0 = (m._row1._y - m._row2._x) * val2;
+ _sub._v1 = (m._row3._x + m._row1._z) * val2;
+ _sub._v2 = (m._row3._y + m._row2._z) * val2;
+ }
+ } else {
+ double val1 = 0.5 / sqrt(total);
+ _field0 = sqrt(total) * 0.5;
+ _sub._v1 = (m._row2._z - m._row3._y) * val1;
+ _sub._v2 = (m._row3._x - m._row1._z) * val1;
+ _sub._v3 = (m._row1._y - m._row2._x) * val1;
+ }
+}
+
void CStarControlSub26::fn5(double val, CStarControlSub26 *s1, CStarControlSub26 *s2) {
- // TODO
+ CStarControlSub26 sub1 = *this;
+ CStarControlSub26 sub2, sub3, sub4;
+ double val1 = sub1.fn2(s1);
+
+ if (val1 < 0.0) {
+ val1 = -val1;
+ sub2.setup(-sub1._field0, -sub1._sub._v1, -sub1._sub._v2, -sub1._sub._v3);
+ sub1 = sub2;
+ }
+
+ if (val1 - -1.0 <= 0.00001) {
+ double sval1 = sub1._sub._v1;
+ double sval3 = sub1._sub._v3;
+ double sval2 = -sub1._sub._v2;
+ double sval0 = -sub1._field0;
+
+ sub2._sub._v1 = sval2;
+ sub2._sub._v2 = sval1;
+ sub2._sub._v3 = sval0;
+ sub2._field0 = sval3;
+
+ double sinVal = sin(val * M_PI);
+ double val2 = sinVal * sval2;
+ double val3 = sin((0.5 - val) * M_PI);
+ double val4 = sinVal * sval0;
+ double val5 = sub1._sub._v3 * val3;
+
+ sub2._sub._v1 = val2 + sub1._sub._v1 * val3;
+ sub2._sub._v2 = sub1._sub._v2 * val3 + sub1._sub._v1 * sinVal;
+ sub2._sub._v3 = val4 + val5;
+ } else {
+ double val2;
+ const CStarControlSub26 *sp;
+
+ if (1.0 - val1 <= 0.00001) {
+ val2 = 1.0 - val;
+ sp = s1->fn3(&sub3, val);
+ } else {
+ double cosVal = acos(val1);
+ double sinVal = sin(cosVal);
+ val2 = sin((1.0 - val) * cosVal) / sinVal;
+ sp = s1->fn3(&sub3, sin(cosVal * val) / sinVal);
+ }
+
+ const CStarControlSub26 *sp2 = sub1.fn3(&sub4, val2);
+ sub2.setup(sp2->_field0 + sp->_field0, sp->_sub._v1 + sp2->_sub._v1,
+ sp->_sub._v2 + sp2->_sub._v2, sp->_sub._v3 + sp2->_sub._v3);
+ *s2 = sub2;
+ }
}
} // 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 670007efa8..081e5e42b1 100644
--- a/engines/titanic/star_control/star_control_sub26.h
+++ b/engines/titanic/star_control/star_control_sub26.h
@@ -23,6 +23,8 @@
#ifndef TITANIC_STAR_CONTROL_SUB26_H
#define TITANIC_STAR_CONTROL_SUB26_H
+#include "titanic/star_control/dmatrix.h"
+
namespace Titanic {
class CStarControlSub26 {
@@ -33,6 +35,9 @@ class CStarControlSub26 {
Sub() : _v1(0.0), _v2(0.0), _v3(0.0) {}
};
+private:
+ double fn2(const CStarControlSub26 *src);
+ const CStarControlSub26 *fn3(const CStarControlSub26 *src, double val);
public:
double _field0;
Sub _sub;
@@ -50,6 +55,7 @@ public:
void copyFrom(const CStarControlSub26 *src);
double fn1() const;
+ void fn4(const DMatrix &m);
void fn5(double val, CStarControlSub26 *s1, CStarControlSub26 *s2);
};