X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=support%2Fcamera.rs;h=db6c55ac6b103723999c7efd959ed1650cd91ce3;hb=db8dabba713ca281b3c8c49642eccf5a6f0af250;hp=c036abff537281412fc90fa1b085d6269d02a627;hpb=994db9260d2b405e0af5668b167f19adb9936909;p=mandelwow.git diff --git a/support/camera.rs b/support/camera.rs index c036abf..db6c55a 100644 --- a/support/camera.rs +++ b/support/camera.rs @@ -1,18 +1,11 @@ -extern crate glutin; - use cgmath::{Matrix4, Vector4}; use cgmath::conv::array4x4; -use glutin::ElementState::{Pressed, Released}; -use glutin::Event::{KeyboardInput, MouseMoved}; -use glutin::VirtualKeyCode; -use std::f32::consts::PI; -use support::vec3::Vec3; -use support::vec3::norm; - +use glium; +use glium::glutin::event::{ ElementState, VirtualKeyCode, WindowEvent }; use std::f32; - -//use glutin::Event; -//use VirtualKeyCode; +use std::f32::consts::PI; +use crate::support::vec3::Vec3; +use crate::support::vec3::norm; #[derive(Default)] pub struct CameraState { @@ -170,9 +163,11 @@ impl CameraState { //println!("camera_dir = {:?}", self.dir); } - pub fn process_input(&mut self, event: &glutin::Event) { + pub fn process_input(&mut self, event: &WindowEvent) { + //println!("camera event={:?}", event); match event { - &MouseMoved(x, y) => { + &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; @@ -183,67 +178,27 @@ impl CameraState { self.mouse_x = x; self.mouse_y = y; } - &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; + &WindowEvent::KeyboardInput { input, .. } => { + let pressed = input.state == 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, + _ => (), + } }, - _ => {} + _ => (), } } }