Skip to content

Commit

Permalink
Account for viewports when converting from screen to view space.
Browse files Browse the repository at this point in the history
  • Loading branch information
aevyrie committed Jan 19, 2024
1 parent f525b27 commit 9ec0474
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,14 @@ impl EditorCamInputEvent {
let screen_to_view_space = |camera: &Camera,
proj: &Projection,
controller: &EditorCam,
viewport_position: Vec2|
target_position: Vec2|
-> Option<DVec3> {
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;
Expand Down

0 comments on commit 9ec0474

Please sign in to comment.