aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic
diff options
context:
space:
mode:
authorDavid Fioramonti2018-05-24 05:58:57 -0700
committerThierry Crozat2018-07-03 23:08:48 +0100
commitfb3dcb9ee0ff3b74e8c0a60cdc2c52821d7c879e (patch)
tree0c130ff1cc5658bac50f7567e2ee80b39e1ac883 /engines/titanic
parentccd46b7db90c5ea10394d9143111868ff3d5c5df (diff)
downloadscummvm-rg350-fb3dcb9ee0ff3b74e8c0a60cdc2c52821d7c879e.tar.gz
scummvm-rg350-fb3dcb9ee0ff3b74e8c0a60cdc2c52821d7c879e.tar.bz2
scummvm-rg350-fb3dcb9ee0ff3b74e8c0a60cdc2c52821d7c879e.zip
TITANIC: Use degree conversion common math funcs
I tested the star puzzle and it is still good.
Diffstat (limited to 'engines/titanic')
-rw-r--r--engines/titanic/star_control/fpose.cpp7
-rw-r--r--engines/titanic/star_control/fvector.cpp19
-rw-r--r--engines/titanic/star_control/fvector.h2
-rw-r--r--engines/titanic/star_control/star_closeup.cpp29
-rw-r--r--engines/titanic/star_control/star_closeup.h1
-rw-r--r--engines/titanic/star_control/star_points1.cpp7
-rw-r--r--engines/titanic/star_control/star_points2.cpp7
-rw-r--r--engines/titanic/star_control/viewport.cpp6
8 files changed, 41 insertions, 37 deletions
diff --git a/engines/titanic/star_control/fpose.cpp b/engines/titanic/star_control/fpose.cpp
index f3ba1b17d0..5e98344b69 100644
--- a/engines/titanic/star_control/fpose.cpp
+++ b/engines/titanic/star_control/fpose.cpp
@@ -24,6 +24,8 @@
#include "titanic/star_control/matrix_transform.h"
#include "titanic/star_control/matrix_inv.h"
+#include "common/math.h"
+
namespace Titanic {
// Non-member functions
@@ -91,9 +93,8 @@ void FPose::identity() {
// Source: https://en.wikipedia.org/wiki/Rotation_matrix
void FPose::setRotationMatrix(Axis axis, float amount) {
- const float ROTATION = (float)(2 * M_PI / 360.0);
- float sinVal = sin(amount * ROTATION);
- float cosVal = cos(amount * ROTATION);
+ float sinVal = sin(Common::deg2rad<float>(amount));
+ float cosVal = cos(Common::deg2rad<float>(amount));
switch (axis) {
case X_AXIS:
diff --git a/engines/titanic/star_control/fvector.cpp b/engines/titanic/star_control/fvector.cpp
index 46094dbdfc..6ebd297a1f 100644
--- a/engines/titanic/star_control/fvector.cpp
+++ b/engines/titanic/star_control/fvector.cpp
@@ -22,7 +22,8 @@
#include "titanic/star_control/fvector.h"
#include "titanic/star_control/fpose.h"
-//#include "common/textconsole.h"
+
+#include "common/math.h"
namespace Titanic {
@@ -44,8 +45,8 @@ FVector FVector::crossProduct(const FVector &src) const {
}
void FVector::rotVectAxisY(float angleDeg) {
- float sinVal = sin(angleDeg * Deg2Rad);
- float cosVal = cos(angleDeg * Deg2Rad);
+ float sinVal = sin(Common::deg2rad<double>(angleDeg));
+ float cosVal = cos(Common::deg2rad<double>(angleDeg));
float x = cosVal * _x - sinVal * _z;
float z = cosVal * _z + sinVal * _x;
@@ -115,14 +116,14 @@ FPose FVector::getFrameTransform(const FVector &v) {
FPose matrix1, matrix2, matrix3, matrix4;
FVector vector1 = getAnglesAsVect();
- matrix1.setRotationMatrix(X_AXIS, vector1._y * Rad2Deg);
- matrix2.setRotationMatrix(Y_AXIS, vector1._z * Rad2Deg);
+ matrix1.setRotationMatrix(X_AXIS, Common::rad2deg<double>(vector1._y));
+ matrix2.setRotationMatrix(Y_AXIS, Common::rad2deg<double>(vector1._z));
fposeProd(matrix1, matrix2, matrix3);
matrix4 = matrix3.inverseTransform();
vector1 = v.getAnglesAsVect();
- matrix1.setRotationMatrix(X_AXIS, vector1._y * Rad2Deg);
- matrix2.setRotationMatrix(Y_AXIS, vector1._z * Rad2Deg);
+ matrix1.setRotationMatrix(X_AXIS, Common::rad2deg<double>(vector1._y));
+ matrix2.setRotationMatrix(Y_AXIS, Common::rad2deg<double>(vector1._z));
fposeProd(matrix1, matrix2, matrix3);
fposeProd(matrix4, matrix3, matrix1);
@@ -132,8 +133,8 @@ FPose FVector::getFrameTransform(const FVector &v) {
FPose FVector::formRotXY() const {
FVector v1 = getAnglesAsVect();
FPose m1, m2;
- m1.setRotationMatrix(X_AXIS, v1._y * Rad2Deg);
- m2.setRotationMatrix(Y_AXIS, v1._z * Rad2Deg);
+ m1.setRotationMatrix(X_AXIS, Common::rad2deg<double>(v1._y));
+ m2.setRotationMatrix(Y_AXIS, Common::rad2deg<double>(v1._z));
FPose m3;
fposeProd(m1, m2, m3);
return m3;
diff --git a/engines/titanic/star_control/fvector.h b/engines/titanic/star_control/fvector.h
index 5ec3aa0bb4..1e25c9a3ee 100644
--- a/engines/titanic/star_control/fvector.h
+++ b/engines/titanic/star_control/fvector.h
@@ -27,8 +27,6 @@
namespace Titanic {
-const double Rad2Deg = 180.0 / M_PI;
-const double Deg2Rad = 1.0 / Rad2Deg;
enum Axis { X_AXIS, Y_AXIS, Z_AXIS };
class FPose;
diff --git a/engines/titanic/star_control/star_closeup.cpp b/engines/titanic/star_control/star_closeup.cpp
index 3bc3623d58..04b4c8636b 100644
--- a/engines/titanic/star_control/star_closeup.cpp
+++ b/engines/titanic/star_control/star_closeup.cpp
@@ -26,6 +26,8 @@
#include "titanic/star_control/surface_area.h"
#include "titanic/titanic.h"
+#include "common/math.h"
+
namespace Titanic {
#define MKTAG_BE(a3,a2,a1,a0) ((uint32)((a3) | ((a2) << 8) | ((a1) << 16) | ((a0) << 24)))
@@ -65,7 +67,6 @@ bool CStarCloseup::setup() {
}
bool CStarCloseup::setup2(int val1, int val2) {
- const float FACTOR = 2 * M_PI / 360.0;
const int VALUES1[] = { 0x800, 0xC00, 0x1000, 0x1400, 0x1800 };
const int VALUES2[] = {
0xF95BCD, 0xA505A0, 0xFFAD43, 0x98F4EB, 0xF3EFA5, 0,
@@ -83,7 +84,7 @@ bool CStarCloseup::setup2(int val1, int val2) {
e->_pixel3 = 0x40;
e->_field8 = g_vm->getRandomNumber(3) + 3;
e->_fieldC = g_vm->getRandomNumber(255);
- e->_field10 = FACTOR * 7.0;
+ e->_field10 = Common::deg2rad<double>(7.0);
e->_field14 = 0.0084687499;
++e;
@@ -93,7 +94,7 @@ bool CStarCloseup::setup2(int val1, int val2) {
e->_pixel3 = 0;
e->_field8 = g_vm->getRandomNumber(3) + 3;
e->_fieldC = g_vm->getRandomNumber(255);
- e->_field10 = FACTOR * 3.0;
+ e->_field10 = Common::deg2rad<double>(3.0);
e->_field14 = 0.021011719;
++e;
@@ -113,7 +114,7 @@ bool CStarCloseup::setup2(int val1, int val2) {
e->_pixel3 = 0;
e->_field8 = g_vm->getRandomNumber(3) + 3;
e->_fieldC = g_vm->getRandomNumber(255);
- e->_field10 = FACTOR * 2.0;
+ e->_field10 = Common::deg2rad<double>(2.0);
e->_field14 = 0.01178125;
++e;
@@ -123,7 +124,7 @@ bool CStarCloseup::setup2(int val1, int val2) {
e->_pixel3 = 0;
e->_field8 = g_vm->getRandomNumber(3) + 3;
e->_fieldC = g_vm->getRandomNumber(255);
- e->_field10 = FACTOR * 1.0;
+ e->_field10 = Common::deg2rad<double>(1.0);
e->_field14 = 0.24791406;
++e;
@@ -133,7 +134,7 @@ bool CStarCloseup::setup2(int val1, int val2) {
e->_pixel3 = 0xe6;
e->_field8 = g_vm->getRandomNumber(3) + 3;
e->_fieldC = g_vm->getRandomNumber(255);
- e->_field10 = FACTOR * 3.0;
+ e->_field10 = Common::deg2rad<double>(3.0);
e->_field14 = 0.20832032;
++e;
@@ -143,7 +144,7 @@ bool CStarCloseup::setup2(int val1, int val2) {
e->_pixel3 = 0x28;
e->_field8 = g_vm->getRandomNumber(3) + 3;
e->_fieldC = g_vm->getRandomNumber(255);
- e->_field10 = FACTOR * 1.0;
+ e->_field10 = Common::deg2rad<double>(1.0);
e->_field14 = 0.088164061;
++e;
@@ -153,7 +154,7 @@ bool CStarCloseup::setup2(int val1, int val2) {
e->_pixel3 = 0xf0;
e->_field8 = g_vm->getRandomNumber(3) + 3;
e->_fieldC = g_vm->getRandomNumber(255);
- e->_field10 = FACTOR * 2.0;
+ e->_field10 = Common::deg2rad<double>(2.0);
e->_field14 = 0.084375001;
++e;
@@ -163,7 +164,7 @@ bool CStarCloseup::setup2(int val1, int val2) {
e->_pixel3 = 0x20;
e->_field8 = g_vm->getRandomNumber(3) + 3;
e->_fieldC = g_vm->getRandomNumber(255);
- e->_field10 = FACTOR * 17.0;
+ e->_field10 = Common::deg2rad<double>(17.0);
e->_field14 = 1 / 256.0;
} else {
for (int ctr = 0; ctr < 5; ++ctr) {
@@ -174,9 +175,8 @@ bool CStarCloseup::setup2(int val1, int val2) {
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 * (float)g_vm->getRandomNumber(15);
+ e->_field10 = Common::deg2rad<double>((double)g_vm->getRandomNumber(15));
e->_field14 = ((float)g_vm->getRandomNumber(0xfffffffe)
* 50.0 / 65536.0) / 256.0;
}
@@ -492,7 +492,6 @@ bool CStarCloseup::setupEntry(int width, int height, int index, float val) {
SubEntry &entry = _array[index];
entry.clear();
- const float FACTOR = 2.0 * M_PI / 360.0;
int d1Count, d2Count, size3, height1;
int ctr, ctr2, idx, incr;
float vx, vy, yVal, degrees, cosVal, sinVal, angle;
@@ -511,12 +510,12 @@ bool CStarCloseup::setupEntry(int width, int height, int index, float val) {
for (ctr = height - 2, idx = 1, yVal = vy; ctr > 0; --ctr, yVal += vy) {
degrees = 0.0;
- cosVal = cos(yVal * FACTOR);
- sinVal = sin(yVal * FACTOR);
+ cosVal = cos(Common::deg2rad<float>(yVal));
+ sinVal = sin(Common::deg2rad<float>(yVal));
if (width > 0) {
for (int xCtr = 0; xCtr < width; ++xCtr, ++idx, degrees += vx) {
- angle = degrees * FACTOR;
+ angle = Common::deg2rad<float>(degrees);
FVector &tempV = entry._data2[idx];
tempV._x = sin(angle) * sinVal * val;
diff --git a/engines/titanic/star_control/star_closeup.h b/engines/titanic/star_control/star_closeup.h
index fae3731300..04962e6760 100644
--- a/engines/titanic/star_control/star_closeup.h
+++ b/engines/titanic/star_control/star_closeup.h
@@ -77,6 +77,7 @@ class CStarCloseup {
/**
* Maintains a pre-calculated table of sine values
+ * TODO: May be able to reuse common/sinetables.h
*/
struct SineTable {
private:
diff --git a/engines/titanic/star_control/star_points1.cpp b/engines/titanic/star_control/star_points1.cpp
index 0328743a98..7aabe216a4 100644
--- a/engines/titanic/star_control/star_points1.cpp
+++ b/engines/titanic/star_control/star_points1.cpp
@@ -26,10 +26,11 @@
#include "titanic/support/files_manager.h"
#include "titanic/titanic.h"
+#include "common/math.h"
+
namespace Titanic {
#define ARRAY_COUNT 876
-const double FACTOR = 2 * M_PI / 360.0;
CStarPoints1::CStarPoints1() {
}
@@ -48,8 +49,8 @@ bool CStarPoints1::initialize() {
double v2 = stream->readSint32LE();
entry._flag = stream->readUint32LE() != 0;
- v1 *= 0.015 * FACTOR;
- v2 *= 0.0099999998 * FACTOR;
+ v1 *= Common::deg2rad<double>(0.015);
+ v2 *= Common::deg2rad<double>(0.0099999998);
entry._x = cos(v2) * 3000000.0 * cos(v1);
entry._y = sin(v1) * 3000000.0 * cos(v2);
diff --git a/engines/titanic/star_control/star_points2.cpp b/engines/titanic/star_control/star_points2.cpp
index aa5444f16b..6e91a6ef36 100644
--- a/engines/titanic/star_control/star_points2.cpp
+++ b/engines/titanic/star_control/star_points2.cpp
@@ -26,10 +26,11 @@
#include "titanic/support/files_manager.h"
#include "titanic/titanic.h"
+#include "common/math.h"
+
namespace Titanic {
#define ARRAY_COUNT 80
-const double FACTOR = 2 * M_PI / 360.0;
bool CStarPoints2::initialize() {
// Get a reference to the starfield points resource
@@ -51,8 +52,8 @@ bool CStarPoints2::initialize() {
for (int fctr = 0; fctr < 2; ++fctr) {
v1 = stream->readSint32LE();
v2 = stream->readSint32LE();
- v1 *= 0.015 * FACTOR;
- v2 *= FACTOR / 100.0;
+ v1 *= Common::deg2rad<double>(0.015);
+ v2 *= Common::deg2rad<double>(0.01);
vectors[fctr]->_x = cos(v1) * 3000000.0 * cos(v2);
vectors[fctr]->_y = sin(v1) * 3000000.0 * cos(v2);
diff --git a/engines/titanic/star_control/viewport.cpp b/engines/titanic/star_control/viewport.cpp
index d66ff423c6..b6482dad46 100644
--- a/engines/titanic/star_control/viewport.cpp
+++ b/engines/titanic/star_control/viewport.cpp
@@ -26,6 +26,8 @@
#include "titanic/support/simple_file.h"
#include "titanic/titanic.h"
+#include "common/math.h"
+
namespace Titanic {
CViewport::CViewport() {
@@ -299,8 +301,8 @@ void CViewport::reset() {
_center = FPoint((double)_width * 0.5, (double)_height * 0.5);
_centerVector._x = MIN(_center._x, _center._y);
- _centerVector._y = tan(_centerYAngleDegrees * Deg2Rad);
- _centerVector._z = tan(_centerZAngleDegrees * Deg2Rad);
+ _centerVector._y = tan(Common::deg2rad<double>(_centerYAngleDegrees));
+ _centerVector._z = tan(Common::deg2rad<double>(_centerZAngleDegrees));
}
const FMatrix &CViewport::getOrientation() const {