2019-05-15 14:52:37 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
class CMatrix
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RwMatrix m_matrix;
|
|
|
|
RwMatrix *m_attachment;
|
|
|
|
bool m_hasRwMatrix; // are we the owner?
|
|
|
|
|
2020-09-14 17:48:49 +00:00
|
|
|
CMatrix(void);
|
|
|
|
CMatrix(CMatrix const &m);
|
|
|
|
CMatrix(RwMatrix *matrix, bool owner = false);
|
2019-06-29 11:38:37 +00:00
|
|
|
CMatrix(float scale){
|
|
|
|
m_attachment = nil;
|
|
|
|
m_hasRwMatrix = false;
|
|
|
|
SetScale(scale);
|
|
|
|
}
|
2020-09-14 17:48:49 +00: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 14:52:37 +00:00
|
|
|
|
2020-05-13 08:38:05 +00:00
|
|
|
const CVector &GetPosition(void) const { return *(CVector*)&m_matrix.pos; }
|
|
|
|
CVector& GetPosition(void) { return *(CVector*)&m_matrix.pos; }
|
2019-07-08 15:07:34 +00:00
|
|
|
CVector &GetRight(void) { return *(CVector*)&m_matrix.right; }
|
|
|
|
CVector &GetForward(void) { return *(CVector*)&m_matrix.up; }
|
|
|
|
CVector &GetUp(void) { return *(CVector*)&m_matrix.at; }
|
2019-07-08 19:37:47 +00:00
|
|
|
|
2020-09-14 17:48:49 +00:00
|
|
|
void SetTranslate(float x, float y, float z);
|
2019-07-08 19:37:47 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
void Translate(const CVector &trans){ Translate(trans.x, trans.y, trans.z); }
|
|
|
|
|
2020-09-14 17:48:49 +00:00
|
|
|
void SetScale(float s);
|
2019-07-27 09:53:51 +00:00
|
|
|
void Scale(float scale)
|
|
|
|
{
|
2019-10-16 23:22:39 +00:00
|
|
|
float *pFloatMatrix = (float*)&m_matrix;
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
for (int j = 0; j < 3; j++)
|
|
|
|
pFloatMatrix[i * 4 + j] *= scale;
|
2019-07-27 09:53:51 +00:00
|
|
|
}
|
2020-05-31 15:05:49 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2019-07-27 09:53:51 +00:00
|
|
|
|
2019-07-08 19:37:47 +00:00
|
|
|
|
2020-09-14 17:48:49 +00:00
|
|
|
void SetRotateXOnly(float angle);
|
|
|
|
void SetRotateYOnly(float angle);
|
|
|
|
void SetRotateZOnly(float angle);
|
2019-10-03 19:28:56 +00:00
|
|
|
void SetRotateZOnlyScaled(float angle, float scale) {
|
|
|
|
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;
|
|
|
|
|
|
|
|
m_matrix.up.x = -s * scale;
|
|
|
|
m_matrix.up.y = c * scale;
|
|
|
|
m_matrix.up.z = 0.0f;
|
|
|
|
|
|
|
|
m_matrix.at.x = 0.0f;
|
|
|
|
m_matrix.at.y = 0.0f;
|
|
|
|
m_matrix.at.z = scale;
|
|
|
|
}
|
2020-09-14 17:48:49 +00:00
|
|
|
void SetRotateX(float angle);
|
|
|
|
void SetRotateY(float angle);
|
|
|
|
void SetRotateZ(float angle);
|
2019-07-27 09:53:51 +00:00
|
|
|
void SetRotate(float xAngle, float yAngle, float zAngle);
|
|
|
|
void Rotate(float x, float y, float z);
|
2019-08-22 22:44:38 +00:00
|
|
|
void RotateX(float x);
|
2020-05-31 15:05:49 +00:00
|
|
|
void RotateY(float y);
|
2019-09-29 16:44:51 +00:00
|
|
|
void RotateZ(float z);
|
2019-06-24 14:57:54 +00:00
|
|
|
|
2019-07-27 09:53:51 +00:00
|
|
|
void Reorthogonalise(void);
|
2020-09-14 17:48:49 +00:00
|
|
|
void CopyOnlyMatrix(CMatrix *other);
|
|
|
|
void SetUnity(void);
|
|
|
|
void ResetOrientation(void);
|
2020-07-29 09:17:53 +00:00
|
|
|
void CopyRwMatrix(RwMatrix *matrix){
|
|
|
|
m_matrix = *matrix;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CopyToRwMatrix(RwMatrix *matrix){
|
|
|
|
*matrix = m_matrix;
|
|
|
|
RwMatrixUpdate(matrix);
|
|
|
|
}
|
|
|
|
|
2020-05-30 17:08:31 +00:00
|
|
|
void SetTranslateOnly(float x, float y, float z) {
|
|
|
|
m_matrix.pos.x = x;
|
|
|
|
m_matrix.pos.y = y;
|
|
|
|
m_matrix.pos.z = z;
|
|
|
|
}
|
|
|
|
void SetTranslateOnly(const CVector& pos) {
|
|
|
|
SetTranslateOnly(pos.x, pos.y, pos.z);
|
|
|
|
}
|
2020-09-14 17:48:49 +00:00
|
|
|
void CheckIntegrity(){}
|
2019-05-15 14:52:37 +00:00
|
|
|
};
|
|
|
|
|
2019-07-27 09:53:51 +00:00
|
|
|
|
|
|
|
CMatrix &Invert(const CMatrix &src, CMatrix &dst);
|
2020-09-14 17:48:49 +00:00
|
|
|
CMatrix Invert(const CMatrix &matrix);
|
2019-07-27 09:53:51 +00:00
|
|
|
CMatrix operator*(const CMatrix &m1, const CMatrix &m2);
|
2019-10-26 22:46:48 +00:00
|
|
|
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);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2019-05-15 14:52:37 +00:00
|
|
|
|
2019-07-07 16:36:55 +00:00
|
|
|
|
2019-06-22 22:34:11 +00: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 17:48:49 +00:00
|
|
|
void CompressFromFullMatrix(CMatrix &other);
|
|
|
|
void DecompressIntoFullMatrix(CMatrix &other);
|
2019-07-08 15:07:34 +00:00
|
|
|
};
|
2020-05-13 02:31:14 +00:00
|
|
|
|
|
|
|
class CCompressedMatrix : public CCompressedMatrixNotAligned
|
|
|
|
{
|
|
|
|
int _alignment; // no clue what would this align to
|
|
|
|
};
|