From 29a96d64bb1bbf05d009a1159fcf7b5c5521a7b3 Mon Sep 17 00:00:00 2001 From: Orange Date: Sun, 14 Sep 2025 04:48:56 +0300 Subject: [PATCH] Adds 2D screen to world conversion Adds an overload for screen_to_world that accepts a 2D screen position. Renames screen_to_dnc to screen_to_ndc for clarity. --- include/omath/projection/camera.hpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/include/omath/projection/camera.hpp b/include/omath/projection/camera.hpp index 6d84cb6..5cb6294 100644 --- a/include/omath/projection/camera.hpp +++ b/include/omath/projection/camera.hpp @@ -195,7 +195,14 @@ namespace omath::projection [[nodiscard]] std::expected, Error> screen_to_world(const Vector3& screen_pos) const noexcept { - return view_port_to_screen(screen_to_dnc(screen_pos)); + return view_port_to_screen(screen_to_ndc(screen_pos)); + } + + [[nodiscard]] + std::expected, Error> screen_to_world(const Vector2& screen_pos) const noexcept + { + const auto& [x, y] = screen_pos; + return screen_to_world({x, y, 1.f}); } protected: @@ -234,7 +241,7 @@ namespace omath::projection return {(ndc.x + 1.f) / 2.f * m_view_port.m_width, (1.f - ndc.y) / 2.f * m_view_port.m_height, ndc.z}; } - [[nodiscard]] Vector3 screen_to_dnc(const Vector3& screen_pos) const noexcept + [[nodiscard]] Vector3 screen_to_ndc(const Vector3& screen_pos) const noexcept { return {screen_pos.x / m_view_port.m_width * 2.f - 1.f, 1.f - screen_pos.y / m_view_port.m_height * 2.f, screen_pos.z};