Unified math functions

This commit is contained in:
Silent 2019-12-11 21:37:18 +01:00
parent f3113ba0ee
commit 9b26855d3d
No known key found for this signature in database
GPG key ID: AE53149BB0C45AF1
16 changed files with 547 additions and 569 deletions

View file

@ -1,83 +0,0 @@
#ifndef __GENERAL
#define __GENERAL
#include <cstdint>
class CRGBA
{
public:
BYTE r, g, b, a;
inline CRGBA() {}
inline CRGBA(const CRGBA& in)
: r(in.r), g(in.g), b(in.b), a(in.a)
{}
inline CRGBA(const CRGBA& in, BYTE alpha)
: r(in.r), g(in.g), b(in.b), a(alpha)
{}
inline CRGBA(BYTE red, BYTE green, BYTE blue, BYTE alpha = 255)
: r(red), g(green), b(blue), a(alpha)
{}
};
class CRect
{
public:
float x1, y1;
float x2, y2;
inline CRect() {}
inline CRect(float a, float b, float c, float d)
: x1(a), y1(b), x2(c), y2(d)
{}
};
class CVector
{
public:
float x, y, z;
CVector()
{}
constexpr CVector(float fX, float fY, float fZ=0.0f)
: x(fX), y(fY), z(fZ)
{}
CVector& operator+=(const CVector& vec)
{ x += vec.x; y += vec.y; z += vec.z;
return *this; }
CVector& operator-=(const CVector& vec)
{ x -= vec.x; y -= vec.y; z -= vec.z;
return *this; }
inline float Magnitude() const
{ return sqrt(x * x + y * y + z * z); }
inline constexpr float MagnitudeSqr() const
{ return x * x + y * y + z * z; }
inline CVector& Normalize()
{ float fInvLen = 1.0f / Magnitude(); x *= fInvLen; y *= fInvLen; z *= fInvLen; return *this; }
friend inline float DotProduct(const CVector& vec1, const CVector& vec2)
{ return vec1.x * vec2.x + vec1.x * vec2.y + vec1.z * vec2.z; }
friend inline CVector CrossProduct(const CVector& vec1, const CVector& vec2)
{ return CVector( vec1.y * vec2.z - vec1.z * vec2.y,
vec1.z * vec2.x - vec1.x * vec2.z,
vec1.x * vec2.y - vec1.y * vec2.x); }
friend inline CVector operator*(const CVector& in, float fMul)
{ return CVector(in.x * fMul, in.y * fMul, in.z * fMul); }
friend inline CVector operator+(const CVector& vec1, const CVector& vec2)
{ return CVector(vec1.x + vec2.x, vec1.y + vec2.y, vec1.z + vec2.z); }
friend inline CVector operator-(const CVector& vec1, const CVector& vec2)
{ return CVector(vec1.x - vec2.x, vec1.y - vec2.y, vec1.z - vec2.z); }
friend inline CVector operator-(const CVector& vec)
{ return CVector(-vec.x, -vec.y, -vec.z); }
};
#endif

518
SilentPatch/Maths.h Normal file
View file

@ -0,0 +1,518 @@
#ifndef __MATHS__H
#define __MATHS__H
#include <rwcore.h>
constexpr double RAD_TO_DEG (180.0/3.1415926535897932385);
constexpr double DEG_TO_RAD (3.1415926535897932385/180.0);
class CRGBA
{
public:
uint8_t r, g, b, a;
inline CRGBA() {}
inline constexpr CRGBA(const CRGBA& in)
: r(in.r), g(in.g), b(in.b), a(in.a)
{}
inline constexpr CRGBA(const CRGBA& in, uint8_t alpha)
: r(in.r), g(in.g), b(in.b), a(alpha)
{}
inline constexpr CRGBA(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255)
: r(red), g(green), b(blue), a(alpha)
{}
friend constexpr CRGBA Blend(const CRGBA& From, const CRGBA& To, double BlendVal)
{ const double InvBlendVal = 1.0 - BlendVal;
return CRGBA( uint8_t(To.r * BlendVal + From.r * InvBlendVal),
uint8_t(To.g * BlendVal + From.g * InvBlendVal),
uint8_t(To.b * BlendVal + From.b * InvBlendVal),
uint8_t(To.a * BlendVal + From.a * InvBlendVal)); }
friend constexpr CRGBA BlendSqr(const CRGBA& From, const CRGBA& To, double BlendVal)
{ const double InvBlendVal = 1.0 - BlendVal;
return CRGBA( uint8_t(sqrt((To.r * To.r) * BlendVal + (From.r * From.r) * InvBlendVal)),
uint8_t(sqrt((To.g * To.g) * BlendVal + (From.g * From.g) * InvBlendVal)),
uint8_t(sqrt((To.b * To.b) * BlendVal + (From.b * From.b) * InvBlendVal)),
uint8_t(sqrt((To.a * To.a) * BlendVal + (From.a * From.a) * InvBlendVal))); }
};
class CRect
{
public:
float x1, y1;
float x2, y2;
inline CRect() {}
inline constexpr CRect(float a, float b, float c, float d)
: x1(a), y1(b), x2(c), y2(d)
{}
};
class CVector
{
public:
float x, y, z;
CVector()
{}
constexpr CVector(float fX, float fY, float fZ=0.0f)
: x(fX), y(fY), z(fZ)
{}
constexpr CVector(const RwV3d& rwVec)
: x(rwVec.x), y(rwVec.y), z(rwVec.z)
{}
CVector& operator+=(const CVector& vec)
{ x += vec.x; y += vec.y; z += vec.z;
return *this; }
CVector& operator+=(const RwV3d& vec)
{ x += vec.x; y += vec.y; z += vec.z;
return *this; }
CVector& operator-=(const CVector& vec)
{ x -= vec.x; y -= vec.y; z -= vec.z;
return *this; }
CVector& operator-=(const RwV3d& vec)
{ x -= vec.x; y -= vec.y; z -= vec.z;
return *this; }
inline float Magnitude() const
{ return sqrt(x * x + y * y + z * z); }
inline constexpr float MagnitudeSqr() const
{ return x * x + y * y + z * z; }
inline CVector& Normalize()
{ float fInvLen = 1.0f / Magnitude(); x *= fInvLen; y *= fInvLen; z *= fInvLen; return *this; }
friend inline float DotProduct(const CVector& vec1, const CVector& vec2)
{ return vec1.x * vec2.x + vec1.x * vec2.y + vec1.z * vec2.z; }
friend inline CVector CrossProduct(const CVector& vec1, const CVector& vec2)
{ return CVector( vec1.y * vec2.z - vec1.z * vec2.y,
vec1.z * vec2.x - vec1.x * vec2.z,
vec1.x * vec2.y - vec1.y * vec2.x); }
friend inline CVector operator*(const CVector& in, float fMul)
{ return CVector(in.x * fMul, in.y * fMul, in.z * fMul); }
friend inline CVector operator+(const CVector& vec1, const CVector& vec2)
{ return CVector(vec1.x + vec2.x, vec1.y + vec2.y, vec1.z + vec2.z); }
friend inline CVector operator+(const CVector& vec1, const RwV3d& vec2)
{ return CVector(vec1.x + vec2.x, vec1.y + vec2.y, vec1.z + vec2.z); }
friend inline CVector operator-(const CVector& vec1, const CVector& vec2)
{ return CVector(vec1.x - vec2.x, vec1.y - vec2.y, vec1.z - vec2.z); }
friend inline CVector operator-(const CVector& vec1, const RwV3d& vec2)
{ return CVector(vec1.x - vec2.x, vec1.y - vec2.y, vec1.z - vec2.z); }
friend inline CVector operator-(const CVector& vec)
{ return CVector(-vec.x, -vec.y, -vec.z); }
inline CVector& FromMultiply(const class CMatrix& mat, const CVector& vec);
inline CVector& FromMultiply3X3(const class CMatrix& mat, const CVector& vec);
};
class CVector2D
{
public:
float x, y;
CVector2D()
{}
constexpr CVector2D(float fX, float fY)
: x(fX), y(fY)
{}
CVector2D& operator+=(const CVector2D& vec)
{ x += vec.x; y += vec.y;
return *this; }
CVector2D& operator-=(const CVector2D& vec)
{ x -= vec.x; y -= vec.y;
return *this; }
inline float Magnitude() const
{ return sqrt(x * x + y * y); }
inline constexpr float MagnitudeSqr() const
{ return x * x + y * y; }
inline CVector2D& Normalize()
{ float fInvLen = 1.0f / Magnitude(); x *= fInvLen; y *= fInvLen; return *this; }
friend inline float DotProduct(const CVector2D& vec1, const CVector2D& vec2)
{ return vec1.x * vec2.x + vec1.x * vec2.y; }
friend inline CVector2D operator*(const CVector2D& in, float fMul)
{ return CVector2D(in.x * fMul, in.y * fMul); }
friend inline CVector2D operator+(const CVector2D& vec1, const CVector2D& vec2)
{ return CVector2D(vec1.x + vec2.x, vec1.y + vec2.y); }
friend inline CVector2D operator-(const CVector2D& vec1, const CVector2D& vec2)
{ return CVector2D(vec1.x - vec2.x, vec1.y - vec2.y); }
friend inline CVector2D operator-(const CVector2D& vec)
{ return CVector2D(-vec.x, -vec.y); }
};
class CSphere
{
public:
RwSphere sphere;
public:
void Set(float fRadius, const CVector& vecCenter)
{
sphere.center.x = vecCenter.x;
sphere.center.y = vecCenter.y;
sphere.center.z = vecCenter.z;
sphere.radius = fRadius;
}
};
class CMatrix
{
private:
RwMatrix m_matrix;
RwMatrix* m_pMatrix = nullptr;
RwBool m_haveRwMatrix = FALSE;
public:
inline CMatrix() = default;
inline CMatrix(RwMatrix* pMatrix, bool bHasMatrix=false)
{ Attach(pMatrix, bHasMatrix); }
inline CMatrix(const CMatrix& theMatrix)
: m_matrix(theMatrix.m_matrix)
{}
inline CMatrix(const CVector& vecRight, const CVector& vecUp, const CVector& vecAt, const CVector& vecPos)
{
GetRight() = vecRight;
GetUp() = vecUp;
GetAt() = vecAt;
GetPos() = vecPos;
}
inline ~CMatrix()
{ if ( m_haveRwMatrix && m_pMatrix )
RwMatrixDestroy(m_pMatrix); }
inline CMatrix& operator*=(const CMatrix& right)
{
CVector vright(this->m_matrix.right.x * right.m_matrix.right.x + this->m_matrix.right.y * right.m_matrix.up.x + this->m_matrix.right.z * right.m_matrix.at.x + right.m_matrix.pos.x,
this->m_matrix.right.x * right.m_matrix.right.y + this->m_matrix.right.y * right.m_matrix.up.y + this->m_matrix.right.z * right.m_matrix.at.y + right.m_matrix.pos.y,
this->m_matrix.right.x * right.m_matrix.right.z + this->m_matrix.right.y * right.m_matrix.up.z + this->m_matrix.right.z * right.m_matrix.at.z + right.m_matrix.pos.z);
CVector vup(this->m_matrix.up.x * right.m_matrix.right.x + this->m_matrix.up.y * right.m_matrix.up.x + this->m_matrix.up.z * right.m_matrix.at.x + right.m_matrix.pos.x,
this->m_matrix.up.x * right.m_matrix.right.y + this->m_matrix.up.y * right.m_matrix.up.y + this->m_matrix.up.z * right.m_matrix.at.y + right.m_matrix.pos.y,
this->m_matrix.up.x * right.m_matrix.right.z + this->m_matrix.up.y * right.m_matrix.up.z + this->m_matrix.up.z * right.m_matrix.at.z + right.m_matrix.pos.z);
CVector vat(this->m_matrix.at.x * right.m_matrix.right.x + this->m_matrix.at.y * right.m_matrix.up.x + this->m_matrix.at.z * right.m_matrix.at.x + right.m_matrix.pos.x,
this->m_matrix.at.x * right.m_matrix.right.y + this->m_matrix.at.y * right.m_matrix.up.y + this->m_matrix.at.z * right.m_matrix.at.y + right.m_matrix.pos.y,
this->m_matrix.at.x * right.m_matrix.right.z + this->m_matrix.at.y * right.m_matrix.up.z + this->m_matrix.at.z * right.m_matrix.at.z + right.m_matrix.pos.z);
CVector vpos(this->m_matrix.pos.x * right.m_matrix.right.x + this->m_matrix.pos.y * right.m_matrix.up.x + this->m_matrix.pos.z * right.m_matrix.at.x + right.m_matrix.pos.x,
this->m_matrix.pos.x * right.m_matrix.right.y + this->m_matrix.pos.y * right.m_matrix.up.y + this->m_matrix.pos.z * right.m_matrix.at.y + right.m_matrix.pos.y,
this->m_matrix.pos.x * right.m_matrix.right.z + this->m_matrix.pos.y * right.m_matrix.up.z + this->m_matrix.pos.z * right.m_matrix.at.z + right.m_matrix.pos.z);
GetRight() = vright;
GetUp() = vup;
GetAt() = vat;
GetPos() = vpos;
return *this;
}
friend inline CMatrix operator*(const CMatrix& Rot1, const CMatrix& Rot2)
{ return CMatrix( CVector(Rot1.m_matrix.right.x * Rot2.m_matrix.right.x + Rot1.m_matrix.right.y * Rot2.m_matrix.up.x + Rot1.m_matrix.right.z * Rot2.m_matrix.at.x + Rot2.m_matrix.pos.x,
Rot1.m_matrix.right.x * Rot2.m_matrix.right.y + Rot1.m_matrix.right.y * Rot2.m_matrix.up.y + Rot1.m_matrix.right.z * Rot2.m_matrix.at.y + Rot2.m_matrix.pos.y,
Rot1.m_matrix.right.x * Rot2.m_matrix.right.z + Rot1.m_matrix.right.y * Rot2.m_matrix.up.z + Rot1.m_matrix.right.z * Rot2.m_matrix.at.z + Rot2.m_matrix.pos.z),
CVector(Rot1.m_matrix.up.x * Rot2.m_matrix.right.x + Rot1.m_matrix.up.y * Rot2.m_matrix.up.x + Rot1.m_matrix.up.z * Rot2.m_matrix.at.x + Rot2.m_matrix.pos.x,
Rot1.m_matrix.up.x * Rot2.m_matrix.right.y + Rot1.m_matrix.up.y * Rot2.m_matrix.up.y + Rot1.m_matrix.up.z * Rot2.m_matrix.at.y + Rot2.m_matrix.pos.y,
Rot1.m_matrix.up.x * Rot2.m_matrix.right.z + Rot1.m_matrix.up.y * Rot2.m_matrix.up.z + Rot1.m_matrix.up.z * Rot2.m_matrix.at.z + Rot2.m_matrix.pos.z),
CVector(Rot1.m_matrix.at.x * Rot2.m_matrix.right.x + Rot1.m_matrix.at.y * Rot2.m_matrix.up.x + Rot1.m_matrix.at.z * Rot2.m_matrix.at.x + Rot2.m_matrix.pos.x,
Rot1.m_matrix.at.x * Rot2.m_matrix.right.y + Rot1.m_matrix.at.y * Rot2.m_matrix.up.y + Rot1.m_matrix.at.z * Rot2.m_matrix.at.y + Rot2.m_matrix.pos.y,
Rot1.m_matrix.at.x * Rot2.m_matrix.right.z + Rot1.m_matrix.at.y * Rot2.m_matrix.up.z + Rot1.m_matrix.at.z * Rot2.m_matrix.at.z + Rot2.m_matrix.pos.z),
CVector(Rot1.m_matrix.pos.x * Rot2.m_matrix.right.x + Rot1.m_matrix.pos.y * Rot2.m_matrix.up.x + Rot1.m_matrix.pos.z * Rot2.m_matrix.at.x + Rot2.m_matrix.pos.x,
Rot1.m_matrix.pos.x * Rot2.m_matrix.right.y + Rot1.m_matrix.pos.y * Rot2.m_matrix.up.y + Rot1.m_matrix.pos.z * Rot2.m_matrix.at.y + Rot2.m_matrix.pos.y,
Rot1.m_matrix.pos.x * Rot2.m_matrix.right.z + Rot1.m_matrix.pos.y * Rot2.m_matrix.up.z + Rot1.m_matrix.pos.z * Rot2.m_matrix.at.z + Rot2.m_matrix.pos.z)); };
friend inline CVector operator*(const CMatrix& m_matrix, const CVector& vec)
{ return CVector(m_matrix.m_matrix.up.x * vec.y + m_matrix.m_matrix.right.x * vec.x + m_matrix.m_matrix.at.x * vec.z + m_matrix.m_matrix.pos.x,
m_matrix.m_matrix.up.y * vec.y + m_matrix.m_matrix.right.y * vec.x + m_matrix.m_matrix.at.y * vec.z + m_matrix.m_matrix.pos.y,
m_matrix.m_matrix.up.z * vec.y + m_matrix.m_matrix.right.z * vec.x + m_matrix.m_matrix.at.z * vec.z + m_matrix.m_matrix.pos.z); };
friend inline CMatrix operator+(const CMatrix& Rot1, const CMatrix& Rot2)
{ return CMatrix( Rot1.GetRight() + Rot2.GetRight(), Rot1.GetUp() + Rot2.GetUp(), Rot1.GetAt() + Rot2.GetAt(), Rot1.GetPos() + Rot2.GetPos() ); }
inline CMatrix& operator=(const CMatrix& mat)
{
m_matrix = mat.m_matrix;
if ( m_pMatrix != nullptr )
UpdateRwMatrix(m_pMatrix);
return *this;
}
inline CMatrix& operator+=(const CMatrix& mat)
{
GetRight() += mat.GetRight();
GetUp() += mat.GetUp();
GetAt() += mat.GetAt();
GetPos() += mat.GetPos();
return *this;
}
friend inline CMatrix& Invert(const CMatrix& src, CMatrix& dst)
{
dst.GetRight() = CVector(src.m_matrix.right.x, src.m_matrix.up.x, src.m_matrix.at.x);
dst.GetUp() = CVector(src.m_matrix.right.y, src.m_matrix.up.y, src.m_matrix.at.y);
dst.GetAt() = CVector(src.m_matrix.right.z, src.m_matrix.up.z, src.m_matrix.at.z);
dst.GetPos() = -(dst.GetRight() * src.GetPos().x + dst.GetUp() * src.GetPos().y + dst.GetAt() * src.GetPos().z);
return dst;
}
friend inline CMatrix Invert(const CMatrix& src)
{
CMatrix NewMatrix;
Invert(src, NewMatrix);
return NewMatrix;
}
friend inline CVector Multiply3x3(const CMatrix& m_matrix, const CVector& vec)
{ return CVector(m_matrix.m_matrix.up.x * vec.y + m_matrix.m_matrix.right.x * vec.x + m_matrix.m_matrix.at.x * vec.z,
m_matrix.m_matrix.up.y * vec.y + m_matrix.m_matrix.right.y * vec.x + m_matrix.m_matrix.at.y * vec.z,
m_matrix.m_matrix.up.z * vec.y + m_matrix.m_matrix.right.z * vec.x + m_matrix.m_matrix.at.z * vec.z); };
friend inline CVector Multiply3x3(const CVector& vec, const CMatrix& m_matrix)
{ return CVector(DotProduct(m_matrix.GetRight(), vec), DotProduct(m_matrix.GetUp(), vec), DotProduct(m_matrix.GetAt(), vec)); }
inline CVector& GetRight()
{ return *reinterpret_cast<CVector*>(&m_matrix.right); }
inline CVector& GetUp()
{ return *reinterpret_cast<CVector*>(&m_matrix.up); }
inline CVector& GetAt()
{ return *reinterpret_cast<CVector*>(&m_matrix.at); }
inline CVector& GetPos()
{ return *reinterpret_cast<CVector*>(&m_matrix.pos); }
inline const CVector& GetRight() const
{ return *reinterpret_cast<const CVector*>(&m_matrix.right); }
inline const CVector& GetUp() const
{ return *reinterpret_cast<const CVector*>(&m_matrix.up); }
inline const CVector& GetAt() const
{ return *reinterpret_cast<const CVector*>(&m_matrix.at); }
inline const CVector& GetPos() const
{ return *reinterpret_cast<const CVector*>(&m_matrix.pos); }
inline void SetTranslateOnly(float fX, float fY, float fZ)
{ m_matrix.pos.x = fX; m_matrix.pos.y = fY; m_matrix.pos.z = fZ; }
inline void SetRotateX(float fAngle)
{ SetRotateXOnly(fAngle); m_matrix.pos.x = 0.0f; m_matrix.pos.y = 0.0f; m_matrix.pos.z = 0.0f; }
inline void SetRotateY(float fAngle)
{ SetRotateYOnly(fAngle); m_matrix.pos.x = 0.0f; m_matrix.pos.y = 0.0f; m_matrix.pos.z = 0.0f; }
inline void SetRotateZ(float fAngle)
{ SetRotateZOnly(fAngle); m_matrix.pos.x = 0.0f; m_matrix.pos.y = 0.0f; m_matrix.pos.z = 0.0f; }
inline void SetRotate(float fAngleX, float fAngleY, float fAngleZ)
{ SetRotateOnly(fAngleX, fAngleY, fAngleZ); m_matrix.pos.x = 0.0f; m_matrix.pos.y = 0.0f; m_matrix.pos.z = 0.0f; }
inline void SetTranslate(float fX, float fY, float fZ)
{ m_matrix.right.x = 1.0f; m_matrix.right.y = 0.0f; m_matrix.right.z = 0.0f;
m_matrix.up.x = 0.0f; m_matrix.up.y = 1.0f; m_matrix.up.z = 0.0f;
m_matrix.at.x = 0.0f; m_matrix.at.y = 0.0f; m_matrix.at.z = 1.0f;
SetTranslateOnly(fX, fY, fZ); }
inline void ResetOrientation()
{
m_matrix.right.x = 1.0f; m_matrix.right.y = 0.0f; m_matrix.right.z = 0.0f;
m_matrix.up.x = 0.0f; m_matrix.up.y = 1.0f; m_matrix.up.z = 0.0f;
m_matrix.at.x = 0.0f; m_matrix.at.y = 0.0f; m_matrix.at.z = 1.0f;
}
inline void SetUnity()
{
ResetOrientation();
m_matrix.pos.x = 0.0f; m_matrix.pos.y = 0.0f; m_matrix.pos.z = 0.0f;
}
inline void SetScale(float fScale)
{
m_matrix.right.x = fScale; m_matrix.right.y = 0.0f; m_matrix.right.z = 0.0f;
m_matrix.up.x = 0.0f; m_matrix.up.y = fScale; m_matrix.up.z = 0.0f;
m_matrix.at.x = 0.0f; m_matrix.at.y = 0.0f; m_matrix.at.z = fScale;
m_matrix.pos.x = 0.0f; m_matrix.pos.y = 0.0f; m_matrix.pos.z = 0.0f;
}
inline void RotateX(float fAngle)
{
CMatrix RotationMatrix;
RotationMatrix.SetRotateX(fAngle);
*this *= RotationMatrix;
}
inline void RotateY(float fAngle)
{
CMatrix RotationMatrix;
RotationMatrix.SetRotateY(fAngle);
*this *= RotationMatrix;
}
inline void RotateZ(float fAngle)
{
CMatrix RotationMatrix;
RotationMatrix.SetRotateZ(fAngle);
*this *= RotationMatrix;
}
inline void Rotate(float fAngleX, float fAngleY, float fAngleZ)
{
CMatrix RotationMatrix;
RotationMatrix.SetRotate(fAngleX, fAngleY, fAngleZ);
*this *= RotationMatrix;
}
inline void SetRotateXOnly(float fAngle)
{
m_matrix.right.x = 1.0f;
m_matrix.right.y = 0.0f;
m_matrix.right.z = 0.0f;
m_matrix.up.x = 0.0f;
m_matrix.up.y = cos(fAngle);
m_matrix.up.z = sin(fAngle);
m_matrix.at.x = 0.0f;
m_matrix.at.y = -sin(fAngle);
m_matrix.at.z = cos(fAngle);
}
inline void SetRotateYOnly(float fAngle)
{
m_matrix.right.x = cos(fAngle);
m_matrix.right.y = 0.0f;
m_matrix.right.z = sin(fAngle);
m_matrix.up.x = 0.0f;
m_matrix.up.y = 1.0f;
m_matrix.up.z = 0.0f;
m_matrix.at.x = -sin(fAngle);
m_matrix.at.y = 0.0f;
m_matrix.at.z = cos(fAngle);
}
inline void SetRotateZOnly(float fAngle)
{
m_matrix.at.x = 0.0f;
m_matrix.at.y = 0.0f;
m_matrix.at.z = 1.0f;
m_matrix.up.x = -sin(fAngle);
m_matrix.up.y = cos(fAngle);
m_matrix.up.z = 0.0f;
m_matrix.right.x = cos(fAngle);
m_matrix.right.y = sin(fAngle);
m_matrix.right.z = 0.0f;
}
inline void SetRotateOnly(float fAngleX, float fAngleY, float fAngleZ)
{
m_matrix.right.x = cos(fAngleZ) * cos(fAngleY) - sin(fAngleZ) * sin(fAngleX) * sin(fAngleY);
m_matrix.right.y = cos(fAngleZ) * sin(fAngleX) * sin(fAngleY) + sin(fAngleZ) * cos(fAngleY);
m_matrix.right.z = -cos(fAngleX) * sin(fAngleY);
m_matrix.up.x = -sin(fAngleZ) * cos(fAngleX);
m_matrix.up.y = cos(fAngleZ) * cos(fAngleX);
m_matrix.up.z = sin(fAngleX);
m_matrix.at.x = sin(fAngleZ) * sin(fAngleX) * cos(fAngleY) + cos(fAngleZ) * sin(fAngleY);
m_matrix.at.y = sin(fAngleZ) * sin(fAngleY) - cos(fAngleZ) * sin(fAngleX) * cos(fAngleY);
m_matrix.at.z = cos(fAngleX) * cos(fAngleY);
}
inline void Attach(RwMatrix* pMatrix, bool bHasMatrix)
{
if ( m_pMatrix && m_haveRwMatrix )
RwMatrixDestroy(m_pMatrix);
m_pMatrix = pMatrix;
m_haveRwMatrix = bHasMatrix;
Update();
}
inline void AttachRw(RwMatrix* pMatrix, bool bHasMatrix)
{
if ( m_pMatrix && m_haveRwMatrix )
RwMatrixDestroy(m_pMatrix);
m_pMatrix = pMatrix;
m_haveRwMatrix = bHasMatrix;
UpdateRW();
}
inline void Detach()
{
if ( m_pMatrix )
{
if ( m_haveRwMatrix )
RwMatrixDestroy(m_pMatrix);
m_pMatrix = nullptr;
}
}
inline void UpdateRW() const
{
if ( m_pMatrix )
UpdateRwMatrix(m_pMatrix);
}
inline void Update()
{
UpdateMatrix(m_pMatrix);
}
inline void UpdateMatrix(RwMatrix* pMatrix)
{
m_matrix.right = pMatrix->right;
m_matrix.up = pMatrix->up;
m_matrix.at = pMatrix->at;
m_matrix.pos = pMatrix->pos;
}
inline void UpdateRwMatrix(RwMatrix* pMatrix) const
{
pMatrix->right = m_matrix.right;
pMatrix->up = m_matrix.up;
pMatrix->at = m_matrix.at;
pMatrix->pos = m_matrix.pos;
RwMatrixUpdate(pMatrix);
}
inline void CopyToRwMatrix(RwMatrix* pMatrix) const
{
pMatrix->right = m_pMatrix->right;
pMatrix->up = m_pMatrix->up;
pMatrix->at = m_pMatrix->at;
pMatrix->pos = m_pMatrix->pos;
RwMatrixUpdate(pMatrix);
}
inline void CopyOnlyMatrix(const CMatrix& from)
{
m_matrix = from.m_matrix;
}
};
// These need to land here
inline CVector& CVector::FromMultiply(const CMatrix& mat, const CVector& vec)
{
return *this = mat * vec;
}
inline CVector& CVector::FromMultiply3X3(const CMatrix& mat, const CVector& vec)
{
return *this = Multiply3x3(mat, vec);
}
#endif

View file

@ -54,4 +54,7 @@ RwBool RwIm2DRenderLine(RwIm2DVertex *vertices, RwInt32 numVertices, RwInt32 ver
RwReal RwIm2DGetNearScreenZ()
{
return GTARWSRCGLOBAL(dOpenDevice).zBufferNear;
}
}
// Unreachable stub
RwBool RwMatrixDestroy(RwMatrix* mpMat) { assert(!"Unreachable!"); return TRUE; }

View file

@ -1,6 +1,6 @@
#pragma once
#include "General.h"
#include "Maths.h"
#if _GTA_III
#include "../SilentPatchIII/VehicleIII.h"

View file

@ -1,6 +1,6 @@
#include "StdAfx.h"
#include "General.h"
#include "Maths.h"
#include "Timer.h"
#include "Utils/Patterns.h"
#include "Common.h"
@ -41,14 +41,6 @@ struct RsGlobalType
void* pad;
};
struct RwV2d
{
float x; /**< X value*/
float y; /**< Y value */
};
DebugMenuAPI gDebugMenuAPI;
static HMODULE hDLLModule;

View file

@ -48,7 +48,7 @@
<ClInclude Include="..\SilentPatch\Common.h" />
<ClInclude Include="..\SilentPatch\Common_ddraw.h" />
<ClInclude Include="..\SilentPatch\debugmenu_public.h" />
<ClInclude Include="..\SilentPatch\General.h" />
<ClInclude Include="..\SilentPatch\Maths.h" />
<ClInclude Include="..\SilentPatch\RWGTA.h" />
<ClInclude Include="..\SilentPatch\StdAfx.h" />
<ClInclude Include="..\SilentPatch\StoredCar.h" />

View file

@ -50,9 +50,6 @@
<ClInclude Include="..\SilentPatch\Timer.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\SilentPatch\General.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\SilentPatch\StdAfx.h">
<Filter>Header Files</Filter>
</ClInclude>
@ -83,6 +80,9 @@
<ClInclude Include="..\SilentPatch\RWGTA.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\SilentPatch\Maths.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\SilentPatch\SilentPatch.rc">

View file

@ -11,58 +11,6 @@ public:
float m_heading;
};
class CRGBA
{
public:
uint8_t r, g, b, a;
inline CRGBA() {}
inline constexpr CRGBA(const CRGBA& in)
: r(in.r), g(in.g), b(in.b), a(in.a)
{}
inline constexpr CRGBA(const CRGBA& in, uint8_t alpha)
: r(in.r), g(in.g), b(in.b), a(alpha)
{}
inline constexpr CRGBA(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha = 255)
: r(red), g(green), b(blue), a(alpha)
{}
friend constexpr CRGBA Blend(const CRGBA& From, const CRGBA& To, double BlendVal)
{ double InvBlendVal = 1.0 - BlendVal;
return CRGBA( uint8_t(To.r * BlendVal + From.r * InvBlendVal),
uint8_t(To.g * BlendVal + From.g * InvBlendVal),
uint8_t(To.b * BlendVal + From.b * InvBlendVal),
uint8_t(To.a * BlendVal + From.a * InvBlendVal)); }
friend constexpr CRGBA BlendSqr(const CRGBA& From, const CRGBA& To, double BlendVal)
{ double InvBlendVal = 1.0 - BlendVal;
return CRGBA( uint8_t(sqrt((To.r * To.r) * BlendVal + (From.r * From.r) * InvBlendVal)),
uint8_t(sqrt((To.g * To.g) * BlendVal + (From.g * From.g) * InvBlendVal)),
uint8_t(sqrt((To.b * To.b) * BlendVal + (From.b * From.b) * InvBlendVal)),
uint8_t(sqrt((To.a * To.a) * BlendVal + (From.a * From.a) * InvBlendVal))); }
// SilentPatch
CRGBA* BlendGangColour(uint8_t r, uint8_t g, uint8_t b, uint8_t a);
CRGBA* BlendGangColour_Dynamic(uint8_t r, uint8_t g, uint8_t b, uint8_t a);
};
class CRect
{
public:
float x1, y1;
float x2, y2;
inline CRect() {}
inline constexpr CRect(float a, float b, float c, float d)
: x1(a), y1(b), x2(c), y2(d)
{}
};
class CPlaceable
{
private:

View file

@ -1,399 +0,0 @@
#ifndef __MATHS__H
#define __MATHS__H
#define RAD_TO_DEG (180.0/M_PI)
#define DEG_TO_RAD (M_PI/180.0)
class CVector
{
public:
float x, y, z;
CVector()
{}
constexpr CVector(float fX, float fY, float fZ=0.0f)
: x(fX), y(fY), z(fZ)
{}
constexpr CVector(const RwV3d& rwVec)
: x(rwVec.x), y(rwVec.y), z(rwVec.z)
{}
CVector& operator+=(const CVector& vec)
{ x += vec.x; y += vec.y; z += vec.z;
return *this; }
CVector& operator+=(const RwV3d& vec)
{ x += vec.x; y += vec.y; z += vec.z;
return *this; }
CVector& operator-=(const CVector& vec)
{ x -= vec.x; y -= vec.y; z -= vec.z;
return *this; }
CVector& operator-=(const RwV3d& vec)
{ x -= vec.x; y -= vec.y; z -= vec.z;
return *this; }
inline float Magnitude() const
{ return sqrt(x * x + y * y + z * z); }
inline constexpr float MagnitudeSqr() const
{ return x * x + y * y + z * z; }
inline CVector& Normalize()
{ float fInvLen = 1.0f / Magnitude(); x *= fInvLen; y *= fInvLen; z *= fInvLen; return *this; }
friend inline float DotProduct(const CVector& vec1, const CVector& vec2)
{ return vec1.x * vec2.x + vec1.x * vec2.y + vec1.z * vec2.z; }
friend inline CVector CrossProduct(const CVector& vec1, const CVector& vec2)
{ return CVector( vec1.y * vec2.z - vec1.z * vec2.y,
vec1.z * vec2.x - vec1.x * vec2.z,
vec1.x * vec2.y - vec1.y * vec2.x); }
friend inline CVector operator*(const CVector& in, float fMul)
{ return CVector(in.x * fMul, in.y * fMul, in.z * fMul); }
friend inline CVector operator+(const CVector& vec1, const CVector& vec2)
{ return CVector(vec1.x + vec2.x, vec1.y + vec2.y, vec1.z + vec2.z); }
friend inline CVector operator+(const CVector& vec1, const RwV3d& vec2)
{ return CVector(vec1.x + vec2.x, vec1.y + vec2.y, vec1.z + vec2.z); }
friend inline CVector operator-(const CVector& vec1, const CVector& vec2)
{ return CVector(vec1.x - vec2.x, vec1.y - vec2.y, vec1.z - vec2.z); }
friend inline CVector operator-(const CVector& vec1, const RwV3d& vec2)
{ return CVector(vec1.x - vec2.x, vec1.y - vec2.y, vec1.z - vec2.z); }
friend inline CVector operator-(const CVector& vec)
{ return CVector(-vec.x, -vec.y, -vec.z); }
};
class CVector2D
{
public:
float x, y;
CVector2D()
{}
constexpr CVector2D(float fX, float fY)
: x(fX), y(fY)
{}
CVector2D& operator+=(const CVector2D& vec)
{ x += vec.x; y += vec.y;
return *this; }
CVector2D& operator-=(const CVector2D& vec)
{ x -= vec.x; y -= vec.y;
return *this; }
inline float Magnitude() const
{ return sqrt(x * x + y * y); }
inline constexpr float MagnitudeSqr() const
{ return x * x + y * y; }
inline CVector2D& Normalize()
{ float fInvLen = 1.0f / Magnitude(); x *= fInvLen; y *= fInvLen; return *this; }
friend inline float DotProduct(const CVector2D& vec1, const CVector2D& vec2)
{ return vec1.x * vec2.x + vec1.x * vec2.y; }
friend inline CVector2D operator*(const CVector2D& in, float fMul)
{ return CVector2D(in.x * fMul, in.y * fMul); }
friend inline CVector2D operator+(const CVector2D& vec1, const CVector2D& vec2)
{ return CVector2D(vec1.x + vec2.x, vec1.y + vec2.y); }
friend inline CVector2D operator-(const CVector2D& vec1, const CVector2D& vec2)
{ return CVector2D(vec1.x - vec2.x, vec1.y - vec2.y); }
friend inline CVector2D operator-(const CVector2D& vec)
{ return CVector2D(-vec.x, -vec.y); }
};
class CMatrix
{
private:
RwMatrix matrix;
RwMatrix* pMatrix = nullptr;
BOOL haveRwMatrix = FALSE;
public:
inline CMatrix() = default;
inline CMatrix(RwMatrix* pMatrix, bool bHasMatrix=false)
{ Attach(pMatrix, bHasMatrix); }
inline CMatrix(const CMatrix& theMatrix)
: matrix(theMatrix.matrix)
{}
inline CMatrix(const CVector& vecRight, const CVector& vecUp, const CVector& vecAt, const CVector& vecPos)
{
matrix.right.x = vecRight.x;
matrix.right.y = vecRight.y;
matrix.right.z = vecRight.z;
matrix.up.x = vecUp.x;
matrix.up.y = vecUp.y;
matrix.up.z = vecUp.z;
matrix.at.x = vecAt.x;
matrix.at.y = vecAt.y;
matrix.at.z = vecAt.z;
matrix.pos.x = vecPos.x;
matrix.pos.y = vecPos.y;
matrix.pos.z = vecPos.z;
}
inline ~CMatrix()
{ if ( haveRwMatrix && pMatrix )
RwMatrixDestroy(pMatrix); }
inline CMatrix& operator*=(const CMatrix& right)
{
CVector vright(this->matrix.right.x * right.matrix.right.x + this->matrix.right.y * right.matrix.up.x + this->matrix.right.z * right.matrix.at.x + right.matrix.pos.x,
this->matrix.right.x * right.matrix.right.y + this->matrix.right.y * right.matrix.up.y + this->matrix.right.z * right.matrix.at.y + right.matrix.pos.y,
this->matrix.right.x * right.matrix.right.z + this->matrix.right.y * right.matrix.up.z + this->matrix.right.z * right.matrix.at.z + right.matrix.pos.z);
CVector vup(this->matrix.up.x * right.matrix.right.x + this->matrix.up.y * right.matrix.up.x + this->matrix.up.z * right.matrix.at.x + right.matrix.pos.x,
this->matrix.up.x * right.matrix.right.y + this->matrix.up.y * right.matrix.up.y + this->matrix.up.z * right.matrix.at.y + right.matrix.pos.y,
this->matrix.up.x * right.matrix.right.z + this->matrix.up.y * right.matrix.up.z + this->matrix.up.z * right.matrix.at.z + right.matrix.pos.z);
CVector vat(this->matrix.at.x * right.matrix.right.x + this->matrix.at.y * right.matrix.up.x + this->matrix.at.z * right.matrix.at.x + right.matrix.pos.x,
this->matrix.at.x * right.matrix.right.y + this->matrix.at.y * right.matrix.up.y + this->matrix.at.z * right.matrix.at.y + right.matrix.pos.y,
this->matrix.at.x * right.matrix.right.z + this->matrix.at.y * right.matrix.up.z + this->matrix.at.z * right.matrix.at.z + right.matrix.pos.z);
CVector vpos(this->matrix.pos.x * right.matrix.right.x + this->matrix.pos.y * right.matrix.up.x + this->matrix.pos.z * right.matrix.at.x + right.matrix.pos.x,
this->matrix.pos.x * right.matrix.right.y + this->matrix.pos.y * right.matrix.up.y + this->matrix.pos.z * right.matrix.at.y + right.matrix.pos.y,
this->matrix.pos.x * right.matrix.right.z + this->matrix.pos.y * right.matrix.up.z + this->matrix.pos.z * right.matrix.at.z + right.matrix.pos.z);
GetRight() = vright;
GetUp() = vup;
GetAt() = vat;
GetPos() = vpos;
return *this;
}
friend inline CMatrix operator*(const CMatrix& Rot1, const CMatrix& Rot2)
{ return CMatrix( CVector(Rot1.matrix.right.x * Rot2.matrix.right.x + Rot1.matrix.right.y * Rot2.matrix.up.x + Rot1.matrix.right.z * Rot2.matrix.at.x + Rot2.matrix.pos.x,
Rot1.matrix.right.x * Rot2.matrix.right.y + Rot1.matrix.right.y * Rot2.matrix.up.y + Rot1.matrix.right.z * Rot2.matrix.at.y + Rot2.matrix.pos.y,
Rot1.matrix.right.x * Rot2.matrix.right.z + Rot1.matrix.right.y * Rot2.matrix.up.z + Rot1.matrix.right.z * Rot2.matrix.at.z + Rot2.matrix.pos.z),
CVector(Rot1.matrix.up.x * Rot2.matrix.right.x + Rot1.matrix.up.y * Rot2.matrix.up.x + Rot1.matrix.up.z * Rot2.matrix.at.x + Rot2.matrix.pos.x,
Rot1.matrix.up.x * Rot2.matrix.right.y + Rot1.matrix.up.y * Rot2.matrix.up.y + Rot1.matrix.up.z * Rot2.matrix.at.y + Rot2.matrix.pos.y,
Rot1.matrix.up.x * Rot2.matrix.right.z + Rot1.matrix.up.y * Rot2.matrix.up.z + Rot1.matrix.up.z * Rot2.matrix.at.z + Rot2.matrix.pos.z),
CVector(Rot1.matrix.at.x * Rot2.matrix.right.x + Rot1.matrix.at.y * Rot2.matrix.up.x + Rot1.matrix.at.z * Rot2.matrix.at.x + Rot2.matrix.pos.x,
Rot1.matrix.at.x * Rot2.matrix.right.y + Rot1.matrix.at.y * Rot2.matrix.up.y + Rot1.matrix.at.z * Rot2.matrix.at.y + Rot2.matrix.pos.y,
Rot1.matrix.at.x * Rot2.matrix.right.z + Rot1.matrix.at.y * Rot2.matrix.up.z + Rot1.matrix.at.z * Rot2.matrix.at.z + Rot2.matrix.pos.z),
CVector(Rot1.matrix.pos.x * Rot2.matrix.right.x + Rot1.matrix.pos.y * Rot2.matrix.up.x + Rot1.matrix.pos.z * Rot2.matrix.at.x + Rot2.matrix.pos.x,
Rot1.matrix.pos.x * Rot2.matrix.right.y + Rot1.matrix.pos.y * Rot2.matrix.up.y + Rot1.matrix.pos.z * Rot2.matrix.at.y + Rot2.matrix.pos.y,
Rot1.matrix.pos.x * Rot2.matrix.right.z + Rot1.matrix.pos.y * Rot2.matrix.up.z + Rot1.matrix.pos.z * Rot2.matrix.at.z + Rot2.matrix.pos.z)); };
friend inline CVector operator*(const CMatrix& matrix, const CVector& vec)
{ return CVector(matrix.matrix.up.x * vec.y + matrix.matrix.right.x * vec.x + matrix.matrix.at.x * vec.z + matrix.matrix.pos.x,
matrix.matrix.up.y * vec.y + matrix.matrix.right.y * vec.x + matrix.matrix.at.y * vec.z + matrix.matrix.pos.y,
matrix.matrix.up.z * vec.y + matrix.matrix.right.z * vec.x + matrix.matrix.at.z * vec.z + matrix.matrix.pos.z); };
inline CVector& GetRight()
{ return *reinterpret_cast<CVector*>(&matrix.right); }
inline CVector& GetUp()
{ return *reinterpret_cast<CVector*>(&matrix.up); }
inline CVector& GetAt()
{ return *reinterpret_cast<CVector*>(&matrix.at); }
inline CVector& GetPos()
{ return *reinterpret_cast<CVector*>(&matrix.pos); }
inline const CVector& GetRight() const
{ return *reinterpret_cast<const CVector*>(&matrix.right); }
inline const CVector& GetUp() const
{ return *reinterpret_cast<const CVector*>(&matrix.up); }
inline const CVector& GetAt() const
{ return *reinterpret_cast<const CVector*>(&matrix.at); }
inline const CVector& GetPos() const
{ return *reinterpret_cast<const CVector*>(&matrix.pos); }
inline void SetTranslateOnly(float fX, float fY, float fZ)
{ matrix.pos.x = fX; matrix.pos.y = fY; matrix.pos.z = fZ; }
inline void SetRotateX(float fAngle)
{ SetRotateXOnly(fAngle); matrix.pos.x = 0.0f; matrix.pos.y = 0.0f; matrix.pos.z = 0.0f; }
inline void SetRotateY(float fAngle)
{ SetRotateYOnly(fAngle); matrix.pos.x = 0.0f; matrix.pos.y = 0.0f; matrix.pos.z = 0.0f; }
inline void SetRotateZ(float fAngle)
{ SetRotateZOnly(fAngle); matrix.pos.x = 0.0f; matrix.pos.y = 0.0f; matrix.pos.z = 0.0f; }
inline void SetRotate(float fAngleX, float fAngleY, float fAngleZ)
{ SetRotateOnly(fAngleX, fAngleY, fAngleZ); matrix.pos.x = 0.0f; matrix.pos.y = 0.0f; matrix.pos.z = 0.0f; }
inline void SetTranslate(float fX, float fY, float fZ)
{ matrix.right.x = 1.0f; matrix.right.y = 0.0f; matrix.right.z = 0.0f;
matrix.up.x = 0.0f; matrix.up.y = 1.0f; matrix.up.z = 0.0f;
matrix.at.x = 0.0f; matrix.at.y = 0.0f; matrix.at.z = 1.0f;
SetTranslateOnly(fX, fY, fZ); }
inline void SetUnity()
{
matrix.right.x = 1.0f; matrix.right.y = 0.0f; matrix.right.z = 0.0f;
matrix.up.x = 0.0f; matrix.up.y = 1.0f; matrix.up.z = 0.0f;
matrix.at.x = 0.0f; matrix.at.y = 0.0f; matrix.at.z = 1.0f;
matrix.pos.x = 0.0f; matrix.pos.y = 0.0f; matrix.pos.z = 0.0f;
}
inline void SetScale(float fScale)
{
matrix.right.x = fScale; matrix.right.y = 0.0f; matrix.right.z = 0.0f;
matrix.up.x = 0.0f; matrix.up.y = fScale; matrix.up.z = 0.0f;
matrix.at.x = 0.0f; matrix.at.y = 0.0f; matrix.at.z = fScale;
matrix.pos.x = 0.0f; matrix.pos.y = 0.0f; matrix.pos.z = 0.0f;
}
inline void RotateX(float fAngle)
{
CMatrix RotationMatrix;
RotationMatrix.SetRotateX(fAngle);
*this *= RotationMatrix;
}
inline void RotateY(float fAngle)
{
CMatrix RotationMatrix;
RotationMatrix.SetRotateY(fAngle);
*this *= RotationMatrix;
}
inline void RotateZ(float fAngle)
{
CMatrix RotationMatrix;
RotationMatrix.SetRotateZ(fAngle);
*this *= RotationMatrix;
}
inline void Rotate(float fAngleX, float fAngleY, float fAngleZ)
{
CMatrix RotationMatrix;
RotationMatrix.SetRotate(fAngleX, fAngleY, fAngleZ);
*this *= RotationMatrix;
}
inline void SetRotateXOnly(float fAngle)
{
matrix.right.x = 1.0f;
matrix.right.y = 0.0f;
matrix.right.z = 0.0f;
matrix.up.x = 0.0f;
matrix.up.y = cos(fAngle);
matrix.up.z = sin(fAngle);
matrix.at.x = 0.0f;
matrix.at.y = -sin(fAngle);
matrix.at.z = cos(fAngle);
}
inline void SetRotateYOnly(float fAngle)
{
matrix.right.x = cos(fAngle);
matrix.right.y = 0.0f;
matrix.right.z = sin(fAngle);
matrix.up.x = 0.0f;
matrix.up.y = 1.0f;
matrix.up.z = 0.0f;
matrix.at.x = -sin(fAngle);
matrix.at.y = 0.0f;
matrix.at.z = cos(fAngle);
}
inline void SetRotateZOnly(float fAngle)
{
matrix.at.x = 0.0f;
matrix.at.y = 0.0f;
matrix.at.z = 1.0f;
matrix.up.x = -sin(fAngle);
matrix.up.y = cos(fAngle);
matrix.up.z = 0.0f;
matrix.right.x = cos(fAngle);
matrix.right.y = sin(fAngle);
matrix.right.z = 0.0f;
}
inline void SetRotateOnly(float fAngleX, float fAngleY, float fAngleZ)
{
matrix.right.x = cos(fAngleZ) * cos(fAngleY) - sin(fAngleZ) * sin(fAngleX) * sin(fAngleY);
matrix.right.y = cos(fAngleZ) * sin(fAngleX) * sin(fAngleY) + sin(fAngleZ) * cos(fAngleY);
matrix.right.z = -cos(fAngleX) * sin(fAngleY);
matrix.up.x = -sin(fAngleZ) * cos(fAngleX);
matrix.up.y = cos(fAngleZ) * cos(fAngleX);
matrix.up.z = sin(fAngleX);
matrix.at.x = sin(fAngleZ) * sin(fAngleX) * cos(fAngleY) + cos(fAngleZ) * sin(fAngleY);
matrix.at.y = sin(fAngleZ) * sin(fAngleY) - cos(fAngleZ) * sin(fAngleX) * cos(fAngleY);
matrix.at.z = cos(fAngleX) * cos(fAngleY);
}
inline void Attach(RwMatrix* pMatrix, bool bHasMatrix)
{
if ( this->pMatrix && haveRwMatrix )
RwMatrixDestroy(this->pMatrix);
this->pMatrix = pMatrix;
haveRwMatrix = bHasMatrix;
Update();
}
inline void AttachRw(RwMatrix* pMatrix, bool bHasMatrix)
{
if ( this->pMatrix && haveRwMatrix )
RwMatrixDestroy(this->pMatrix);
this->pMatrix = pMatrix;
haveRwMatrix = bHasMatrix;
UpdateRW();
}
inline void Detach()
{
if ( pMatrix )
{
if ( haveRwMatrix )
RwMatrixDestroy(pMatrix);
pMatrix = nullptr;
}
}
inline void UpdateRW() const
{
if ( pMatrix )
UpdateRwMatrix(pMatrix);
}
inline void Update()
{
UpdateMatrix(pMatrix);
}
inline void UpdateMatrix(RwMatrix* pMatrix)
{
matrix.right = pMatrix->right;
matrix.up = pMatrix->up;
matrix.at = pMatrix->at;
matrix.pos = pMatrix->pos;
}
inline void UpdateRwMatrix(RwMatrix* pMatrix) const
{
pMatrix->right = matrix.right;
pMatrix->up = matrix.up;
pMatrix->at = matrix.at;
pMatrix->pos = matrix.pos;
RwMatrixUpdate(pMatrix);
}
inline void CopyToRwMatrix(RwMatrix* pMatrix) const
{
pMatrix->right = this->pMatrix->right;
pMatrix->up = this->pMatrix->up;
pMatrix->at = this->pMatrix->at;
pMatrix->pos = this->pMatrix->pos;
RwMatrixUpdate(pMatrix);
}
inline void CopyOnlyMatrix(const CMatrix& from)
{
matrix = from.matrix;
}
};
#endif

View file

@ -611,22 +611,22 @@ bool GetCurrentZoneLockedOrUnlocked_Steam(float fPosX, float fPosY)
return true;
}
CRGBA* CRGBA::BlendGangColour(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
CRGBA* __fastcall BlendGangColour(CRGBA* pThis, void*, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
{
const double colourIntensity = std::min( static_cast<double>(pCurrZoneInfo->ZoneColour.a) / 120.0, 1.0 );
*this = CRGBA(BlendSqr( HudColour[3], CRGBA(r, g, b), colourIntensity ), a);
return this;
*pThis = CRGBA(BlendSqr( HudColour[3], CRGBA(r, g, b), colourIntensity ), a);
return pThis;
}
static bool bColouredZoneNames;
CRGBA* CRGBA::BlendGangColour_Dynamic(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
CRGBA* __fastcall BlendGangColour_Dynamic(CRGBA* pThis, void*, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
{
if ( bColouredZoneNames )
{
return BlendGangColour(r, g, b, a);
return BlendGangColour(pThis, nullptr, r, g, b, a);
}
*this = CRGBA(HudColour[3], a);
return this;
*pThis = CRGBA(HudColour[3], a);
return pThis;
}
void SunAndMoonFarClip()
@ -2719,7 +2719,7 @@ BOOL InjectDelayedPatches_10()
Patch<WORD>(0x58ADBE, 0x0E75);
Patch<WORD>(0x58ADC5, 0x0775);
InjectHook(0x58ADE4, &CRGBA::BlendGangColour_Dynamic);
InjectHook(0x58ADE4, &BlendGangColour_Dynamic);
if ( bHasDebugMenu )
{
@ -3154,7 +3154,7 @@ BOOL InjectDelayedPatches_11()
Patch<WORD>(0x58B58E, 0x0E75);
Patch<WORD>(0x58B595, 0x0775);
InjectHook(0x58B5B4, &CRGBA::BlendGangColour);
InjectHook(0x58B5B4, &BlendGangColour);
}
else if ( INIoption == 0 )
{
@ -3325,7 +3325,7 @@ BOOL InjectDelayedPatches_Steam()
Patch<WORD>(0x598F65, 0x0C75);
Patch<WORD>(0x598F6B, 0x0675);
InjectHook(0x598F87, &CRGBA::BlendGangColour);
InjectHook(0x598F87, &BlendGangColour);
}
else if ( INIoption == 0 )
{

View file

@ -224,6 +224,7 @@ copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\newsteam_r2_lowvio
<ClInclude Include="..\SilentPatch\FLAC\metadata.h" />
<ClInclude Include="..\SilentPatch\FLAC\ordinals.h" />
<ClInclude Include="..\SilentPatch\FLAC\stream_decoder.h" />
<ClInclude Include="..\SilentPatch\Maths.h" />
<ClInclude Include="..\SilentPatch\resource1.h" />
<ClInclude Include="..\SilentPatch\TheFLAUtils.h" />
<ClInclude Include="..\SilentPatch\Utils\DelimStringReader.h" />
@ -235,7 +236,6 @@ copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\newsteam_r2_lowvio
<ClInclude Include="FLACDecoderSA.h" />
<ClInclude Include="GeneralSA.h" />
<ClInclude Include="LinkListSA.h" />
<ClInclude Include="Maths.h" />
<ClInclude Include="ModelInfoSA.h" />
<ClInclude Include="PedSA.h" />
<ClInclude Include="PlayerInfoSA.h" />

View file

@ -122,9 +122,6 @@
<ClInclude Include="LinkListSA.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Maths.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="PNGFile.h">
<Filter>Header Files</Filter>
</ClInclude>
@ -173,6 +170,9 @@
<ClInclude Include="..\SilentPatch\Utils\Patterns.h">
<Filter>Header Files\Utils</Filter>
</ClInclude>
<ClInclude Include="..\SilentPatch\Maths.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\SilentPatch\SilentPatch.rc">

View file

@ -1,6 +1,5 @@
#pragma once
#include "General.h"
#include <rwcore.h>
#include <rpworld.h>

View file

@ -1,10 +1,10 @@
#include "StdAfx.h"
#include "Maths.h"
#include "Timer.h"
#include "Utils/Patterns.h"
#include "Common.h"
#include "Common_ddraw.h"
#include "General.h"
#include "ModelInfoVC.h"
#include <memory>

View file

@ -173,7 +173,7 @@
<ItemGroup>
<ClInclude Include="..\SilentPatch\Common_ddraw.h" />
<ClInclude Include="..\SilentPatch\debugmenu_public.h" />
<ClInclude Include="..\SilentPatch\General.h" />
<ClInclude Include="..\SilentPatch\Maths.h" />
<ClInclude Include="..\SilentPatch\RWGTA.h" />
<ClInclude Include="..\SilentPatch\StdAfx.h" />
<ClInclude Include="..\SilentPatch\StoredCar.h" />

View file

@ -24,9 +24,6 @@
<ClInclude Include="..\SilentPatch\Timer.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\SilentPatch\General.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\SilentPatch\StdAfx.h">
<Filter>Header Files</Filter>
</ClInclude>
@ -57,6 +54,9 @@
<ClInclude Include="..\SilentPatch\RWGTA.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\SilentPatch\Maths.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\SilentPatch\Timer.cpp">