- &KeyboardInput(Pressed, _, Some(VirtualKeyCode::Up)) => {
- self.moving_up = true;
- },
- &KeyboardInput(Released, _, Some(VirtualKeyCode::Up)) => {
- self.moving_up = false;
- },
- &KeyboardInput(Pressed, _, Some(VirtualKeyCode::Down)) => {
- self.moving_down = true;
- },
- &KeyboardInput(Released, _, Some(VirtualKeyCode::Down)) => {
- self.moving_down = false;
- },
- &KeyboardInput(Pressed, _, Some(VirtualKeyCode::Left)) => {
- self.moving_left = true;
- },
- &KeyboardInput(Released, _, Some(VirtualKeyCode::Left)) => {
- self.moving_left = false;
- },
- &KeyboardInput(Pressed, _, Some(VirtualKeyCode::Right)) => {
- self.moving_right = true;
- },
- &KeyboardInput(Released, _, Some(VirtualKeyCode::Right)) => {
- self.moving_right = false;
- },
- &KeyboardInput(Pressed, _, Some(VirtualKeyCode::A)) => {
- self.turning_left = true;
- },
- &KeyboardInput(Released, _, Some(VirtualKeyCode::A)) => {
- self.turning_left = false;
- },
- &KeyboardInput(Pressed, _, Some(VirtualKeyCode::D)) => {
- self.turning_right = true;
- },
- &KeyboardInput(Released, _, Some(VirtualKeyCode::D)) => {
- self.turning_right = false;
- },
- &KeyboardInput(Pressed, _, Some(VirtualKeyCode::W)) => {
- self.moving_forward = true;
- },
- &KeyboardInput(Released, _, Some(VirtualKeyCode::W)) => {
- self.moving_forward = false;
- },
- &KeyboardInput(Pressed, _, Some(VirtualKeyCode::S)) => {
- self.moving_backward = true;
- },
- &KeyboardInput(Released, _, Some(VirtualKeyCode::S)) => {
- self.moving_backward = false;
- },
- &KeyboardInput(Pressed, _, Some(VirtualKeyCode::R)) => {
- self.turning_up = true;
- },
- &KeyboardInput(Released, _, Some(VirtualKeyCode::R)) => {
- self.turning_up = false;
- },
- &KeyboardInput(Pressed, _, Some(VirtualKeyCode::F)) => {
- self.turning_down = true;
- },
- &KeyboardInput(Released, _, Some(VirtualKeyCode::F)) => {
- self.turning_down = false;
- },
- _ => {}
+ &glium::glutin::WindowEvent::CursorMoved { position, .. } => {
+ let (x, y) = (position.x as i32, position.y as i32);
+ if self.mouse_x == -1 {
+ // Set initial absolute position.
+ self.mouse_x = x;
+ self.mouse_y = y;
+ }
+ self.rel_x += x - self.mouse_x;
+ self.rel_y += y - self.mouse_y;
+ self.mouse_x = x;
+ self.mouse_y = y;
+ }
+ &glium::glutin::WindowEvent::KeyboardInput { input, .. } => {
+ let pressed = input.state == glium::glutin::ElementState::Pressed;
+ let key = match input.virtual_keycode {
+ Some(key) => key,
+ None => return,
+ };
+ match key {
+ VirtualKeyCode::Left => self.moving_left = pressed,
+ VirtualKeyCode::Right => self.moving_right = pressed,
+ VirtualKeyCode::Up => self.moving_up = pressed,
+ VirtualKeyCode::Down => self.moving_down = pressed,
+ VirtualKeyCode::W => self.moving_forward = pressed,
+ VirtualKeyCode::S => self.moving_backward = pressed,
+ VirtualKeyCode::A => self.turning_left = pressed,
+ VirtualKeyCode::D => self.turning_right = pressed,
+ VirtualKeyCode::R => self.turning_up = pressed,
+ VirtualKeyCode::F => self.turning_down = pressed,
+ _ => (),
+ }
+ },
+ _ => (),