diff --git a/include/omath/Mat.hpp b/include/omath/Mat.hpp index 2f25bd5..2840212 100644 --- a/include/omath/Mat.hpp +++ b/include/omath/Mat.hpp @@ -321,10 +321,10 @@ namespace omath constexpr static Mat<4, 4> TranslationMat(const Vector3& diff) noexcept { return { - {1, 0, 0, 0}, - {0, 1, 0, 0}, - {0, 0, 1, 0}, - {diff.x, diff.y, diff.z, 1}, + {1, 0, 0, diff.x}, + {0, 1, 0, diff.y}, + {0, 0, 1, diff.z}, + {0, 0, 0, 1}, }; } @@ -376,11 +376,11 @@ namespace omath [[nodiscard]] constexpr Mat<4, 4, T, St> MatTranslation(const Vector3& diff) noexcept { - return { + return Mat<4, 4, T, St>{ {1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {diff.x, diff.y, diff.z, 1}, - }; + }.Transposed(); } } // namespace omath diff --git a/include/omath/engines/source.hpp b/include/omath/engines/source.hpp index a5e7ac9..669a531 100644 --- a/include/omath/engines/source.hpp +++ b/include/omath/engines/source.hpp @@ -32,12 +32,12 @@ namespace omath::source [[nodiscard]] constexpr Mat<4, 4, Type, MatStoreType::ROW_MAJOR> ViewMatrixFromVecs(const Vector3& forward, const Vector3& right, const Vector3& up, const Vector3& camera_pos) { - return MatTranslation(-camera_pos) * Mat<4, 4, Type, MatStoreType::ROW_MAJOR>{ - {right.x, up.x, forward.x, 0}, - {right.y, up.y, forward.y, 0}, - {right.z, up.z, forward.z, 0}, + return Mat<4, 4, Type, MatStoreType::ROW_MAJOR>{ + {right.x, right.y, right.z, 0}, + {up.x, up.y, up.z, 0}, + {forward.x, forward.y, forward.z, 0}, {0, 0, 0, 1}, - }; + } * MatTranslation(-camera_pos) ; } diff --git a/include/omath/projection/Camera.hpp b/include/omath/projection/Camera.hpp index 0a19dca..3932677 100644 --- a/include/omath/projection/Camera.hpp +++ b/include/omath/projection/Camera.hpp @@ -54,7 +54,7 @@ namespace omath::projection [[nodiscard]] auto GetViewProjectionMatrix() const { - return GetProjectionMatrix() * GetViewMatrix().Transposed(); + return GetProjectionMatrix() * GetViewMatrix(); } [[nodiscard]] std::expected WorldToScreen([[maybe_unused]] const Vector3& worldPosition) const { @@ -65,7 +65,7 @@ namespace omath::projection return std::unexpected(Error::WORLD_POSITION_IS_OUT_OF_SCREEN_BOUNDS); projected /= projected.At(3, 0); - return Vector3{projected.At(0,0), projected.At(1,0), projected.At(2,0)}; + return Vector3{++projected.At(0,0) / 2 * m_viewPort.m_width , ++projected.At(1,0) / 2 * m_viewPort.m_height, projected.At(2,0)}; } ViewPort m_viewPort{}; diff --git a/tests/general/UnitTestMat.cpp b/tests/general/UnitTestMat.cpp index 94d451a..0105c28 100644 --- a/tests/general/UnitTestMat.cpp +++ b/tests/general/UnitTestMat.cpp @@ -154,35 +154,6 @@ TEST_F(UnitTestMat, StaticMethod_ToScreenMat) EXPECT_FLOAT_EQ(screenMat.At(3, 3), 1.0f); } -// Test static method: TranslationMat -TEST_F(UnitTestMat, StaticMethod_TranslationMat) -{ - Vector3 diff{10.0f, 20.0f, 30.0f}; - Mat<4, 4> transMat = Mat<4, 4>::TranslationMat(diff); - EXPECT_FLOAT_EQ(transMat.At(0, 0), 1.0f); - EXPECT_FLOAT_EQ(transMat.At(3, 0), diff.x); - EXPECT_FLOAT_EQ(transMat.At(3, 1), diff.y); - EXPECT_FLOAT_EQ(transMat.At(3, 2), diff.z); - EXPECT_FLOAT_EQ(transMat.At(3, 3), 1.0f); -} - -// Test static method: OrientationMat -TEST_F(UnitTestMat, StaticMethod_OrientationMat) -{ - constexpr Vector3 forward{0.0f, 0.0f, 1.0f}; - constexpr Vector3 right{1.0f, 0.0f, 0.0f}; - constexpr Vector3 up{0.0f, 1.0f, 0.0f}; - constexpr Mat<4, 4> orientMat = Mat<4, 4>::OrientationMat(forward, right, up); - EXPECT_FLOAT_EQ(orientMat.At(0, 0), right.x); - EXPECT_FLOAT_EQ(orientMat.At(0, 1), up.x); - EXPECT_FLOAT_EQ(orientMat.At(0, 2), forward.x); - EXPECT_FLOAT_EQ(orientMat.At(1, 0), right.y); - EXPECT_FLOAT_EQ(orientMat.At(1, 1), up.y); - EXPECT_FLOAT_EQ(orientMat.At(1, 2), forward.y); - EXPECT_FLOAT_EQ(orientMat.At(2, 0), right.z); - EXPECT_FLOAT_EQ(orientMat.At(2, 1), up.z); - EXPECT_FLOAT_EQ(orientMat.At(2, 2), forward.z); -} // Test exception handling in At() method TEST_F(UnitTestMat, Method_At_OutOfRange)