18 [Tooltip(
"Higher stiffness will keep the bouncy hand closer to the tracked hand data.")]
22 [Tooltip(
"Higher damping will suppress more motion and reduce oscillation.")]
27 private Pose? _leftPose =
null;
28 private Pose? _previousLeftPose =
null;
29 private float _leftAge = 0f;
30 private Pose? _rightPose =
null;
31 private Pose? _previousRightPose =
null;
32 private float _rightAge = 0f;
35 private Pose? _fixedLeftPose =
null;
36 private Pose? _fixedPreviousLeftPose =
null;
37 private float _fixedLeftAge = 0f;
38 private Pose? _fixedRightPose =
null;
39 private Pose? _fixedPreviousRightPose =
null;
40 private float _fixedRightAge = 0f;
46 var leftHand = inputFrame.Hands.Query().FirstOrDefault(h => h.IsLeft);
47 var rightHand = inputFrame.Hands.Query().FirstOrDefault(h => !h.IsLeft);
59 if (Time.inFixedTimeStep) {
62 ref _fixedLeftPose, ref _fixedPreviousLeftPose, ref _fixedLeftAge);
63 processHand(rightHand,
64 ref _fixedRightPose, ref _fixedPreviousRightPose, ref _fixedRightAge);
68 processHand(leftHand, ref _leftPose, ref _previousLeftPose, ref _leftAge);
69 processHand(rightHand, ref _rightPose, ref _previousRightPose, ref _rightAge);
74 private void processHand(
Hand hand,
75 ref
Pose? maybeCurPose,
76 ref
Pose? maybePrevPose,
85 var framePose = hand.GetPalmPose();
87 if (!maybeCurPose.HasValue) {
90 maybeCurPose = framePose;
92 else if (!maybePrevPose.HasValue) {
94 maybePrevPose = maybeCurPose;
95 maybeCurPose = framePose;
110 var curPose = maybeCurPose.Value;
111 var prevPose = maybePrevPose.Value;
112 integratePose(ref curPose, ref prevPose,
113 targetPose: framePose, deltaTime: deltaTime);
114 hand.SetPalmPose(curPose);
115 maybeCurPose = curPose;
116 maybePrevPose = prevPose;
126 private void integratePose(ref Pose curPose, ref Pose prevPose,
127 Pose targetPose,
float deltaTime) {
129 var deltaPose = curPose.inverse * prevPose;
130 deltaPose =
new Pose(-deltaPose.position,
Quaternion.Inverse(deltaPose.rotation));
131 deltaPose = Pose.Lerp(deltaPose, Pose.identity,
damping * deltaTime);
134 Pose tempPose = curPose;
135 curPose = curPose * deltaPose;
139 curPose = Pose.Lerp(curPose, targetPose,
stiffness * deltaTime);
The Frame class represents a set of hand and finger tracking data detected in a single frame.
The Hand class reports the physical characteristics of a detected hand.
float TimeVisible
The duration of time this Hand has been visible to the Leap Motion Controller.
override void ProcessFrame(ref Frame inputFrame)
Post-processes the input frame in place to give hands bouncy-feeling physics.
A position and rotation. You can multiply two poses; this acts like Matrix4x4 multiplication,...