summaryrefslogtreecommitdiffstats
path: root/src/math/Matrix.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/math/Matrix.h70
1 files changed, 43 insertions, 27 deletions
diff --git a/src/math/Matrix.h b/src/math/Matrix.h
index d8f6388d..9d50a4f6 100644
--- a/src/math/Matrix.h
+++ b/src/math/Matrix.h
@@ -3,7 +3,18 @@
class CMatrix
{
public:
- RwMatrix m_matrix;
+ union
+ {
+ float f[4][4];
+ struct
+ {
+ float rx, ry, rz, rw;
+ float fx, fy, fz, fw;
+ float ux, uy, uz, uw;
+ float px, py, pz, pw;
+ };
+ };
+
RwMatrix *m_attachment;
bool m_hasRwMatrix; // are we the owner?
@@ -25,31 +36,36 @@ public:
CMatrix &operator+=(CMatrix const &rhs);
CMatrix &operator*=(CMatrix const &rhs);
- 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; }
+ CVector &GetPosition(void) { return *(CVector*)&px; }
+ CVector &GetRight(void) { return *(CVector*)℞ }
+ CVector &GetForward(void) { return *(CVector*)&fx; }
+ CVector &GetUp(void) { return *(CVector*)&ux; }
+
+ const CVector &GetPosition(void) const { return *(CVector*)&px; }
+ const CVector &GetRight(void) const { return *(CVector*)℞ }
+ const CVector &GetForward(void) const { return *(CVector*)&fx; }
+ const CVector &GetUp(void) const { return *(CVector*)&ux; }
+
void SetTranslate(float x, float y, float z);
void SetTranslate(const CVector &trans){ SetTranslate(trans.x, trans.y, trans.z); }
void Translate(float x, float y, float z){
- m_matrix.pos.x += x;
- m_matrix.pos.y += y;
- m_matrix.pos.z += z;
+ px += x;
+ py += y;
+ pz += z;
}
void Translate(const CVector &trans){ Translate(trans.x, trans.y, trans.z); }
void SetScale(float s);
void Scale(float scale)
{
- 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;
+ f[i][j] *= scale;
}
@@ -60,17 +76,17 @@ public:
float c = Cos(angle);
float s = Sin(angle);
- m_matrix.right.x = c * scale;
- m_matrix.right.y = s * scale;
- m_matrix.right.z = 0.0f;
+ rx = c * scale;
+ ry = s * scale;
+ rz = 0.0f;
- m_matrix.up.x = -s * scale;
- m_matrix.up.y = c * scale;
- m_matrix.up.z = 0.0f;
+ fx = -s * scale;
+ fy = c * scale;
+ fz = 0.0f;
- m_matrix.at.x = 0.0f;
- m_matrix.at.y = 0.0f;
- m_matrix.at.z = scale;
+ ux = 0.0f;
+ uy = 0.0f;
+ uz = scale;
}
void SetRotateX(float angle);
void SetRotateY(float angle);
@@ -82,13 +98,13 @@ public:
void RotateZ(float z);
void Reorthogonalise(void);
- void CopyOnlyMatrix(CMatrix *other);
+ void CopyOnlyMatrix(const CMatrix &other);
void SetUnity(void);
void ResetOrientation(void);
void SetTranslateOnly(float x, float y, float z) {
- m_matrix.pos.x = x;
- m_matrix.pos.y = y;
- m_matrix.pos.z = z;
+ px = x;
+ py = y;
+ pz = z;
}
void SetTranslateOnly(const CVector& pos) {
SetTranslateOnly(pos.x, pos.y, pos.z);
@@ -102,11 +118,11 @@ CMatrix Invert(const CMatrix &matrix);
CMatrix operator*(const CMatrix &m1, const CMatrix &m2);
inline CVector MultiplyInverse(const CMatrix &mat, const CVector &vec)
{
- CVector v(vec.x - mat.m_matrix.pos.x, vec.y - mat.m_matrix.pos.y, vec.z - mat.m_matrix.pos.z);
+ CVector v(vec.x - mat.px, vec.y - mat.py, vec.z - mat.pz);
return CVector(
- mat.m_matrix.right.x * v.x + mat.m_matrix.right.y * v.y + mat.m_matrix.right.z * v.z,
- mat.m_matrix.up.x * v.x + mat.m_matrix.up.y * v.y + mat.m_matrix.up.z * v.z,
- mat.m_matrix.at.x * v.x + mat.m_matrix.at.y * v.y + mat.m_matrix.at.z * v.z);
+ mat.rx * v.x + mat.ry * v.y + mat.rz * v.z,
+ mat.fx * v.x + mat.fy * v.y + mat.fz * v.z,
+ mat.ux * v.x + mat.uy * v.y + mat.uz * v.z);
}