SkeletalHand.cs
2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/******************************************************************************
* Copyright (C) Leap Motion, Inc. 2011-2017. *
* Leap Motion proprietary and confidential. *
* *
* Use subject to the terms of the Leap Motion SDK Agreement available at *
* https://developer.leapmotion.com/sdk_agreement, or another agreement *
* between Leap Motion and you, your company or other organization. *
******************************************************************************/
using UnityEngine;
using System.Collections;
using Leap;
namespace Leap.Unity{
/**
* A hand object consisting of discrete, component parts.
*
* The hand can have game objects for the palm, wrist and forearm, as well as fingers.
*/
public class SkeletalHand : HandModel {
public override ModelType HandModelType {
get {
return ModelType.Graphics;
}
}
protected const float PALM_CENTER_OFFSET = 0.015f;
void Start() {
// Ignore collisions with self.
Leap.Unity.Utils.IgnoreCollisions(gameObject, gameObject);
for (int i = 0; i < fingers.Length; ++i) {
if (fingers[i] != null) {
fingers[i].fingerType = (Finger.FingerType)i;
}
}
}
/** Updates the hand and its component parts by setting their positions and rotations. */
public override void UpdateHand() {
SetPositions();
}
protected Vector3 GetPalmCenter() {
Vector3 offset = PALM_CENTER_OFFSET * Vector3.Scale(GetPalmDirection(), transform.lossyScale);
return GetPalmPosition() - offset;
}
protected void SetPositions() {
for (int f = 0; f < fingers.Length; ++f) {
if (fingers[f] != null) {
fingers[f].UpdateFinger();
}
}
if (palm != null) {
palm.position = GetPalmCenter();
palm.rotation = GetPalmRotation();
}
if (wristJoint != null) {
wristJoint.position = GetWristPosition();
wristJoint.rotation = GetPalmRotation();
}
if (forearm != null) {
forearm.position = GetArmCenter();
forearm.rotation = GetArmRotation();
}
}
}
}