From 9ec0474b9862bfa9d9c6bc33dcfb714f7fb075fb Mon Sep 17 00:00:00 2001 From: Aevyrie Date: Thu, 18 Jan 2024 16:52:12 -0800 Subject: [PATCH] Account for viewports when converting from screen to view space. --- src/input.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/input.rs b/src/input.rs index 039f925..99ed63e 100644 --- a/src/input.rs +++ b/src/input.rs @@ -135,10 +135,14 @@ impl EditorCamInputEvent { let screen_to_view_space = |camera: &Camera, proj: &Projection, controller: &EditorCam, - viewport_position: Vec2| + target_position: Vec2| -> Option { + let mut viewport_position = if let Some(rect) = camera.logical_viewport_rect() { + target_position.as_dvec2() - rect.min.as_dvec2() + } else { + target_position.as_dvec2() + }; let target_size = camera.logical_viewport_size()?.as_dvec2(); - let mut viewport_position = viewport_position.as_dvec2(); // Flip the Y co-ordinate origin from the top to the bottom. viewport_position.y = target_size.y - viewport_position.y; let ndc = viewport_position * 2. / target_size - DVec2::ONE;