2019-05-15 16:52:37 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
class CMatrix
|
|
|
|
{
|
|
|
|
public:
|
2021-01-18 20:06:59 +01:00
|
|
|
union
|
|
|
|
{
|
|
|
|
float f[4][4];
|
|
|
|
struct
|
|
|
|
{
|
2021-01-19 16:09:06 +01:00
|
|
|
float rx, ry, rz, rw;
|
|
|
|
float fx, fy, fz, fw;
|
|
|
|
float ux, uy, uz, uw;
|
|
|
|
float px, py, pz, pw;
|
2021-01-18 20:06:59 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-05-15 16:52:37 +02:00
|
|
|
RwMatrix *m_attachment;
|
|
|
|
bool m_hasRwMatrix; // are we the owner?
|
|
|
|
|
2020-09-14 19:48:49 +02:00
|
|
|
CMatrix(void);
|
|
|
|
CMatrix(CMatrix const &m);
|
|
|
|
CMatrix(RwMatrix *matrix, bool owner = false);
|
2019-06-29 13:38:37 +02:00
|
|
|
CMatrix(float scale){
|
|
|
|
m_attachment = nil;
|
|
|
|
m_hasRwMatrix = false;
|
|
|
|
SetScale(scale);
|
|
|
|
}
|
2020-09-14 19:48:49 +02:00
|
|
|
~CMatrix(void);
|
|
|
|
void Attach(RwMatrix *matrix, bool owner = false);
|
|
|
|
void AttachRW(RwMatrix *matrix, bool owner = false);
|
|
|
|
void Detach(void);
|
|
|
|
void Update(void);
|
|
|
|
void UpdateRW(void);
|
|
|
|
void operator=(CMatrix const &rhs);
|
|
|
|
CMatrix &operator+=(CMatrix const &rhs);
|
|
|
|
CMatrix &operator*=(CMatrix const &rhs);
|
2019-05-15 16:52:37 +02:00
|
|
|
|
2021-01-19 16:09:06 +01:00
|
|
|
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; }
|
|
|
|
|
2019-07-08 21:37:47 +02:00
|
|
|
|
2020-09-14 19:48:49 +02:00
|
|
|
void SetTranslate(float x, float y, float z);
|
2019-07-08 21:37:47 +02:00
|
|
|
void SetTranslate(const CVector &trans){ SetTranslate(trans.x, trans.y, trans.z); }
|
|
|
|
void Translate(float x, float y, float z){
|
2021-01-19 16:09:06 +01:00
|
|
|
px += x;
|
|
|
|
py += y;
|
|
|
|
pz += z;
|
2019-07-08 21:37:47 +02:00
|
|
|
}
|
|
|
|
void Translate(const CVector &trans){ Translate(trans.x, trans.y, trans.z); }
|
|
|
|
|
2020-09-14 19:48:49 +02:00
|
|
|
void SetScale(float s);
|
2019-07-27 11:53:51 +02:00
|
|
|
void Scale(float scale)
|
|
|
|
{
|
2019-10-17 01:22:39 +02:00
|
|
|
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
|
2021-01-18 20:06:59 +01:00
|
|
|
f[i][j] *= scale;
|
2019-07-27 11:53:51 +02:00
|
|
|
}
|
|
|
|
|
2019-07-08 21:37:47 +02:00
|
|
|
|
2020-09-14 19:48:49 +02:00
|
|
|
void SetRotateXOnly(float angle);
|
|
|
|
void SetRotateYOnly(float angle);
|
|
|
|
void SetRotateZOnly(float angle);
|
|
|
|
void SetRotateX(float angle);
|
|
|
|
void SetRotateY(float angle);
|
|
|
|
void SetRotateZ(float angle);
|
2019-07-27 11:53:51 +02:00
|
|
|
void SetRotate(float xAngle, float yAngle, float zAngle);
|
|
|
|
void Rotate(float x, float y, float z);
|
2019-08-23 00:44:38 +02:00
|
|
|
void RotateX(float x);
|
2020-05-31 17:45:26 +02:00
|
|
|
void RotateY(float y);
|
2019-09-29 18:44:51 +02:00
|
|
|
void RotateZ(float z);
|
2019-06-24 16:57:54 +02:00
|
|
|
|
2019-07-27 11:53:51 +02:00
|
|
|
void Reorthogonalise(void);
|
2021-01-18 20:06:59 +01:00
|
|
|
void CopyOnlyMatrix(const CMatrix &other);
|
2020-09-14 19:48:49 +02:00
|
|
|
void SetUnity(void);
|
|
|
|
void ResetOrientation(void);
|
2020-07-01 18:03:52 +02:00
|
|
|
void SetTranslateOnly(float x, float y, float z) {
|
2021-01-19 16:09:06 +01:00
|
|
|
px = x;
|
|
|
|
py = y;
|
|
|
|
pz = z;
|
2020-07-01 18:03:52 +02:00
|
|
|
}
|
|
|
|
void SetTranslateOnly(const CVector& pos) {
|
|
|
|
SetTranslateOnly(pos.x, pos.y, pos.z);
|
|
|
|
}
|
2020-09-14 19:48:49 +02:00
|
|
|
void CheckIntegrity(){}
|
2019-05-15 16:52:37 +02:00
|
|
|
};
|
|
|
|
|
2019-07-27 11:53:51 +02:00
|
|
|
|
|
|
|
CMatrix &Invert(const CMatrix &src, CMatrix &dst);
|
2020-09-14 19:48:49 +02:00
|
|
|
CMatrix Invert(const CMatrix &matrix);
|
2019-07-27 11:53:51 +02:00
|
|
|
CMatrix operator*(const CMatrix &m1, const CMatrix &m2);
|
2019-10-27 00:46:48 +02:00
|
|
|
inline CVector MultiplyInverse(const CMatrix &mat, const CVector &vec)
|
|
|
|
{
|
2021-01-19 16:09:06 +01:00
|
|
|
CVector v(vec.x - mat.px, vec.y - mat.py, vec.z - mat.pz);
|
2019-10-27 00:46:48 +02:00
|
|
|
return CVector(
|
2021-01-19 16:09:06 +01:00
|
|
|
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);
|
2019-10-27 00:46:48 +02:00
|
|
|
}
|
|
|
|
|
2019-05-15 16:52:37 +02:00
|
|
|
|
2019-07-07 18:36:55 +02:00
|
|
|
|
2019-06-23 00:34:11 +02:00
|
|
|
class CCompressedMatrixNotAligned
|
|
|
|
{
|
|
|
|
CVector m_vecPos;
|
|
|
|
int8 m_rightX;
|
|
|
|
int8 m_rightY;
|
|
|
|
int8 m_rightZ;
|
|
|
|
int8 m_upX;
|
|
|
|
int8 m_upY;
|
|
|
|
int8 m_upZ;
|
|
|
|
public:
|
2020-09-14 19:48:49 +02:00
|
|
|
void CompressFromFullMatrix(CMatrix &other);
|
|
|
|
void DecompressIntoFullMatrix(CMatrix &other);
|
2019-07-08 17:07:34 +02:00
|
|
|
};
|
2020-05-13 04:31:14 +02:00
|
|
|
|
|
|
|
class CCompressedMatrix : public CCompressedMatrixNotAligned
|
|
|
|
{
|
|
|
|
int _alignment; // no clue what would this align to
|
|
|
|
};
|