feat: ipd label

This commit is contained in:
galister
2024-03-28 11:51:10 +01:00
parent 1438d3e7eb
commit 810c0cac63
5 changed files with 39 additions and 3 deletions

View File

@@ -34,6 +34,7 @@ pub enum TrackedDeviceRole {
pub struct InputState {
pub hmd: Affine3A,
pub ipd: f32,
pub pointers: [Pointer; 2],
pub devices: Vec<TrackedDevice>,
}
@@ -42,6 +43,7 @@ impl InputState {
pub fn new() -> Self {
Self {
hmd: Affine3A::IDENTITY,
ipd: 0.0,
pointers: [Pointer::new(0), Pointer::new(1)],
devices: Vec::new(),
}

View File

@@ -93,6 +93,14 @@ pub fn openvr_run(running: Arc<AtomicBool>) -> Result<(), BackendError> {
AppState::from_graphics(graphics)?
};
if let Ok(ipd) = system_mgr.get_tracked_device_property::<f32>(
TrackedDeviceIndex::HMD,
ETrackedDeviceProperty::Prop_UserIpdMeters_Float,
) {
state.input_state.ipd = (ipd * 10000.0).round() * 0.1;
log::info!("IPD: {:.1} mm", state.input_state.ipd);
}
let _ = install_manifest(&mut app_mgr);
let mut overlays = OverlayContainer::<OpenVrOverlayData>::new(&mut state)?;
@@ -162,6 +170,18 @@ pub fn openvr_run(running: Arc<AtomicBool>) -> Result<(), BackendError> {
| EVREventType::VREvent_SceneApplicationChanged => {
playspace.playspace_changed(&mut compositor_mgr, &mut chaperone_mgr);
}
EVREventType::VREvent_IpdChanged => {
if let Ok(ipd) = system_mgr.get_tracked_device_property::<f32>(
TrackedDeviceIndex::HMD,
ETrackedDeviceProperty::Prop_UserIpdMeters_Float,
) {
let ipd = (ipd * 10000.0).round() * 0.1;
if (ipd - state.input_state.ipd).abs() > 0.05 {
log::info!("IPD: {:.1} mm -> {:.1} mm", state.input_state.ipd, ipd);
}
state.input_state.ipd = ipd;
}
}
_ => {}
}
}

View File

@@ -109,10 +109,12 @@ pub(super) unsafe fn create_overlay_session(
}
}
pub(super) fn hmd_pose_from_views(views: &[xr::View]) -> Affine3A {
pub(super) fn hmd_pose_from_views(views: &[xr::View]) -> (Affine3A, f32) {
let ipd;
let pos = {
let pos0: Vec3 = unsafe { std::mem::transmute(views[0].pose.position) };
let pos1: Vec3 = unsafe { std::mem::transmute(views[1].pose.position) };
ipd = (pos0.distance(pos1) * 1000.0).round() * 0.1;
(pos0 + pos1) * 0.5
};
let rot = {
@@ -121,7 +123,7 @@ pub(super) fn hmd_pose_from_views(views: &[xr::View]) -> Affine3A {
quat_lerp(rot0, rot1, 0.5)
};
Affine3A::from_rotation_translation(rot, pos)
(Affine3A::from_rotation_translation(rot, pos), ipd)
}
fn quat_lerp(a: Quat, mut b: Quat, t: f32) -> Quat {

View File

@@ -220,7 +220,8 @@ pub fn openxr_run(running: Arc<AtomicBool>) -> Result<(), BackendError> {
&xr_state.stage,
)?;
app_state.input_state.hmd = helpers::hmd_pose_from_views(&views);
(app_state.input_state.hmd, app_state.input_state.ipd) =
helpers::hmd_pose_from_views(&views);
overlays
.iter_mut()