Skip to content

Commit

Permalink
Linux in VM fix: manually calculate delta in MouseMotion
Browse files Browse the repository at this point in the history
For the third issue on #35 (comment)
https://github.com/tomaka/glutin/issues/1084 MouseMotion event returns absolute instead of relative values, when running Linux in a VM
  • Loading branch information
iceiix committed Nov 30, 2018
1 parent a765f2a commit a46b525
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/main.rs
Expand Up @@ -76,6 +76,8 @@ pub struct Game {
dpi_factor: f64,
last_mouse_x: f64,
last_mouse_y: f64,
last_mouse_xrel: f64,
last_mouse_yrel: f64,
is_fullscreen: bool,
}

Expand Down Expand Up @@ -212,6 +214,8 @@ fn main() {
dpi_factor,
last_mouse_x: 0.0,
last_mouse_y: 0.0,
last_mouse_xrel: 0.0,
last_mouse_yrel: 0.0,
is_fullscreen: false,
};
game.renderer.camera.pos = cgmath::Point3::new(0.5, 13.2, 0.5);
Expand Down Expand Up @@ -278,7 +282,13 @@ fn handle_window_event(window: &mut glutin::GlWindow,
use glutin::*;
match event {
Event::DeviceEvent{event, ..} => match event {
DeviceEvent::MouseMotion{delta:(xrel, yrel)} => {
DeviceEvent::MouseMotion{delta:(xrel1, yrel1)} => {
let xrel = xrel1 - game.last_mouse_xrel;
let yrel = yrel1 - game.last_mouse_yrel;

game.last_mouse_xrel = xrel1;
game.last_mouse_yrel = yrel1;

use std::f64::consts::PI;

if game.focused {
Expand Down

0 comments on commit a46b525

Please sign in to comment.