openxr haptics

This commit is contained in:
galister
2024-02-04 03:34:50 +01:00
parent d7c8b49efa
commit e846014a88
2 changed files with 20 additions and 2 deletions

View File

@@ -3,7 +3,10 @@ use std::time::{Duration, Instant};
use glam::{bool, Affine3A, Quat, Vec3};
use openxr as xr;
use crate::{backend::input::Pointer, state::AppState};
use crate::{
backend::input::{Haptics, Pointer},
state::AppState,
};
use super::XrState;
@@ -77,6 +80,21 @@ impl OpenXrInputSource {
}
}
pub fn haptics(&self, xr: &XrState, hand: usize, haptics: &Haptics) {
let action = &self.hands[hand].source.action_haptics;
let duration_nanos = (haptics.duration as f64) * 1_000_000_000.0;
let _ = action.apply_feedback(
&xr.session,
xr::Path::NULL,
&xr::HapticVibration::new()
.amplitude(haptics.intensity)
.frequency(haptics.frequency)
.duration(xr::Duration::from_nanos(duration_nanos as _)),
);
}
pub fn update(&self, xr: &XrState, state: &mut AppState) {
xr.session
.sync_actions(&[(&self.action_set).into()])

View File

@@ -233,7 +233,7 @@ pub fn openxr_run(running: Arc<AtomicBool>) -> Result<(), BackendError> {
&app_state.input_state.hmd,
);
if let Some(haptics) = haptics {
//TODO!
input_source.haptics(&xr_state, idx, haptics);
}
}