From fc35cb33d0f58efce3a2a2b58818b7e40631a1cf Mon Sep 17 00:00:00 2001 From: Alice Cecile Date: Wed, 20 Nov 2024 19:47:05 -0500 Subject: [PATCH] Release notes for accumulated mouse inputs (#1828) --- .../14044_Accumulated_mouse_inputs.md | 28 +++++++++++++++++++ .../0.15/release-notes/_release-notes.toml | 7 +++++ 2 files changed, 35 insertions(+) create mode 100644 release-content/0.15/release-notes/14044_Accumulated_mouse_inputs.md diff --git a/release-content/0.15/release-notes/14044_Accumulated_mouse_inputs.md b/release-content/0.15/release-notes/14044_Accumulated_mouse_inputs.md new file mode 100644 index 0000000000..34cddcd6de --- /dev/null +++ b/release-content/0.15/release-notes/14044_Accumulated_mouse_inputs.md @@ -0,0 +1,28 @@ + + + +"How much has the player moved their mouse this frame" is a natural question for games when the player is trying to aim or scroll a map. +Unfortunately, the operating system, and thus [`winit`], only provides us with a stream of events, in the form of individual [`MouseMotion`] events. + +To get the summarized information (and the equivalent [`MouseScroll`]) information that most game systems care about, you had to sum them yourself. + +```rust +pub fn accumulate_mouse_motion_system( + mut mouse_motion_event: EventReader, + mut accumulated_mouse_motion: ResMut, +) { + let mut delta = Vec2::ZERO; + for event in mouse_motion_event.read() { + delta += event.delta; + } + accumulated_mouse_motion.delta = delta; +} +``` + +Bevy now does this for you, exposed in the new [`AccumulatedMouseMotion`] and [`AccumulatedMouseScroll`] resources. + +[`winit`]: https://docs.rs/winit/latest/winit/ +[`MouseMotion`]: https://docs.rs/bevy/0.15.0/bevy/input/mouse/struct.MouseMotion.html +[`MouseScroll`]: https://docs.rs/bevy/0.15.0/bevy/input/mouse/struct.MouseScroll.html +[`AccumulatedMouseMotion`]: https://docs.rs/bevy/0.15.0/bevy/input/mouse/struct.AccumulatedMouseMotion.html +[`AccumulatedMouseScroll`]: https://docs.rs/bevy/0.15.0/bevy/input/mouse/struct.AccumulatedMouseScroll.html diff --git a/release-content/0.15/release-notes/_release-notes.toml b/release-content/0.15/release-notes/_release-notes.toml index 9a053f61a4..9972d6de68 100644 --- a/release-content/0.15/release-notes/_release-notes.toml +++ b/release-content/0.15/release-notes/_release-notes.toml @@ -418,6 +418,13 @@ contributors = ["@IceSentry"] prs = [14663] file_name = "14663_shader_storage_buffer.md" +[[release_notes]] +title = "Accumulated mouse inputs" +authors = ["@Aztro-dev", "@alice-i-cecile"] +contributors = [] +prs = [14044] +file_name = "14044_Accumulated_mouse_inputs.md" + [[release_notes]] title = "Stable interpolation and smooth following" authors = ["@mweatherley"]