Tanoda
ProjectionPostProcessProvider.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using UnityEngine;
10
11namespace Leap.Unity.Examples {
12
14
15 [Header("Projection")]
16 public Transform headTransform;
17
18 [Tooltip("The scale of the projection of any hand distance from the approximated "
19 + "shoulder beyond the handMergeDistance.")]
20 [Range(0f, 15f)]
21 public float projectionScale = 10f;
22
23 [Tooltip("The distance from the approximated shoulder beyond which any additional "
24 + "distance is exponentiated by the projectionExponent.")]
25 [Range(0f, 1f)]
26 public float handMergeDistance = 0.35f;
27
28 public override void ProcessFrame(ref Frame inputFrame) {
29 // Calculate the position of the head and the basis to calculate shoulder position.
30 if (headTransform == null) { headTransform = Camera.main.transform; }
31 Vector3 headPos = headTransform.position;
32 var shoulderBasis = Quaternion.LookRotation(
33 Vector3.ProjectOnPlane(headTransform.forward, Vector3.up),
34 Vector3.up);
35
36 foreach (var hand in inputFrame.Hands) {
37 // Approximate shoulder position with magic values.
38 Vector3 shoulderPos = headPos
39 + (shoulderBasis * (new Vector3(0f, -0.13f, -0.1f)
40 + Vector3.left * 0.15f * (hand.IsLeft ? 1f : -1f)));
41
42 // Calculate the projection of the hand if it extends beyond the
43 // handMergeDistance.
44 Vector3 shoulderToHand = hand.PalmPosition.ToVector3() - shoulderPos;
45 float handShoulderDist = shoulderToHand.magnitude;
46 float projectionDistance = Mathf.Max(0f, handShoulderDist - handMergeDistance);
47 float projectionAmount = 1f + (projectionDistance * projectionScale);
48 hand.SetTransform(shoulderPos + shoulderToHand * projectionAmount,
49 hand.Rotation.ToQuaternion());
50 }
51 }
52
53 }
54}
The Frame class represents a set of hand and finger tracking data detected in a single frame.
Definition: Frame.cs:24
float projectionScale
Transform headTransform
float handMergeDistance
override void ProcessFrame(ref Frame inputFrame)