mirror of
https://github.com/mii443/rust-openvr.git
synced 2025-08-23 00:35:31 +00:00
Now uses new sys binding
- refactored Struct_ and Enum_ prefixes from old bindgen version - added error implementation for rendering system (was blocked by valve) - started with camera implementation (has_camera done)
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -8,3 +8,4 @@
|
|||||||
/src/sys/target/
|
/src/sys/target/
|
||||||
*.lock
|
*.lock
|
||||||
Cargo.lock
|
Cargo.lock
|
||||||
|
/idea/
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "openvr"
|
name = "openvr"
|
||||||
version = "0.3.0"
|
version = "0.4.0"
|
||||||
authors = [
|
authors = [
|
||||||
"Colin Sherratt",
|
"Colin Sherratt",
|
||||||
"Erick Tryzelaar",
|
"Erick Tryzelaar",
|
||||||
@ -19,7 +19,7 @@ name = "openvr"
|
|||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
openvr_sys = "0.1.2"
|
openvr_sys = "1.0.2"
|
||||||
|
|
||||||
[dev_dependencies]
|
[dev_dependencies]
|
||||||
glium = "0.14.0"
|
glium = "0.14.0"
|
||||||
|
26
examples/camera.rs
Normal file
26
examples/camera.rs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
extern crate openvr;
|
||||||
|
|
||||||
|
pub fn main () {
|
||||||
|
// init vr system
|
||||||
|
let system = match openvr::init() {
|
||||||
|
Ok(ivr) => ivr,
|
||||||
|
Err(err) => {
|
||||||
|
println!("Failed to create IVRSystem subsystem {:?}", err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let camera = match openvr::subsystems::tracked_camera() {
|
||||||
|
Ok(ivr) => ivr,
|
||||||
|
Err(err) => {
|
||||||
|
println!("Failed to create IVRTrackedCamera subsystem {:?}", err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for device in system.tracked_devices(0.0).connected_iter() {
|
||||||
|
println!("Device found: {}", device.index);
|
||||||
|
println!("\t{:?}", device.device_class());
|
||||||
|
println!("\t{:?}", camera.has_camera(&device));
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
use openvr_sys;
|
use openvr_sys;
|
||||||
use openvr_sys::Enum_EVREye::*;
|
use openvr_sys::EVREye::*;
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub struct Size {
|
pub struct Size {
|
||||||
@ -70,7 +70,7 @@ impl TextureBounds {
|
|||||||
|
|
||||||
/// Convert a bounds to a openvr_bounds
|
/// Convert a bounds to a openvr_bounds
|
||||||
pub fn to_raw(self) -> openvr_sys::VRTextureBounds_t {
|
pub fn to_raw(self) -> openvr_sys::VRTextureBounds_t {
|
||||||
openvr_sys::VRTextureBounds_t{
|
openvr_sys::VRTextureBounds_t {
|
||||||
uMin: self.u_min,
|
uMin: self.u_min,
|
||||||
uMax: self.u_max,
|
uMax: self.u_max,
|
||||||
vMin: self.v_min,
|
vMin: self.v_min,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use openvr_sys;
|
use openvr_sys;
|
||||||
use openvr_sys::Enum_EGraphicsAPIConvention::*;
|
use openvr_sys::EGraphicsAPIConvention::*;
|
||||||
use openvr_sys::Enum_EVRSubmitFlags::*;
|
use openvr_sys::EVRSubmitFlags::*;
|
||||||
use openvr_sys::Enum_EColorSpace::*;
|
use openvr_sys::EColorSpace::*;
|
||||||
use common::*;
|
use common::*;
|
||||||
use tracking::*;
|
use tracking::*;
|
||||||
|
|
||||||
@ -16,7 +16,7 @@ impl IVRCompositor {
|
|||||||
/// Check to see if the compositor is fullscreen
|
/// Check to see if the compositor is fullscreen
|
||||||
pub fn is_fullscreen(&self) -> bool {
|
pub fn is_fullscreen(&self) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
let comp = * { self.0 as *mut openvr_sys::Struct_VR_IVRCompositor_FnTable };
|
let comp = * { self.0 as *mut openvr_sys::VR_IVRCompositor_FnTable };
|
||||||
comp.IsFullscreen.unwrap()() > 0
|
comp.IsFullscreen.unwrap()() > 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -24,7 +24,7 @@ impl IVRCompositor {
|
|||||||
/// Check if compositor can render a scene
|
/// Check if compositor can render a scene
|
||||||
pub fn can_render_scene(&self) -> bool {
|
pub fn can_render_scene(&self) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
let comp = * { self.0 as *mut openvr_sys::Struct_VR_IVRCompositor_FnTable };
|
let comp = * { self.0 as *mut openvr_sys::VR_IVRCompositor_FnTable };
|
||||||
comp.CanRenderScene.unwrap()() > 0
|
comp.CanRenderScene.unwrap()() > 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -37,7 +37,7 @@ impl IVRCompositor {
|
|||||||
unsafe {
|
unsafe {
|
||||||
use std;
|
use std;
|
||||||
|
|
||||||
let comp = * { self.0 as *mut openvr_sys::Struct_VR_IVRCompositor_FnTable };
|
let comp = * { self.0 as *mut openvr_sys::VR_IVRCompositor_FnTable };
|
||||||
let mut t = openvr_sys::Texture_t {
|
let mut t = openvr_sys::Texture_t {
|
||||||
eType: EGraphicsAPIConvention_API_OpenGL,
|
eType: EGraphicsAPIConvention_API_OpenGL,
|
||||||
eColorSpace: EColorSpace_ColorSpace_Auto,
|
eColorSpace: EColorSpace_ColorSpace_Auto,
|
||||||
@ -58,7 +58,7 @@ impl IVRCompositor {
|
|||||||
use std;
|
use std;
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let comp = * { self.0 as *mut openvr_sys::Struct_VR_IVRCompositor_FnTable };
|
let comp = * { self.0 as *mut openvr_sys::VR_IVRCompositor_FnTable };
|
||||||
let mut data: [openvr_sys::TrackedDevicePose_t; 16] = std::mem::zeroed();
|
let mut data: [openvr_sys::TrackedDevicePose_t; 16] = std::mem::zeroed();
|
||||||
|
|
||||||
comp.WaitGetPoses.unwrap()(
|
comp.WaitGetPoses.unwrap()(
|
||||||
|
46
src/error.rs
46
src/error.rs
@ -48,10 +48,10 @@ macro_rules! impl_raw_error {
|
|||||||
fn is_err(&self) -> bool {
|
fn is_err(&self) -> bool {
|
||||||
match *self {
|
match *self {
|
||||||
$none_name => {
|
$none_name => {
|
||||||
true
|
false
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
false
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -70,20 +70,34 @@ macro_rules! impl_raw_error {
|
|||||||
|
|
||||||
use std::ffi::CStr;
|
use std::ffi::CStr;
|
||||||
use openvr_sys::*;
|
use openvr_sys::*;
|
||||||
use openvr_sys::Enum_ETrackedPropertyError::*;
|
use openvr_sys::ETrackedPropertyError::*;
|
||||||
use openvr_sys::Enum_EVRInitError::*;
|
use openvr_sys::EVRInitError::*;
|
||||||
use openvr_sys::Enum_EVRRenderModelError::*;
|
use openvr_sys::EVRRenderModelError::*;
|
||||||
|
use openvr_sys::EVRTrackedCameraError::*;
|
||||||
|
|
||||||
impl_raw_error!(
|
impl_raw_error!(
|
||||||
system,
|
system,
|
||||||
Struct_VR_IVRSystem_FnTable,
|
VR_IVRSystem_FnTable,
|
||||||
GetPropErrorNameFromEnum,
|
GetPropErrorNameFromEnum,
|
||||||
ETrackedPropertyError,
|
ETrackedPropertyError,
|
||||||
ETrackedPropertyError_TrackedProp_Success);
|
ETrackedPropertyError_TrackedProp_Success);
|
||||||
|
|
||||||
|
impl_raw_error!(
|
||||||
|
render_models,
|
||||||
|
VR_IVRRenderModels_FnTable,
|
||||||
|
GetRenderModelErrorNameFromEnum,
|
||||||
|
EVRRenderModelError,
|
||||||
|
EVRRenderModelError_VRRenderModelError_None);
|
||||||
|
|
||||||
|
impl_raw_error!(
|
||||||
|
tracked_camera,
|
||||||
|
VR_IVRTrackedCamera_FnTable,
|
||||||
|
GetCameraErrorNameFromEnum,
|
||||||
|
EVRTrackedCameraError,
|
||||||
|
EVRTrackedCameraError_VRTrackedCameraError_None);
|
||||||
|
|
||||||
// The init error has some special function to retrieve string
|
// The init error has some special function to retrieve string
|
||||||
impl RawError for Enum_EVRInitError {
|
impl RawError for EVRInitError {
|
||||||
fn is_err(&self) -> bool {
|
fn is_err(&self) -> bool {
|
||||||
match *self {
|
match *self {
|
||||||
EVRInitError_VRInitError_None => {
|
EVRInitError_VRInitError_None => {
|
||||||
@ -103,21 +117,3 @@ impl RawError for Enum_EVRInitError {
|
|||||||
String::from(sstr)
|
String::from(sstr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// RenderModelError has no implementation in 0.1.19 unfortunately
|
|
||||||
impl RawError for Enum_EVRRenderModelError {
|
|
||||||
fn is_err(&self) -> bool {
|
|
||||||
match *self {
|
|
||||||
EVRRenderModelError_VRRenderModelError_None => {
|
|
||||||
true
|
|
||||||
},
|
|
||||||
_ => {
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn message(&self) -> String {
|
|
||||||
String::from(format!("{:?}", *self))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -12,7 +12,7 @@ impl IVRExtendedDisplay {
|
|||||||
/// Get the window bounds
|
/// Get the window bounds
|
||||||
pub fn window_bounds(&self) -> Rectangle {
|
pub fn window_bounds(&self) -> Rectangle {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ext = * { self.0 as *mut openvr_sys::Struct_VR_IVRExtendedDisplay_FnTable };
|
let ext = * { self.0 as *mut openvr_sys::VR_IVRExtendedDisplay_FnTable };
|
||||||
|
|
||||||
let mut size = Size{width: 0, height: 0};
|
let mut size = Size{width: 0, height: 0};
|
||||||
let mut pos = Position{x: 0, y: 0};
|
let mut pos = Position{x: 0, y: 0};
|
||||||
@ -35,7 +35,7 @@ impl IVRExtendedDisplay {
|
|||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let ext = * { self.0 as *mut openvr_sys::Struct_VR_IVRExtendedDisplay_FnTable };
|
let ext = * { self.0 as *mut openvr_sys::VR_IVRExtendedDisplay_FnTable };
|
||||||
|
|
||||||
let mut size = Size{width: 0, height: 0};
|
let mut size = Size{width: 0, height: 0};
|
||||||
let mut pos = Position{x: 0, y: 0};
|
let mut pos = Position{x: 0, y: 0};
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
extern crate openvr_sys;
|
extern crate openvr_sys;
|
||||||
use openvr_sys::Enum_EVRInitError::*;
|
|
||||||
use openvr_sys::Enum_EVRApplicationType::*;
|
use openvr_sys::EVRInitError::*;
|
||||||
|
use openvr_sys::EVRApplicationType::*;
|
||||||
|
|
||||||
pub mod common;
|
pub mod common;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
@ -9,6 +10,7 @@ pub mod system;
|
|||||||
pub mod extended_display;
|
pub mod extended_display;
|
||||||
pub mod compositor;
|
pub mod compositor;
|
||||||
pub mod render_models;
|
pub mod render_models;
|
||||||
|
pub mod tracked_camera;
|
||||||
pub mod subsystems;
|
pub mod subsystems;
|
||||||
|
|
||||||
pub use system::IVRSystem;
|
pub use system::IVRSystem;
|
||||||
@ -22,7 +24,7 @@ pub use error::*;
|
|||||||
pub use common::Eye;
|
pub use common::Eye;
|
||||||
|
|
||||||
/// Inits the open vr interface and returns the system
|
/// Inits the open vr interface and returns the system
|
||||||
pub fn init() -> Result<system::IVRSystem, Error<openvr_sys::Enum_EVRInitError>> {
|
pub fn init() -> Result<system::IVRSystem, Error<openvr_sys::EVRInitError>> {
|
||||||
let mut err = EVRInitError_VRInitError_None;
|
let mut err = EVRInitError_VRInitError_None;
|
||||||
let app_type = EVRApplicationType_VRApplication_Scene;
|
let app_type = EVRApplicationType_VRApplication_Scene;
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use openvr_sys;
|
use openvr_sys;
|
||||||
use openvr_sys::Enum_EVRRenderModelError::*;
|
use openvr_sys::EVRRenderModelError::*;
|
||||||
|
|
||||||
use std::string::String;
|
use std::string::String;
|
||||||
use std::ptr::null_mut;
|
use std::ptr::null_mut;
|
||||||
@ -7,7 +7,7 @@ use std::slice;
|
|||||||
use subsystems::render_models;
|
use subsystems::render_models;
|
||||||
use error::*;
|
use error::*;
|
||||||
|
|
||||||
pub struct IVRRenderModels(*const ());
|
pub struct IVRRenderModels(pub *const ());
|
||||||
|
|
||||||
pub struct RenderModel(*mut openvr_sys::RenderModel_t);
|
pub struct RenderModel(*mut openvr_sys::RenderModel_t);
|
||||||
pub struct RenderModelTexture(*mut openvr_sys::RenderModel_TextureMap_t);
|
pub struct RenderModelTexture(*mut openvr_sys::RenderModel_TextureMap_t);
|
||||||
@ -17,7 +17,7 @@ trait AsyncError {
|
|||||||
fn is_loading(&self) -> bool;
|
fn is_loading(&self) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsyncError for Error<openvr_sys::Enum_EVRRenderModelError> {
|
impl AsyncError for Error<openvr_sys::EVRRenderModelError> {
|
||||||
fn is_loading(&self) -> bool {
|
fn is_loading(&self) -> bool {
|
||||||
match self.to_raw() {
|
match self.to_raw() {
|
||||||
EVRRenderModelError_VRRenderModelError_Loading => {
|
EVRRenderModelError_VRRenderModelError_Loading => {
|
||||||
@ -34,7 +34,7 @@ impl Drop for RenderModel {
|
|||||||
/// will inform openvr that the memory for the render model is no longer required
|
/// will inform openvr that the memory for the render model is no longer required
|
||||||
fn drop (&mut self) {
|
fn drop (&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let models = * { render_models().unwrap().0 as *mut openvr_sys::Struct_VR_IVRRenderModels_FnTable};
|
let models = * { render_models().unwrap().0 as *mut openvr_sys::VR_IVRRenderModels_FnTable};
|
||||||
models.FreeRenderModel.unwrap()(
|
models.FreeRenderModel.unwrap()(
|
||||||
self.0
|
self.0
|
||||||
);
|
);
|
||||||
@ -46,7 +46,7 @@ impl Drop for RenderModelTexture {
|
|||||||
/// will inform openvr that the memory for the render model is no longer required
|
/// will inform openvr that the memory for the render model is no longer required
|
||||||
fn drop (&mut self) {
|
fn drop (&mut self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
let models = * { render_models().unwrap().0 as *mut openvr_sys::Struct_VR_IVRRenderModels_FnTable};
|
let models = * { render_models().unwrap().0 as *mut openvr_sys::VR_IVRRenderModels_FnTable};
|
||||||
models.FreeTexture.unwrap()(
|
models.FreeTexture.unwrap()(
|
||||||
self.0
|
self.0
|
||||||
);
|
);
|
||||||
@ -73,9 +73,9 @@ impl RenderModel {
|
|||||||
|
|
||||||
/// asynchronosly loads the texture for the current render model
|
/// asynchronosly loads the texture for the current render model
|
||||||
/// see IVRRenderModels::load_async for info how openvr async work
|
/// see IVRRenderModels::load_async for info how openvr async work
|
||||||
pub fn load_texture_async(&self) -> Result<RenderModelTexture, Error<openvr_sys::Enum_EVRRenderModelError>> {
|
pub fn load_texture_async(&self) -> Result<RenderModelTexture, Error<openvr_sys::EVRRenderModelError>> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let models = * { render_models().unwrap().0 as *mut openvr_sys::Struct_VR_IVRRenderModels_FnTable};
|
let models = * { render_models().unwrap().0 as *mut openvr_sys::VR_IVRRenderModels_FnTable};
|
||||||
let mut resp: *mut openvr_sys::RenderModel_TextureMap_t = null_mut();
|
let mut resp: *mut openvr_sys::RenderModel_TextureMap_t = null_mut();
|
||||||
|
|
||||||
let err = models.LoadTexture_Async.unwrap()(
|
let err = models.LoadTexture_Async.unwrap()(
|
||||||
@ -96,7 +96,7 @@ impl RenderModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// loads the texture for current model
|
/// loads the texture for current model
|
||||||
pub fn load_texture(&self) -> Result<RenderModelTexture, Error<openvr_sys::Enum_EVRRenderModelError>> {
|
pub fn load_texture(&self) -> Result<RenderModelTexture, Error<openvr_sys::EVRRenderModelError>> {
|
||||||
use std;
|
use std;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
@ -144,7 +144,7 @@ impl IVRRenderModels {
|
|||||||
/// Returns the amount of render models available
|
/// Returns the amount of render models available
|
||||||
pub fn get_count(&self) -> u32 {
|
pub fn get_count(&self) -> u32 {
|
||||||
unsafe {
|
unsafe {
|
||||||
let models = * { self.0 as *mut openvr_sys::Struct_VR_IVRRenderModels_FnTable};
|
let models = * { self.0 as *mut openvr_sys::VR_IVRRenderModels_FnTable};
|
||||||
|
|
||||||
models.GetRenderModelCount.unwrap()()
|
models.GetRenderModelCount.unwrap()()
|
||||||
}
|
}
|
||||||
@ -153,7 +153,7 @@ impl IVRRenderModels {
|
|||||||
/// Returns the name of an available render model
|
/// Returns the name of an available render model
|
||||||
pub fn get_name(&self, index: u32) -> String {
|
pub fn get_name(&self, index: u32) -> String {
|
||||||
unsafe {
|
unsafe {
|
||||||
let models = * { self.0 as *mut openvr_sys::Struct_VR_IVRRenderModels_FnTable};
|
let models = * { self.0 as *mut openvr_sys::VR_IVRRenderModels_FnTable};
|
||||||
let name_out = String::with_capacity(256);
|
let name_out = String::with_capacity(256);
|
||||||
|
|
||||||
let size = models.GetRenderModelName.unwrap()(
|
let size = models.GetRenderModelName.unwrap()(
|
||||||
@ -199,7 +199,7 @@ impl IVRRenderModels {
|
|||||||
use std;
|
use std;
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let models = * { self.0 as *mut openvr_sys::Struct_VR_IVRRenderModels_FnTable};
|
let models = * { self.0 as *mut openvr_sys::VR_IVRRenderModels_FnTable};
|
||||||
let mut resp: *mut openvr_sys::RenderModel_t = null_mut();
|
let mut resp: *mut openvr_sys::RenderModel_t = null_mut();
|
||||||
let cname = std::ffi::CString::new(name.as_str()).unwrap();
|
let cname = std::ffi::CString::new(name.as_str()).unwrap();
|
||||||
let rawname = cname.into_raw();
|
let rawname = cname.into_raw();
|
||||||
|
@ -1,16 +1,17 @@
|
|||||||
extern crate openvr_sys;
|
extern crate openvr_sys;
|
||||||
use openvr_sys::Enum_EVRInitError::*;
|
use openvr_sys::EVRInitError::*;
|
||||||
|
|
||||||
use error::*;
|
use error::*;
|
||||||
use system::IVRSystem;
|
use system::IVRSystem;
|
||||||
use extended_display::IVRExtendedDisplay;
|
use extended_display::IVRExtendedDisplay;
|
||||||
use compositor::IVRCompositor;
|
use compositor::IVRCompositor;
|
||||||
use render_models::IVRRenderModels;
|
use render_models::IVRRenderModels;
|
||||||
|
use tracked_camera::IVRTrackedCamera;
|
||||||
|
|
||||||
use std;
|
use std;
|
||||||
|
|
||||||
/// gets the current vr system interface (initialization is required beforehand)
|
/// gets the current vr system interface (initialization is required beforehand)
|
||||||
pub fn system() -> Result<IVRSystem, Error<openvr_sys::Enum_EVRInitError>> {
|
pub fn system() -> Result<IVRSystem, Error<openvr_sys::EVRInitError>> {
|
||||||
let mut err = EVRInitError_VRInitError_None;
|
let mut err = EVRInitError_VRInitError_None;
|
||||||
let name = std::ffi::CString::new("FnTable:IVRSystem_012").unwrap();
|
let name = std::ffi::CString::new("FnTable:IVRSystem_012").unwrap();
|
||||||
let ptr = unsafe {
|
let ptr = unsafe {
|
||||||
@ -30,7 +31,7 @@ pub fn system() -> Result<IVRSystem, Error<openvr_sys::Enum_EVRInitError>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// gets the current vr extended display interface (initialization is required beforehand)
|
/// gets the current vr extended display interface (initialization is required beforehand)
|
||||||
pub fn extended_display() -> Result<IVRExtendedDisplay, Error<openvr_sys::Enum_EVRInitError>> {
|
pub fn extended_display() -> Result<IVRExtendedDisplay, Error<openvr_sys::EVRInitError>> {
|
||||||
let mut err = EVRInitError_VRInitError_None;
|
let mut err = EVRInitError_VRInitError_None;
|
||||||
let name = std::ffi::CString::new("FnTable:IVRExtendedDisplay_001").unwrap();
|
let name = std::ffi::CString::new("FnTable:IVRExtendedDisplay_001").unwrap();
|
||||||
let ptr = unsafe {
|
let ptr = unsafe {
|
||||||
@ -50,7 +51,7 @@ pub fn extended_display() -> Result<IVRExtendedDisplay, Error<openvr_sys::Enum_E
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// gets the current vr extended display interface (initialization is required beforehand)
|
/// gets the current vr extended display interface (initialization is required beforehand)
|
||||||
pub fn compositor() -> Result<IVRCompositor, Error<openvr_sys::Enum_EVRInitError>> {
|
pub fn compositor() -> Result<IVRCompositor, Error<openvr_sys::EVRInitError>> {
|
||||||
let mut err = EVRInitError_VRInitError_None;
|
let mut err = EVRInitError_VRInitError_None;
|
||||||
let name = std::ffi::CString::new("FnTable:IVRCompositor_013").unwrap();
|
let name = std::ffi::CString::new("FnTable:IVRCompositor_013").unwrap();
|
||||||
let ptr = unsafe {
|
let ptr = unsafe {
|
||||||
@ -70,7 +71,7 @@ pub fn compositor() -> Result<IVRCompositor, Error<openvr_sys::Enum_EVRInitError
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// gets the current vr extended display interface (initialization is required beforehand)
|
/// gets the current vr extended display interface (initialization is required beforehand)
|
||||||
pub fn render_models() -> Result<IVRRenderModels, Error<openvr_sys::Enum_EVRInitError>> {
|
pub fn render_models() -> Result<IVRRenderModels, Error<openvr_sys::EVRInitError>> {
|
||||||
let mut err = EVRInitError_VRInitError_None;
|
let mut err = EVRInitError_VRInitError_None;
|
||||||
let name = std::ffi::CString::new("FnTable:IVRRenderModels_005").unwrap();
|
let name = std::ffi::CString::new("FnTable:IVRRenderModels_005").unwrap();
|
||||||
let ptr = unsafe {
|
let ptr = unsafe {
|
||||||
@ -88,3 +89,23 @@ pub fn render_models() -> Result<IVRRenderModels, Error<openvr_sys::Enum_EVRInit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// gets the current vr extended display interface (initialization is required beforehand)
|
||||||
|
pub fn tracked_camera() -> Result<IVRTrackedCamera, Error<openvr_sys::EVRInitError>> {
|
||||||
|
let mut err = EVRInitError_VRInitError_None;
|
||||||
|
let name = std::ffi::CString::new("FnTable:IVRTrackedCamera_003").unwrap();
|
||||||
|
let ptr = unsafe {
|
||||||
|
openvr_sys::VR_GetGenericInterface(name.as_ptr(), &mut err)
|
||||||
|
};
|
||||||
|
|
||||||
|
match err {
|
||||||
|
EVRInitError_VRInitError_None => {
|
||||||
|
unsafe {
|
||||||
|
return Ok(IVRTrackedCamera::from_raw(ptr as *const ()));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
return Err(Error::from_raw(err));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use openvr_sys;
|
use openvr_sys;
|
||||||
use openvr_sys::Enum_EGraphicsAPIConvention::*;
|
use openvr_sys::EGraphicsAPIConvention::*;
|
||||||
use openvr_sys::Enum_ETrackingUniverseOrigin::*;
|
use openvr_sys::ETrackingUniverseOrigin::*;
|
||||||
|
|
||||||
use common::*;
|
use common::*;
|
||||||
use tracking::*;
|
use tracking::*;
|
||||||
@ -15,7 +15,7 @@ impl IVRSystem {
|
|||||||
/// Get the recommended render target size
|
/// Get the recommended render target size
|
||||||
pub fn recommended_render_target_size(&self) -> Size {
|
pub fn recommended_render_target_size(&self) -> Size {
|
||||||
unsafe {
|
unsafe {
|
||||||
let system = * { self.0 as *mut openvr_sys::Struct_VR_IVRSystem_FnTable };
|
let system = * { self.0 as *mut openvr_sys::VR_IVRSystem_FnTable };
|
||||||
|
|
||||||
let mut size = Size{width: 0, height: 0};
|
let mut size = Size{width: 0, height: 0};
|
||||||
system.GetRecommendedRenderTargetSize.unwrap()(
|
system.GetRecommendedRenderTargetSize.unwrap()(
|
||||||
@ -32,7 +32,7 @@ impl IVRSystem {
|
|||||||
/// assumes opengl conventions
|
/// assumes opengl conventions
|
||||||
pub fn projection_matrix(&self, eye: Eye, near: f32, far: f32) -> [[f32; 4]; 4] {
|
pub fn projection_matrix(&self, eye: Eye, near: f32, far: f32) -> [[f32; 4]; 4] {
|
||||||
unsafe {
|
unsafe {
|
||||||
let system = * { self.0 as *mut openvr_sys::Struct_VR_IVRSystem_FnTable };
|
let system = * { self.0 as *mut openvr_sys::VR_IVRSystem_FnTable };
|
||||||
|
|
||||||
let mat = system.GetProjectionMatrix.unwrap()(
|
let mat = system.GetProjectionMatrix.unwrap()(
|
||||||
eye.to_raw(),
|
eye.to_raw(),
|
||||||
@ -47,7 +47,7 @@ impl IVRSystem {
|
|||||||
/// Computes the distortion caused by the optics
|
/// Computes the distortion caused by the optics
|
||||||
pub fn compute_distortion(&self, eye: Eye, u: f32, v: f32) -> DistortionCoordinates {
|
pub fn compute_distortion(&self, eye: Eye, u: f32, v: f32) -> DistortionCoordinates {
|
||||||
unsafe {
|
unsafe {
|
||||||
let system = * { self.0 as *mut openvr_sys::Struct_VR_IVRSystem_FnTable };
|
let system = * { self.0 as *mut openvr_sys::VR_IVRSystem_FnTable };
|
||||||
let coord = system.ComputeDistortion.unwrap()(
|
let coord = system.ComputeDistortion.unwrap()(
|
||||||
eye.to_raw(),
|
eye.to_raw(),
|
||||||
u, v
|
u, v
|
||||||
@ -63,7 +63,7 @@ impl IVRSystem {
|
|||||||
/// Computes the distortion caused by the optics
|
/// Computes the distortion caused by the optics
|
||||||
pub fn eye_to_head_transform(&self, eye: Eye) -> [[f32; 4]; 3] {
|
pub fn eye_to_head_transform(&self, eye: Eye) -> [[f32; 4]; 3] {
|
||||||
unsafe {
|
unsafe {
|
||||||
let system = * { self.0 as *mut openvr_sys::Struct_VR_IVRSystem_FnTable };
|
let system = * { self.0 as *mut openvr_sys::VR_IVRSystem_FnTable };
|
||||||
let mat = system.GetEyeToHeadTransform.unwrap()(
|
let mat = system.GetEyeToHeadTransform.unwrap()(
|
||||||
eye.to_raw(),
|
eye.to_raw(),
|
||||||
);
|
);
|
||||||
@ -74,7 +74,7 @@ impl IVRSystem {
|
|||||||
/// Computes the distortion caused by the optics
|
/// Computes the distortion caused by the optics
|
||||||
pub fn time_since_last_vsync(&self) -> Option<(f32, u64)> {
|
pub fn time_since_last_vsync(&self) -> Option<(f32, u64)> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let system = * { self.0 as *mut openvr_sys::Struct_VR_IVRSystem_FnTable };
|
let system = * { self.0 as *mut openvr_sys::VR_IVRSystem_FnTable };
|
||||||
let mut frame = 0;
|
let mut frame = 0;
|
||||||
let mut sync = 0.;
|
let mut sync = 0.;
|
||||||
let found = system.GetTimeSinceLastVsync.unwrap()(
|
let found = system.GetTimeSinceLastVsync.unwrap()(
|
||||||
@ -98,7 +98,7 @@ impl IVRSystem {
|
|||||||
use std;
|
use std;
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let system = * { self.0 as *mut openvr_sys::Struct_VR_IVRSystem_FnTable };
|
let system = * { self.0 as *mut openvr_sys::VR_IVRSystem_FnTable };
|
||||||
let mut data: [openvr_sys::TrackedDevicePose_t; 16] = std::mem::zeroed();
|
let mut data: [openvr_sys::TrackedDevicePose_t; 16] = std::mem::zeroed();
|
||||||
system.GetDeviceToAbsoluteTrackingPose.unwrap()(
|
system.GetDeviceToAbsoluteTrackingPose.unwrap()(
|
||||||
ETrackingUniverseOrigin_TrackingUniverseSeated,
|
ETrackingUniverseOrigin_TrackingUniverseSeated,
|
||||||
|
29
src/tracked_camera.rs
Normal file
29
src/tracked_camera.rs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
use openvr_sys;
|
||||||
|
|
||||||
|
use tracking::*;
|
||||||
|
use error::*;
|
||||||
|
|
||||||
|
pub struct IVRTrackedCamera(pub *const ());
|
||||||
|
|
||||||
|
impl IVRTrackedCamera {
|
||||||
|
pub unsafe fn from_raw(ptr: *const ()) -> Self {
|
||||||
|
IVRTrackedCamera(ptr as *mut ())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// checks whether the current system has a camera
|
||||||
|
pub fn has_camera(&self, device: &TrackedDevicePose) -> Result<bool, Error<openvr_sys::EVRTrackedCameraError>> {
|
||||||
|
unsafe {
|
||||||
|
let cam = * { self.0 as *mut openvr_sys::VR_IVRTrackedCamera_FnTable };
|
||||||
|
let mut has_cam = 0i32;
|
||||||
|
|
||||||
|
let error = Error::from_raw(
|
||||||
|
cam.HasCamera.unwrap()(device.index as u32, &mut has_cam as *mut i32));
|
||||||
|
|
||||||
|
if error.is_ok() {
|
||||||
|
return Ok(has_cam > 0i32);
|
||||||
|
} else {
|
||||||
|
return Err(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
use openvr_sys;
|
use openvr_sys;
|
||||||
use openvr_sys::Enum_ETrackedPropertyError::*;
|
use openvr_sys::ETrackedPropertyError::*;
|
||||||
|
|
||||||
use subsystems::*;
|
use subsystems::*;
|
||||||
use error::*;
|
use error::*;
|
||||||
@ -27,8 +27,8 @@ pub enum TrackedDeviceStringProperty {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl TrackedDeviceStringProperty {
|
impl TrackedDeviceStringProperty {
|
||||||
pub fn to_raw(&self) -> openvr_sys::Enum_ETrackedDeviceProperty {
|
pub fn to_raw(&self) -> openvr_sys::ETrackedDeviceProperty {
|
||||||
use openvr_sys::Enum_ETrackedDeviceProperty::*;
|
use openvr_sys::ETrackedDeviceProperty::*;
|
||||||
use self::TrackedDeviceStringProperty::*;
|
use self::TrackedDeviceStringProperty::*;
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
@ -64,9 +64,9 @@ pub enum TrackedDeviceClass {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl TrackedDeviceClass {
|
impl TrackedDeviceClass {
|
||||||
pub fn to_raw(&self) -> openvr_sys::Enum_ETrackedDeviceClass {
|
pub fn to_raw(&self) -> openvr_sys::ETrackedDeviceClass {
|
||||||
use self::TrackedDeviceClass::*;
|
use self::TrackedDeviceClass::*;
|
||||||
use openvr_sys::Enum_ETrackedDeviceClass::*;
|
use openvr_sys::ETrackedDeviceClass::*;
|
||||||
|
|
||||||
match *self {
|
match *self {
|
||||||
Invalid => ETrackedDeviceClass_TrackedDeviceClass_Invalid,
|
Invalid => ETrackedDeviceClass_TrackedDeviceClass_Invalid,
|
||||||
@ -77,9 +77,9 @@ impl TrackedDeviceClass {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_raw(raw: openvr_sys::Enum_ETrackedDeviceClass) -> Self {
|
pub fn from_raw(raw: openvr_sys::ETrackedDeviceClass) -> Self {
|
||||||
use self::TrackedDeviceClass::*;
|
use self::TrackedDeviceClass::*;
|
||||||
use openvr_sys::Enum_ETrackedDeviceClass::*;
|
use openvr_sys::ETrackedDeviceClass::*;
|
||||||
|
|
||||||
match raw {
|
match raw {
|
||||||
ETrackedDeviceClass_TrackedDeviceClass_Invalid => Invalid,
|
ETrackedDeviceClass_TrackedDeviceClass_Invalid => Invalid,
|
||||||
@ -105,15 +105,15 @@ impl TrackedDevicePose {
|
|||||||
// returns the device class of the tracked object
|
// returns the device class of the tracked object
|
||||||
pub fn device_class(&self) -> TrackedDeviceClass {
|
pub fn device_class(&self) -> TrackedDeviceClass {
|
||||||
unsafe {
|
unsafe {
|
||||||
let system = * { system().unwrap().0 as *mut openvr_sys::Struct_VR_IVRSystem_FnTable};
|
let system = * { system().unwrap().0 as *mut openvr_sys::VR_IVRSystem_FnTable};
|
||||||
TrackedDeviceClass::from_raw(system.GetTrackedDeviceClass.unwrap()(self.index as u32))
|
TrackedDeviceClass::from_raw(system.GetTrackedDeviceClass.unwrap()(self.index as u32))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// gets a propery as a string
|
/// gets a propery as a string
|
||||||
pub fn get_property_string(&self, property: TrackedDeviceStringProperty) -> Result<String, Error<openvr_sys::Enum_ETrackedPropertyError>> {
|
pub fn get_property_string(&self, property: TrackedDeviceStringProperty) -> Result<String, Error<openvr_sys::ETrackedPropertyError>> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let system = * { system().unwrap().0 as *mut openvr_sys::Struct_VR_IVRSystem_FnTable};
|
let system = * { system().unwrap().0 as *mut openvr_sys::VR_IVRSystem_FnTable};
|
||||||
|
|
||||||
let val_out = String::with_capacity(256);
|
let val_out = String::with_capacity(256);
|
||||||
let mut err = ETrackedPropertyError_TrackedProp_Success;
|
let mut err = ETrackedPropertyError_TrackedProp_Success;
|
||||||
|
Reference in New Issue
Block a user