mouselook
This commit is contained in:
@@ -18,6 +18,7 @@ pub trait Scene<D: gfx::Device,
|
||||
depth: &gfx::handle::DepthStencilView<D::Resources, view::DepthFormat>);
|
||||
|
||||
fn origin(&self) -> na::Matrix4<f32>;
|
||||
fn mouselook(&self) -> na::Matrix4<f32>;
|
||||
}
|
||||
|
||||
pub enum Event {
|
||||
|
||||
@@ -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<D: gfx::Device,
|
||||
|
||||
start_time: SystemTime,
|
||||
treadmills: (f32, f32),
|
||||
mouselook: na::Matrix4<f32>,
|
||||
pads: BTreeMap<u32, (TrackMode, Option<vr::ControllerState>)>,
|
||||
|
||||
_worldmap: model::World,
|
||||
@@ -171,6 +172,7 @@ impl<D: gfx::Device, F: gfx::Factory<D::Resources>> WorldScene<D, F> {
|
||||
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<D: gfx::Device,
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
|
||||
// mouselook
|
||||
Piston(Input::Move(Motion::MouseCursor(x, y))) => {
|
||||
self.mouselook = (
|
||||
na::Rotation3::new(na::Vector3::<f32>::new(y as f32 / 300.0, 0.0, 0.0)) *
|
||||
na::Rotation3::new(na::Vector3::<f32>::new(0.0, x as f32 / 300.0, 0.0))
|
||||
).to_homogeneous();
|
||||
},
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
@@ -371,6 +381,10 @@ impl<D: gfx::Device,
|
||||
&normal,
|
||||
).to_homogeneous()
|
||||
}
|
||||
|
||||
fn mouselook(&self) -> na::Matrix4<f32> {
|
||||
self.mouselook
|
||||
}
|
||||
}
|
||||
|
||||
fn get_data_model() -> model::World {
|
||||
|
||||
@@ -105,7 +105,7 @@ impl ViewRoot<gfx_device_gl::Device, ColorFormat, DepthFormat> {
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user