Skip to content

Commit

Permalink
TITANIC: Added DAffine functions that combines several vector operations
Browse files Browse the repository at this point in the history
  • Loading branch information
dafioram committed Sep 1, 2017
1 parent 24c2e3c commit f01115f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 29 deletions.
17 changes: 17 additions & 0 deletions engines/titanic/star_control/daffine.cpp
Expand Up @@ -116,6 +116,13 @@ void DAffine::setRotationMatrix(Axis axis, double angleDeg) {
}
}

void DAffine::rotVectAxisY(double angleDeg) {
_col1.rotVectAxisY(angleDeg);
_col2.rotVectAxisY(angleDeg);
_col3.rotVectAxisY(angleDeg);
_col4.rotVectAxisY(angleDeg);
}

DAffine DAffine::inverseTransform() const {
DAffine m;

Expand Down Expand Up @@ -212,4 +219,14 @@ DAffine DAffine::compose(const DAffine &m) {
return dm;
}

DAffine DAffine::compose2(const DAffine &m) {
DAffine dm;
dm._col1 = _col1.dAffMatrixProdVec(m);
dm._col2 = _col2.dAffMatrixProdVec(m);
dm._col3 = _col3.dAffMatrixProdVec(m);
dm._col4 = _col4.dAffMatrixProdVec(m);

return dm;
}

} // End of namespace Titanic
7 changes: 7 additions & 0 deletions engines/titanic/star_control/daffine.h
Expand Up @@ -62,6 +62,11 @@ class DAffine {
*/
void setRotationMatrix(Axis axis, double angleDeg);

/**
* Rotate this DAffine about the Y axis
*/
void rotVectAxisY(double angleDeg);

/**
* Return the Inverse of this Daffine
*/
Expand All @@ -80,6 +85,8 @@ class DAffine {
* as multiplying two matrices of dimensions 3x4.
*/
DAffine compose(const DAffine &m);

DAffine compose2(const DAffine &m);
};

} // End of namespace Titanic
Expand Down
46 changes: 17 additions & 29 deletions engines/titanic/star_control/star_camera.cpp
Expand Up @@ -320,10 +320,8 @@ void CStarCamera::setViewportAngle(const FPoint &angles) {
case TWO_LOCKED: {
FVector tempV2;
DAffine m1, m2, sub;
DVector mrow1, mrow2, mrow3;
DVector tempV1, diffV, multV, multV2, tempV3, tempV4, tempV5, tempV6, tempV7;
DVector tempV8, tempV9, tempV10, tempV11, tempV12;
DVector tempV13, tempV14, tempV15, tempV16;
FVector mrow1, mrow2, mrow3;
FVector tempV1, diffV, multV, multV2, tempV3, tempV7;

DAffine subX(0, _lockedStarsPos._row1);
DAffine subY(Y_AXIS, angles._y);
Expand Down Expand Up @@ -361,22 +359,22 @@ void CStarCamera::setViewportAngle(const FPoint &angles) {
tempV7._y = m3._row3._y * rowScale2 + tempV3._y;
tempV7._x = m3._row3._x * rowScale2 + tempV3._x;

mrow3 = tempV8 = tempV7;
tempV3 = tempV3.dAffMatrixProdVec(subX);
mrow1 = mrow1.dAffMatrixProdVec(subX);
mrow2 = mrow2.dAffMatrixProdVec(subX);
mrow3 = mrow3.dAffMatrixProdVec(subX);
mrow3 = tempV7;
tempV3 = tempV3.MatProdColVect(subX);
mrow1 = mrow1.MatProdColVect(subX);
mrow2 = mrow2.MatProdColVect(subX);
mrow3 = mrow3.MatProdColVect(subX);

tempV3 = tempV3.dAffMatrixProdVec(m1);
mrow1 = mrow1.dAffMatrixProdVec(m1);
mrow2 = mrow2.dAffMatrixProdVec(m1);
mrow3 = mrow3.dAffMatrixProdVec(m1);
tempV3 = tempV3.MatProdColVect(m1);
mrow1 = mrow1.MatProdColVect(m1);
mrow2 = mrow2.MatProdColVect(m1);
mrow3 = mrow3.MatProdColVect(m1);

mrow1 -= tempV3;
mrow2 -= tempV3;
mrow3 -= tempV3;

double unusedScale=0.0;
float unusedScale=0.0;
if (!mrow1.normalize(unusedScale) ||
!mrow2.normalize(unusedScale) ||
!mrow3.normalize(unusedScale)) {
Expand All @@ -385,11 +383,9 @@ void CStarCamera::setViewportAngle(const FPoint &angles) {
assert(unusedScale);
}

tempV16 = tempV3;

m3.set(mrow1, mrow2, mrow3);
_viewport.setOrientation(m3);
_viewport.setPosition(tempV16);
_viewport.setPosition(tempV3);
break;
}

Expand Down Expand Up @@ -561,26 +557,18 @@ bool CStarCamera::lockMarker2(CViewport *viewport, const FVector &secondStarPosi
tempV3._z = newOr._row3._z * rowScale2 + m4._col1._z;
m4._col4 = tempV3;


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);
m4 = m4.compose2(m2);

float minDistance;
FVector x1(viewPosition);
FVector x2(m4._col1);
// Find the angle of rotation for m4._col1 that gives the minimum distance to viewPosition
float minDegree = calcAngleForMinDist(x1,x2,minDistance);

m4._col1.rotVectAxisY((double)minDegree);
m4._col2.rotVectAxisY((double)minDegree);
m4._col3.rotVectAxisY((double)minDegree);
m4._col4.rotVectAxisY((double)minDegree);
m4._col1 = m4._col1.dAffMatrixProdVec(m1);
m4._col2 = m4._col2.dAffMatrixProdVec(m1);
m4._col3 = m4._col3.dAffMatrixProdVec(m1);
m4._col4 = m4._col4.dAffMatrixProdVec(m1);
m4.rotVectAxisY((double)minDegree);
m4 = m4.compose2(m1);

m4._col3 -= m4._col1;
m4._col2 -= m4._col1;
Expand Down

0 comments on commit f01115f

Please sign in to comment.