summaryrefslogtreecommitdiffstats
path: root/src/math
diff options
context:
space:
mode:
Diffstat (limited to 'src/math')
-rw-r--r--src/math/Matrix.cpp29
-rw-r--r--src/math/Matrix.h34
-rw-r--r--src/math/Vector2D.h8
3 files changed, 32 insertions, 39 deletions
diff --git a/src/math/Matrix.cpp b/src/math/Matrix.cpp
index a8b1b182..3ac3e2b9 100644
--- a/src/math/Matrix.cpp
+++ b/src/math/Matrix.cpp
@@ -458,62 +458,39 @@ CMatrix &
Invert(const CMatrix &src, CMatrix &dst)
{
// TODO: VU0 code
- // GTA handles this as a raw 4x4 orthonormal matrix
- // and trashes the RW flags, let's not do that
float (*scr_fm)[4] = (float (*)[4])&src.m_matrix;
float (*dst_fm)[4] = (float (*)[4])&dst.m_matrix;
dst_fm[3][0] = dst_fm[3][1] = dst_fm[3][2] = 0.0f;
-#ifndef FIX_BUGS
- dst_fm[3][3] = scr_fm[3][3];
-#endif
dst_fm[0][0] = scr_fm[0][0];
dst_fm[0][1] = scr_fm[1][0];
dst_fm[0][2] = scr_fm[2][0];
-#ifndef FIX_BUGS
- dst_fm[0][3] = scr_fm[3][0];
-#endif
+
dst_fm[1][0] = scr_fm[0][1];
dst_fm[1][1] = scr_fm[1][1];
dst_fm[1][2] = scr_fm[2][1];
-#ifndef FIX_BUGS
- dst_fm[1][3] = scr_fm[3][1];
-#endif
+
dst_fm[2][0] = scr_fm[0][2];
dst_fm[2][1] = scr_fm[1][2];
dst_fm[2][2] = scr_fm[2][2];
-#ifndef FIX_BUGS
- dst_fm[2][3] = scr_fm[3][2];
-#endif
+
dst_fm[3][0] += dst_fm[0][0] * scr_fm[3][0];
dst_fm[3][1] += dst_fm[0][1] * scr_fm[3][0];
dst_fm[3][2] += dst_fm[0][2] * scr_fm[3][0];
-#ifndef FIX_BUGS
- dst_fm[3][3] += dst_fm[0][3] * scr_fm[3][0];
-#endif
dst_fm[3][0] += dst_fm[1][0] * scr_fm[3][1];
dst_fm[3][1] += dst_fm[1][1] * scr_fm[3][1];
dst_fm[3][2] += dst_fm[1][2] * scr_fm[3][1];
-#ifndef FIX_BUGS
- dst_fm[3][3] += dst_fm[1][3] * scr_fm[3][1];
-#endif
dst_fm[3][0] += dst_fm[2][0] * scr_fm[3][2];
dst_fm[3][1] += dst_fm[2][1] * scr_fm[3][2];
dst_fm[3][2] += dst_fm[2][2] * scr_fm[3][2];
-#ifndef FIX_BUGS
- dst_fm[3][3] += dst_fm[2][3] * scr_fm[3][2];
-#endif
dst_fm[3][0] = -dst_fm[3][0];
dst_fm[3][1] = -dst_fm[3][1];
dst_fm[3][2] = -dst_fm[3][2];
-#ifndef FIX_BUGS
- dst_fm[3][3] = scr_fm[3][3] - dst_fm[3][3];
-#endif
return dst;
}
diff --git a/src/math/Matrix.h b/src/math/Matrix.h
index d8f6388d..bf811af7 100644
--- a/src/math/Matrix.h
+++ b/src/math/Matrix.h
@@ -23,9 +23,19 @@ public:
void UpdateRW(void);
void operator=(CMatrix const &rhs);
CMatrix &operator+=(CMatrix const &rhs);
+#ifdef RWCORE_H
+ operator RwMatrix (void) const {
+ return m_matrix;
+ }
+
+ operator RwMatrix *(void) {
+ return &m_matrix;
+ }
+#endif
CMatrix &operator*=(CMatrix const &rhs);
- CVector &GetPosition(void){ return *(CVector*)&m_matrix.pos; }
+ const CVector &GetPosition(void) const { return *(CVector*)&m_matrix.pos; }
+ CVector& GetPosition(void) { return *(CVector*)&m_matrix.pos; }
CVector &GetRight(void) { return *(CVector*)&m_matrix.right; }
CVector &GetForward(void) { return *(CVector*)&m_matrix.up; }
CVector &GetUp(void) { return *(CVector*)&m_matrix.at; }
@@ -44,13 +54,18 @@ public:
{
float *pFloatMatrix = (float*)&m_matrix;
for (int i = 0; i < 3; i++)
-#ifdef FIX_BUGS // BUGFIX from VC
for (int j = 0; j < 3; j++)
-#else
- for (int j = 0; j < 4; j++)
-#endif
pFloatMatrix[i * 4 + j] *= scale;
}
+ void Scale(float sx, float sy, float sz)
+ {
+ float *pFloatMatrix = (float*)&m_matrix;
+ for (int i = 0; i < 3; i++){
+ pFloatMatrix[i * 4 + 0] *= sx;
+ pFloatMatrix[i * 4 + 1] *= sy;
+ pFloatMatrix[i * 4 + 2] *= sz;
+ }
+ }
void SetRotateXOnly(float angle);
@@ -85,6 +100,15 @@ public:
void CopyOnlyMatrix(CMatrix *other);
void SetUnity(void);
void ResetOrientation(void);
+ void CopyRwMatrix(RwMatrix *matrix){
+ m_matrix = *matrix;
+ }
+
+ void CopyToRwMatrix(RwMatrix *matrix){
+ *matrix = m_matrix;
+ RwMatrixUpdate(matrix);
+ }
+
void SetTranslateOnly(float x, float y, float z) {
m_matrix.pos.x = x;
m_matrix.pos.y = y;
diff --git a/src/math/Vector2D.h b/src/math/Vector2D.h
index 0235dbe5..2c4e57b5 100644
--- a/src/math/Vector2D.h
+++ b/src/math/Vector2D.h
@@ -13,14 +13,6 @@ public:
void Normalise(void) {
float sq = MagnitudeSqr();
- // assert(sq != 0.0f); // just be safe here
- float invsqrt = RecipSqrt(sq);
- x *= invsqrt;
- y *= invsqrt;
- }
-
- void NormaliseSafe(void) {
- float sq = MagnitudeSqr();
if(sq > 0.0f){
float invsqrt = RecipSqrt(sq);
x *= invsqrt;