Permalink
Browse files

STARTREK: Half-done implementation of drawR3Shape

Handles drawing, scaling, probably rotating objects in space.
  • Loading branch information...
Drenn1 authored and sev- committed Jul 23, 2018
1 parent 565bf0e commit eff87179da0554446837a732bb6855f6c7f8a890
@@ -56,7 +56,7 @@ class TFixedInt : Common::Serializable {
* Constructor from other fixed-point formats.
*/
template<typename T2, uint otherTB, uint otherDB>
TFixedInt<T, totalBits, decimalBits>(const TFixedInt<T2, otherTB, otherDB> &fi) {
explicit TFixedInt<T, totalBits, decimalBits>(const TFixedInt<T2, otherTB, otherDB> &fi) {
int diff = otherDB - decimalBits;
if (otherDB >= decimalBits)
val = fi.raw() >> diff;
@@ -76,12 +76,16 @@ class TFixedInt : Common::Serializable {
return ((double)val) / (1 << decimalBits);
}

TFixedInt operator-() const {
return fromRaw(-val);
}

/**
* Multiplication with an int, with the result being an int. Use this if the result
* might exceed the capacity of this type.
*/
int16 multToInt(int32 i) {
return (val * i) >> decimalBits;
return ((int32)(val * i)) >> decimalBits;
}

/**
@@ -90,6 +94,12 @@ class TFixedInt : Common::Serializable {
TFixedInt operator*(int32 i) const {
return fromRaw(val * i);
}
/**
* Multiplication with a FixedInt, with the result being the same type.
*/
TFixedInt operator*(const TFixedInt &f) const {
return fromRaw(((int32)(val * f.val)) >> decimalBits);
}
/**
* Division with an int, with the result being the same type.
*/
@@ -173,6 +183,8 @@ typedef TFixedInt<int16, 16, 8> Fixed8;
// Fixed-point (16.16) number
typedef TFixedInt<int32, 32, 16> Fixed16;

typedef Fixed8 Angle;

}

#endif
@@ -105,6 +105,10 @@ void Graphics::fillBackgroundRect(const Common::Rect &rect, byte color) {
}
}

byte *Graphics::getBackgroundPixels() {
return _backgroundImage->pixels;
}

void Graphics::clearScreenAndPriBuffer() {
Common::fill(_priData, _priData + sizeof(_priData), 0);

@@ -131,6 +135,17 @@ void Graphics::loadPalette(const Common::String &paletteName) {
lutStream->read(_lutData, 256);
}

void Graphics::copyRectBetweenBitmaps(Bitmap *destBitmap, int destX, int destY, Bitmap *srcBitmap, int srcX, int srcY, int width, int height) {
byte *src = srcBitmap->pixels + srcX + srcY * srcBitmap->width;
byte *dest = destBitmap->pixels + destX + destY * destBitmap->width;

for (int y = 0; y < height; y++) {
memcpy(dest, src, width);
src += srcBitmap->width;
dest += destBitmap->width;
}
}

void Graphics::fadeinScreen() {
while (_paletteFadeLevel <= 100) {
TrekEvent event;
@@ -58,10 +58,13 @@ class Graphics {
* @param drawRect The clipped rectangle to draw at (must be within the drawable space)
*/
void drawBitmapToBackground(const Common::Rect &origRect, const Common::Rect &drawRect, SharedPtr<Bitmap> bitmap);

void fillBackgroundRect(const Common::Rect &rect, byte color);
byte *getBackgroundPixels();

void clearScreenAndPriBuffer();
void loadPalette(const String &paletteFile);
void copyRectBetweenBitmaps(Bitmap *destBitmap, int destX, int destY, Bitmap *srcBitmap, int srcX, int srcY, int width, int height);
void fadeinScreen();
void fadeoutScreen();
void setPaletteFadeLevel(byte *palData, int fadeLevel);
@@ -24,7 +24,7 @@

namespace StarTrek {

Fixed14 StarTrekEngine::sin(Fixed8 angle) {
Fixed14 StarTrekEngine::sin(Angle angle) {
int16 i = angle.raw();
if (angle < 0) {
i %= 0x400;
@@ -46,14 +46,14 @@ Fixed14 StarTrekEngine::sin(Fixed8 angle) {
f = -_sineTable.getTable()[i & 0xff];
else if (i < 0x400)
f = -_sineTable.getTable()[256 - (i & 0xff)];
return Fixed16(f);
return Fixed14(f);
}

Fixed14 StarTrekEngine::cos(Fixed8 angle) {
Fixed14 StarTrekEngine::cos(Angle angle) {
return sin(angle + 1.0);
}

Fixed8 StarTrekEngine::atan2(int32 deltaX, int32 deltaY) {
Angle StarTrekEngine::atan2(int32 deltaX, int32 deltaY) {
const int16 atanTable[] = {
0x0000, 0x0064, 0x00c9, 0x012d, 0x0192, 0x01f6, 0x025b, 0x02c0,
0x0324, 0x0389, 0x03ee, 0x0453, 0x04b8, 0x051d, 0x0582, 0x05e8,
@@ -85,9 +85,9 @@ Fixed8 StarTrekEngine::atan2(int32 deltaX, int32 deltaY) {

Fixed14 ratio;
if (deltaY > deltaX)
ratio = Fixed14::fromRaw(((deltaX & 0xffff0000) >> 2) / (deltaY >> 16));
ratio = Fixed14::fromRaw(((deltaX & 0xffff0000) >> 2) / deltaY);
else
ratio = Fixed14::fromRaw(((deltaY & 0xffff0000) >> 2) / (deltaX >> 16));
ratio = Fixed14::fromRaw(((deltaY & 0xffff0000) >> 2) / deltaX);

int16 endIndex = 128;
int16 index = 0;
@@ -123,7 +123,7 @@ Fixed8 StarTrekEngine::atan2(int32 deltaX, int32 deltaY) {
angle = -256 + angle;
}

return Fixed8::fromRaw(angle);
return Angle::fromRaw(angle);
}

}
Oops, something went wrong.

0 comments on commit eff8717

Please sign in to comment.