This commit is contained in:
2024-08-27 17:35:17 +03:00
parent 8fc9a54958
commit e5dbb78b15
2 changed files with 15 additions and 12 deletions

View File

@@ -23,7 +23,7 @@ namespace omath::projection
Matrix Camera::GetViewMatrix() const
{
return GetOrientationMatrix() * GetTranslationMatrix();
return GetTranslationMatrix() * GetOrientationMatrix();
}
Matrix Camera::GetProjectionMatrix() const
@@ -41,9 +41,9 @@ namespace omath::projection
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},
{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)};
}
}

View File

@@ -1,6 +1,7 @@
//
// Created by Vlad on 27.08.2024.
//
#include <complex>
#include <gtest/gtest.h>
#include <omath/Matrix.h>
#include <print>
@@ -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());
}