Tanoda
RigidFinger.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{
15 public class RigidFinger : SkeletalFinger {
16
17 public float filtering = 0.5f;
18
19 void Start() {
20 for (int i = 0; i < bones.Length; ++i) {
21 if (bones[i] != null) {
22 bones[i].GetComponent<Rigidbody>().maxAngularVelocity = Mathf.Infinity;
23 }
24 }
25 }
26
27 public override void UpdateFinger() {
28 for (int i = 0; i < bones.Length; ++i) {
29 if (bones[i] != null) {
30 // Set bone dimensions.
31 CapsuleCollider capsule = bones[i].GetComponent<CapsuleCollider>();
32 if (capsule != null) {
33 // Initialization
34 capsule.direction = 2;
35 bones[i].localScale = new Vector3(1f/transform.lossyScale.x, 1f/transform.lossyScale.y, 1f/transform.lossyScale.z);
36
37 // Update
38 capsule.radius = GetBoneWidth(i) / 2f;
39 capsule.height = GetBoneLength(i) + GetBoneWidth(i);
40 }
41
42 Rigidbody boneBody = bones[i].GetComponent<Rigidbody>();
43 if (boneBody) {
44 boneBody.MovePosition(GetBoneCenter(i));
45 boneBody.MoveRotation(GetBoneRotation(i));
46 } else {
47 bones[i].position = GetBoneCenter(i);
48 bones[i].rotation = GetBoneRotation(i);
49 }
50 }
51 }
52 }
53 }
54}
Quaternion GetBoneRotation(int bone_type)
Definition: FingerModel.cs:140
Vector3 GetBoneCenter(int bone_type)
Definition: FingerModel.cs:116
float GetBoneLength(int bone_type)
Definition: FingerModel.cs:152
float GetBoneWidth(int bone_type)
Definition: FingerModel.cs:157
override void UpdateFinger()
Definition: RigidFinger.cs:27