openvr haptics

This commit is contained in:
galister
2024-02-04 03:16:30 +01:00
parent b5d970e5fd
commit d7c8b49efa
7 changed files with 76 additions and 23 deletions

View File

@@ -1,4 +1,4 @@
use std::{array, io::Write, path::Path};
use std::{array, io::Write, path::Path, time::Duration};
use ovr_overlay::{
input::{ActionHandle, ActionSetHandle, ActiveActionSet, InputManager, InputValueHandle},
@@ -11,7 +11,7 @@ use ovr_overlay::{
};
use crate::{
backend::input::{TrackedDevice, TrackedDeviceRole},
backend::input::{Haptics, TrackedDevice, TrackedDeviceRole},
state::AppState,
};
@@ -119,6 +119,18 @@ impl OpenVrInputSource {
})
}
pub fn haptics(&mut self, input: &mut InputManager, hand: usize, haptics: &Haptics) {
let hnd = self.hands[hand].haptics_hnd;
let _ = input.trigger_haptic_vibration_action(
hnd,
0.0,
Duration::from_secs_f32(haptics.duration),
haptics.frequency,
haptics.intensity,
INPUT_ANY,
);
}
pub fn update(
&mut self,
input: &mut InputManager,

View File

@@ -162,8 +162,8 @@ pub fn openvr_run(running: Arc<AtomicBool>) -> Result<(), BackendError> {
space_mover.update(&mut chaperone_mgr, &mut overlays, &state);
let pointer_lengths = interact(&mut overlays, &mut state);
for (idx, len) in pointer_lengths.iter().enumerate() {
let lengths_haptics = interact(&mut overlays, &mut state);
for (idx, (len, haptics)) in lengths_haptics.iter().enumerate() {
lines.draw_from(
pointer_lines[idx],
state.input_state.pointers[idx].pose,
@@ -171,6 +171,9 @@ pub fn openvr_run(running: Arc<AtomicBool>) -> Result<(), BackendError> {
state.input_state.pointers[idx].interaction.mode as usize + 1,
&state.input_state.hmd,
);
if let Some(haptics) = haptics {
input_source.haptics(&mut input_mngr, idx, haptics)
}
}
lines.update(&mut overlay_mngr, &mut state);