From 35fded8ec05e129016927310b1cb7c659c94fc0e Mon Sep 17 00:00:00 2001 From: josh Date: Thu, 1 Feb 2024 17:17:04 -0500 Subject: [PATCH] Implement Mat4x4::WorldX/Y/Z/IsFinite --- include/J3ML/LinearAlgebra/Matrix4x4.h | 10 ++++++--- src/J3ML/LinearAlgebra/Matrix4x4.cpp | 30 ++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/include/J3ML/LinearAlgebra/Matrix4x4.h b/include/J3ML/LinearAlgebra/Matrix4x4.h index b10693e..878c329 100644 --- a/include/J3ML/LinearAlgebra/Matrix4x4.h +++ b/include/J3ML/LinearAlgebra/Matrix4x4.h @@ -20,6 +20,7 @@ namespace LinearAlgebra { */ class Matrix4x4 { public: + // TODO: Implement assertions to ensure matrix bounds are not violated! enum { Rows = 4 }; enum { Cols = 4 }; @@ -80,6 +81,9 @@ namespace LinearAlgebra { Vector4 GetRow(int index) const; Vector4 GetColumn(int index) const; + Vector3 GetRow3(int index) const; + + Vector3 GetColumn3(int index) const; float &At(int row, int col); float At(int x, int y) const; @@ -154,9 +158,9 @@ namespace LinearAlgebra { - 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);} + Vector2 operator * (const Vector2& rhs) const; + Vector3 operator * (const Vector3& rhs) const; + Vector4 operator * (const Vector4& rhs) const; Matrix4x4 operator * (const Matrix3x3 &rhs) const; diff --git a/src/J3ML/LinearAlgebra/Matrix4x4.cpp b/src/J3ML/LinearAlgebra/Matrix4x4.cpp index 016f7bd..12c0356 100644 --- a/src/J3ML/LinearAlgebra/Matrix4x4.cpp +++ b/src/J3ML/LinearAlgebra/Matrix4x4.cpp @@ -374,4 +374,34 @@ namespace LinearAlgebra { Vector3 Matrix4x4::Diagonal3() const { return Vector3 { At(0, 0), At(1,1), At(2,2) }; } + + Vector4 Matrix4x4::WorldX() const { + return GetColumn3(0); + } + + Vector4 Matrix4x4::WorldY() const { + return GetColumn3(1); + } + + Vector4 Matrix4x4::WorldZ() const { + return GetColumn3(2); + } + + bool Matrix4x4::IsFinite() const { + for(int iy = 0; iy < Rows; ++iy) + for(int ix = 0; ix < Cols; ++ix) + if (!std::isfinite(elems[iy][ix])) + return false; + return true; + } + + Vector3 Matrix4x4::GetColumn3(int index) const { + return Vector3{At(0, index), At(1, index), At(2, index)}; + } + + Vector2 Matrix4x4::operator*(const Vector2 &rhs) const { return this->Transform(rhs);} + + Vector3 Matrix4x4::operator*(const Vector3 &rhs) const { return this->Transform(rhs);} + + Vector4 Matrix4x4::operator*(const Vector4 &rhs) const { return this->Transform(rhs);} } \ No newline at end of file