winit: DeviceEvent::MouseMotion returns the last set value even if the mouse isn't moving
I’ve been working on implementing a first person fly camera, using MouseMotion for offset. however, even moving a mouse and stopping, doesn’t update the delta values to (0, 0) instead it keeps the last value that was set.
I understand it works by checking for mouse move, however checking and setting 0,0 if its same as last value to mitigate this introduces a lag upon camera moving around and looking.
This is what I tried and got me lag:
let (mut last_x, mut last_y) = (0f64, 0f64);
let (mut checked_x, mut checked_y) = (0f32, 0f32);
DeviceEvent::MouseMotion { delta: (x, y) } => {
let x = *x;
let y = *y;
if x == last_x && y == last_y
{
checked_x = 0f32;
checked_y = 0f32;
} else {
checked_x = x as f32;
checked_y = y as f32;
}
last_x = x;
last_y = y;
}
Any way to either not lag or have the last value set to 0? I don’t know if anything else there is to use instead for the camera…
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 29 (11 by maintainers)
here,
https://user-images.githubusercontent.com/35463470/165662749-8174c5b5-12e8-4905-a005-4c8466eb82bb.mp4