Skip to content

Commit

Permalink
TITANIC: Move Matrix4Inv out of starcamera and into FPose function
Browse files Browse the repository at this point in the history
  • Loading branch information
dafioram committed Sep 2, 2017
1 parent d55406b commit d6ca9ed
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 38 deletions.
50 changes: 27 additions & 23 deletions engines/titanic/star_control/fpose.cpp
Expand Up @@ -22,6 +22,7 @@

#include "titanic/star_control/fpose.h"
#include "titanic/star_control/matrix_transform.h"
#include "titanic/star_control/matrix_inv.h"

namespace Titanic {

Expand Down Expand Up @@ -159,29 +160,32 @@ void FPose::copyFrom(const FMatrix &src) {
}

FPose FPose::inverseTransform() const {
FPose result;

result._row1._x = _row1._x;
result._row2._x = _row1._y;
result._row3._x = _row1._z;
result._row1._y = _row2._x;
result._row2._y = _row2._y;
result._row3._y = _row2._z;
result._row1._z = _row3._x;
result._row2._z = _row3._y;
result._row3._z = _row3._z;

result._vector._x = -(_vector._x * result._row1._x
+ _vector._y * result._row2._x
+ _vector._z * result._row3._x);
result._vector._y = -(_vector._x * result._row1._y
+ _vector._y * result._row2._y
+ _vector._z * result._row3._y);
result._vector._z = -(_vector._x * result._row1._z
+ _vector._y * result._row2._z
+ _vector._z * result._row3._z);

return result;
FPose matrix_inv;

matrix_inv._row1._x = _row1._x;
matrix_inv._row2._x = _row1._y;
matrix_inv._row3._x = _row1._z;
matrix_inv._row1._y = _row2._x;
matrix_inv._row2._y = _row2._y;
matrix_inv._row3._y = _row2._z;
matrix_inv._row1._z = _row3._x;
matrix_inv._row2._z = _row3._y;
matrix_inv._row3._z = _row3._z;

float A[16]={_row1._x,_row1._y,_row1._z, 0.0,
_row2._x,_row2._y,_row2._z, 0.0,
_row3._x,_row3._y,_row3._z, 0.0,
_vector._x,_vector._y,_vector._z, 1.0};
// Inverse matrix
float B[16]={};

// B contains inverse of A
matrix4Inverse<float>(A,B);
matrix_inv._vector._x=B[12];
matrix_inv._vector._y=B[13];
matrix_inv._vector._z=B[14];

return matrix_inv;
}

//TODO: Check math and provide source
Expand Down
18 changes: 3 additions & 15 deletions engines/titanic/star_control/star_camera.cpp
Expand Up @@ -26,7 +26,7 @@
#include "titanic/star_control/fmatrix.h"
#include "titanic/star_control/fpoint.h"
#include "titanic/star_control/marked_camera_mover.h"
#include "titanic/star_control/matrix_inv.h"
//#include "titanic/star_control/matrix_inv.h"
#include "titanic/star_control/unmarked_camera_mover.h"
#include "titanic/star_control/error_code.h"
#include "titanic/support/simple_file.h"
Expand Down Expand Up @@ -525,20 +525,8 @@ bool CStarCamera::lockMarker2(CViewport *viewport, const FVector &secondStarPosi
FPose m10 = starDelta.formRotXY();
FPose m11;
fposeProd(m10,m3,m11);

float A[16]={m11._row1._x,m11._row1._y,m11._row1._z, 0.0,
m11._row2._x,m11._row2._y,m11._row2._z, 0.0,
m11._row3._x,m11._row3._y,m11._row3._z, 0.0,
m11._vector._x,m11._vector._y,m11._vector._z, 1.0};
// Inverse matrix
float B[16]={};

// B contains inverse of A
matrix4Inverse<float>(A,B);
m10=m11.inverseTransform();
m10._vector._x=B[12];
m10._vector._y=B[13];
m10._vector._z=B[14];

m10 = m11.inverseTransform();

FVector oldPos = _viewport._position;

Expand Down

0 comments on commit d6ca9ed

Please sign in to comment.