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

Use mouse event relative motion to calculate mouse velocity #56754

Merged
merged 1 commit into from
Jan 24, 2022

Conversation

madmiraal
Copy link
Contributor

Currently, mouse velocity is updated when set_mouse_position() is called. This has two side effects:

  1. Mouse velocity is updated every time set_mouse_position() is called even when the mouse hasn't moved. This results in large mouse velocities when, for example, the mouse is warped.
  2. Mouse velocity is not updated when the mouse moves, but the mouse position doesn't change. This results in mouse velocities being zero when using MOUSE_MODE_CAPTURED.

This PR uses InputEventMouseMotion's relative motion to update the mouse's velocity instead of calls to set_mouse_position(). This ensures that mouse velocities are updated when the mouse is captured.

Note: set_mouse_position() tends to be called to update the velocity before setting a InputEventMouseMotion's velocity property using get_last_mouse_velocity(). With this change the velocity (and position) aren't updated until the event is parsed. So calling set_mouse_position() to update the velocity is no longer meaningful. Therefore, these lines have been removed. Although it would appear that this would make the velocity value used in InputEventMouseMotion out of date, the reality is that, to ensure the velocity is precise and not jittery, the velocity is only updated every 0.1 seconds. This is far less frequent than InputEventMouseMotion events are generated (around every 0.008 seconds). Therefore, calling set_mouse_position() to update the velocity before setting a InputEventMouseMotion's velocity property, was ineffective anyway.

Note2: This change doesn't fix mouse warping from setting the mouse velocity. Mouse warping events should be filtered. However, at least on Linux, this is not happening. See #8414, which is still happening even though the issue has been closed.

Note3: #45592, reports a different issue, which highlighted a different problem: mouse velocities are not properly clearing old residual movements. However, #45592 arose, because of trying to find a workaround to mouse speeds being zero, when using MOUSE_MODE_CAPTURED.

@bruvzg
Copy link
Member

bruvzg commented Jan 24, 2022

Note2: This change doesn't fix mouse warping from setting the mouse velocity. Mouse warping events should be filtered. However, at least on Linux, this is not happening. See #8414, which is still happening even though the issue has been closed.

Not a Linux specific issue, it's the same on macOS.

@akien-mga
Copy link
Member

Note2: This change doesn't fix mouse warping from setting the mouse velocity. Mouse warping events should be filtered. However, at least on Linux, this is not happening. See #8414, which is still happening even though the issue has been closed.

Not a Linux specific issue, it's the same on macOS.

I would suggest opening a new issue. Reopening a 2017 issue won't give it much visibility and it lacks a reproduction project.

@akien-mga akien-mga merged commit 57a057f into godotengine:master Jan 24, 2022
@akien-mga
Copy link
Member

Thanks!

@madmiraal
Copy link
Contributor Author

I would suggest opening a new issue. Reopening a 2017 issue won't give it much visibility and it lacks a reproduction project.

I've created issue #57119.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants