mirror of
https://github.com/mii443/rust-openvr.git
synced 2025-08-22 16:25:36 +00:00
@ -22,7 +22,7 @@ use super::*;
|
||||
impl<'a> Compositor<'a> {
|
||||
pub fn vulkan_instance_extensions_required(&self) -> Vec<CString> {
|
||||
let temp = unsafe {
|
||||
let n = (self.0.GetVulkanInstanceExtensionsRequired.unwrap())(ptr::null_mut(), 0);
|
||||
let n = self.0.GetVulkanInstanceExtensionsRequired.unwrap()(ptr::null_mut(), 0);
|
||||
let mut buffer: Vec<u8> = Vec::new();
|
||||
buffer.resize(n as usize, mem::uninitialized());
|
||||
(self.0.GetVulkanInstanceExtensionsRequired.unwrap())(buffer.as_mut_ptr() as *mut i8, n);
|
||||
@ -33,7 +33,7 @@ impl<'a> Compositor<'a> {
|
||||
|
||||
pub fn vulkan_device_extensions_required(&self, physical_device: *mut VkPhysicalDevice_T) -> Vec<CString> {
|
||||
let temp = unsafe {
|
||||
let n = (self.0.GetVulkanDeviceExtensionsRequired.unwrap())(physical_device, ptr::null_mut(), 0);
|
||||
let n = self.0.GetVulkanDeviceExtensionsRequired.unwrap()(physical_device, ptr::null_mut(), 0);
|
||||
let mut buffer: Vec<u8> = Vec::new();
|
||||
buffer.resize(n as usize, mem::uninitialized());
|
||||
(self.0.GetVulkanDeviceExtensionsRequired.unwrap())(physical_device as *mut _, buffer.as_mut_ptr() as *mut i8, n);
|
||||
@ -44,7 +44,7 @@ impl<'a> Compositor<'a> {
|
||||
|
||||
/// Sets tracking space returned by WaitGetPoses
|
||||
pub fn set_tracking_space(&self, origin: TrackingUniverseOrigin) {
|
||||
unsafe { (self.0.SetTrackingSpace.unwrap())(origin as sys::ETrackingUniverseOrigin) }
|
||||
unsafe { self.0.SetTrackingSpace.unwrap()(origin as sys::ETrackingUniverseOrigin) }
|
||||
}
|
||||
|
||||
/// Block until a few milliseconds before the next vsync, then return poses for the next step of rendering and game
|
||||
@ -54,8 +54,8 @@ impl<'a> Compositor<'a> {
|
||||
pub fn wait_get_poses(&self) -> Result<WaitPoses, CompositorError> {
|
||||
unsafe {
|
||||
let mut result: WaitPoses = mem::uninitialized();
|
||||
let e = (self.0.WaitGetPoses.unwrap())(result.render.data.as_mut().as_mut_ptr() as *mut _, result.render.data.len() as u32,
|
||||
result.game.data.as_mut().as_mut_ptr() as *mut _, result.game.data.len() as u32);
|
||||
let e = self.0.WaitGetPoses.unwrap()(result.render.as_mut().as_mut_ptr() as *mut _, result.render.len() as u32,
|
||||
result.game.as_mut().as_mut_ptr() as *mut _, result.game.len() as u32);
|
||||
if e == sys::EVRCompositorError_EVRCompositorError_VRCompositorError_None {
|
||||
Ok(result)
|
||||
} else {
|
||||
|
12
src/lib.rs
12
src/lib.rs
@ -1,7 +1,7 @@
|
||||
extern crate openvr_sys;
|
||||
|
||||
use std::sync::atomic::{Ordering, AtomicBool, ATOMIC_BOOL_INIT};
|
||||
use std::{fmt, error, slice};
|
||||
use std::{fmt, error};
|
||||
use std::ffi::CStr;
|
||||
|
||||
use openvr_sys as sys;
|
||||
@ -123,13 +123,3 @@ pub enum Eye {
|
||||
Left = sys::EVREye_EVREye_Eye_Left as isize,
|
||||
Right = sys::EVREye_EVREye_Eye_Right as isize,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct TrackedDevicePoses {
|
||||
data: [TrackedDevicePose; sys::k_unMaxTrackedDeviceCount as usize]
|
||||
}
|
||||
|
||||
impl TrackedDevicePoses {
|
||||
pub fn iter(&self) -> slice::Iter<TrackedDevicePose> { self.data.iter() }
|
||||
pub fn len(&self) -> usize { self.data.len() }
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ impl<'a> System<'a> {
|
||||
pub fn recommended_render_target_size(&self) -> (u32, u32) {
|
||||
unsafe {
|
||||
let mut result: (u32, u32) = mem::uninitialized();
|
||||
(self.0.GetRecommendedRenderTargetSize.unwrap())(&mut result.0, &mut result.1);
|
||||
self.0.GetRecommendedRenderTargetSize.unwrap()(&mut result.0, &mut result.1);
|
||||
result
|
||||
}
|
||||
}
|
||||
@ -27,7 +27,7 @@ impl<'a> System<'a> {
|
||||
///
|
||||
/// Clip plane distances are in meters.
|
||||
pub fn projection_matrix(&self, eye: Eye, near_z: f32, far_z: f32) -> [[f32; 4]; 4] {
|
||||
unsafe { (self.0.GetProjectionMatrix.unwrap())(eye as sys::EVREye, near_z, far_z) }.m
|
||||
unsafe { self.0.GetProjectionMatrix.unwrap()(eye as sys::EVREye, near_z, far_z) }.m
|
||||
}
|
||||
|
||||
/// Returns the raw project values to use for the specified eye. Most games should use GetProjectionMatrix instead
|
||||
@ -36,7 +36,7 @@ impl<'a> System<'a> {
|
||||
pub fn projection_raw(&self, eye: Eye) -> RawProjection {
|
||||
unsafe {
|
||||
let mut result: RawProjection = mem::uninitialized();
|
||||
(self.0.GetProjectionRaw.unwrap())(eye as sys::EVREye, &mut result.left, &mut result.right, &mut result.top, &mut result.bottom);
|
||||
self.0.GetProjectionRaw.unwrap()(eye as sys::EVREye, &mut result.left, &mut result.right, &mut result.top, &mut result.bottom);
|
||||
result
|
||||
}
|
||||
}
|
||||
@ -55,7 +55,7 @@ impl<'a> System<'a> {
|
||||
pub fn time_since_last_vsync(&self) -> Option<(f32, u64)> {
|
||||
unsafe {
|
||||
let mut result: (f32, u64) = mem::uninitialized();
|
||||
if (self.0.GetTimeSinceLastVsync.unwrap())(&mut result.0, &mut result.1) {
|
||||
if self.0.GetTimeSinceLastVsync.unwrap()(&mut result.0, &mut result.1) {
|
||||
Some(result)
|
||||
} else {
|
||||
None
|
||||
@ -80,15 +80,15 @@ impl<'a> System<'a> {
|
||||
pub fn device_to_absolute_tracking_pose(&self, origin: TrackingUniverseOrigin, predicted_seconds_to_photons_from_now: f32) -> TrackedDevicePoses {
|
||||
unsafe {
|
||||
let mut result: TrackedDevicePoses = mem::uninitialized();
|
||||
(self.0.GetDeviceToAbsoluteTrackingPose.unwrap())(origin as sys::ETrackingUniverseOrigin, predicted_seconds_to_photons_from_now,
|
||||
result.data.as_mut().as_mut_ptr() as *mut _, result.data.len() as u32);
|
||||
self.0.GetDeviceToAbsoluteTrackingPose.unwrap()(origin as sys::ETrackingUniverseOrigin, predicted_seconds_to_photons_from_now,
|
||||
result.as_mut().as_mut_ptr() as *mut _, result.len() as u32);
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
pub fn tracked_device_class(&self, index: TrackedDeviceIndex) -> TrackedDeviceClass {
|
||||
use self::TrackedDeviceClass::*;
|
||||
match unsafe { (self.0.GetTrackedDeviceClass.unwrap())(index) } {
|
||||
match unsafe { self.0.GetTrackedDeviceClass.unwrap()(index) } {
|
||||
sys::ETrackedDeviceClass_ETrackedDeviceClass_TrackedDeviceClass_Invalid => Invalid,
|
||||
sys::ETrackedDeviceClass_ETrackedDeviceClass_TrackedDeviceClass_HMD => HMD,
|
||||
sys::ETrackedDeviceClass_ETrackedDeviceClass_TrackedDeviceClass_Controller => Controller,
|
||||
@ -100,7 +100,7 @@ impl<'a> System<'a> {
|
||||
}
|
||||
|
||||
pub fn is_tracked_device_connected(&self, index: TrackedDeviceIndex) -> bool {
|
||||
unsafe { (self.0.IsTrackedDeviceConnected.unwrap())(index) }
|
||||
unsafe { self.0.IsTrackedDeviceConnected.unwrap()(index) }
|
||||
}
|
||||
|
||||
pub fn poll_next_event_with_pose(&self, origin: TrackingUniverseOrigin) -> Option<(EventInfo, TrackedDevicePose)> {
|
||||
@ -136,6 +136,22 @@ impl<'a> System<'a> {
|
||||
green: coord.rfGreen
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns the device index associated with a specific role, for example the left hand or the right hand.
|
||||
pub fn tracked_device_index_for_controller_role(&self, role: TrackedControllerRole) -> Option<TrackedDeviceIndex> {
|
||||
let x = unsafe { self.0.GetTrackedDeviceIndexForControllerRole.unwrap()(role as sys::ETrackedControllerRole) };
|
||||
if x == tracked_device_index::INVALID { None } else { Some(x) }
|
||||
}
|
||||
|
||||
/// Returns the controller type associated with a device index.
|
||||
pub fn get_controller_role_for_tracked_device_index(&self, i: TrackedDeviceIndex) -> Option<TrackedControllerRole> {
|
||||
let x = unsafe { self.0.GetControllerRoleForTrackedDeviceIndex.unwrap()(i) };
|
||||
match x {
|
||||
sys::ETrackedControllerRole_ETrackedControllerRole_TrackedControllerRole_LeftHand => Some(TrackedControllerRole::LeftHand),
|
||||
sys::ETrackedControllerRole_ETrackedControllerRole_TrackedControllerRole_RightHand => Some(TrackedControllerRole::RightHand),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Values represent the tangents of the half-angles from the center view axis
|
||||
|
@ -30,6 +30,7 @@ impl TrackedDevicePose {
|
||||
pub fn device_is_connected(&self) -> bool { self.0.bDeviceIsConnected }
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub enum TrackingResult {
|
||||
Uninitialized = sys::ETrackingResult_ETrackingResult_TrackingResult_Uninitialized as isize,
|
||||
CalibratingInProgress = sys::ETrackingResult_ETrackingResult_TrackingResult_Calibrating_InProgress as isize,
|
||||
@ -38,6 +39,7 @@ pub enum TrackingResult {
|
||||
RunningOutOfRange = sys::ETrackingResult_ETrackingResult_TrackingResult_Running_OutOfRange as isize,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub enum TrackedDeviceClass {
|
||||
Invalid = sys::ETrackedDeviceClass_ETrackedDeviceClass_TrackedDeviceClass_Invalid as isize,
|
||||
HMD = sys::ETrackedDeviceClass_ETrackedDeviceClass_TrackedDeviceClass_HMD as isize,
|
||||
@ -56,3 +58,11 @@ pub mod tracked_device_index {
|
||||
}
|
||||
|
||||
pub type TrackedDeviceProperty = sys::ETrackedDeviceProperty;
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub enum TrackedControllerRole {
|
||||
LeftHand = sys::ETrackedControllerRole_ETrackedControllerRole_TrackedControllerRole_LeftHand as isize,
|
||||
RightHand = sys::ETrackedControllerRole_ETrackedControllerRole_TrackedControllerRole_RightHand as isize,
|
||||
}
|
||||
|
||||
pub type TrackedDevicePoses = [TrackedDevicePose; sys::k_unMaxTrackedDeviceCount as usize];
|
||||
|
Reference in New Issue
Block a user