mirror of
https://github.com/bevyengine/bevy
synced 2024-11-21 20:23:28 +00:00
Fix sprite picking backend not considering the viewport of the camera. (#16386)
# Objective - When picking sprites, the pointer is offset from the mouse, causing you to pick sprites you're not mousing over! ## Solution - Shift over the cursor by the minimum of the viewport. ## Testing - I was already using the bevy_mod_picking PR for my project, so it seems to work! - I tested this on the sprite_example (making the camera only render to part of the viewport), and it also works there. ## Notes - This is just https://github.com/aevyrie/bevy_mod_picking/pull/365 but in Bevy form. - We don't need to renormalize the viewport in any way since the viewport is specified in pixels, so all that matters is that the origin is correct. Co-authored-by: johanhelsing <johanhelsing@gmail.com>
This commit is contained in:
parent
6beeaa89d3
commit
4eaebd4608
1 changed files with 7 additions and 2 deletions
|
@ -71,8 +71,13 @@ pub fn sprite_picking(
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
let Ok(cursor_ray_world) = camera.viewport_to_world(cam_transform, location.position)
|
let viewport_pos = camera
|
||||||
else {
|
.logical_viewport_rect()
|
||||||
|
.map(|v| v.min)
|
||||||
|
.unwrap_or_default();
|
||||||
|
let pos_in_viewport = location.position - viewport_pos;
|
||||||
|
|
||||||
|
let Ok(cursor_ray_world) = camera.viewport_to_world(cam_transform, pos_in_viewport) else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
let cursor_ray_len = cam_ortho.far - cam_ortho.near;
|
let cursor_ray_len = cam_ortho.far - cam_ortho.near;
|
||||||
|
|
Loading…
Reference in a new issue