tracking basestation and controllers

This commit is contained in:
2016-09-12 19:45:51 -07:00
parent 6e3ba7f6db
commit 251ace63a7
3 changed files with 111 additions and 46 deletions

View File

@@ -1,11 +1,17 @@
extern crate gfx;
extern crate gfx_device_gl;
extern crate nalgebra as na;
extern crate num_traits;
extern crate openvr as vr;
extern crate openvr_sys;
use self::gfx::{tex, Factory, Typed};
pub use self::vr::Eye;
pub use self::vr::tracking::TrackedDeviceClass;
use self::na::Inverse;
use self::num_traits::identities::Zero;
use self::num_traits::identities::One;
pub struct VR {
system: vr::IVRSystem,
@@ -40,6 +46,16 @@ impl VR {
pub fn recommended_render_target_size(&self) -> vr::common::Size {
self.system.recommended_render_target_size()
}
pub fn projection_matrix(self: &Self, eye: Eye, near: f32, far: f32) -> na::Matrix4<f32> {
self.system.projection_matrix(eye, near, far).as_matrix4()
}
pub fn head_to_eye_transform(self: &Self, eye: Eye) -> na::Matrix4<f32> {
let mut mat = self.system.eye_to_head_transform(eye).as_matrix4();
assert!(mat.inverse_mut(), "inverse eye matrix");
mat
}
}
impl Drop for VR {
@@ -48,6 +64,28 @@ impl Drop for VR {
}
}
pub trait AsMatrix4<N> {
fn as_matrix4(self) -> na::Matrix4<N>;
}
impl<N: Copy + Zero + One> AsMatrix4<N> for [[N; 4]; 3] {
#[inline]
fn as_matrix4(self) -> na::Matrix4<N> {
na::Matrix4::new(self[0][0], self[0][1], self[0][2], self[0][3],
self[1][0], self[1][1], self[1][2], self[1][3],
self[2][0], self[2][1], self[2][2], self[2][3],
N::zero(), N::zero(), N::zero(), N::one())
}
}
impl<N: Copy> AsMatrix4<N> for [[N; 4]; 4] {
#[inline]
fn as_matrix4(self) -> na::Matrix4<N> {
na::Matrix4::new(self[0][0], self[0][1], self[0][2], self[0][3],
self[1][0], self[1][1], self[1][2], self[1][3],
self[2][0], self[2][1], self[2][2], self[2][3],
self[3][0], self[3][1], self[3][2], self[3][3])
}
}
pub fn create_eyebuffer<T>(factory: &mut gfx_device_gl::Factory,
size: vr::common::Size)
-> Result<(gfx::handle::Texture<gfx_device_gl::Resources,