mouselook
This commit is contained in:
@@ -18,6 +18,7 @@ pub trait Scene<D: gfx::Device,
|
|||||||
depth: &gfx::handle::DepthStencilView<D::Resources, view::DepthFormat>);
|
depth: &gfx::handle::DepthStencilView<D::Resources, view::DepthFormat>);
|
||||||
|
|
||||||
fn origin(&self) -> na::Matrix4<f32>;
|
fn origin(&self) -> na::Matrix4<f32>;
|
||||||
|
fn mouselook(&self) -> na::Matrix4<f32>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Event {
|
pub enum Event {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ use std::time::SystemTime;
|
|||||||
use gfx::{self, texture};
|
use gfx::{self, texture};
|
||||||
use gfx::traits::FactoryExt;
|
use gfx::traits::FactoryExt;
|
||||||
use na;
|
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 PI: f32 = ::std::f32::consts::PI;
|
||||||
const TWO_PI_CIRC: f32 = 2.0 * PI / 256.0;
|
const TWO_PI_CIRC: f32 = 2.0 * PI / 256.0;
|
||||||
@@ -134,6 +134,7 @@ pub struct WorldScene<D: gfx::Device,
|
|||||||
|
|
||||||
start_time: SystemTime,
|
start_time: SystemTime,
|
||||||
treadmills: (f32, f32),
|
treadmills: (f32, f32),
|
||||||
|
mouselook: na::Matrix4<f32>,
|
||||||
pads: BTreeMap<u32, (TrackMode, Option<vr::ControllerState>)>,
|
pads: BTreeMap<u32, (TrackMode, Option<vr::ControllerState>)>,
|
||||||
|
|
||||||
_worldmap: model::World,
|
_worldmap: model::World,
|
||||||
@@ -171,6 +172,7 @@ impl<D: gfx::Device, F: gfx::Factory<D::Resources>> WorldScene<D, F> {
|
|||||||
slice: slice,
|
slice: slice,
|
||||||
start_time: SystemTime::now(),
|
start_time: SystemTime::now(),
|
||||||
treadmills: (0.0, 0.0),
|
treadmills: (0.0, 0.0),
|
||||||
|
mouselook: na::Matrix4::identity(),
|
||||||
pads: BTreeMap::new(),
|
pads: BTreeMap::new(),
|
||||||
|
|
||||||
_worldmap: worldmap,
|
_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,
|
&normal,
|
||||||
).to_homogeneous()
|
).to_homogeneous()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn mouselook(&self) -> na::Matrix4<f32> {
|
||||||
|
self.mouselook
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_data_model() -> model::World {
|
fn get_data_model() -> model::World {
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ impl ViewRoot<gfx_device_gl::Device, ColorFormat, DepthFormat> {
|
|||||||
1.0).to_homogeneous();
|
1.0).to_homogeneous();
|
||||||
let proj_mat = na::geometry::Perspective3::new(1.0, 90.0, NEAR, FAR);
|
let proj_mat = na::geometry::Perspective3::new(1.0, 90.0, NEAR, FAR);
|
||||||
let scene_mat = scene.origin();
|
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(),
|
let trans = Trans { viewmodel: *viewmodel_mat.as_ref(),
|
||||||
matrix: *(proj_mat.as_matrix() * viewmodel_mat).as_ref() };
|
matrix: *(proj_mat.as_matrix() * viewmodel_mat).as_ref() };
|
||||||
window.encoder.update_constant_buffer(&self.trans, &trans);
|
window.encoder.update_constant_buffer(&self.trans, &trans);
|
||||||
|
|||||||
Reference in New Issue
Block a user