aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic
diff options
context:
space:
mode:
authorDavid Fioramonti2017-08-29 18:11:37 -0700
committerDavid Fioramonti2017-08-30 19:53:13 -0700
commitf1e673c133b977050cce320e1fbebc13172279cf (patch)
treebf8067197f41783d63bd52ce6fbf20cc67eab979 /engines/titanic
parent6a43e8d95894f5f5fd99e2f9707465cc8fe909d1 (diff)
downloadscummvm-rg350-f1e673c133b977050cce320e1fbebc13172279cf.tar.gz
scummvm-rg350-f1e673c133b977050cce320e1fbebc13172279cf.tar.bz2
scummvm-rg350-f1e673c133b977050cce320e1fbebc13172279cf.zip
TITANIC: StarCamera separate function for calculating angle
This makes lockMarker2 more manageable.
Diffstat (limited to 'engines/titanic')
-rw-r--r--engines/titanic/star_control/star_camera.cpp38
-rw-r--r--engines/titanic/star_control/star_camera.h8
2 files changed, 31 insertions, 15 deletions
diff --git a/engines/titanic/star_control/star_camera.cpp b/engines/titanic/star_control/star_camera.cpp
index 1ece7efd73..b4517b9aa4 100644
--- a/engines/titanic/star_control/star_camera.cpp
+++ b/engines/titanic/star_control/star_camera.cpp
@@ -512,7 +512,7 @@ bool CStarCamera::lockMarker2(CViewport *viewport, const FVector &secondStarPosi
if (_starLockState != ONE_LOCKED)
return true;
FVector firstStarPosition = _lockedStarsPos._row1;
- DAffine m2(X_AXIS, firstStarPosition); // Identity matrix and col4 as the 1st stars position
+ DAffine m2(0, firstStarPosition); // Identity matrix and col4 as the 1st stars position
DVector tempV1 = secondStarPosition - firstStarPosition;
DAffine m1 = tempV1.rotXY();
m1 = m1.compose(m2);
@@ -558,20 +558,9 @@ bool CStarCamera::lockMarker2(CViewport *viewport, const FVector &secondStarPosi
m4._col2 = m4._col2.dAffMatrixProdVec(m2);
m4._col4 = m4._col4.dAffMatrixProdVec(m2);
- // Find the angle that gives the minimum distance
- DVector tempPos;
- double minDistance = 1.0e20;
- int minDegree = 0;
- for (int degree = 0; degree < 360; ++degree) {
- tempPos = m4._col1;
- tempPos.rotVectAxisY((double)degree);
- double distance = tempV2.getDistance(tempPos);
-
- if (distance < minDistance) {
- minDistance = distance;
- minDegree = degree;
- }
- }
+ double minDistance;
+ // Find the angle of rotation for m4._col1 that gives the minimum distance to tempV2
+ double minDegree = calcAngleForMinDist(tempV2,m4._col1,minDistance);
m4._col1.rotVectAxisY((double)minDegree);
m4._col2.rotVectAxisY((double)minDegree);
@@ -631,4 +620,23 @@ bool CStarCamera::lockMarker3(CViewport *viewport, const FVector &thirdStarPosit
return true;
}
+double CStarCamera::calcAngleForMinDist(DVector &x, DVector &y, double &minDistance) {
+ DVector tempPos;
+ minDistance = 1.0e20;
+ double minDegree = 0.0;
+ double degInc = 1.0; // one degree steps
+ int nDegrees = floor(360.0/degInc);
+ for (int i = 0; i < nDegrees; ++i) {
+ tempPos = y;
+ tempPos.rotVectAxisY((double)degInc*i);
+ double distance = x.getDistance(tempPos);
+
+ if (distance < minDistance) {
+ minDistance = distance;
+ minDegree = (double) degInc*i;
+ }
+ }
+ return minDegree;
+}
+
} // End of namespace Titanic
diff --git a/engines/titanic/star_control/star_camera.h b/engines/titanic/star_control/star_camera.h
index 7243f44fc8..71be90d345 100644
--- a/engines/titanic/star_control/star_camera.h
+++ b/engines/titanic/star_control/star_camera.h
@@ -198,6 +198,14 @@ public:
virtual void save(SimpleFile *file, int indent);
/**
+ * Calculates the angle of rotation of y that achieves
+ * the minimum distance to x.
+ * The angle is in degrees.
+ * Also returns the minimum distance calculated
+ */
+ double calcAngleForMinDist(DVector &x, DVector &y, double &minDistance);
+
+ /**
* Returns true for whether the camera has been moved
*/
bool isMoved() const { return _isMoved; }