diff options
author | David Fioramonti | 2017-09-01 03:55:54 -0700 |
---|---|---|
committer | David Fioramonti | 2017-09-01 04:30:55 -0700 |
commit | 24c2e3ce4f6dc70e73efe164c5546dbdc55b90ec (patch) | |
tree | 52fdddeeb7c6d767764399ca1ef8ddbb9c67cb8f /engines/titanic/star_control | |
parent | 0df15f0b0de7c31f75dab63836e92bc7899aa51d (diff) | |
download | scummvm-rg350-24c2e3ce4f6dc70e73efe164c5546dbdc55b90ec.tar.gz scummvm-rg350-24c2e3ce4f6dc70e73efe164c5546dbdc55b90ec.tar.bz2 scummvm-rg350-24c2e3ce4f6dc70e73efe164c5546dbdc55b90ec.zip |
TITANIC: Replace all external uses of DVector with FVector
Wherever DVector was used outside of DAffine and CMatrixTransform
I replaced with FVectors. So Internally those functions are still
using DVectors.
This required adding some new functions to FVector that duplicated
functionality in DVector.
Diffstat (limited to 'engines/titanic/star_control')
-rw-r--r-- | engines/titanic/star_control/fvector.cpp | 61 | ||||
-rw-r--r-- | engines/titanic/star_control/fvector.h | 32 | ||||
-rw-r--r-- | engines/titanic/star_control/star_camera.cpp | 60 | ||||
-rw-r--r-- | engines/titanic/star_control/star_camera.h | 2 | ||||
-rw-r--r-- | engines/titanic/star_control/unmarked_camera_mover.cpp | 4 |
5 files changed, 127 insertions, 32 deletions
diff --git a/engines/titanic/star_control/fvector.cpp b/engines/titanic/star_control/fvector.cpp index d880a134f5..4f0fd7db68 100644 --- a/engines/titanic/star_control/fvector.cpp +++ b/engines/titanic/star_control/fvector.cpp @@ -22,6 +22,7 @@ #include "titanic/star_control/fvector.h" #include "titanic/star_control/dvector.h" +#include "titanic/star_control/daffine.h" #include "titanic/star_control/fpose.h" //#include "common/algorithm.h" //#include "common/textconsole.h" @@ -48,6 +49,16 @@ FVector FVector::crossProduct(const FVector &src) const { ); } +void FVector::rotVectAxisY(float angleDeg) { + float sinVal = sin(angleDeg * Deg2Rad); + float cosVal = cos(angleDeg * Deg2Rad); + float x = cosVal * _x - sinVal * _z; + float z = cosVal * _z + sinVal * _x; + + _x = x; + _z = z; +} + bool FVector::normalize(float & hyp) { hyp = sqrt(_x * _x + _y * _y + _z * _z); if (hyp==0) { @@ -73,6 +84,23 @@ FVector FVector::addAndNormalize(const FVector &v) const { return tempV; } +FVector FVector::getAnglesAsVect() const { + FVector vector = *this; + FVector dest; + + if (!vector.normalize(dest._x)) { + // Makes this vector have magnitude=1, put the scale amount in dest._x, + // but if it is unsuccessful, crash + assert(dest._x); + } + + dest._y = acos(vector._y); // radian distance/angle that this vector's y component is from the +y axis, + // result is restricted to [0,pi] + dest._z = atan2(vector._x,vector._z); // result is restricted to [-pi,pi] + + return dest; +} + float FVector::getDistance(const FVector &src) const { float xd = src._x - _x; float yd = src._y - _y; @@ -81,6 +109,14 @@ float FVector::getDistance(const FVector &src) const { return sqrt(xd * xd + yd * yd + zd * zd); } +FVector FVector::MatProdColVect(const DAffine &pose) const { + FVector v; + v._x = pose._col1._x * _x + pose._col2._x * _y + pose._col3._x * _z + pose._col4._x; + v._y = pose._col1._y * _x + pose._col2._y * _y + pose._col3._y * _z + pose._col4._y; + v._z = pose._col1._z * _x + pose._col2._z * _y + pose._col3._z * _z + pose._col4._z; + return v; +} + FVector FVector::MatProdRowVect(const FPose &pose) const { FVector v; v._x = pose._row2._x * _y + pose._row3._x * _z + pose._row1._x * _x + pose._vector._x; @@ -89,6 +125,31 @@ FVector FVector::MatProdRowVect(const FPose &pose) const { return v; } +DAffine FVector::getFrameTransform(const FVector &v) { + DAffine matrix1, matrix2, matrix3, matrix4; + + FVector vector1 = getAnglesAsVect(); + matrix1.setRotationMatrix(X_AXIS, vector1._y * Rad2Deg); + matrix2.setRotationMatrix(Y_AXIS, vector1._z * Rad2Deg); + matrix3 = matrix1.compose(matrix2); + matrix4 = matrix3.inverseTransform(); + + vector1 = v.getAnglesAsVect(); + matrix1.setRotationMatrix(X_AXIS, vector1._y * Rad2Deg); + matrix2.setRotationMatrix(Y_AXIS, vector1._z * Rad2Deg); + matrix3 = matrix1.compose(matrix2); + + return matrix4.compose(matrix3); +} + +DAffine FVector::formRotXY() const { + FVector v1 = getAnglesAsVect(); + DAffine m1, m2; + m1.setRotationMatrix(X_AXIS, v1._y * Rad2Deg); + m2.setRotationMatrix(Y_AXIS, v1._z * Rad2Deg); + return m1.compose(m2); +} + Common::String FVector::toString() const { return Common::String::format("(%.3f,%.3f,%.3f)", _x, _y, _z); } diff --git a/engines/titanic/star_control/fvector.h b/engines/titanic/star_control/fvector.h index 5303702699..18270253c3 100644 --- a/engines/titanic/star_control/fvector.h +++ b/engines/titanic/star_control/fvector.h @@ -33,6 +33,7 @@ enum Axis { X_AXIS, Y_AXIS, Z_AXIS }; class FPose; class DVector; +class DAffine; /** * Floating point vector class. @@ -66,6 +67,11 @@ public: FVector crossProduct(const FVector &src) const; /** + * Rotate this vector about the Y axis + */ + void rotVectAxisY(float angleDeg); + + /** * Attempts to normalizes the vector so the length from origin equals 1.0 * Return value is whether or not it was successful in normalizing * First argument is scale value that normalizes the vector @@ -83,6 +89,14 @@ public: FVector addAndNormalize(const FVector &v) const; /** + * Returns a vector, v, that represents a magnitude, and two angles in radians + * 1. Scale this vector to be unit magnitude and store scale in x component of v + * 2. X rotation angle from +y axis of this vector is put in y component of v + * 3. z component output of v is the 4-quadrant angle that z makes with x (Y axis rotation) + */ + FVector getAnglesAsVect() const; + + /** * Returns the distance between a specified point and this one */ float getDistance(const FVector &src) const; @@ -94,6 +108,24 @@ public: FVector MatProdRowVect(const FPose &pose) const; /** + * Returns a vector that is this vector on the right as a column vector + * times the 4x3 fpose matrix on the left. + */ + FVector MatProdColVect(const DAffine &pose) const; + + /** + * Returns a matrix that contains the frame rotation based on this vector and + * a vector rotation based on input vector v + */ + DAffine getFrameTransform(const FVector &v); + + /** + * Constructs an affine matrix that does a x then a y axis frame rotation + * based on the orientation of this vector + */ + DAffine formRotXY() const; + + /** * Returns true if the passed vector equals this one */ bool operator==(const FVector &src) const { diff --git a/engines/titanic/star_control/star_camera.cpp b/engines/titanic/star_control/star_camera.cpp index c9cffd481f..a763f85770 100644 --- a/engines/titanic/star_control/star_camera.cpp +++ b/engines/titanic/star_control/star_camera.cpp @@ -522,33 +522,33 @@ bool CStarCamera::lockMarker2(CViewport *viewport, const FVector &secondStarPosi _isInLockingProcess = true; FVector firstStarPosition = _lockedStarsPos._row1; DAffine m2(0, firstStarPosition); // Identity matrix and col4 as the 1st stars position - DVector starDelta = secondStarPosition - firstStarPosition; + FVector starDelta = secondStarPosition - firstStarPosition; DAffine m1 = starDelta.formRotXY(); m1 = m1.compose(m2); m2 = m1.inverseTransform(); - DVector oldPos = _viewport._position; + FVector oldPos = _viewport._position; DAffine m4; m4._col1 = viewport->_position; - m4._col2 = DVector(0.0, 0.0, 0.0); - m4._col3 = DVector(0.0, 0.0, 0.0); - m4._col4 = DVector(0.0, 0.0, 0.0); + m4._col2 = FVector(0.0, 0.0, 0.0); + m4._col3 = FVector(0.0, 0.0, 0.0); + m4._col4 = FVector(0.0, 0.0, 0.0); FMatrix newOr = viewport->getOrientation(); - double yVal1 = newOr._row1._y * rowScale2; - double zVal1 = newOr._row1._z * rowScale2; - double xVal1 = newOr._row2._x * rowScale2; - double yVal2 = newOr._row2._y * rowScale2; - double zVal2 = newOr._row2._z * rowScale2; - double zVal3 = zVal1 + m4._col1._z; - double yVal3 = yVal1 + m4._col1._y; - double xVal2 = newOr._row1._x * rowScale2 + m4._col1._x; - double zVal4 = zVal2 + m4._col1._z; - double yVal4 = yVal2 + m4._col1._y; - double xVal3 = xVal1 + m4._col1._x; - - DVector tempV4(xVal2, yVal3, zVal3); - DVector tempV3(xVal3, yVal4, zVal4); + float yVal1 = newOr._row1._y * rowScale2; + float zVal1 = newOr._row1._z * rowScale2; + float xVal1 = newOr._row2._x * rowScale2; + float yVal2 = newOr._row2._y * rowScale2; + float zVal2 = newOr._row2._z * rowScale2; + float zVal3 = zVal1 + m4._col1._z; + float yVal3 = yVal1 + m4._col1._y; + float xVal2 = newOr._row1._x * rowScale2 + m4._col1._x; + float zVal4 = zVal2 + m4._col1._z; + float yVal4 = yVal2 + m4._col1._y; + float xVal3 = xVal1 + m4._col1._x; + + FVector tempV4(xVal2, yVal3, zVal3); + FVector tempV3(xVal3, yVal4, zVal4); m4._col3 = tempV4; FVector tempV5; @@ -561,15 +561,17 @@ bool CStarCamera::lockMarker2(CViewport *viewport, const FVector &secondStarPosi tempV3._z = newOr._row3._z * rowScale2 + m4._col1._z; m4._col4 = tempV3; - DVector viewPosition = oldPos.dAffMatrixProdVec(m2); + FVector viewPosition = oldPos.MatProdColVect(m2); m4._col1 = m4._col1.dAffMatrixProdVec(m2); m4._col3 = m4._col3.dAffMatrixProdVec(m2); m4._col2 = m4._col2.dAffMatrixProdVec(m2); m4._col4 = m4._col4.dAffMatrixProdVec(m2); - double minDistance; + float minDistance; + FVector x1(viewPosition); + FVector x2(m4._col1); // Find the angle of rotation for m4._col1 that gives the minimum distance to viewPosition - double minDegree = calcAngleForMinDist(viewPosition,m4._col1,minDistance); + float minDegree = calcAngleForMinDist(x1,x2,minDistance); m4._col1.rotVectAxisY((double)minDegree); m4._col2.rotVectAxisY((double)minDegree); @@ -627,20 +629,20 @@ bool CStarCamera::lockMarker3(CViewport *viewport, const FVector &thirdStarPosit return true; } -double CStarCamera::calcAngleForMinDist(DVector &x, DVector &y, double &minDistance) { - DVector tempPos; +float CStarCamera::calcAngleForMinDist(FVector &x, FVector &y, float &minDistance) { + FVector tempPos; minDistance = 1.0e20; - double minDegree = 0.0; - double degInc = 1.0; // one degree steps + float minDegree = 0.0; + float 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); + tempPos.rotVectAxisY((float)degInc*i); + float distance = x.getDistance(tempPos); if (distance < minDistance) { minDistance = distance; - minDegree = (double) degInc*i; + minDegree = (float) degInc*i; } } return minDegree; diff --git a/engines/titanic/star_control/star_camera.h b/engines/titanic/star_control/star_camera.h index 72c26c12a6..3ffb74950a 100644 --- a/engines/titanic/star_control/star_camera.h +++ b/engines/titanic/star_control/star_camera.h @@ -211,7 +211,7 @@ public: * The angle is in degrees. * Also returns the minimum distance calculated */ - double calcAngleForMinDist(DVector &x, DVector &y, double &minDistance); + float calcAngleForMinDist(FVector &x, FVector &y, float &minDistance); /** * Returns true for whether the camera has been moved diff --git a/engines/titanic/star_control/unmarked_camera_mover.cpp b/engines/titanic/star_control/unmarked_camera_mover.cpp index c1459ec372..7295f4a485 100644 --- a/engines/titanic/star_control/unmarked_camera_mover.cpp +++ b/engines/titanic/star_control/unmarked_camera_mover.cpp @@ -50,8 +50,8 @@ void CUnmarkedCameraMover::transitionBetweenOrientations(const FVector &v1, cons if (isLocked()) decLockCount(); - DVector vector1 = v1; - DVector vector2 = v2; + FVector vector1 = v1; + FVector vector2 = v2; DAffine matrix1 = vector2.getFrameTransform(vector1); DAffine matrix2 = matrix1.compose(m); |