aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorPaul Gilbert2017-08-30 19:54:36 -0400
committerGitHub2017-08-30 19:54:36 -0400
commit4557c31c547fabb527ac68977b77b02ef6fdc2a4 (patch)
treea32e7d0c587a2c3a78e86606404707d7ca81d2b8 /engines
parent6a5aa12bfa5c3e16ad19531765ed27cb8080fb32 (diff)
parent5cf2f16ca0549cbfe72e6bee54050b0051be3503 (diff)
downloadscummvm-rg350-4557c31c547fabb527ac68977b77b02ef6fdc2a4.tar.gz
scummvm-rg350-4557c31c547fabb527ac68977b77b02ef6fdc2a4.tar.bz2
scummvm-rg350-4557c31c547fabb527ac68977b77b02ef6fdc2a4.zip
Merge pull request #1001 from dafioram/viewport_refactor
TITANIC: Viewport refactor
Diffstat (limited to 'engines')
-rw-r--r--engines/titanic/star_control/base_stars.cpp14
-rw-r--r--engines/titanic/star_control/dvector.h3
-rw-r--r--engines/titanic/star_control/fpose.cpp59
-rw-r--r--engines/titanic/star_control/fpose.h11
-rw-r--r--engines/titanic/star_control/fvector.h2
-rw-r--r--engines/titanic/star_control/star_camera.cpp56
-rw-r--r--engines/titanic/star_control/star_camera.h22
-rw-r--r--engines/titanic/star_control/star_closeup.cpp22
-rw-r--r--engines/titanic/star_control/star_field.cpp2
-rw-r--r--engines/titanic/star_control/star_view.cpp12
-rw-r--r--engines/titanic/star_control/viewport.cpp198
-rw-r--r--engines/titanic/star_control/viewport.h66
12 files changed, 288 insertions, 179 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/dvector.h b/engines/titanic/star_control/dvector.h
index 4b85c0342d..e9ca257498 100644
--- a/engines/titanic/star_control/dvector.h
+++ b/engines/titanic/star_control/dvector.h
@@ -27,9 +27,6 @@
namespace Titanic {
-const double Rad2Deg = 180.0 / M_PI;
-const double Deg2Rad = 1.0 / Rad2Deg;
-
class DAffine;
/**
diff --git a/engines/titanic/star_control/fpose.cpp b/engines/titanic/star_control/fpose.cpp
index e7aafcfe2d..e0c042a74d 100644
--- a/engines/titanic/star_control/fpose.cpp
+++ b/engines/titanic/star_control/fpose.cpp
@@ -24,6 +24,25 @@
namespace Titanic {
+// Non-member functions
+
+void fposeProd(const FPose &a, const FPose &m, FPose &C) {
+ C._row1._x = a._row1._y * m._row2._x + a._row1._z * m._row3._x + a._row1._x * m._row1._x;
+ C._row1._y = a._row1._x * m._row1._y + m._row2._y * a._row1._y + m._row3._y * a._row1._z;
+ C._row1._z = a._row1._x * m._row1._z + a._row1._y * m._row2._z + a._row1._z * m._row3._z;
+ C._row2._x = m._row1._x * a._row2._x + m._row3._x * a._row2._z + m._row2._x * a._row2._y;
+ C._row2._y = m._row3._y * a._row2._z + m._row1._y * a._row2._x + m._row2._y * a._row2._y;
+ C._row2._z = a._row2._z * m._row3._z + a._row2._x * m._row1._z + a._row2._y * m._row2._z;
+ C._row3._x = m._row1._x * a._row3._x + a._row3._z * m._row3._x + a._row3._y * m._row2._x;
+ C._row3._y = a._row3._y * m._row2._y + a._row3._z * m._row3._y + a._row3._x * m._row1._y;
+ C._row3._z = a._row3._x * m._row1._z + a._row3._y * m._row2._z + a._row3._z * m._row3._z;
+ C._vector._x = m._row1._x * a._vector._x + a._vector._y * m._row2._x + a._vector._z * m._row3._x + m._vector._x;
+ C._vector._y = a._vector._z * m._row3._y + a._vector._y * m._row2._y + a._vector._x * m._row1._y + a._vector._y;
+ C._vector._z = a._vector._y * m._row2._z + a._vector._z * m._row3._z + a._vector._x * m._row1._z + m._vector._z;
+}
+
+// Member functions
+
FPose::FPose() {
clear();
}
@@ -37,45 +56,7 @@ FPose::FPose(const FPose &src) : FMatrix() {
}
FPose::FPose(const FPose &s1, const FPose &s2) {
- _row1._x = s2._row1._x * s1._row1._x
- + s1._row1._z * s2._row3._x
- + s1._row1._y * s2._row2._x;
- _row1._y = s1._row1._x * s2._row1._y
- + s2._row3._y * s1._row1._z
- + s2._row2._y * s1._row1._y;
- _row1._z = s1._row1._x * s2._row1._z
- + s2._row3._z * s1._row1._z
- + s2._row2._z * s1._row1._y;
- _row2._x = s2._row1._x * s1._row2._x
- + s1._row2._y * s2._row2._x
- + s1._row2._z * s2._row3._x;
- _row2._y = s1._row2._y * s2._row2._y
- + s1._row2._z * s2._row3._y
- + s2._row1._y * s1._row2._x;
- _row2._z = s2._row1._z * s1._row2._x
- + s1._row2._y * s2._row2._z
- + s1._row2._z * s2._row3._z;
- _row3._x = s2._row1._x * s1._row3._x
- + s1._row3._y * s2._row2._x
- + s1._row3._z * s2._row3._x;
- _row3._y = s1._row3._z * s2._row3._y
- + s1._row3._y * s2._row2._y
- + s2._row1._y * s1._row3._x;
- _row3._z = s2._row3._z * s1._row3._z
- + s2._row2._z * s1._row3._y
- + s2._row1._z * s1._row3._x;
- _vector._x = s2._row1._x * s1._vector._x
- + s1._vector._y * s2._row2._x
- + s1._vector._z * s2._row3._x
- + s2._vector._x;
- _vector._y = s1._vector._z * s2._row3._y
- + s1._vector._y * s2._row2._y
- + s1._vector._x * s2._row1._y
- + s2._vector._y;
- _vector._z = s1._vector._y * s2._row2._z
- + s1._vector._z * s2._row3._z
- + s1._vector._x * s2._row1._z
- + s2._vector._z;
+ fposeProd(s1,s2,*this);
}
void FPose::identity() {
diff --git a/engines/titanic/star_control/fpose.h b/engines/titanic/star_control/fpose.h
index c25790f527..5287ff0516 100644
--- a/engines/titanic/star_control/fpose.h
+++ b/engines/titanic/star_control/fpose.h
@@ -38,6 +38,10 @@ public:
FPose();
FPose(Axis axis, float amount);
FPose(const FPose &src);
+
+ /**
+ * This fpose is the fpose product of s1 (on the left) and s2 (on the right)
+ */
FPose(const FPose &s1, const FPose &s2);
/**
@@ -66,6 +70,13 @@ public:
FPose inverseTransform() const;
};
+/**
+ * Puts the fpose product between a and m in C, C = am
+ * Caller must preallocate output matrix
+ * Similar to matProd
+ */
+void fposeProd(const FPose &a, const FPose &m, FPose &C);
+
} // End of namespace Titanic
#endif /* TITANIC_FPOSE_H */
diff --git a/engines/titanic/star_control/fvector.h b/engines/titanic/star_control/fvector.h
index d4ba754138..5303702699 100644
--- a/engines/titanic/star_control/fvector.h
+++ b/engines/titanic/star_control/fvector.h
@@ -27,6 +27,8 @@
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_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 7bfccd1721..b22abe6eff 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 d2bdce00e0..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);
+ 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() {
- const double FACTOR = 2 * M_PI / 360.0;
-
_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 * FACTOR);
- _centerVector._z = tan(_field1C * FACTOR);
- _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