mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 07:03:25 +00:00
patch
This commit is contained in:
@@ -5,7 +5,6 @@
|
||||
#include <utility>
|
||||
#include <stdexcept>
|
||||
#include <utility>
|
||||
#include <cmath>
|
||||
|
||||
|
||||
namespace omath
|
||||
|
||||
@@ -31,21 +31,20 @@ namespace omath::projection
|
||||
const float fRight = std::tan(angles::DegreesToRadians(m_fieldOfView) / 2.f);
|
||||
const float fLeft = -fRight;
|
||||
|
||||
const float vFov = angles::DegreesToRadians(m_fieldOfView) * (m_viewPort.y / m_viewPort.x);
|
||||
const float verticalFov = angles::DegreesToRadians(m_fieldOfView) * (m_viewPort.y / m_viewPort.x);
|
||||
|
||||
const float fTop = std::tan(vFov / 2.f);
|
||||
const float fBottom = -fTop;
|
||||
const float top = std::tan(verticalFov / 2.f);
|
||||
const float botton = -top;
|
||||
|
||||
const auto m_fFar = m_farPlaneDistance;
|
||||
const auto m_fNear = m_nearPlaneDistance;
|
||||
const auto far = m_farPlaneDistance;
|
||||
const auto near = m_nearPlaneDistance;
|
||||
|
||||
return Matrix({
|
||||
{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},
|
||||
{1.555f / (fRight - fLeft), 0.f, 0.f, 0.f},
|
||||
{0.f, 1.15f / (top - botton), 0.f, 0.f},
|
||||
{0.f, 0.f, (far + near) / (far - near), 1.f},
|
||||
{0.f, 0.f, -near * far / (far - near), 0.f},
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
Matrix Camera::GetTranslationMatrix() const
|
||||
@@ -90,6 +89,6 @@ namespace omath::projection
|
||||
|
||||
projected *= Matrix::ToScreenMatrix(m_viewPort.x, m_viewPort.y);
|
||||
|
||||
return Vector3{projected.At(0, 0), projected.At(0, 2), projected.At(0, 1)};
|
||||
return Vector3{projected.At(0, 0), projected.At(0, 1), projected.At(0, 2)};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
|
||||
TEST(UnitTestProjection, IsPointOnScreen)
|
||||
{
|
||||
const omath::projection::Camera camera({0, 0, 0}, {0, 0.f, 0.f} , {1920.f, 1080.f, 0.f}, 110, 0.1, 500);
|
||||
const omath::projection::Camera camera({5, 0, 0}, {0, 0.f, 0.f} , {1920.f, 1080.f, 0.f}, 110, 0.1, 500);
|
||||
|
||||
const auto proj = camera.WorldToScreen({5, 0, 0});
|
||||
const auto proj = camera.WorldToScreen({10, 0, 0});
|
||||
if (proj)
|
||||
std::print("{} {} {}", proj->x, proj->z, proj->y);
|
||||
std::print("{} {} {}", proj->x, proj->y, proj->z);
|
||||
EXPECT_TRUE(proj.has_value());
|
||||
}
|
||||
Reference in New Issue
Block a user