1
0
forked from josh/j3ml

Implement Mat4x4 Translate, Transform, FromTranslation

This commit is contained in:
2024-01-31 18:34:15 -05:00
parent 132b8a0a66
commit 40e69d5c4f
11 changed files with 202 additions and 49 deletions

View File

@@ -76,7 +76,8 @@ namespace LinearAlgebra {
void SetTranslatePart(float translateX, float translateY, float translateZ);
void SetTranslatePart(const Vector3& offset);
void SetRotatePart(const Quaternion& q);
void SetRotatePart(const Matrix3x3& r);
void Set3x3Part(const Matrix3x3& r);
void SetRow(int row, const Vector3& rowVector, float m_r3);
@@ -86,6 +87,7 @@ namespace LinearAlgebra {
Vector4 GetRow(int index) const;
Vector4 GetColumn(int index) const;
float &At(int row, int col);
float At(int x, int y) const;
/// Tests if this matrix does not contain any NaNs or infs.
@@ -109,11 +111,21 @@ namespace LinearAlgebra {
Matrix4x4 Transpose() const;
Vector2 Transform(float tx, float ty) const;
Vector2 Transform(const Vector2& rhs) const;
Vector3 Transform(float tx, float ty, float tz) const;
Vector3 Transform(const Vector3& rhs) const;
Vector4 Transform(float tx, float ty, float tz, float tw) const;
Vector4 Transform(const Vector4& rhs) const;
Matrix4x4 Translate(const Vector3& rhs) const;
static Matrix4x4 FromTranslation(const Vector3& rhs);
static Matrix4x4 D3DOrthoProjLH(float nearPlane, float farPlane, float hViewportSize, float vViewportSize);
static Matrix4x4 D3DOrthoProjRH(float nearPlane, float farPlane, float hViewportSize, float vViewportSize);
static Matrix4x4 D3DPerspProjLH(float nearPlane, float farPlane, float hViewportSize, float vViewportSize);
@@ -139,6 +151,8 @@ namespace LinearAlgebra {
Matrix4x4 operator *(float scalar) const;
Matrix4x4 operator /(float scalar) const;
Vector2 operator * (const Vector2& rhs) const { return this->Transform(rhs);}
Vector3 operator * (const Vector3& rhs) const { return this->Transform(rhs);}
Vector4 operator * (const Vector4& rhs) const { return this->Transform(rhs);}
@@ -149,23 +163,13 @@ namespace LinearAlgebra {
Matrix4x4 operator * (const Matrix4x4& rhs) const;
Matrix4x4 &operator = (const Matrix3x3& rhs)
{
SetRotatePart(rhs);
SetTranslatePart(0,0,0);
SetRow(3, 0, 0, 0, 1);
return *this;
}
Matrix4x4 &operator = (const Quaternion& rhs)
{
*this = rhs.ToMatrix4x4();
return *this;
}
Matrix4x4 &operator = (const Matrix3x3& rhs);
Matrix4x4 &operator = (const Quaternion& rhs);
Matrix4x4 &operator = (const Matrix4x4& rhs) = default;
protected:
float elems[4][4];
void SetMatrixRotatePart(Matrix4x4 &m, const Quaternion &q);
};
}