mirror of
https://github.com/mii443/rust-openvr.git
synced 2025-08-23 00:35:31 +00:00
added enum wrappers for all used enums
This commit is contained in:
@ -40,7 +40,7 @@ pub fn main() {
|
|||||||
|
|
||||||
for device in system.tracked_devices(0.0).connected_iter() {
|
for device in system.tracked_devices(0.0).connected_iter() {
|
||||||
println!("device found :) -> {}",
|
println!("device found :) -> {}",
|
||||||
device.get_property_string(openvr::ETrackedDeviceProperty_Prop_RenderModelName_String).unwrap_or_else(|_| { panic!("No render model")} ));
|
device.get_property_string(openvr::tracking::TrackedDeviceStringProperty::RenderModelName).unwrap_or_else(|_| { panic!("No render model")} ));
|
||||||
|
|
||||||
println!("\t{:?}", device);
|
println!("\t{:?}", device);
|
||||||
println!("\t{:?}", device.device_class());
|
println!("\t{:?}", device.device_class());
|
||||||
@ -210,7 +210,7 @@ pub fn main() {
|
|||||||
|
|
||||||
for device in tracked_devices.connected_iter() {
|
for device in tracked_devices.connected_iter() {
|
||||||
match device.device_class() {
|
match device.device_class() {
|
||||||
openvr::ETrackedDeviceClass_TrackedDeviceClass_HMD => {
|
openvr::tracking::TrackedDeviceClass::HMD => {
|
||||||
let matrix = {
|
let matrix = {
|
||||||
let raw = device.to_device;
|
let raw = device.to_device;
|
||||||
let mat = nalgebra::Matrix4::new(
|
let mat = nalgebra::Matrix4::new(
|
||||||
@ -223,7 +223,7 @@ pub fn main() {
|
|||||||
left_matrix *= matrix;
|
left_matrix *= matrix;
|
||||||
right_matrix *= matrix;
|
right_matrix *= matrix;
|
||||||
},
|
},
|
||||||
openvr::ETrackedDeviceClass_TrackedDeviceClass_TrackingReference => {
|
openvr::tracking::TrackedDeviceClass::TrackingReference => {
|
||||||
if once { continue; }
|
if once { continue; }
|
||||||
once = true;
|
once = true;
|
||||||
|
|
||||||
|
@ -59,6 +59,15 @@ impl TextureBounds {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn full() -> Self {
|
||||||
|
TextureBounds {
|
||||||
|
u_min: 0.0,
|
||||||
|
u_max: 1.0,
|
||||||
|
v_min: 0.0,
|
||||||
|
v_max: 1.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// 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{
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
extern crate openvr_sys;
|
extern crate openvr_sys;
|
||||||
pub use openvr_sys::Enum_EVRInitError::*;
|
use openvr_sys::Enum_EVRInitError::*;
|
||||||
pub use openvr_sys::Enum_EVRApplicationType::*;
|
use openvr_sys::Enum_EVRApplicationType::*;
|
||||||
pub use openvr_sys::Enum_ETrackedDeviceProperty::*;
|
|
||||||
pub use openvr_sys::Enum_ETrackedDeviceClass::*;
|
|
||||||
|
|
||||||
pub mod common;
|
pub mod common;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
|
@ -4,6 +4,93 @@ use openvr_sys::Enum_ETrackedPropertyError::*;
|
|||||||
use subsystems::*;
|
use subsystems::*;
|
||||||
use error::*;
|
use error::*;
|
||||||
|
|
||||||
|
/// Describes a string property of a tracked device
|
||||||
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
pub enum TrackedDeviceStringProperty {
|
||||||
|
TrackingSystemName,
|
||||||
|
ModelNumber,
|
||||||
|
SerialNumber,
|
||||||
|
RenderModelName,
|
||||||
|
ManufacturerName,
|
||||||
|
TrackingFirmwareVersion,
|
||||||
|
HardwareRevision,
|
||||||
|
AllWirelessDongleDescriptions,
|
||||||
|
ConnectedWirelessDongle,
|
||||||
|
FirmwareManualUpdateURL,
|
||||||
|
FirmwareProgrammingTarget,
|
||||||
|
DisplayMCImageLeft,
|
||||||
|
DisplayMCImageRight,
|
||||||
|
DisplayGCImage,
|
||||||
|
CameraFirmwareDescription,
|
||||||
|
AttachedDeviceId,
|
||||||
|
ModeLabel
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TrackedDeviceStringProperty {
|
||||||
|
pub fn to_raw(&self) -> openvr_sys::Enum_ETrackedDeviceProperty {
|
||||||
|
use openvr_sys::Enum_ETrackedDeviceProperty::*;
|
||||||
|
use self::TrackedDeviceStringProperty::*;
|
||||||
|
|
||||||
|
match *self {
|
||||||
|
TrackingSystemName => ETrackedDeviceProperty_Prop_TrackingSystemName_String,
|
||||||
|
ModelNumber => ETrackedDeviceProperty_Prop_ModelNumber_String,
|
||||||
|
SerialNumber => ETrackedDeviceProperty_Prop_SerialNumber_String,
|
||||||
|
RenderModelName => ETrackedDeviceProperty_Prop_RenderModelName_String,
|
||||||
|
ManufacturerName => ETrackedDeviceProperty_Prop_ManufacturerName_String,
|
||||||
|
TrackingFirmwareVersion => ETrackedDeviceProperty_Prop_TrackingFirmwareVersion_String,
|
||||||
|
HardwareRevision => ETrackedDeviceProperty_Prop_HardwareRevision_String,
|
||||||
|
AllWirelessDongleDescriptions => ETrackedDeviceProperty_Prop_AllWirelessDongleDescriptions_String,
|
||||||
|
ConnectedWirelessDongle => ETrackedDeviceProperty_Prop_ConnectedWirelessDongle_String,
|
||||||
|
FirmwareManualUpdateURL => ETrackedDeviceProperty_Prop_Firmware_ManualUpdateURL_String,
|
||||||
|
FirmwareProgrammingTarget => ETrackedDeviceProperty_Prop_Firmware_ProgrammingTarget_String,
|
||||||
|
DisplayMCImageLeft => ETrackedDeviceProperty_Prop_DisplayMCImageLeft_String,
|
||||||
|
DisplayMCImageRight => ETrackedDeviceProperty_Prop_DisplayMCImageRight_String,
|
||||||
|
DisplayGCImage => ETrackedDeviceProperty_Prop_DisplayGCImage_String,
|
||||||
|
CameraFirmwareDescription => ETrackedDeviceProperty_Prop_CameraFirmwareDescription_String,
|
||||||
|
AttachedDeviceId => ETrackedDeviceProperty_Prop_AttachedDeviceId_String,
|
||||||
|
ModeLabel => ETrackedDeviceProperty_Prop_ModeLabel_String
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Describes the class of a tracked device
|
||||||
|
#[derive(Debug, Copy, Clone)]
|
||||||
|
pub enum TrackedDeviceClass {
|
||||||
|
Invalid,
|
||||||
|
HMD,
|
||||||
|
Controller,
|
||||||
|
TrackingReference,
|
||||||
|
Other,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TrackedDeviceClass {
|
||||||
|
pub fn to_raw(&self) -> openvr_sys::Enum_ETrackedDeviceClass {
|
||||||
|
use self::TrackedDeviceClass::*;
|
||||||
|
use openvr_sys::Enum_ETrackedDeviceClass::*;
|
||||||
|
|
||||||
|
match *self {
|
||||||
|
Invalid => ETrackedDeviceClass_TrackedDeviceClass_Invalid,
|
||||||
|
HMD => ETrackedDeviceClass_TrackedDeviceClass_HMD,
|
||||||
|
Controller => ETrackedDeviceClass_TrackedDeviceClass_Controller,
|
||||||
|
TrackingReference => ETrackedDeviceClass_TrackedDeviceClass_TrackingReference,
|
||||||
|
Other => ETrackedDeviceClass_TrackedDeviceClass_Other,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn from_raw(raw: openvr_sys::Enum_ETrackedDeviceClass) -> Self {
|
||||||
|
use self::TrackedDeviceClass::*;
|
||||||
|
use openvr_sys::Enum_ETrackedDeviceClass::*;
|
||||||
|
|
||||||
|
match raw {
|
||||||
|
ETrackedDeviceClass_TrackedDeviceClass_Invalid => Invalid,
|
||||||
|
ETrackedDeviceClass_TrackedDeviceClass_HMD => HMD,
|
||||||
|
ETrackedDeviceClass_TrackedDeviceClass_Controller => Controller,
|
||||||
|
ETrackedDeviceClass_TrackedDeviceClass_TrackingReference => TrackingReference,
|
||||||
|
ETrackedDeviceClass_TrackedDeviceClass_Other => Other,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub struct TrackedDevicePose {
|
pub struct TrackedDevicePose {
|
||||||
pub index: usize,
|
pub index: usize,
|
||||||
@ -16,15 +103,15 @@ pub struct TrackedDevicePose {
|
|||||||
|
|
||||||
impl TrackedDevicePose {
|
impl TrackedDevicePose {
|
||||||
// returns the device class of the tracked object
|
// returns the device class of the tracked object
|
||||||
pub fn device_class(&self) -> openvr_sys::Enum_ETrackedDeviceClass {
|
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::Struct_VR_IVRSystem_FnTable};
|
||||||
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: openvr_sys::Enum_ETrackedDeviceProperty) -> Result<String, Error<openvr_sys::Enum_ETrackedPropertyError>> {
|
pub fn get_property_string(&self, property: TrackedDeviceStringProperty) -> Result<String, Error<openvr_sys::Enum_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::Struct_VR_IVRSystem_FnTable};
|
||||||
|
|
||||||
@ -33,7 +120,7 @@ impl TrackedDevicePose {
|
|||||||
|
|
||||||
let size = system.GetStringTrackedDeviceProperty.unwrap()(
|
let size = system.GetStringTrackedDeviceProperty.unwrap()(
|
||||||
self.index as u32,
|
self.index as u32,
|
||||||
property,
|
property.to_raw(),
|
||||||
val_out.as_ptr() as *mut i8,
|
val_out.as_ptr() as *mut i8,
|
||||||
256,
|
256,
|
||||||
&mut err
|
&mut err
|
||||||
|
Reference in New Issue
Block a user