RigidHand.cs
2.43 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
73
74
75
/******************************************************************************
* 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 physics model for our rigid hand made out of various Unity Collider. */
public class RigidHand : SkeletalHand {
public override ModelType HandModelType {
get {
return ModelType.Physics;
}
}
public float filtering = 0.5f;
public override bool SupportsEditorPersistence() {
return true;
}
public override void InitHand() {
base.InitHand();
}
public override void UpdateHand() {
for (int f = 0; f < fingers.Length; ++f) {
if (fingers[f] != null) {
fingers[f].UpdateFinger();
}
}
if (palm != null) {
Rigidbody palmBody = palm.GetComponent<Rigidbody>();
if (palmBody) {
palmBody.MovePosition(GetPalmCenter());
palmBody.MoveRotation(GetPalmRotation());
} else {
palm.position = GetPalmCenter();
palm.rotation = GetPalmRotation();
}
}
if (forearm != null) {
// Set arm dimensions.
CapsuleCollider capsule = forearm.GetComponent<CapsuleCollider>();
if (capsule != null) {
// Initialization
capsule.direction = 2;
forearm.localScale = new Vector3(1f / transform.lossyScale.x, 1f / transform.lossyScale.y, 1f / transform.lossyScale.z);
// Update
capsule.radius = GetArmWidth() / 2f;
capsule.height = GetArmLength() + GetArmWidth();
}
Rigidbody forearmBody = forearm.GetComponent<Rigidbody>();
if (forearmBody) {
forearmBody.MovePosition(GetArmCenter());
forearmBody.MoveRotation(GetArmRotation());
} else {
forearm.position = GetArmCenter();
forearm.rotation = GetArmRotation();
}
}
}
}
}