Tanoda
HandModel.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;
10using System.Collections;
11using Leap;
12
13namespace Leap.Unity{
25 public abstract class HandModel : HandModelBase {
26
27 [SerializeField]
28 private Chirality handedness;
29 public override Chirality Handedness {
30 get { return handedness; }
31 set { handedness = value; }
32 }
33
34 private ModelType handModelType;
35 public override abstract ModelType HandModelType {
36 get;
37 }
38
40 public const int NUM_FINGERS = 5;
41
45 public float handModelPalmWidth = 0.085f;
48
49 // Unity references
51 public Transform palm;
53 public Transform forearm;
55 public Transform wristJoint;
57 public Transform elbowJoint;
58
59 // Leap references
61 protected Hand hand_;
62
66 public Vector3 GetPalmPosition() {
67 return hand_.PalmPosition.ToVector3();
68 }
69
73 public Quaternion GetPalmRotation() {
74 if (hand_ != null) {
75 // The hand Basis vectors are calculated explicitly. This requires using Basis.CalculateRotation()
76 // instead of Basis.quaternion.
77 return hand_.Basis.CalculateRotation();
78 }
79 if (palm) {
80 return palm.rotation;
81 }
82 return Quaternion.identity;
83 }
84
88 public Vector3 GetPalmDirection() {
89 if (hand_ != null) {
90 return hand_.Direction.ToVector3();
91 }
92 if (palm) {
93 return palm.forward;
94 }
95 return Vector3.forward;
96 }
97
101 public Vector3 GetPalmNormal() {
102 if (hand_ != null) {
103 return hand_.PalmNormal.ToVector3();
104 }
105 if (palm) {
106 return -palm.up;
107 }
108 return -Vector3.up;
109 }
110
114 public Vector3 GetArmDirection() {
115 if (hand_ != null) {
116 return hand_.Arm.Direction.ToVector3();
117 }
118 if (forearm) {
119 return forearm.forward;
120 }
121 return Vector3.forward;
122 }
123
127 public Vector3 GetArmCenter() {
128 if (hand_ != null) {
129 Vector leap_center = 0.5f * (hand_.Arm.WristPosition + hand_.Arm.ElbowPosition);
130 return leap_center.ToVector3();
131 }
132 if (forearm) {
133 return forearm.position;
134 }
135 return Vector3.zero;
136 }
137
139 public float GetArmLength() {
140 return (hand_.Arm.WristPosition - hand_.Arm.ElbowPosition).Magnitude;
141 }
142
144 public float GetArmWidth() {
145 return hand_.Arm.Width;
146 }
147
151 public Vector3 GetElbowPosition() {
152 if (hand_ != null) {
153 Vector3 local_position = hand_.Arm.ElbowPosition.ToVector3();
154 return local_position;
155 }
156 if (elbowJoint) {
157 return elbowJoint.position;
158 }
159 return Vector3.zero;
160 }
161
165 public Vector3 GetWristPosition() {
166 if (hand_ != null) {
167 Vector3 local_position = hand_.Arm.WristPosition.ToVector3();
168 return local_position;
169 }
170 if (wristJoint) {
171 return wristJoint.position;
172 }
173 return Vector3.zero;
174 }
175
179 public Quaternion GetArmRotation() {
180 if (hand_ != null) {
181 Quaternion local_rotation = hand_.Arm.Rotation.ToQuaternion();
182 return local_rotation;
183 }
184 if (forearm) {
185 return forearm.rotation;
186 }
187 return Quaternion.identity;
188 }
189
196 public override Hand GetLeapHand() {
197 return hand_;
198 }
199
205 public override void SetLeapHand(Hand hand) {
206 hand_ = hand;
207 for (int i = 0; i < fingers.Length; ++i) {
208 if (fingers[i] != null) {
210 }
211 }
212 }
213
219 public override void InitHand() {
220 for (int f = 0; f < fingers.Length; ++f) {
221 if (fingers[f] != null) {
223 fingers[f].InitFinger();
224 }
225 }
226 }
227
233 public int LeapID() {
234 if (hand_ != null) {
235 return hand_.Id;
236 }
237 return -1;
238 }
239
246 public override abstract void UpdateHand();
247 }
248}
Vector WristPosition
The position of the wrist.
Definition: Arm.cs:86
Vector ElbowPosition
The position of the elbow. If not in view, the elbow position is estimated based on typical human ana...
Definition: Arm.cs:71
LeapQuaternion Rotation
The orientation of this Bone as a Quaternion.
Definition: Bone.cs:126
Vector Direction
The normalized direction of the bone from base to tip.
Definition: Bone.cs:102
float Width
The average width of the flesh around the bone.
Definition: Bone.cs:114
The Finger class represents a tracked finger.
Definition: Finger.cs:20
FingerType
Enumerates the names of the fingers.
Definition: Finger.cs:167
The Hand class reports the physical characteristics of a detected hand.
Definition: Hand.cs:26
Vector Direction
The direction from the palm position toward the fingers.
Definition: Hand.cs:196
LeapTransform Basis
The transform of the hand.
Definition: Hand.cs:204
Vector PalmNormal
The normal vector to the palm. If your hand is flat, this vector will point downward,...
Definition: Hand.cs:184
Arm Arm
The arm to which this hand is attached.
Definition: Hand.cs:311
Vector PalmPosition
The center position of the palm.
Definition: Hand.cs:165
int Id
A unique ID assigned to this Hand object, whose value remains the same across consecutive frames whil...
Definition: Hand.cs:152
Finger.FingerType fingerType
Definition: FingerModel.cs:34
virtual void InitFinger()
Definition: FingerModel.cs:69
void SetLeapHand(Hand hand)
Definition: FingerModel.cs:53
Vector3 GetWristPosition()
Definition: HandModel.cs:165
Transform elbowJoint
Definition: HandModel.cs:57
Vector3 GetPalmPosition()
Definition: HandModel.cs:66
Vector3 GetArmDirection()
Definition: HandModel.cs:114
const int NUM_FINGERS
Definition: HandModel.cs:40
Vector3 GetArmCenter()
Definition: HandModel.cs:127
Quaternion GetArmRotation()
Definition: HandModel.cs:179
Vector3 GetPalmDirection()
Definition: HandModel.cs:88
Vector3 GetElbowPosition()
Definition: HandModel.cs:151
Transform forearm
Definition: HandModel.cs:53
FingerModel[] fingers
Definition: HandModel.cs:47
Quaternion GetPalmRotation()
Definition: HandModel.cs:73
Transform wristJoint
Definition: HandModel.cs:55
override void InitHand()
Definition: HandModel.cs:219
override void SetLeapHand(Hand hand)
Definition: HandModel.cs:205
override Hand GetLeapHand()
Definition: HandModel.cs:196
Vector3 GetPalmNormal()
Definition: HandModel.cs:101
abstract override ModelType HandModelType
Definition: HandModel.cs:35
abstract override void UpdateHand()
float handModelPalmWidth
Definition: HandModel.cs:45
override Chirality Handedness
Definition: HandModel.cs:29
The Vector struct represents a three-component mathematical vector or point such as a direction or po...
Definition: Vector.cs:36