Skip to content

Commit 7f04906

Browse files
KrzysztofZywieckiKrzysztof Zywiecki
andauthored
Removed conversion from pointer physical coordinates to viewport local coordinates in bevy_picking make_ray function (#18870)
# Objective - Fixes #18856. ## Solution After PR #17633, `Camera::viewport_to_world` method corrects `viewport_position` passed in that input so that it's offset by camera's viewport. `Camera::viewport_to_world` is used by `make_ray` function which in turn also offsets pointer position by viewport position, which causes picking objects to be shifted by viewport position, and it wasn't removed in the aforementioned PR. This second offsetting in `make_ray` was removed. ## Testing - I tested simple_picking example by applying some horizontal offset to camera's viewport. - I tested my application that displayed a single rectangle with picking on two cameras arranged in a row. When using local bevy with this fix, both cameras can be used for picking correctly. - I modified split_screen example: I added observer to ground plane that changes color on hover, and removed UI as it interfered with picking both on master and my branch. On master, only top left camera was triggering the observer, and on my branch all cameras could change plane's color on hover. - I added viewport offset to mesh_picking, with my changes it works correctly, while on master picking ray is shifted. - Sprite picking with viewport offset doesn't work both on master and on this branch. These are the only scenarios I tested. I think other picking functions that use this function should be tested but I couldn't track more uses of it. Co-authored-by: Krzysztof Zywiecki <krzysiu@pop-os.Dlink>
1 parent 17da7e1 commit 7f04906

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

crates/bevy_picking/src/backend.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,8 @@ pub mod ray {
229229
if !pointer_loc.is_in_viewport(camera, primary_window_entity) {
230230
return None;
231231
}
232-
let mut viewport_pos = pointer_loc.position;
233-
if let Some(viewport) = &camera.viewport {
234-
let viewport_logical = camera.to_logical(viewport.physical_position)?;
235-
viewport_pos -= viewport_logical;
236-
}
237-
camera.viewport_to_world(camera_tfm, viewport_pos).ok()
232+
camera
233+
.viewport_to_world(camera_tfm, pointer_loc.position)
234+
.ok()
238235
}
239236
}

0 commit comments

Comments
 (0)