Skip to content

Commit de79d3f

Browse files
authored
Mention in the docs for pointer events that these are in screen-space. (#19518)
# Objective - Fixes #18109. ## Solution - All these docs now mention screen-space vs world-space. - `start_pos` and `latest_pos` both link to `viewport_to_world` and `viewport_to_world_2d`. - The remaining cases are all deltas. Unfortunately `Camera` doesn't have an appropriate method for these cases, and implementing one would be non-trivial (e.g., the delta could have a different world-space size based on the depth). For these cases, I just link to `Camera` and suggest using some of its methods. Not a great solution, but at least it gets users on the correct track.
1 parent e1230fd commit de79d3f

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

crates/bevy_picking/src/events.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,11 @@ pub struct Move {
208208
/// Information about the picking intersection.
209209
pub hit: HitData,
210210
/// The change in position since the last move event.
211+
///
212+
/// This is stored in screen pixels, not world coordinates. Screen pixels go from top-left to
213+
/// bottom-right, whereas (in 2D) world coordinates go from bottom-left to top-right. Consider
214+
/// using methods on [`Camera`](bevy_render::camera::Camera) to convert from screen-space to
215+
/// world-space.
211216
pub delta: Vec2,
212217
}
213218

@@ -228,8 +233,18 @@ pub struct Drag {
228233
/// Pointer button pressed and moved to trigger this event.
229234
pub button: PointerButton,
230235
/// The total distance vector of a drag, measured from drag start to the current position.
236+
///
237+
/// This is stored in screen pixels, not world coordinates. Screen pixels go from top-left to
238+
/// bottom-right, whereas (in 2D) world coordinates go from bottom-left to top-right. Consider
239+
/// using methods on [`Camera`](bevy_render::camera::Camera) to convert from screen-space to
240+
/// world-space.
231241
pub distance: Vec2,
232242
/// The change in position since the last drag event.
243+
///
244+
/// This is stored in screen pixels, not world coordinates. Screen pixels go from top-left to
245+
/// bottom-right, whereas (in 2D) world coordinates go from bottom-left to top-right. Consider
246+
/// using methods on [`Camera`](bevy_render::camera::Camera) to convert from screen-space to
247+
/// world-space.
233248
pub delta: Vec2,
234249
}
235250

@@ -240,6 +255,11 @@ pub struct DragEnd {
240255
/// Pointer button pressed, moved, and released to trigger this event.
241256
pub button: PointerButton,
242257
/// The vector of drag movement measured from start to final pointer position.
258+
///
259+
/// This is stored in screen pixels, not world coordinates. Screen pixels go from top-left to
260+
/// bottom-right, whereas (in 2D) world coordinates go from bottom-left to top-right. Consider
261+
/// using methods on [`Camera`](bevy_render::camera::Camera) to convert from screen-space to
262+
/// world-space.
243263
pub distance: Vec2,
244264
}
245265

@@ -296,8 +316,20 @@ pub struct DragDrop {
296316
#[reflect(Clone, PartialEq)]
297317
pub struct DragEntry {
298318
/// The position of the pointer at drag start.
319+
///
320+
/// This is stored in screen pixels, not world coordinates. Screen pixels go from top-left to
321+
/// bottom-right, whereas (in 2D) world coordinates go from bottom-left to top-right. Consider
322+
/// using [`Camera::viewport_to_world`](bevy_render::camera::Camera::viewport_to_world) or
323+
/// [`Camera::viewport_to_world_2d`](bevy_render::camera::Camera::viewport_to_world_2d) to
324+
/// convert from screen-space to world-space.
299325
pub start_pos: Vec2,
300326
/// The latest position of the pointer during this drag, used to compute deltas.
327+
///
328+
/// This is stored in screen pixels, not world coordinates. Screen pixels go from top-left to
329+
/// bottom-right, whereas (in 2D) world coordinates go from bottom-left to top-right. Consider
330+
/// using [`Camera::viewport_to_world`](bevy_render::camera::Camera::viewport_to_world) or
331+
/// [`Camera::viewport_to_world_2d`](bevy_render::camera::Camera::viewport_to_world_2d) to
332+
/// convert from screen-space to world-space.
301333
pub latest_pos: Vec2,
302334
}
303335

0 commit comments

Comments
 (0)