Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experimental hand tracking gestures #1715

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 86 additions & 2 deletions alvr/server/src/tracking.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::{to_ffi_quat, FfiDeviceMotion, FfiHandSkeleton};
use alvr_common::{
glam::{EulerRot, Quat, Vec3},
DeviceMotion, Pose, HEAD_ID, LEFT_HAND_ID, RIGHT_HAND_ID,
prelude::warn,
DeviceMotion, Pose, HEAD_ID, LEFT_HAND_ID, LEFT_TRIGGER_CLICK_ID,
RIGHT_HAND_ID, RIGHT_TRIGGER_CLICK_ID,
};
use alvr_session::{
settings_schema::Switch, HeadsetConfig, PositionRecenteringMode, RotationRecenteringMode,
Expand Down Expand Up @@ -265,7 +267,89 @@ pub fn to_openvr_hand_skeleton(
* Quat::from_euler(EulerRot::YXZ, -FRAC_PI_2, FRAC_PI_2, 0.0),
position: gj[1].position,
};

// test pinch
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is not the right function where to do this. to_openvr_hand_skeleton was supposed to be a "pure" function, ie no side effects. You can create another function with the only purpose of detecting and sending pinches.

{
let thumb_tip: Pose = gj[5];
let index_tip: Pose = gj[10];
let middle_tip: Pose = gj[15];
let ring_tip: Pose = gj[20];
let little_tip: Pose = gj[25];
let index_pinch = thumb_tip.position.distance(index_tip.position) < 0.010;
let middle_pinch = thumb_tip.position.distance(middle_tip.position) < 0.010;
let ring_pinch = thumb_tip.position.distance(ring_tip.position) < 0.010;
let little_pinch = thumb_tip.position.distance(little_tip.position) < 0.010;
if device_id == *LEFT_HAND_ID {
if index_pinch {
unsafe {
crate::SetButton(
*LEFT_TRIGGER_CLICK_ID,
crate::FfiButtonValue {
type_: crate::FfiButtonType_BUTTON_TYPE_BINARY,
__bindgen_anon_1: crate::FfiButtonValue__bindgen_ty_1 {
binary: true.into(),
},
},
)
};
warn!("thumb/index pinch detected on left hand");
} else {
unsafe {
crate::SetButton(
*LEFT_TRIGGER_CLICK_ID,
crate::FfiButtonValue {
type_: crate::FfiButtonType_BUTTON_TYPE_BINARY,
__bindgen_anon_1: crate::FfiButtonValue__bindgen_ty_1 {
binary: false.into(),
},
},
)
}
warn!("thumb/index unpinch detected on left hand");
}
if middle_pinch {
warn!("thumb/middle pinch detected on left hand");
} else if ring_pinch {
warn!("thumb/ring pinch detected on left hand");
} else if little_pinch {
warn!("thumb/little pinch detected on left hand");
}
} else {
if index_pinch {
unsafe {
crate::SetButton(
*RIGHT_TRIGGER_CLICK_ID,
crate::FfiButtonValue {
type_: crate::FfiButtonType_BUTTON_TYPE_BINARY,
__bindgen_anon_1: crate::FfiButtonValue__bindgen_ty_1 {
binary: true.into(),
},
},
)
}
warn!("thumb/index pinch detected on right hand");
} else {
unsafe {
crate::SetButton(
*RIGHT_TRIGGER_CLICK_ID,
crate::FfiButtonValue {
type_: crate::FfiButtonType_BUTTON_TYPE_BINARY,
__bindgen_anon_1: crate::FfiButtonValue__bindgen_ty_1 {
binary: false.into(),
},
},
)
}
warn!("thumb/index unpinch detected on right hand");
}
if middle_pinch {
warn!("thumb/middle pinch detected on right hand");
} else if ring_pinch {
warn!("thumb/ring pinch detected on right hand");
} else if little_pinch {
warn!("thumb/little pinch detected on right hand");
}
}
}
[
// Palm. NB: this is ignored by SteamVR
Pose::default(),
Expand Down