feat(objects): sk controller for input method tip

This commit is contained in:
Nova
2022-10-01 22:55:59 -04:00
parent c75798cbe9
commit 55a50140a5
3 changed files with 46 additions and 2 deletions

View File

@@ -0,0 +1,41 @@
use crate::nodes::{
input::{tip::Tip, InputMethod, InputType},
spatial::Spatial,
};
use glam::Mat4;
use portable_atomic::Ordering;
use std::sync::{Arc, Weak};
use stereokit::{input::Handed, StereoKit};
pub struct SkController {
tip: Arc<InputMethod>,
handed: Handed,
}
impl SkController {
pub fn new(handed: Handed) -> Self {
SkController {
tip: InputMethod::new(
Spatial::new(Weak::new(), None, Mat4::IDENTITY),
InputType::Tip(Tip::default()),
),
handed,
}
}
pub fn update(&mut self, sk: &StereoKit) {
if let InputType::Tip(tip) = &mut *self.tip.specialization.lock() {
let controller = sk.input_controller(self.handed);
*self.tip.enabled.lock() = controller.tracked.is_active();
if controller.tracked.is_active() {
self.tip.spatial.set_local_transform_components(
None,
Some(controller.pose.position.into()),
Some(controller.pose.orientation.into()),
None,
);
}
tip.select.store(controller.trigger, Ordering::Relaxed);
tip.grab.store(controller.grip, Ordering::Relaxed);
}
}
}