diff --git a/src/scene.rs b/src/scene.rs index 9b6b0e4..dc256f7 100644 --- a/src/scene.rs +++ b/src/scene.rs @@ -18,6 +18,7 @@ pub trait Scene); fn origin(&self) -> na::Matrix4; + fn mouselook(&self) -> na::Matrix4; } pub enum Event { diff --git a/src/scenes/world.rs b/src/scenes/world.rs index ccab251..27c5e10 100644 --- a/src/scenes/world.rs +++ b/src/scenes/world.rs @@ -14,7 +14,7 @@ use std::time::SystemTime; use gfx::{self, texture}; use gfx::traits::FactoryExt; use na; -use piston::input::{Button, ButtonArgs, ButtonState, Input, Key}; +use piston::input::{Button, ButtonArgs, ButtonState, Input, Key, Motion}; const PI: f32 = ::std::f32::consts::PI; const TWO_PI_CIRC: f32 = 2.0 * PI / 256.0; @@ -134,6 +134,7 @@ pub struct WorldScene, pads: BTreeMap)>, _worldmap: model::World, @@ -171,6 +172,7 @@ impl> WorldScene { slice: slice, start_time: SystemTime::now(), treadmills: (0.0, 0.0), + mouselook: na::Matrix4::identity(), pads: BTreeMap::new(), _worldmap: worldmap, @@ -277,6 +279,14 @@ impl () } } + + // mouselook + Piston(Input::Move(Motion::MouseCursor(x, y))) => { + self.mouselook = ( + na::Rotation3::new(na::Vector3::::new(y as f32 / 300.0, 0.0, 0.0)) * + na::Rotation3::new(na::Vector3::::new(0.0, x as f32 / 300.0, 0.0)) + ).to_homogeneous(); + }, _ => () } } @@ -371,6 +381,10 @@ impl na::Matrix4 { + self.mouselook + } } fn get_data_model() -> model::World { diff --git a/src/view.rs b/src/view.rs index be71cd7..bfbe8ba 100644 --- a/src/view.rs +++ b/src/view.rs @@ -105,7 +105,7 @@ impl ViewRoot { 1.0).to_homogeneous(); let proj_mat = na::geometry::Perspective3::new(1.0, 90.0, NEAR, FAR); let scene_mat = scene.origin(); - let viewmodel_mat = head_mat * scene_mat; + let viewmodel_mat = scene.mouselook() * head_mat * scene_mat; let trans = Trans { viewmodel: *viewmodel_mat.as_ref(), matrix: *(proj_mat.as_matrix() * viewmodel_mat).as_ref() }; window.encoder.update_constant_buffer(&self.trans, &trans);