Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add resources for accumulated mouse motion and mouse scroll #13915

Closed
alice-i-cecile opened this issue Jun 18, 2024 · 5 comments · Fixed by #14044
Closed

Add resources for accumulated mouse motion and mouse scroll #13915

alice-i-cecile opened this issue Jun 18, 2024 · 5 comments · Fixed by #14044
Labels
A-Input Player input via keyboard, mouse, gamepad, and more C-Feature A new feature, making something new possible D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it!

Comments

@alice-i-cecile
Copy link
Member

alice-i-cecile commented Jun 18, 2024

What problem does this solve or what need does it fill?

When working with inputs from mice for gameplay purposes, it is very common to want an aggregate view of "how much did the mouse move this frame?" or "how much did the player scroll?".

This is primarily used for controlling camera positions, such as when zooming or panning a map, or when working with

What solution would you like?

Add two resources, each of which stores a simple Vec2: AccumulatedMouseMotion and AccumulatedMouseScroll. Reset them to zero at the start of each frame in a system, then sum the corresponding events.

What alternative(s) have you considered?

Users can sum these events themselves, and replicate the code listed above. This is a waste of time / confusing to them, and it's quite possible to get the timing of this wrong, leading to laggy or buggy input data.

It's also quite plausible that users (like me, historically) end up doing this computation multiple times across different parts of their app, leading to wasteful and inconsistent results.

Additional context

I needed this functionality in leafwing-input-manager, and decided to solve it the right way in Leafwing-Studios/leafwing-input-manager#543. The code associated with the AccumulatorPlugin can be ripped out and ported quite directly to bevy_input.

MouseScroll is a bit of a wrinkle: there's two possible units that could be sent. Ultimately, for the context of "gameplay data about what the player's mouse did", I don't think we care, as long as the same amount of physical motion results in about the same amount of accumulation. We may want to apply some sort of scaling factor to convert, but I'm not familiar enough with this behavior to know how to test it to check.

@alice-i-cecile alice-i-cecile added C-Feature A new feature, making something new possible A-Input Player input via keyboard, mouse, gamepad, and more S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it! D-Straightforward Simple bug fixes and API improvements, docs, test and examples labels Jun 18, 2024
@BackupMiles
Copy link

Hi! I am interested in working on this issue, may it be assigned to me?

@bugsweeper
Copy link
Contributor

bugsweeper commented Jun 19, 2024

@BackupMiles , usualy nobody assigns tasks in bevy, just write that you are working on it, and nobody else will waste their time. Just don't forget to write message if you change your mind

@BackupMiles
Copy link

Thank you for clarifying @bugsweeper, then I will gladly work on this issue 👍

@BackupMiles
Copy link

Just a quick question: where would be a good place to ask more info about the project/code?

@alice-i-cecile
Copy link
Member Author

Either in this issue or in #input-dev :) Just ping me.

github-merge-queue bot pushed a commit that referenced this issue Jul 1, 2024
# Objective

- Add the `AccumulatedMouseMotion` and `AccumulatedMouseScroll`
resources to make it simpler to track mouse motion/scroll changes
- Closes #13915

## Solution

- Created two resources, `AccumulatedMouseMotion` and
`AccumulatedMouseScroll`, and a method that tracks the `MouseMotion` and
`MouseWheel` events and accumulates their deltas every frame.
- Also modified the mouse input example to show how to use the
resources.

## Testing

- Tested the changes by modifying an existing example to use the newly
added resources, and moving/scrolling my trackpad around a ton.

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: Gino Valente <49806985+MrGVSV@users.noreply.github.com>
zmbush pushed a commit to zmbush/bevy that referenced this issue Jul 3, 2024
# Objective

- Add the `AccumulatedMouseMotion` and `AccumulatedMouseScroll`
resources to make it simpler to track mouse motion/scroll changes
- Closes bevyengine#13915

## Solution

- Created two resources, `AccumulatedMouseMotion` and
`AccumulatedMouseScroll`, and a method that tracks the `MouseMotion` and
`MouseWheel` events and accumulates their deltas every frame.
- Also modified the mouse input example to show how to use the
resources.

## Testing

- Tested the changes by modifying an existing example to use the newly
added resources, and moving/scrolling my trackpad around a ton.

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: Gino Valente <49806985+MrGVSV@users.noreply.github.com>
MrGVSV added a commit to MrGVSV/bevy that referenced this issue Jul 5, 2024
# Objective

- Add the `AccumulatedMouseMotion` and `AccumulatedMouseScroll`
resources to make it simpler to track mouse motion/scroll changes
- Closes bevyengine#13915

## Solution

- Created two resources, `AccumulatedMouseMotion` and
`AccumulatedMouseScroll`, and a method that tracks the `MouseMotion` and
`MouseWheel` events and accumulates their deltas every frame.
- Also modified the mouse input example to show how to use the
resources.

## Testing

- Tested the changes by modifying an existing example to use the newly
added resources, and moving/scrolling my trackpad around a ton.

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: Gino Valente <49806985+MrGVSV@users.noreply.github.com>
alice-i-cecile added a commit to Leafwing-Studios/leafwing-input-manager that referenced this issue Jul 24, 2024
alice-i-cecile added a commit to Leafwing-Studios/leafwing-input-manager that referenced this issue Aug 6, 2024
* Add press and release methods to `Buttonlike`

* Add Axislike::send_value

* Add DualAxislike::set_axis_pair

* Change MockInput methods to take impl Buttonlike

* Remove old form of input mocking

* Clippy

* Add workaround for bevyengine/bevy#13915 to tests

* Remove silly test

* Fix some doc tests

* More simple fixes to doc tests

* Wrong KeyCode variant

* Update README to reflect 0.15 changes

* Re-add a FetchUserInput utility trait for now

* Fix redundant doc links

* More test fixing

* Fix doc links

* Fix missing imports for tests

* Fix panic in input_map benchmark

* New documentation lint

* Fix incorrect feature flag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Input Player input via keyboard, mouse, gamepad, and more C-Feature A new feature, making something new possible D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Ready-For-Implementation This issue is ready for an implementation PR. Go for it!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants