From e5dbb78b1586e8ebb53bebc0a819549b0a891e81 Mon Sep 17 00:00:00 2001 From: Orange Date: Tue, 27 Aug 2024 17:35:17 +0300 Subject: [PATCH] patch --- source/projection/Camera.cpp | 20 ++++++++++---------- tests/UnitTestProjection.cpp | 7 +++++-- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/source/projection/Camera.cpp b/source/projection/Camera.cpp index 9fd7851..34217d4 100644 --- a/source/projection/Camera.cpp +++ b/source/projection/Camera.cpp @@ -23,7 +23,7 @@ namespace omath::projection Matrix Camera::GetViewMatrix() const { - return GetOrientationMatrix() * GetTranslationMatrix(); + return GetTranslationMatrix() * GetOrientationMatrix(); } Matrix Camera::GetProjectionMatrix() const @@ -40,10 +40,10 @@ namespace omath::projection const auto m_fNear = m_nearPlaneDistance; return Matrix({ - {2.f / (fRight - fLeft), 0.f, 0.f, 0.f}, - {0.f, 0.f, 2.f / (fTop - fBottom), 0.f}, - {0.f, (m_fFar + m_fNear) / (m_fFar - m_fNear), 0.f, 1.f}, - {0.f, -2.f * m_fNear * m_fFar / (m_fFar - m_fNear), 0.f, 0.f}, + {2.f / (fRight - fLeft), 0.f, 0.f, 0.f}, + {0.f, 2.f / (fTop - fBottom), 0.f, 0.f}, + {0.f, 0.f, (m_fFar + m_fNear) / (m_fFar - m_fNear), 1.f}, + {0.f, 0.f, -2.f * m_fNear * m_fFar / (m_fFar - m_fNear), 0.f}, }); } @@ -52,10 +52,10 @@ namespace omath::projection { return Matrix( { - {1.f, 0.f, 0.f, -m_origin.x}, - {0.f, 1.f, 0.f, -m_origin.y}, - {0.f, 0.f, 1.f, -m_origin.z}, - {0.f, 0.f, 0.f, 1.f}, + {1.f, 0.f, 0.f, 0.f}, + {0.f, 1.f, 0.f, 1.f}, + {0.f, 0.f, 1.f, 0.f}, + {-m_origin.x, -m_origin.y, -m_origin.z, 1.f}, }); } @@ -90,6 +90,6 @@ namespace omath::projection projected *= Matrix::ToScreenMatrix(m_viewPort.x, m_viewPort.y); - return Vector3{projected.At(0, 0), projected.At(0, 1), projected.At(0, 2)}; + return Vector3{projected.At(0, 0), projected.At(0, 2), projected.At(0, 1)}; } } diff --git a/tests/UnitTestProjection.cpp b/tests/UnitTestProjection.cpp index 67f27b3..bb727a3 100644 --- a/tests/UnitTestProjection.cpp +++ b/tests/UnitTestProjection.cpp @@ -1,6 +1,7 @@ // // Created by Vlad on 27.08.2024. // +#include #include #include #include @@ -8,8 +9,10 @@ TEST(UnitTestProjection, IsPointOnScreen) { - const omath::projection::Camera camera({}, {90, 0.f, 0.f} , {1920.f, 1080.f, 0.f}, 120, 10, 100); + const omath::projection::Camera camera({0, 0, 0}, {0, 0.f, 0.f} , {1920.f, 1080.f, 0.f}, 110, 0.1, 500); - const auto proj = camera.WorldToScreen({0, 0, 20}); + const auto proj = camera.WorldToScreen({5, 0, 0}); + if (proj) + std::print("{} {} {}", proj->x, proj->z, proj->y); EXPECT_TRUE(proj.has_value()); } \ No newline at end of file