diff options
| author | Matthew Stewart | 2018-07-19 01:45:15 -0400 |
|---|---|---|
| committer | Eugene Sandulenko | 2018-08-09 08:37:30 +0200 |
| commit | 2b09f698ed47942d84e6c7f503901941116db328 (patch) | |
| tree | b919829cdc96f549118df1980784719e9f86d93a | |
| parent | 710b9db0fd2e724dde746aa9b2319933fe21cbe0 (diff) | |
| download | scummvm-rg350-2b09f698ed47942d84e6c7f503901941116db328.tar.gz scummvm-rg350-2b09f698ed47942d84e6c7f503901941116db328.tar.bz2 scummvm-rg350-2b09f698ed47942d84e6c7f503901941116db328.zip | |
STARTREK: sine & cosine
| -rw-r--r-- | engines/startrek/fixedint.h | 7 | ||||
| -rw-r--r-- | engines/startrek/module.mk | 1 | ||||
| -rw-r--r-- | engines/startrek/space.cpp | 26 | ||||
| -rw-r--r-- | engines/startrek/startrek.cpp | 9 | ||||
| -rw-r--r-- | engines/startrek/startrek.h | 9 |
5 files changed, 34 insertions, 18 deletions
diff --git a/engines/startrek/fixedint.h b/engines/startrek/fixedint.h index 88e9c311e4..cae9efdb94 100644 --- a/engines/startrek/fixedint.h +++ b/engines/startrek/fixedint.h @@ -77,10 +77,11 @@ public: } /** - * Multiplication with an int, with the result being an int. + * Multiplication with an int, with the result being an int. Use this if the result + * might exceed the capacity of this type. */ - int32 multToInt(int32 i) { - return ((val * i) << (totalBits - decimalBits)) >> totalBits; + int16 multToInt(int32 i) { + return (val * i) >> decimalBits; } /** diff --git a/engines/startrek/module.mk b/engines/startrek/module.mk index bef2c8df5b..85250e0813 100644 --- a/engines/startrek/module.mk +++ b/engines/startrek/module.mk @@ -11,6 +11,7 @@ MODULE_OBJS = \ graphics.o \ iwfile.o \ lzss.o \ + math.o \ menu.o \ object.o \ room.o \ diff --git a/engines/startrek/space.cpp b/engines/startrek/space.cpp index a4d09690f8..aeb26155a6 100644 --- a/engines/startrek/space.cpp +++ b/engines/startrek/space.cpp @@ -150,30 +150,32 @@ Point3 StarTrekEngine::constructPoint3ForStarfield(int16 x, int16 y, int16 z) { } Point3 StarTrekEngine::matrixMult(const Matrix &weight, const Point3 &point) { - int32 ret[3]; + Point3 p; for (int i = 0; i < 3; i++) { - ret[i] = weight[i][0].multToInt(point.x & 0xffff) + weight[i][1].multToInt(point.y & 0xffff) + weight[i][2].multToInt(point.z & 0xffff); + p[i] = 0; + for (int j = 0; j < 3; j++) { // FIXME: what is this weird multiplication? + p[i] += (weight[i][j].raw() * (point[j] & 0xffff) << 2) >> 16; + } } - Point3 p; - p.x = ret[0]; - p.y = ret[1]; - p.z = ret[2]; return p; } Point3 StarTrekEngine::matrixMult(const Point3 &point, const Matrix &weight) { Point3 p = Point3(); - p.x = (weight[0][0].multToInt(point.x & 0xffff) + weight[1][0].multToInt(point.y & 0xffff) + weight[2][0].multToInt(point.z & 0xffff)); - p.y = (weight[0][1].multToInt(point.x & 0xffff) + weight[1][1].multToInt(point.y & 0xffff) + weight[2][1].multToInt(point.z & 0xffff)); - p.z = (weight[0][2].multToInt(point.x & 0xffff) + weight[1][2].multToInt(point.y & 0xffff) + weight[2][2].multToInt(point.z & 0xffff)); + for (int i = 0; i < 3; i++) { + p[i] = 0; + for (int j = 0; j < 3; j++) { + p[i] += (weight[j][i].raw() * (point[j] & 0xffff) << 2) >> 16; + } + } return p; } Matrix StarTrekEngine::initMatrix() { Matrix mat; - mat[0][0] = 1; - mat[1][1] = 1; - mat[2][2] = 1; + mat[0][0] = 1.0; + mat[1][1] = 1.0; + mat[2][2] = 1.0; return mat; } diff --git a/engines/startrek/startrek.cpp b/engines/startrek/startrek.cpp index e836e3bd68..c8bad8dae6 100644 --- a/engines/startrek/startrek.cpp +++ b/engines/startrek/startrek.cpp @@ -52,7 +52,8 @@ StarTrekEngine::StarTrekEngine(OSystem *syst, const StarTrekGameDescription *gam _kirkActor(&_actorList[0]), _spockActor(&_actorList[1]), _mccoyActor(&_actorList[2]), - _redshirtActor(&_actorList[3]) { + _redshirtActor(&_actorList[3]), + _sineTable(10) { DebugMan.addDebugChannel(kDebugSound, "sound", "Sound"); DebugMan.addDebugChannel(kDebugGraphics, "graphics", "Graphics"); @@ -367,8 +368,10 @@ void StarTrekEngine::playIntro() { } void StarTrekEngine::initIntroR3ObjectToMove(R3 *r3, int16 srcAngle, int16 srcDepth, int16 destAngle, int16 destDepth, int16 ticks) { - srcAngle = (srcAngle << 9) / 180; - destAngle = (destAngle << 9) / 180; + Fixed8 a1 = Fixed8::fromRaw((srcAngle << 8) / 90); + Fixed8 a2 = Fixed8::fromRaw((destAngle << 8) / 90); + + //r3->pos.x = sin(a1).multToFixed16(srcDepth) + _starfieldPosition.x; } void StarTrekEngine::loadSubtitleSprite(int index, Sprite *sprite) { diff --git a/engines/startrek/startrek.h b/engines/startrek/startrek.h index aab4f3abb4..7ebc47d13f 100644 --- a/engines/startrek/startrek.h +++ b/engines/startrek/startrek.h @@ -30,6 +30,7 @@ #include "common/rect.h" #include "common/scummsys.h" #include "common/serializer.h" +#include "common/sinetables.h" #include "common/str.h" #include "common/stream.h" #include "common/system.h" @@ -210,6 +211,13 @@ protected: Common::Error run(); public: + // math.cpp + /** + * Unit of the angle is "quadrants" (90 degrees = 1.0) + */ + Fixed14 sin(Fixed8 angle); + Fixed14 cos(Fixed8 angle); + // Game modes Common::Error runGameMode(int mode); @@ -542,6 +550,7 @@ public: private: Common::RandomSource _randomSource; + Common::SineTable _sineTable; Common::MacResManager *_macResFork; SharedPtr<Room> _room; |
