From d24c67a94d9f1951d5ce5d8a01981162a6dea188 Mon Sep 17 00:00:00 2001 From: Colin Sherratt Date: Mon, 27 Jan 2014 04:41:45 -0500 Subject: [PATCH] Added getters for HDMInfo --- Makefile | 2 +- lib.rs | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++- test.rs | 17 +++++++- wrapper.cpp | 72 ++++++++++++++++++++++++++++++++- 4 files changed, 201 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index de4b30a..b127742 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ wrapper.o: wrapper.cpp c++ -fPIC -I $(LIBOVR_INCLUDE_PATH) -c -o wrapper.o wrapper.cpp libovr-rs-44316370-0.1.so: libovr_wrapper.a lib.rs - rustc lib.rs + rustc lib.rs -L . test: test.rs libovr-rs-44316370-0.1.so rustc test.rs -L . --link-args="-lovr -ludev -lstdc++ -lc -lX11 -lm -lpthread -lXinerama" diff --git a/lib.rs b/lib.rs index 444d7d7..e52e83c 100644 --- a/lib.rs +++ b/lib.rs @@ -2,7 +2,7 @@ #[crate_type = "lib"]; #[feature(link_args)]; -use std::ptr; +extern mod cgmath; #[link(name="ovr_wrapper")] extern {} @@ -11,6 +11,8 @@ extern {} extern {} mod ll { + use std::libc::{c_uint, c_int, c_float, c_long, c_char}; + pub enum DeviceManager {} pub enum HMDInfo {} pub enum HMDDevice {} @@ -25,6 +27,21 @@ mod ll { pub fn OVR_HDMDevice_GetSensor(hmd: *HMDDevice) -> *SensorDevice; pub fn OVR_SensorFusion() -> *SensorFusion; pub fn OVR_SensorFusion_AttachToSensor(sf: *SensorFusion, sd: *SensorDevice) -> bool; + + pub fn OVR_HMDInfo_GetScreenHResolution(info: *HMDInfo) -> c_uint; + pub fn OVR_HMDInfo_GetScreenVResolution(info: *HMDInfo) -> c_uint; + pub fn OVR_HMDInfo_GetHScreenSize(info: *HMDInfo) -> c_float; + pub fn OVR_HMDInfo_GetVScreenSize(info: *HMDInfo) -> c_float; + pub fn OVR_HMDInfo_GetVScreenCenter(info: *HMDInfo) -> c_float; + pub fn OVR_HMDInfo_GetEyeToScreenDistance(info: *HMDInfo) -> c_float; + pub fn OVR_HMDInfo_GetLensSeparationDistance(info: *HMDInfo) -> c_float; + pub fn OVR_HMDInfo_GetInterpupillaryDistance(info: *HMDInfo) -> c_float; + pub fn OVR_HMDInfo_GetDistortionK(info: *HMDInfo, idx: c_int) -> c_float; + pub fn OVR_HMDInfo_GetChromaAbCorrection(info: *HMDInfo, idx: c_int) -> c_float; + pub fn OVR_HMDInfo_GetDesktopX(info: *HMDInfo) -> c_uint; + pub fn OVR_HMDInfo_GetDesktopY(info: *HMDInfo) -> c_uint; + pub fn OVR_HMDInfo_GetDisplayDeviceName(info: *HMDInfo) -> *c_char; + pub fn OVR_HMDInfo_GetDisplayId(info: *HMDInfo) -> c_long; } } @@ -111,6 +128,101 @@ pub struct HMDInfo { priv ptr: *ll::HMDInfo } +impl HMDInfo +{ + pub fn resolution(&self) -> (uint, uint) + { + unsafe { + let h = ll::OVR_HMDInfo_GetScreenHResolution(self.ptr); + let v = ll::OVR_HMDInfo_GetScreenVResolution(self.ptr); + + (h as uint, v as uint) + } + } + + pub fn size(&self) -> (f32, f32) + { + unsafe { + let h = ll::OVR_HMDInfo_GetHScreenSize(self.ptr); + let v = ll::OVR_HMDInfo_GetVScreenSize(self.ptr); + + (h as f32, v as f32) + } + } + + pub fn desktop(&self) -> (int, int) + { + unsafe { + let h = ll::OVR_HMDInfo_GetDesktopX(self.ptr); + let v = ll::OVR_HMDInfo_GetDesktopY(self.ptr); + + (h as int, v as int) + } + } + + pub fn vertical_center(&self) -> f32 + { + unsafe { + ll::OVR_HMDInfo_GetVScreenCenter(self.ptr) as f32 + } + } + + pub fn eye_to_screen_distance(&self) -> f32 + { + unsafe { + ll::OVR_HMDInfo_GetEyeToScreenDistance(self.ptr) as f32 + } + } + + pub fn lens_separation_distance(&self) -> f32 + { + unsafe { + ll::OVR_HMDInfo_GetLensSeparationDistance(self.ptr) as f32 + } + } + + pub fn interpupillary_distance(&self) -> f32 + { + unsafe { + ll::OVR_HMDInfo_GetInterpupillaryDistance(self.ptr) as f32 + } + } + + pub fn distortion_K(&self) -> [f32, ..4] + { + unsafe { + [ll::OVR_HMDInfo_GetDistortionK(self.ptr, 0) as f32, + ll::OVR_HMDInfo_GetDistortionK(self.ptr, 1) as f32, + ll::OVR_HMDInfo_GetDistortionK(self.ptr, 2) as f32, + ll::OVR_HMDInfo_GetDistortionK(self.ptr, 3) as f32] + } + } + + pub fn chroma_ab_correction(&self) -> [f32, ..4] + { + unsafe { + [ll::OVR_HMDInfo_GetChromaAbCorrection(self.ptr, 0) as f32, + ll::OVR_HMDInfo_GetChromaAbCorrection(self.ptr, 1) as f32, + ll::OVR_HMDInfo_GetChromaAbCorrection(self.ptr, 2) as f32, + ll::OVR_HMDInfo_GetChromaAbCorrection(self.ptr, 3) as f32] + } + } + + pub fn name(&self) -> ~str + { + unsafe { + std::str::raw::from_c_str(ll::OVR_HMDInfo_GetDisplayDeviceName(self.ptr)) + } + } + + pub fn id(&self) -> int + { + unsafe { + ll::OVR_HMDInfo_GetDisplayId(self.ptr) as int + } + } +} + pub struct SensorFusion { priv ptr: *ll::SensorFusion } diff --git a/test.rs b/test.rs index d1543af..4909546 100644 --- a/test.rs +++ b/test.rs @@ -8,11 +8,26 @@ fn main() let dm = ovr::DeviceManager::new().unwrap(); let dev = dm.enumerate().unwrap(); - let info = dev.get_info(); + let info = dev.get_info().unwrap(); 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()); } \ No newline at end of file diff --git a/wrapper.cpp b/wrapper.cpp index 16d7735..e57db77 100644 --- a/wrapper.cpp +++ b/wrapper.cpp @@ -17,7 +17,6 @@ extern "C" return pManager->EnumerateDevices().CreateDevice(); } - // not pointer on purpose! OVR::HMDInfo* OVR_HDMDevice_GetDeviceInfo(OVR::HMDDevice* pHMD) { OVR::HMDInfo *hdm = new OVR::HMDInfo; @@ -40,4 +39,75 @@ extern "C" { return (*SFusion).AttachToSensor(pSensor); } + + + unsigned OVR_HMDInfo_GetScreenHResolution(OVR::HMDInfo* info) + { + return info->HResolution; + } + + unsigned OVR_HMDInfo_GetScreenVResolution(OVR::HMDInfo* info) + { + return info->VResolution; + } + + float OVR_HMDInfo_GetHScreenSize(OVR::HMDInfo* info) + { + return info->HScreenSize; + } + + float OVR_HMDInfo_GetVScreenSize(OVR::HMDInfo* info) + { + return info->VScreenSize; + } + + float OVR_HMDInfo_GetVScreenCenter(OVR::HMDInfo* info) + { + return info->VScreenCenter; + } + + float OVR_HMDInfo_GetEyeToScreenDistance(OVR::HMDInfo* info) + { + return info->EyeToScreenDistance; + } + + float OVR_HMDInfo_GetLensSeparationDistance(OVR::HMDInfo* info) + { + return info->LensSeparationDistance; + } + + float OVR_HMDInfo_GetInterpupillaryDistance(OVR::HMDInfo* info) + { + return info->InterpupillaryDistance; + } + + float OVR_HMDInfo_GetDistortionK(OVR::HMDInfo* info, int idx) + { + return info->DistortionK[idx]; + } + + float OVR_HMDInfo_GetChromaAbCorrection(OVR::HMDInfo* info, int idx) + { + return info->ChromaAbCorrection[idx]; + } + + unsigned OVR_HMDInfo_GetDesktopX(OVR::HMDInfo* info) + { + return info->HResolution; + } + + unsigned OVR_HMDInfo_GetDesktopY(OVR::HMDInfo* info) + { + return info->DesktopY; + } + + char* OVR_HMDInfo_GetDisplayDeviceName(OVR::HMDInfo* info) + { + return info->DisplayDeviceName; + } + + long OVR_HMDInfo_GetDisplayId(OVR::HMDInfo* info) + { + return info->DisplayId; + } } \ No newline at end of file