Permalink
Browse files

STARTREK: sine & cosine

  • Loading branch information...
Drenn1 authored and sev- committed Jul 19, 2018
1 parent 710b9db commit 2b09f698ed47942d84e6c7f503901941116db328
@@ -77,10 +77,11 @@ class TFixedInt : Common::Serializable {
}

/**
* 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;
}

/**
@@ -11,6 +11,7 @@ MODULE_OBJS = \
graphics.o \
iwfile.o \
lzss.o \
math.o \
menu.o \
object.o \
room.o \
@@ -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;
}

@@ -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) {
@@ -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 @@ class StarTrekEngine : public ::Engine {
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 @@ class StarTrekEngine : public ::Engine {

private:
Common::RandomSource _randomSource;
Common::SineTable _sineTable;

Common::MacResManager *_macResFork;
SharedPtr<Room> _room;

0 comments on commit 2b09f69

Please sign in to comment.