diff options
author | David Fioramonti | 2017-08-27 05:18:12 -0700 |
---|---|---|
committer | David Fioramonti | 2017-08-27 05:39:13 -0700 |
commit | 5cf2f16ca0549cbfe72e6bee54050b0051be3503 (patch) | |
tree | e02996f15a5d93be33cf999095b86c1cd3c517fb /engines/titanic/star_control | |
parent | de5e2c96745b77a45d5195361c8381da75b3a943 (diff) | |
download | scummvm-rg350-5cf2f16ca0549cbfe72e6bee54050b0051be3503.tar.gz scummvm-rg350-5cf2f16ca0549cbfe72e6bee54050b0051be3503.tar.bz2 scummvm-rg350-5cf2f16ca0549cbfe72e6bee54050b0051be3503.zip |
TITANIC: Refactoring of Viewport class
1. Improved naming of functions.
E.x., fn17 is now called getRelativePosNoCentering
2. Improved variable names
E.x., _valArray[3] is now _pixel1OffSetX, naming makes sense for it
use in CBaseStars::draw.
3. Lots of comments and TODO added for suspicious behavior
Mentioned unused functions and values that don't get used.
4. Changes in other classes that viewport renaming affected
Some of the star_camera functions were 1-1 mapping of
functions in viewport so I just made the names be the same.
Diffstat (limited to 'engines/titanic/star_control')
-rw-r--r-- | engines/titanic/star_control/base_stars.cpp | 14 | ||||
-rw-r--r-- | engines/titanic/star_control/star_camera.cpp | 56 | ||||
-rw-r--r-- | engines/titanic/star_control/star_camera.h | 22 | ||||
-rw-r--r-- | engines/titanic/star_control/star_closeup.cpp | 22 | ||||
-rw-r--r-- | engines/titanic/star_control/star_field.cpp | 2 | ||||
-rw-r--r-- | engines/titanic/star_control/star_view.cpp | 12 | ||||
-rw-r--r-- | engines/titanic/star_control/viewport.cpp | 198 | ||||
-rw-r--r-- | engines/titanic/star_control/viewport.h | 66 |
8 files changed, 255 insertions, 137 deletions
diff --git a/engines/titanic/star_control/base_stars.cpp b/engines/titanic/star_control/base_stars.cpp index bb902e558e..0fcf8a964f 100644 --- a/engines/titanic/star_control/base_stars.cpp +++ b/engines/titanic/star_control/base_stars.cpp @@ -128,8 +128,8 @@ void CBaseStars::resetEntry(CBaseStarEntry &entry) { void CBaseStars::draw(CSurfaceArea *surfaceArea, CStarCamera *camera, CStarCloseup *closeup) { if (!_data.empty()) { - switch (camera->proc27()) { - case 0: + switch (camera->getStarColor()) { + case WHITE: // draw white, green, and red stars (mostly white) switch (surfaceArea->_bpp) { case 1: draw1(surfaceArea, camera, closeup); @@ -142,7 +142,7 @@ void CBaseStars::draw(CSurfaceArea *surfaceArea, CStarCamera *camera, CStarClose } break; - case 2: + case PINK: // draw pink stars switch (surfaceArea->_bpp) { case 1: draw3(surfaceArea, camera, closeup); @@ -163,7 +163,7 @@ void CBaseStars::draw(CSurfaceArea *surfaceArea, CStarCamera *camera, CStarClose void CBaseStars::draw1(CSurfaceArea *surfaceArea, CStarCamera *camera, CStarCloseup *closeup) { FPose pose = camera->getPose(); - camera->proc36(&_value1, &_value2, &_value3, &_value4); + camera->getRelativeXCenterPixels(&_value1, &_value2, &_value3, &_value4); const double MAX_VAL = 1.0e9 * 1.0e9; FPoint centroid = surfaceArea->_centroid + FPoint(0.5, 0.5); @@ -248,7 +248,7 @@ void CBaseStars::draw1(CSurfaceArea *surfaceArea, CStarCamera *camera, CStarClos void CBaseStars::draw2(CSurfaceArea *surfaceArea, CStarCamera *camera, CStarCloseup *closeup) { FPose pose = camera->getPose(); - camera->proc36(&_value1, &_value2, &_value3, &_value4); + camera->getRelativeXCenterPixels(&_value1, &_value2, &_value3, &_value4); const double MAX_VAL = 1.0e9 * 1.0e9; FPoint centroid = surfaceArea->_centroid + FPoint(0.5, 0.5); @@ -334,7 +334,7 @@ void CBaseStars::draw2(CSurfaceArea *surfaceArea, CStarCamera *camera, CStarClos void CBaseStars::draw3(CSurfaceArea *surfaceArea, CStarCamera *camera, CStarCloseup *closeup) { FPose pose = camera->getPose(); - camera->proc36(&_value1, &_value2, &_value3, &_value4); + camera->getRelativeXCenterPixels(&_value1, &_value2, &_value3, &_value4); const double MAX_VAL = 1.0e9 * 1.0e9; FPoint centroid = surfaceArea->_centroid + FPoint(0.5, 0.5); @@ -441,7 +441,7 @@ void CBaseStars::draw3(CSurfaceArea *surfaceArea, CStarCamera *camera, CStarClos void CBaseStars::draw4(CSurfaceArea *surfaceArea, CStarCamera *camera, CStarCloseup *closeup) { FPose pose = camera->getPose(); - camera->proc36(&_value1, &_value2, &_value3, &_value4); + camera->getRelativeXCenterPixels(&_value1, &_value2, &_value3, &_value4); const double MAX_VAL = 1.0e9 * 1.0e9; FPoint centroid = surfaceArea->_centroid + FPoint(0.5, 0.5); diff --git a/engines/titanic/star_control/star_camera.cpp b/engines/titanic/star_control/star_camera.cpp index 6b4527e79d..f7cedf4d22 100644 --- a/engines/titanic/star_control/star_camera.cpp +++ b/engines/titanic/star_control/star_camera.cpp @@ -86,39 +86,44 @@ void CStarCamera::setOrientation(const FVector &v) { _viewport.setOrientation(v); } +// This never gets called void CStarCamera::proc6(int v) { if (!isLocked()) _viewport.setC(v); } +// This never gets called void CStarCamera::proc7(int v) { if (!isLocked()) _viewport.set10(v); } +// This never gets called void CStarCamera::proc8(int v) { if (!isLocked()) _viewport.set14(v); } -void CStarCamera::proc9(int v) { +// This never gets called +void CStarCamera::setCenterYAngle(int v) { if (!isLocked()) - _viewport.set18(v); + _viewport.setCenterYAngle(v); } -void CStarCamera::proc10(int v) { +// This never gets called +void CStarCamera::setCenterZAngle(int v) { if (!isLocked()) - _viewport.set1C(v); + _viewport.setCenterZAngle(v); } -void CStarCamera::proc11() { +void CStarCamera::randomizeOrientation() { if (!isLocked()) - _viewport.fn12(); + _viewport.randomizeOrientation(); } void CStarCamera::proc12(StarMode mode, double v2) { if (!isLocked()) - _viewport.fn13(mode, v2); + _viewport.changeStarColorPixel(mode, v2); } void CStarCamera::proc13(CViewport *dest) { @@ -183,9 +188,9 @@ void CStarCamera::setPosition(const FPose &pose) { } } -void CStarCamera::proc22(FMatrix &m) { +void CStarCamera::changeOrientation(FMatrix &m) { if (!isLocked()) - _viewport.fn15(m); + _viewport.changeOrientation(m); } FPose CStarCamera::getPose() { @@ -204,30 +209,39 @@ double CStarCamera::proc26() const { return _viewport._field14; } -int CStarCamera::proc27() const { - return _viewport._field24; +StarColor CStarCamera::getStarColor() const { + return _viewport._starColor; } +// Similar to CViewport::fn17/fn18 FVector CStarCamera::getRelativePos(int index, const FVector &src) { FVector dest; - dest._x = ((_viewport._valArray[index] + src._x) * _viewport._centerVector._x) + double val; + if (index == 2) { + val = _viewport._isZero; + } + else { + val = _viewport._valArray[index]; + } + + dest._x = ((val + src._x) * _viewport._centerVector._x) / (_viewport._centerVector._y * src._z); dest._y = src._y * _viewport._centerVector._x / (_viewport._centerVector._z * src._z); dest._z = src._z; return dest; } -FVector CStarCamera::proc29(int index, const FVector &src) { - return _viewport.fn16(index, src); +FVector CStarCamera::getRelativePosNoCentering(int index, const FVector &src) { + return _viewport.getRelativePosNoCentering(index, src); } FVector CStarCamera::proc30(int index, const FVector &v) { - return _viewport.fn17(index, v); + return _viewport.getRelativePosCentering(index, v); } FVector CStarCamera::proc31(int index, const FVector &v) { - return _viewport.fn18(index, v); + return _viewport.getRelativePosCentering2(index, v); } void CStarCamera::setViewportAngle(const FPoint &angles) { @@ -241,7 +255,7 @@ void CStarCamera::setViewportAngle(const FPoint &angles) { FPose subX(X_AXIS, angles._y); FPose subY(Y_AXIS, -angles._x); // needs to be negative or looking left will cause the view to go right FPose sub(subX, subY); - proc22(sub); + changeOrientation(sub); break; } @@ -405,8 +419,8 @@ bool CStarCamera::removeLockedStar() { return true; } -void CStarCamera::proc36(double *v1, double *v2, double *v3, double *v4) { - _viewport.fn19(v1, v2, v3, v4); +void CStarCamera::getRelativeXCenterPixels(double *v1, double *v2, double *v3, double *v4) { + _viewport.getRelativeXCenterPixels(v1, v2, v3, v4); } void CStarCamera::load(SimpleFile *file, int param) { @@ -470,9 +484,9 @@ bool CStarCamera::lockMarker1(FVector v1, FVector v2, FVector v3) { val7 = val3 * v1._z / _viewport._centerVector._x; val8 = val6 / _viewport._centerVector._x; val9 = val2 / _viewport._centerVector._x; - v3._x = val5 - _viewport._valArray[2]; + v3._x = val5 - _viewport._isZero; // TODO: _viewport._isZero is always zero v3._y = val7; - tempV._x = val9 - _viewport._valArray[2]; + tempV._x = val9 - _viewport._isZero; // TODO: _viewport._isZero is always zero tempV._y = val8; float unusedScale = 0.0; diff --git a/engines/titanic/star_control/star_camera.h b/engines/titanic/star_control/star_camera.h index 572995fc1b..6cf0183f0a 100644 --- a/engines/titanic/star_control/star_camera.h +++ b/engines/titanic/star_control/star_camera.h @@ -89,9 +89,9 @@ public: virtual void proc6(int v); virtual void proc7(int v); virtual void proc8(int v); - virtual void proc9(int v); - virtual void proc10(int v); - virtual void proc11(); + virtual void setCenterYAngle(int v); + virtual void setCenterZAngle(int v); + virtual void randomizeOrientation(); virtual void proc12(StarMode mode, double v2); virtual void proc13(CViewport *dest); @@ -132,7 +132,7 @@ public: */ virtual void setPosition(const FPose &pose); - virtual void proc22(FMatrix &m); + virtual void changeOrientation(FMatrix &m); /** * Get the position and direction of the camera @@ -143,14 +143,14 @@ public: virtual double getThreshold() const; virtual double proc26() const; - virtual int proc27() const; + virtual StarColor getStarColor() const; /** * Return the passed vector relative to the center of the viewpoint */ virtual FVector getRelativePos(int index, const FVector &src); - virtual FVector proc29(int index, const FVector &src); + virtual FVector getRelativePosNoCentering(int index, const FVector &src); virtual FVector proc30(int index, const FVector &v); virtual FVector proc31(int index, const FVector &v); @@ -177,7 +177,15 @@ public: * the vector for the star destroys the calling star vector */ virtual bool removeLockedStar(); - virtual void proc36(double *v1, double *v2, double *v3, double *v4); + + /** + * All arguments are return values + * First is the x center coordinate relative to y + * Second is the x center coordinate relative to z + * Third is the first x center pixel offset + * Fourth is the second x center pixel offset + */ + virtual void getRelativeXCenterPixels(double *v1, double *v2, double *v3, double *v4); /** * Load the data for the class from file diff --git a/engines/titanic/star_control/star_closeup.cpp b/engines/titanic/star_control/star_closeup.cpp index 82c88dae39..6ec94bbf38 100644 --- a/engines/titanic/star_control/star_closeup.cpp +++ b/engines/titanic/star_control/star_closeup.cpp @@ -195,7 +195,7 @@ void CStarCloseup::draw(const FPose &pose, const FVector &vector, const FVector CSurfaceArea *surfaceArea, CStarCamera *camera) { const int VALUES[] = { 0, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4 }; float val1 = camera->getThreshold(); - int val2 = camera->proc27(); + StarColor starColor = camera->getStarColor(); if (!_flag) return; @@ -292,7 +292,8 @@ void CStarCloseup::draw(const FPose &pose, const FVector &vector, const FVector } } - if (val2 <= 0) { + switch (starColor) { + case WHITE: surfaceArea->setMode(SA_SOLID); surfaceArea->_pixel = MKTAG_BE(entryP->_pixel1, entryP->_pixel2, entryP->_pixel3, 0); @@ -315,7 +316,8 @@ void CStarCloseup::draw(const FPose &pose, const FVector &vector, const FVector grid2._position._x, grid2._position._y)); } } - } else { + break; + case PINK: surfaceArea->setMode(SA_SOLID); surfaceArea->_pixel = entryP->_pixel1; surfaceArea->setColorFromPixel(); @@ -359,6 +361,9 @@ void CStarCloseup::draw(const FPose &pose, const FVector &vector, const FVector grid2._position._x, grid2._position._y)); } } + break; + default: + assert(0); } } } @@ -397,7 +402,8 @@ void CStarCloseup::draw(const FPose &pose, const FVector &vector, const FVector + newV._x * pose._row1._z + pose._vector._z; } - if (val2 <= 0) { + switch(starColor) { + case WHITE: surfaceArea->setMode(SA_SOLID); surfaceArea->_pixel = pixel1; surfaceArea->setColorFromPixel(); @@ -418,8 +424,9 @@ void CStarCloseup::draw(const FPose &pose, const FVector &vector, const FVector surfaceArea->drawLine(FRect(grid1._position._x, grid1._position._y, grid2._position._x, grid2._position._y)); } - } - } else { + } + break; + case PINK: surfaceArea->setMode(SA_SOLID); surfaceArea->_pixel = pixel2; surfaceArea->setColorFromPixel(); @@ -463,6 +470,9 @@ void CStarCloseup::draw(const FPose &pose, const FVector &vector, const FVector grid2._position._x, grid2._position._y)); } } + break; + default: + assert(0); } } diff --git a/engines/titanic/star_control/star_field.cpp b/engines/titanic/star_control/star_field.cpp index 75a080a352..8a4450e61b 100644 --- a/engines/titanic/star_control/star_field.cpp +++ b/engines/titanic/star_control/star_field.cpp @@ -201,7 +201,7 @@ double CStarField::fn5(CSurfaceArea *surfaceArea, CStarCamera *camera, const CBaseStarEntry *dataP = _markers.getDataPtr(_crosshairs._entryIndex); v2 = dataP->_position; - FVector tv = camera->proc29(2, v2); + FVector tv = camera->getRelativePosNoCentering(2, v2); // First argument is not getting used in CViewport::fn16 if (camera->getThreshold() >= tv._z) return -1.0; diff --git a/engines/titanic/star_control/star_view.cpp b/engines/titanic/star_control/star_view.cpp index bc2c096f9c..ef87fd2aab 100644 --- a/engines/titanic/star_control/star_view.cpp +++ b/engines/titanic/star_control/star_view.cpp @@ -182,7 +182,7 @@ bool CStarView::KeyCharMsg(int key, CErrorCode *errorCode) { case Common::KEYCODE_z: if (matchedIndex == -1) { pose.setRotationMatrix(Y_AXIS, -1.0); - _camera.proc22(pose); + _camera.changeOrientation(pose); _camera.updatePosition(errorCode); return true; } @@ -215,7 +215,7 @@ bool CStarView::KeyCharMsg(int key, CErrorCode *errorCode) { case Common::KEYCODE_x: if (matchedIndex == -1) { pose.setRotationMatrix(Y_AXIS, 1.0); - _camera.proc22(pose); + _camera.changeOrientation(pose); _camera.updatePosition(errorCode); return true; } @@ -224,7 +224,7 @@ bool CStarView::KeyCharMsg(int key, CErrorCode *errorCode) { case Common::KEYCODE_QUOTE: if (matchedIndex == -1) { pose.setRotationMatrix(X_AXIS, 1.0); - _camera.proc22(pose); + _camera.changeOrientation(pose); _camera.updatePosition(errorCode); return true; } @@ -233,7 +233,7 @@ bool CStarView::KeyCharMsg(int key, CErrorCode *errorCode) { case Common::KEYCODE_SLASH: if (matchedIndex == -1) { pose.setRotationMatrix(X_AXIS, -1.0); - _camera.proc22(pose); + _camera.changeOrientation(pose); _camera.updatePosition(errorCode); return true; } @@ -386,8 +386,8 @@ void CStarView::setHasReference() { _photoViewport.setPosition(pos); _photoViewport.setOrientation(orientation); _field218 = false; - _photoViewport.fn13(MODE_PHOTO, 0.0); - _photoViewport.fn13(MODE_STARFIELD, 0.0); + _photoViewport.changeStarColorPixel(MODE_PHOTO, 0.0); + _photoViewport.changeStarColorPixel(MODE_STARFIELD, 0.0); _hasReference = true; reset(); _field218 = true; diff --git a/engines/titanic/star_control/viewport.cpp b/engines/titanic/star_control/viewport.cpp index ba1d7c0383..78206035f8 100644 --- a/engines/titanic/star_control/viewport.cpp +++ b/engines/titanic/star_control/viewport.cpp @@ -28,16 +28,19 @@ namespace Titanic { CViewport::CViewport() { - _fieldC = 0; - _field10 = 800.0; - _field14 = 10000.0; - _field18 = 20.0; - _field1C = 20.0; + _fieldC = 0; // doesn't get used + _field10 = 800.0; // doesn't get used + _field14 = 10000.0; // doesn't get used + _centerYAngleDegrees = 20.0; + _centerZAngleDegrees = 20.0; _width = 600; _height = 340; - _field24 = 0; - _flag = false; - Common::fill(&_valArray[0], &_valArray[5], 0.0); + _starColor = PINK; // default for starview + _poseUpToDate = false; + Common::fill(&_valArray[0], &_valArray[2], 0.0); + _isZero = 0.0; // seems to always be zero + _pixel1OffSetX = 0.0; + _pixel2OffSetX = 0.0; } CViewport::CViewport(CViewport *src) : @@ -46,17 +49,20 @@ CViewport::CViewport(CViewport *src) : _fieldC = src->_fieldC; _field10 = src->_field10; _field14 = src->_field14; - _field18 = src->_field18; - _field1C = src->_field1C; + _centerYAngleDegrees = src->_centerYAngleDegrees; + _centerZAngleDegrees = src->_centerZAngleDegrees; _width = src->_width; _height = src->_height; _center = src->_center; _centerVector = src->_centerVector; - _field24 = src->_field24; + _starColor = src->_starColor; - Common::copy(&src->_valArray[0], &src->_valArray[5], &_valArray[0]); - _flag = false; + Common::copy(&src->_valArray[0], &src->_valArray[2], &_valArray[0]); + _isZero = src->_isZero; + _pixel1OffSetX = src->_pixel1OffSetX; + _pixel2OffSetX = src->_pixel2OffSetX; + _poseUpToDate = false; } void CViewport::copyFrom(const CViewport *src) { @@ -70,19 +76,24 @@ void CViewport::load(SimpleFile *file, int param) { _fieldC = file->readFloat(); _field10 = file->readFloat(); _field14 = file->readFloat(); - _field18 = file->readFloat(); - _field1C = file->readFloat(); + _centerYAngleDegrees = file->readFloat(); + _centerZAngleDegrees = file->readFloat(); int widthHeight = file->readNumber(); _width = widthHeight & 0xffff; _height = widthHeight >> 16; - _field24 = file->readNumber(); + int field24 = file->readNumber(); //0 = White, 2 = Pink + _starColor = (StarColor) field24; - for (int idx = 0; idx < 5; ++idx) + for (int idx = 0; idx < 2; ++idx) _valArray[idx] = file->readFloat(); + _isZero = file->readFloat(); + _pixel1OffSetX = file->readFloat(); + _pixel2OffSetX = file->readFloat(); + _orientation.load(file, param); - _flag = false; + _poseUpToDate = false; } void CViewport::save(SimpleFile *file, int indent) { @@ -92,175 +103,214 @@ void CViewport::save(SimpleFile *file, int indent) { file->writeFloatLine(_fieldC, indent); file->writeFloatLine(_field10, indent); file->writeFloatLine(_field14, indent); - file->writeFloatLine(_field18, indent); - file->writeFloatLine(_field1C, indent); + file->writeFloatLine(_centerYAngleDegrees, indent); + file->writeFloatLine(_centerZAngleDegrees, indent); file->writeNumberLine(_width | (_height << 16), indent); - file->writeNumberLine(_field24, indent); + int field24 = (int) _starColor; + file->writeNumberLine(field24, indent); - for (int idx = 0; idx < 5; ++idx) + for (int idx = 0; idx < 2; ++idx) file->writeFloatLine(_valArray[idx], indent); + file->writeFloatLine(_isZero, indent); + file->writeFloatLine(_pixel1OffSetX, indent); + file->writeFloatLine(_pixel2OffSetX, indent); + _orientation.save(file, indent); } void CViewport::setPosition(const FVector &v) { debugC(DEBUG_INTERMEDIATE, kDebugStarfield, "Setting starmap position to %s", v.toString().c_str()); _position = v; - _flag = false; + _poseUpToDate = false; } void CViewport::setPosition(const FPose &pose) { _position = _position.MatProdRowVect(pose); - _flag = false; + _poseUpToDate = false; } void CViewport::setOrientation(const FMatrix &m) { _orientation = m; - _flag = false; + _poseUpToDate = false; } void CViewport::setOrientation(const FVector &v) { _orientation.set(v); - _flag = false; + _poseUpToDate = false; } +// This never gets called void CViewport::setC(double v) { _fieldC = v; - _flag = false; + _poseUpToDate = false; } +// This never gets called void CViewport::set10(double v) { _field10 = v; - _flag = false; + _poseUpToDate = false; } +// This never gets called void CViewport::set14(double v) { _field10 = v; } -void CViewport::set18(double v) { - _field18 = v; - _flag = false; +void CViewport::setCenterYAngle(double angleDegrees) { + _centerYAngleDegrees = angleDegrees; + _poseUpToDate = false; } -void CViewport::set1C(double v) { - _field1C = v; - _flag = false; +void CViewport::setCenterZAngle(double angleDegrees) { + _centerZAngleDegrees = angleDegrees; + _poseUpToDate = false; } -void CViewport::fn12() { +void CViewport::randomizeOrientation() { _orientation.identity(); - FPose m1(X_AXIS, g_vm->getRandomNumber(359)); - FPose m2(Y_AXIS, g_vm->getRandomNumber(359)); - FPose m3(Z_AXIS, g_vm->getRandomNumber(359)); + double ranRotAngleX = g_vm->getRandomNumber(359); + double ranRotAngleY = g_vm->getRandomNumber(359); + double ranRotAngleZ = g_vm->getRandomNumber(359); + + FPose m1(X_AXIS, ranRotAngleX); + FPose m2(Y_AXIS, ranRotAngleY); + FPose m3(Z_AXIS, ranRotAngleZ); FPose s1(m1, m2); FPose s2(s1, m3); - m1.copyFrom(s2); - _orientation.matRProd(m1); - _flag = false; + _orientation.matRProd(s2); + _poseUpToDate = false; } -void CViewport::fn13(StarMode mode, double val) { +void CViewport::changeStarColorPixel(StarMode mode, double pixelOffSet) { + // pixelOffset is usually 0.0, 30.0, or 28000.0 if (mode == MODE_PHOTO) { - _valArray[0] = val; - _valArray[1] = -val; + _valArray[0] = pixelOffSet; + _valArray[1] = -pixelOffSet; } else { - _valArray[3] = val; - _valArray[4] = -val; + _pixel1OffSetX = pixelOffSet; + _pixel2OffSetX = -pixelOffSet; } - _valArray[2] = 0.0; - _field24 = val ? 2 : 0; + _isZero = 0.0; + _starColor = pixelOffSet ? PINK : WHITE; } void CViewport::reposition(double factor) { _position._x = _orientation._row3._x * factor + _position._x; _position._y = _orientation._row3._y * factor + _position._y; _position._z = _orientation._row3._z * factor + _position._z; - _flag = false; + _poseUpToDate = false; } -void CViewport::fn15(const FMatrix &matrix) { +void CViewport::changeOrientation(const FMatrix &matrix) { _orientation.matLProd(matrix); - _flag = false; + _poseUpToDate = false; } FPose CViewport::getPose() { - if (!_flag) + if (!_poseUpToDate) reset(); return _currentPose; } FPose CViewport::getRawPose() { - if (!_flag) + if (!_poseUpToDate) reset(); return _rawPose; } -FVector CViewport::fn16(int index, const FVector &src) { - FPose temp = getPose(); - FVector dest; - dest._x = temp._row3._x * src._z + temp._row2._x * src._y - + src._x * temp._row1._x + temp._vector._x; - dest._y = temp._row3._y * src._z + temp._row2._y * src._y - + src._x * temp._row1._y + temp._vector._y; - dest._z = temp._row3._z * src._z + temp._row2._z * src._y - + src._x * temp._row1._z + temp._vector._z; +// TODO: should index be used here like +// getRelativePosCentering/getRelativePosCentering2? +// CStarCamera::getRelativePosCentering is calling this with an index of +// 2 which corresponds to _isZero which has value 0. +FVector CViewport::getRelativePosNoCentering(int index, const FVector &src) { + FPose current_pose = getPose(); + FVector dest = src.MatProdRowVect(current_pose); return dest; } -FVector CViewport::fn17(int index, const FVector &src) { +FVector CViewport::getRelativePosCentering(int index, const FVector &src) { FVector dest; FPose pose = getPose(); FVector tv = src.MatProdRowVect(pose); - dest._x = (_valArray[index] + tv._x) + double val; + if (index <2) { + val = _valArray[index]; + } + else if (index == 2) { + val = _isZero; + } + else if (index == 3) { + val = _pixel1OffSetX; + } + else { + val = _pixel2OffSetX; + } + + dest._x = (val + tv._x) * _centerVector._x / (_centerVector._y * tv._z); dest._y = (tv._y * _centerVector._x) / (_centerVector._z * tv._z); dest._z = tv._z; return dest; } -FVector CViewport::fn18(int index, const FVector &src) { + +// TODO: Identical to getRelativePosCentering, was this meant to be different? +FVector CViewport::getRelativePosCentering2(int index, const FVector &src) { FVector dest; FPose pose = getRawPose(); FVector tv = src.MatProdRowVect(pose); - dest._x = (_valArray[index] + tv._x) + double val; + if (index <2) { + val = _valArray[index]; + } + else if (index == 2) { + val = _isZero; + } + else if (index == 3) { + val = _pixel1OffSetX; + } + else { + val = _pixel2OffSetX; + } + + dest._x = (val + tv._x) * _centerVector._x / (_centerVector._y * tv._z); dest._y = (tv._y * _centerVector._x) / (_centerVector._z * tv._z); dest._z = tv._z; return dest; } -void CViewport::fn19(double *v1, double *v2, double *v3, double *v4) { +void CViewport::getRelativeXCenterPixels(double *v1, double *v2, double *v3, double *v4) { *v1 = _centerVector._x / _centerVector._y; *v2 = _centerVector._x / _centerVector._z; - *v3 = _valArray[3]; - *v4 = _valArray[4]; + *v3 = _pixel1OffSetX; + *v4 = _pixel2OffSetX; } void CViewport::reset() { - _rawPose.copyFrom(_orientation); _rawPose._vector = _position; _currentPose = _rawPose.inverseTransform(); + _poseUpToDate = true; _center = FPoint((double)_width * 0.5, (double)_height * 0.5); _centerVector._x = MIN(_center._x, _center._y); - _centerVector._y = tan(_field18 * Deg2Rad); - _centerVector._z = tan(_field1C * Deg2Rad); - _flag = true; + _centerVector._y = tan(_centerYAngleDegrees * Deg2Rad); + _centerVector._z = tan(_centerZAngleDegrees * Deg2Rad); } const FMatrix &CViewport::getOrientation() const { return _orientation; } -} // End of namespace Titanic +} // End of namespace Titanic
\ No newline at end of file diff --git a/engines/titanic/star_control/viewport.h b/engines/titanic/star_control/viewport.h index 1b4ab313b6..9ddb8ef255 100644 --- a/engines/titanic/star_control/viewport.h +++ b/engines/titanic/star_control/viewport.h @@ -30,30 +30,38 @@ class SimpleFile; namespace Titanic { +enum StarColor {WHITE=0,PINK=2}; // The color of the stars when drawn (CBaseStars::draw) + // For starview it should be white + // For skyview it should be pink + /** * Implements the viewport functionality for viewing the star field in - * a given position and orientation + * a given position and orientation. + * CStarCamera is a big user of this class */ class CViewport { private: double _fieldC; - double _field18; - double _field1C; + double _centerYAngleDegrees; + double _centerZAngleDegrees; int _width; int _height; FMatrix _orientation; FPose _currentPose; FPose _rawPose; FPoint _center; - bool _flag; + bool _poseUpToDate; private: void reset(); public: FVector _position; double _field10; double _field14; - int _field24; - double _valArray[5]; + StarColor _starColor; // Used in CBaseStars::draw + double _valArray[2]; // has value 0.0 or 30.0 + double _isZero; + double _pixel1OffSetX; // Used in CBaseStars::draw3 and CBaseStars::draw4 has value 0.0 or 28000.0 + double _pixel2OffSetX; // Used in CBaseStars::draw3 and CBaseStars::draw4 has value 0.0 or -28000.0 FVector _centerVector; public: CViewport(); @@ -94,16 +102,34 @@ public: */ void setOrientation(const FVector &v); - void fn12(); - void fn13(StarMode mode, double val); + void randomizeOrientation(); + /** + * The view has changed between starview and skyview + * Change the enum that tracks the color of the stars + * Also change the X coordinate pixel offset used for star drawing + */ + void changeStarColorPixel(StarMode mode, double pixelOffSet); void reposition(double factor); - void fn15(const FMatrix &matrix); + + /** + * Applys a rotation matrix to the current + * orientation + */ + void changeOrientation(const FMatrix &matrix); FPose getPose(); FPose getRawPose(); - FVector fn16(int index, const FVector &src); - FVector fn17(int index, const FVector &src); - FVector fn18(int index, const FVector &src); - void fn19(double *v1, double *v2, double *v3, double *v4); + FVector getRelativePosNoCentering(int index, const FVector &src); + FVector getRelativePosCentering(int index, const FVector &src); + FVector getRelativePosCentering2(int index, const FVector &src); + + /** + * All arguments are return values + * First is the x center coordinate relative to y + * Second is the x center coordinate relative to z + * Third is the first x center pixel offset + * Fourth is the second x center pixel offset + */ + void getRelativeXCenterPixels(double *v1, double *v2, double *v3, double *v4); /** * Returns the viewport's orientation @@ -113,8 +139,18 @@ public: void setC(double v); void set10(double v); void set14(double v); - void set18(double v); - void set1C(double v); + /** + * Sets the center vector y angle + * The actual center y value doesn't + * change untill reset is called + */ + void setCenterYAngle(double angleDegrees); + /** + * Sets the center vector z angle + * The actual center z value doesn't + * change untill reset is called + */ + void setCenterZAngle(double angleDegrees); }; } // End of namespace Titanic |