Skip to content

Commit 073fa13

Browse files
MattGrayULBryceNewell-UL
authored andcommitted
update XRHandsInputActionUpdater and XRHandsUtils
1 parent c69b768 commit 073fa13

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

Diff for: Packages/Tracking/Core/Runtime/Scripts/XRHandsSubsystem/XRHandsInputActionUpdater.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,10 @@ private static void SendMetaAimStateUpdate(LeapHandState state, XRHand hand)
185185
InputSystem.QueueDeltaStateEvent(metaAimHand.trackingState, UnityEngine.XR.InputTrackingState.Position | UnityEngine.XR.InputTrackingState.Rotation);
186186
InputSystem.QueueDeltaStateEvent(metaAimHand.isTracked, true);
187187

188-
InputSystem.QueueDeltaStateEvent(metaAimHand.indexPressed, hand.CalculatePinchStrength(XRHandJointID.IndexTip) > 0.5f ? true : false);
189-
InputSystem.QueueDeltaStateEvent(metaAimHand.middlePressed, hand.CalculatePinchStrength(XRHandJointID.MiddleTip) > 0.5f ? true : false);
190-
InputSystem.QueueDeltaStateEvent(metaAimHand.ringPressed, hand.CalculatePinchStrength(XRHandJointID.RingTip) > 0.5f ? true : false);
191-
InputSystem.QueueDeltaStateEvent(metaAimHand.littlePressed, hand.CalculatePinchStrength(XRHandJointID.LittleTip) > 0.5f ? true : false);
188+
InputSystem.QueueDeltaStateEvent(metaAimHand.indexPressed, hand.CalculatePinchDistance(XRHandJointID.IndexTip) < 0.02f ? true : false);
189+
InputSystem.QueueDeltaStateEvent(metaAimHand.middlePressed, hand.CalculatePinchDistance(XRHandJointID.MiddleTip) < 0.02f ? true : false);
190+
InputSystem.QueueDeltaStateEvent(metaAimHand.ringPressed, hand.CalculatePinchDistance(XRHandJointID.RingTip) < 0.02f ? true : false);
191+
InputSystem.QueueDeltaStateEvent(metaAimHand.littlePressed, hand.CalculatePinchDistance(XRHandJointID.LittleTip) < 0.02f ? true : false);
192192

193193
InputSystem.QueueDeltaStateEvent(metaAimHand.pinchStrengthIndex, hand.CalculatePinchStrength(XRHandJointID.IndexTip));
194194
InputSystem.QueueDeltaStateEvent(metaAimHand.pinchStrengthMiddle, hand.CalculatePinchStrength(XRHandJointID.MiddleTip));
@@ -245,7 +245,7 @@ static float GetSelecting(XRHand hand)
245245

246246
static float GetActvating(XRHand hand)
247247
{
248-
return hand.CalculatePinchStrength() > 0.8 ? 1 : 0;
248+
return hand.CalculatePinchDistance() < 0.02f ? 1 : 0;
249249
}
250250

251251
static Vector3 GetPalmPosition(XRHand hand)

Diff for: Packages/Tracking/Core/Runtime/Scripts/XRHandsSubsystem/XRHandsUtils.cs

+18-1
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
* between Ultraleap and you, your company or other organization. *
77
******************************************************************************/
88

9+
using Leap.Unity;
910
using UnityEngine;
1011
using UnityEngine.XR.Hands;
1112

12-
namespace Leap.Unity
13+
namespace Leap
1314
{
1415
public static class XRHandsUtils
1516
{
@@ -114,6 +115,22 @@ public static float CalculatePinchStrength(this XRHand hand, XRHandJointID joint
114115
return 0;
115116
}
116117

118+
public static float CalculatePinchDistance(this XRHand hand, XRHandJointID jointToCompare = XRHandJointID.IndexTip)
119+
{
120+
// Get the thumb position.
121+
Vector3 thumbTip = Vector3.zero;
122+
if (hand.GetJoint(XRHandJointID.ThumbTip).TryGetPose(out Pose thumbTipPose)) thumbTip = thumbTipPose.position;
123+
124+
// Compute the distance midpoints between the thumb and thejointToCompare.
125+
if (hand.GetJoint(jointToCompare).TryGetPose(out var fingerTipPose))
126+
{
127+
float distance = (fingerTipPose.position - thumbTip).magnitude;
128+
return distance;
129+
}
130+
131+
return 0;
132+
}
133+
117134
public static Vector3 GetStablePinchPosition(this XRHand hand)
118135
{
119136
Vector3 indexTip = Vector3.zero;

0 commit comments

Comments
 (0)