mirror of
https://github.com/GTAmodding/re3.git
synced 2025-07-18 14:44:11 +00:00
Sync matrix with master
This commit is contained in:
parent
8590457d41
commit
3b52b683e3
8 changed files with 345 additions and 282 deletions
|
@ -3,9 +3,36 @@
|
|||
class CMatrix
|
||||
{
|
||||
public:
|
||||
RwMatrix m_matrix;
|
||||
#ifdef GTA_PS2
|
||||
union
|
||||
{
|
||||
float f[4][4];
|
||||
struct
|
||||
{
|
||||
float rx, ry, rz;
|
||||
RwMatrix *m_attachment;
|
||||
float fx, fy, fz;
|
||||
bool m_hasRwMatrix; // are we the owner?
|
||||
float ux, uy, uz, uw;
|
||||
float px, py, pz, pw;
|
||||
};
|
||||
};
|
||||
#else
|
||||
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?
|
||||
#endif
|
||||
|
||||
CMatrix(void);
|
||||
CMatrix(CMatrix const &m);
|
||||
|
@ -25,36 +52,39 @@ public:
|
|||
CMatrix &operator+=(CMatrix const &rhs);
|
||||
CMatrix &operator*=(CMatrix const &rhs);
|
||||
|
||||
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; }
|
||||
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++)
|
||||
for (int j = 0; j < 3; j++)
|
||||
pFloatMatrix[i * 4 + j] *= scale;
|
||||
f[i][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;
|
||||
f[i][0] *= sx;
|
||||
f[i][1] *= sy;
|
||||
f[i][2] *= sz;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -66,17 +96,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);
|
||||
|
@ -88,22 +118,16 @@ public:
|
|||
void RotateZ(float z);
|
||||
|
||||
void Reorthogonalise(void);
|
||||
void CopyOnlyMatrix(CMatrix *other);
|
||||
void CopyOnlyMatrix(const 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 CopyToRwMatrix(RwMatrix* matrix);
|
||||
|
||||
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);
|
||||
|
@ -117,11 +141,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);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue