RigidFinger.cs
2.04 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
/******************************************************************************
* 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 finger model for our rigid hand made out of various cube Unity Colliders. */
public class RigidFinger : SkeletalFinger {
public float filtering = 0.5f;
void Start() {
for (int i = 0; i < bones.Length; ++i) {
if (bones[i] != null) {
bones[i].GetComponent<Rigidbody>().maxAngularVelocity = Mathf.Infinity;
}
}
}
public override void UpdateFinger() {
for (int i = 0; i < bones.Length; ++i) {
if (bones[i] != null) {
// Set bone dimensions.
CapsuleCollider capsule = bones[i].GetComponent<CapsuleCollider>();
if (capsule != null) {
// Initialization
capsule.direction = 2;
bones[i].localScale = new Vector3(1f/transform.lossyScale.x, 1f/transform.lossyScale.y, 1f/transform.lossyScale.z);
// Update
capsule.radius = GetBoneWidth(i) / 2f;
capsule.height = GetBoneLength(i) + GetBoneWidth(i);
}
Rigidbody boneBody = bones[i].GetComponent<Rigidbody>();
if (boneBody) {
boneBody.MovePosition(GetBoneCenter(i));
boneBody.MoveRotation(GetBoneRotation(i));
} else {
bones[i].position = GetBoneCenter(i);
bones[i].rotation = GetBoneRotation(i);
}
}
}
}
}
}