Skip to content

Commit 29a96d6

Browse files
committed
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.
1 parent 256365e commit 29a96d6

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

include/omath/projection/camera.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,14 @@ namespace omath::projection
195195
[[nodiscard]]
196196
std::expected<Vector3<float>, Error> screen_to_world(const Vector3<float>& screen_pos) const noexcept
197197
{
198-
return view_port_to_screen(screen_to_dnc(screen_pos));
198+
return view_port_to_screen(screen_to_ndc(screen_pos));
199+
}
200+
201+
[[nodiscard]]
202+
std::expected<Vector3<float>, Error> screen_to_world(const Vector2<float>& screen_pos) const noexcept
203+
{
204+
const auto& [x, y] = screen_pos;
205+
return screen_to_world({x, y, 1.f});
199206
}
200207

201208
protected:
@@ -234,7 +241,7 @@ namespace omath::projection
234241
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};
235242
}
236243

237-
[[nodiscard]] Vector3<float> screen_to_dnc(const Vector3<float>& screen_pos) const noexcept
244+
[[nodiscard]] Vector3<float> screen_to_ndc(const Vector3<float>& screen_pos) const noexcept
238245
{
239246
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,
240247
screen_pos.z};

0 commit comments

Comments
 (0)