Tanoda
DebugHand.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 {
21 public class DebugHand : HandModelBase {
22 private Hand hand_;
23
24 [SerializeField]
25 private bool visualizeBasis = true;
26 public bool VisualizeBasis { get { return visualizeBasis; } set { visualizeBasis = value; } }
27
29 protected Color[] colors = { Color.gray, Color.yellow, Color.cyan, Color.magenta };
30
31 public override ModelType HandModelType {
32 get {
33 return ModelType.Graphics;
34 }
35 }
36
37 #pragma warning disable 0649
38 [SerializeField]
39 private Chirality handedness;
40 public override Chirality Handedness {
41 get {
42 return handedness;
43 }
44 set { }
45 }
46 #pragma warning restore 0649
47
48 public override Hand GetLeapHand() {
49 return hand_;
50 }
51
52 public override void SetLeapHand(Hand hand) {
53 hand_ = hand;
54 }
55
56 public override bool SupportsEditorPersistence() {
57 return true;
58 }
59
63 public override void InitHand() {
65 }
66
70 public override void UpdateHand() {
72 }
73
77 protected void DrawDebugLines() {
78 Hand hand = GetLeapHand();
79 Debug.DrawLine(hand.Arm.ElbowPosition.ToVector3(), hand.Arm.WristPosition.ToVector3(), Color.red); //Arm
80 Debug.DrawLine(hand.WristPosition.ToVector3(), hand.PalmPosition.ToVector3(), Color.white); //Wrist to palm line
81 Debug.DrawLine(hand.PalmPosition.ToVector3(), (hand.PalmPosition + hand.PalmNormal * hand.PalmWidth / 2).ToVector3(), Color.black); //Hand Normal
82
83 if (VisualizeBasis) {
84 DrawBasis(hand.PalmPosition, hand.Basis, hand.PalmWidth / 4); //Hand basis
85 DrawBasis(hand.Arm.ElbowPosition, hand.Arm.Basis, .01f); //Arm basis
86 }
87
88 for (int f = 0; f < 5; f++) { //Fingers
89 Finger finger = hand.Fingers[f];
90 for (int i = 0; i < 4; ++i) {
91 Bone bone = finger.Bone((Bone.BoneType)i);
92 Debug.DrawLine(bone.PrevJoint.ToVector3(), bone.PrevJoint.ToVector3() + bone.Direction.ToVector3() * bone.Length, colors[i]);
94 DrawBasis(bone.PrevJoint, bone.Basis, .01f);
95 }
96 }
97 }
98
99 public void DrawBasis(Vector position, LeapTransform basis, float scale) {
100 Vector3 origin = position.ToVector3();
101 Debug.DrawLine(origin, origin + basis.xBasis.ToVector3() * scale, Color.red);
102 Debug.DrawLine(origin, origin + basis.yBasis.ToVector3() * scale, Color.green);
103 Debug.DrawLine(origin, origin + basis.zBasis.ToVector3() * scale, Color.blue);
104 }
105
106 }
107}
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19
UnityEngine.Color Color
Definition: TestScript.cs:32
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
The Bone class represents a tracked bone.
Definition: Bone.cs:26
Vector Direction
The normalized direction of the bone from base to tip.
Definition: Bone.cs:102
BoneType
Enumerates the type of bones.
Definition: Bone.cs:168
LeapTransform Basis
The orthonormal basis vectors for this Bone as a Matrix. The orientation of this Bone as a Quaternion...
Definition: Bone.cs:159
Vector PrevJoint
The base of the bone, closest to the wrist. In anatomical terms, this is the proximal end of the bone...
Definition: Bone.cs:83
float Length
The estimated length of the bone.
Definition: Bone.cs:108
The Finger class represents a tracked finger.
Definition: Finger.cs:20
Bone Bone(Bone.BoneType boneIx)
The bone at a given bone index on this finger.
Definition: Finger.cs:79
The Hand class reports the physical characteristics of a detected hand.
Definition: Hand.cs:26
Vector WristPosition
The position of the wrist of this hand.
Definition: Hand.cs:276
float PalmWidth
The estimated width of the palm when the hand is in a flat position.
Definition: Hand.cs:259
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
List< Finger > Fingers
The list of Finger objects detected in this frame that are attached to this hand, given in order from...
Definition: Hand.cs:159
override void SetLeapHand(Hand hand)
Definition: DebugHand.cs:52
override Chirality Handedness
Definition: DebugHand.cs:40
override Hand GetLeapHand()
Definition: DebugHand.cs:48
override void InitHand()
Definition: DebugHand.cs:63
override void UpdateHand()
Definition: DebugHand.cs:70
override ModelType HandModelType
Definition: DebugHand.cs:31
override bool SupportsEditorPersistence()
Returns whether or not this hand model supports editor persistence. This is false by default and must...
Definition: DebugHand.cs:56
void DrawBasis(Vector position, LeapTransform basis, float scale)
Definition: DebugHand.cs:99
The LeapTransform class represents a transform in three dimensional space.
Vector zBasis
The z-basis of the transform.
Vector xBasis
The x-basis of the transform.
Vector yBasis
The y-basis of the transform.
The Vector struct represents a three-component mathematical vector or point such as a direction or po...
Definition: Vector.cs:36