feat(objects): sk controller for input method tip
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
pub mod mouse_pointer;
|
||||
pub mod sk_controller;
|
||||
pub mod sk_hand;
|
||||
|
||||
41
src/objects/input/sk_controller.rs
Normal file
41
src/objects/input/sk_controller.rs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,8 +41,10 @@ impl SkHand {
|
||||
pub fn update(&mut self, sk: &StereoKit) {
|
||||
if let InputType::Hand(hand) = &mut *self.hand.specialization.lock() {
|
||||
let sk_hand = *sk.input_hand(self.handed);
|
||||
*self.hand.enabled.lock() = sk_hand.tracked_state.is_active();
|
||||
if sk_hand.tracked_state.is_active() {
|
||||
let controller = sk.input_controller(self.handed);
|
||||
*self.hand.enabled.lock() =
|
||||
controller.tracked.is_inactive() && sk_hand.tracked_state.is_active();
|
||||
if *self.hand.enabled.lock() {
|
||||
hand.base.thumb.tip = convert_joint(sk_hand.fingers[0][4]);
|
||||
hand.base.thumb.distal = convert_joint(sk_hand.fingers[0][3]);
|
||||
hand.base.thumb.proximal = convert_joint(sk_hand.fingers[0][2]);
|
||||
|
||||
Reference in New Issue
Block a user