From 1de7f9e55f89466009706cb78780277ed298a667 Mon Sep 17 00:00:00 2001 From: Colin Sherratt Date: Tue, 18 Mar 2014 00:43:36 -0400 Subject: [PATCH] missing files --- .gitmodules | 3 - src/cgmath | 2 +- src/oculus-info/main.rs | 34 ++++++++ src/oculus-vr/Makefile | 4 +- src/oculus-vr/lib.rs | 183 ++++++++++++--------------------------- src/steamworks-vr/lib.rs | 23 ++--- 6 files changed, 103 insertions(+), 146 deletions(-) mode change 160000 => 120000 src/cgmath create mode 100644 src/oculus-info/main.rs diff --git a/.gitmodules b/.gitmodules index 703a69f..cc60014 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ -[submodule "src/cgmath"] - path = src/cgmath - url = https://github.com/bjz/cgmath-rs [submodule "modules/cgmath"] path = modules/cgmath url = https://github.com/bjz/cgmath-rs diff --git a/src/cgmath b/src/cgmath deleted file mode 160000 index 7809e8d..0000000 --- a/src/cgmath +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7809e8d646d5713949e0967417d7178c52de2a25 diff --git a/src/cgmath b/src/cgmath new file mode 120000 index 0000000..cda8296 --- /dev/null +++ b/src/cgmath @@ -0,0 +1 @@ +../modules/cgmath/src/cgmath/ \ No newline at end of file diff --git a/src/oculus-info/main.rs b/src/oculus-info/main.rs new file mode 100644 index 0000000..896132f --- /dev/null +++ b/src/oculus-info/main.rs @@ -0,0 +1,34 @@ + + +extern crate ovr = "oculus-vr"; + +fn main() +{ + ovr::init(); + + let dm = ovr::DeviceManager::new().unwrap(); + let dev = dm.enumerate().unwrap(); + let info = dev.get_info(); + + let sf = ovr::SensorFusion::new().unwrap(); + let sensor = dev.get_sensor().unwrap(); + + sf.attach_to_sensor(&sensor); + + match info.resolution() { + (w, h) => println!("Resolution: {}x{}", w, h) + }; + match info.size() { + (w, h) => println!("Size: {}x{}", w, h) + }; + + println!("Vertical Center: {}", info.vertical_center()); + println!("Eye to screen distance: {}", info.eye_to_screen_distance()); + println!("Lens separation distance: {}", info.lens_separation_distance()); + println!("Interpupillary distance: {}", info.interpupillary_distance()); + println!("distortion K: {:?}", info.distortion_K()); + println!("Chroma Ab Correction: {:?}", info.chroma_ab_correction()); + println!("display name: {:s}", info.name()); + println!("display id: {:?}", info.id()); + println!("display x,y {:?}", info.desktop()); +} \ No newline at end of file diff --git a/src/oculus-vr/Makefile b/src/oculus-vr/Makefile index 83ec64d..942264d 100644 --- a/src/oculus-vr/Makefile +++ b/src/oculus-vr/Makefile @@ -1,6 +1,6 @@ -LIBOVR_INCLUDE_PATH=../thirdparty/OculusSDK/LibOVR/Include/ -LIBOVR_LIB_PATH=../thirdparty/OculusSDK/LibOVR/Lib/Linux/Release/x86_64/libovr.a +LIBOVR_INCLUDE_PATH=../../thirdparty/OculusSDK/LibOVR/Include/ +LIBOVR_LIB_PATH=../../thirdparty/OculusSDK/LibOVR/Lib/Linux/Release/x86_64/libovr.a all: libovr_wrapper.a diff --git a/src/oculus-vr/lib.rs b/src/oculus-vr/lib.rs index 7378fc6..70a3ad6 100644 --- a/src/oculus-vr/lib.rs +++ b/src/oculus-vr/lib.rs @@ -1,12 +1,11 @@ -#[crate_id = "ovr-rs#0.1"]; +#[crate_id = "oculus-vr#0.1"]; #[crate_type = "lib"]; #[feature(link_args)]; extern crate cgmath; -use std::libc::{c_float, time_t, c_void}; +use std::libc::{c_float, time_t}; use std::c_str::ToCStr; -use std::cast::transmute; use cgmath::quaternion::Quat; use cgmath::vector::Vec3; @@ -17,11 +16,10 @@ use cgmath::angle::rad; #[cfg(target_os = "linux")] #[link(name="ovr_wrapper")] -#[link(name="OculusVR")] +#[link(name="ovr")] #[link(name="stdc++")] #[link(name="udev")] #[link(name="Xinerama")] -#[link(name="edid")] extern {} #[cfg(target_os = "macos")] @@ -36,20 +34,20 @@ pub mod ll { pub enum DeviceManager {} pub struct HMDInfo { - HResolution: c_uint, - VResolution: c_uint, - HScreenSize: c_float, - VScreenSize: c_float, - VScreenCenter: c_float, - EyeToScreenDistance: c_float, - LensSeparationDistance: c_float, - InterpupillaryDistance: c_float, - DistortionK: [c_float, ..4], - ChromaAbCorrection: [c_float, ..4], - DesktopX: c_int, - DesktopY: c_int, - DisplayDeviceName: [c_char, ..32], - DisplayId: c_long + horizontal_resolution: c_uint, + vertical_resolution: c_uint, + horizontal_screen_size: c_float, + vertical_screen_size: c_float, + vertical_screen_center: c_float, + eye_to_screen_distance: c_float, + lens_separation_distance: c_float, + interpupillary_distance: c_float, + distortion_k: [c_float, ..4], + chroma_ab_correction: [c_float, ..4], + desktop_x: c_int, + desktop_y: c_int, + display_device_name: [c_char, ..32], + display_id: c_long } @@ -57,20 +55,20 @@ pub mod ll { fn clone(&self) -> HMDInfo { HMDInfo { - HResolution: self.HResolution, - VResolution: self.VResolution, - HScreenSize: self.HScreenSize, - VScreenSize: self.VScreenSize, - VScreenCenter: self.VScreenCenter, - EyeToScreenDistance: self.EyeToScreenDistance, - LensSeparationDistance: self.LensSeparationDistance, - InterpupillaryDistance: self.InterpupillaryDistance, - DistortionK: self.DistortionK, - ChromaAbCorrection: self.ChromaAbCorrection, - DesktopX: self.DesktopX, - DesktopY: self.DesktopY, - DisplayDeviceName: self.DisplayDeviceName, - DisplayId: self.DisplayId, + horizontal_resolution: self.horizontal_resolution, + vertical_resolution: self.vertical_resolution, + horizontal_screen_size: self.horizontal_screen_size, + vertical_screen_size: self.vertical_screen_size, + vertical_screen_center: self.vertical_screen_center, + eye_to_screen_distance: self.eye_to_screen_distance, + lens_separation_distance: self.lens_separation_distance, + interpupillary_distance: self.interpupillary_distance, + distortion_k: self.distortion_k, + chroma_ab_correction: self.chroma_ab_correction, + desktop_x: self.desktop_x, + desktop_y: self.desktop_y, + display_device_name: self.display_device_name, + display_id: self.display_id, } } } @@ -93,13 +91,8 @@ pub mod ll { m41: c_float, m42: c_float, m43: c_float, m44: c_float} #[deriving(Clone)] - pub struct MessageBodyFrame { - Acceleration: Vector3f, - RotationRate: Vector3f, - MagneticField: Vector3f, - Temperature: f32, - TimeDelta: f32, - } + pub enum MessageBodyFrame {} + extern "C" { pub fn OVR_system_init(); @@ -250,65 +243,65 @@ impl HMDInfo { pub fn resolution(&self) -> (uint, uint) { - (self.dat.HResolution as uint, self.dat.VResolution as uint) + (self.dat.horizontal_resolution as uint, self.dat.vertical_resolution as uint) } pub fn size(&self) -> (f32, f32) { - (self.dat.HScreenSize as f32, self.dat.VScreenSize as f32) + (self.dat.horizontal_screen_size as f32, self.dat.vertical_screen_size as f32) } pub fn desktop(&self) -> (int, int) { - (self.dat.DesktopX as int, self.dat.DesktopY as int) + (self.dat.desktop_x as int, self.dat.desktop_y as int) } pub fn vertical_center(&self) -> f32 { - self.dat.VScreenCenter as f32 + self.dat.vertical_screen_center as f32 } pub fn eye_to_screen_distance(&self) -> f32 { - self.dat.EyeToScreenDistance as f32 + self.dat.eye_to_screen_distance as f32 } pub fn lens_separation_distance(&self) -> f32 { - self.dat.LensSeparationDistance as f32 + self.dat.lens_separation_distance as f32 } pub fn interpupillary_distance(&self) -> f32 { - self.dat.InterpupillaryDistance as f32 + self.dat.interpupillary_distance as f32 } pub fn distortion_K(&self) -> [f32, ..4] { - [self.dat.DistortionK[0] as f32, - self.dat.DistortionK[1] as f32, - self.dat.DistortionK[2] as f32, - self.dat.DistortionK[3] as f32] + [self.dat.distortion_k[0] as f32, + self.dat.distortion_k[1] as f32, + self.dat.distortion_k[2] as f32, + self.dat.distortion_k[3] as f32] } pub fn chroma_ab_correction(&self) -> [f32, ..4] { - [self.dat.ChromaAbCorrection[0] as f32, - self.dat.ChromaAbCorrection[1] as f32, - self.dat.ChromaAbCorrection[2] as f32, - self.dat.ChromaAbCorrection[3] as f32] + [self.dat.chroma_ab_correction[0] as f32, + self.dat.chroma_ab_correction[1] as f32, + self.dat.chroma_ab_correction[2] as f32, + self.dat.chroma_ab_correction[3] as f32] } pub fn name(&self) -> ~str { unsafe { - std::str::raw::from_c_str(&self.dat.DisplayDeviceName[0]) + std::str::raw::from_c_str(&self.dat.display_device_name[0]) } } pub fn id(&self) -> int { - self.dat.DisplayId as int + self.dat.display_id as int } } @@ -576,34 +569,9 @@ impl SensorFusion { Vec3::new(vec.x, vec.y, vec.z) } } - - pub fn on_message(&self, msg: &Message) - { - unsafe { - match *msg { - MsgBody(ref body) => { - ll::OVR_SensorFusion_OnMessage(self.ptr, transmute(body)); - } - } - } - } } -extern "C" fn chan_callback(chan: *c_void, msg: *ll::MessageBodyFrame) -{ - if chan.is_null() || msg.is_null() { - return; - } - - unsafe { - let chan: &Chan = transmute(chan); - let msg: &ll::MessageBodyFrame = transmute(msg); - - chan.send(MsgBody(MessageBody::from_raw(msg))); - } -} - -/*pub struct SensorDevice { +pub struct SensorDevice { priv ptr: *ll::SensorDevice, priv msg: Option<*ll::MessageHandler> } @@ -613,56 +581,11 @@ impl Drop for SensorDevice fn drop(&mut self) { unsafe { - // free chan - match self.msg { - Some(msg) => { - let chan = ll::OVR_MessageHandler_move_ptr(msg); - let _: ~Chan = transmute(chan); - ll::OVR_MessageHandler_drop(msg); - }, - None => () - } - ll::OVR_SensorDevice_drop(self.ptr); } } } -impl SensorDevice { - pub fn register_chan(&mut self, chan: ~Chan) - { - if self.msg.is_none() { - unsafe { - self.msg = Some(ll::OVR_MessageHandler(transmute(chan), chan_callback)); - let msg = self.msg.as_ref().unwrap(); - - ll::OVR_SensorDevice_SetMessageHandler(self.ptr, *msg); - } - } - } -}*/ - -struct MessageBody { - acceleration: Vec3, - rotation_rate: Vec3, - magnetic_field: Vec3, - temperature: f32, - time_delta: f32 -} - -impl MessageBody { - fn from_raw(mbf: &ll::MessageBodyFrame) -> MessageBody - { - unsafe { - transmute(*mbf) - } - } -} - -pub enum Message { - MsgBody(MessageBody) -} - pub fn create_reference_matrices(hmd: &HMDInfo, view_center: &Mat4, scale: f32) -> ((Mat4, Mat4), (Mat4, Mat4)) @@ -700,7 +623,7 @@ pub fn create_reference_matrices(hmd: &HMDInfo, view_center: &Mat4, scale: pub static SHADER_FRAG_CHROMAB: &'static str = "#version 400 uniform vec2 LensCenter; -uniform vec2 ScreenCenter; +uniform vec2 screen_center; uniform vec2 ScaleIn; uniform vec2 ScaleOut; uniform vec4 HmdWarpParam; @@ -724,7 +647,7 @@ void main() vec2 tcBlue = LensCenter + ScaleOut * thetaBlue; - if (!all(equal(clamp(tcBlue, ScreenCenter-vec2(0.25,0.5), ScreenCenter+vec2(0.25,0.5)), tcBlue))) { + if (!all(equal(clamp(tcBlue, screen_center-vec2(0.25,0.5), screen_center+vec2(0.25,0.5)), tcBlue))) { color = vec4(0.); return; } diff --git a/src/steamworks-vr/lib.rs b/src/steamworks-vr/lib.rs index fb81c12..dbe8a83 100644 --- a/src/steamworks-vr/lib.rs +++ b/src/steamworks-vr/lib.rs @@ -1,7 +1,10 @@ -#[crate_id = "steam-vr-rs#0.1"]; +#[allow(non_camel_case_types)]; + +#[crate_id = "steamworks-vr#0.1"]; #[crate_type = "lib"]; #[feature(link_args)]; + extern crate cgmath; use std::libc::{c_float}; @@ -121,7 +124,7 @@ pub struct Hmd priv ptr: *ll::IHmd } -enum HmdErrorInit +pub enum HmdErrorInit { InstallationNotFound, InstallationCorrupt, @@ -135,14 +138,14 @@ enum HmdErrorInit NotInitialized, } -enum IPCError +pub enum IPCError { ServerInitFailed, ConnectFailed, SharedStateInitFailed, } -enum HmdError { +pub enum HmdError { Init(HmdErrorInit), Driver_Failed, IPC(IPCError), @@ -176,7 +179,7 @@ impl HmdError } } -enum HmdEye +pub enum HmdEye { EyeLeft, EyeRight @@ -192,7 +195,7 @@ impl HmdEye { } } -enum GraphicsAPIConvention +pub enum GraphicsAPIConvention { DirectX, OpenGL @@ -209,26 +212,26 @@ impl GraphicsAPIConvention } } -struct DistortionCoordinates +pub struct DistortionCoordinates { red: [f32, ..2], green: [f32, ..2], blue: [f32, ..2] } -enum HmdTrackingResultCalibrating +pub enum HmdTrackingResultCalibrating { Calibrating_InProgress, Calibrating_OutOfRange } -enum HmdTrackingResultRunning +pub enum HmdTrackingResultRunning { Running_OK, Running_OutOfRange } -enum HmdTrackingResult +pub enum HmdTrackingResult { Uninitialized, Calibration(HmdTrackingResultCalibrating),