comparison Orchestland/Assets/LeapMotion/Scripts/Hands/SkeletalHand.cs @ 1:f7675884f2a1

Add Orchestland project
author Daiki OYAKAWA <e135764@ie.u-ryukyu.ac.jp>
date Fri, 17 Jul 2015 23:09:20 +0900
parents
children
comparison
equal deleted inserted replaced
0:347d21cdfc22 1:f7675884f2a1
1 /******************************************************************************\
2 * Copyright (C) Leap Motion, Inc. 2011-2014. *
3 * Leap Motion proprietary. Licensed under Apache 2.0 *
4 * Available at http://www.apache.org/licenses/LICENSE-2.0.html *
5 \******************************************************************************/
6
7 using UnityEngine;
8 using System.Collections;
9 using Leap;
10
11 /**
12 * A hand object consisting of discrete, component parts.
13 *
14 * The hand can have game objects for the palm, wrist and forearm, as well as fingers.
15 */
16 public class SkeletalHand : HandModel {
17
18 protected const float PALM_CENTER_OFFSET = 0.0150f;
19
20 void Start() {
21 // Ignore collisions with self.
22 Leap.Utils.IgnoreCollisions(gameObject, gameObject);
23
24 for (int i = 0; i < fingers.Length; ++i) {
25 if (fingers[i] != null) {
26 fingers[i].fingerType = (Finger.FingerType)i;
27 }
28 }
29 }
30
31 /** Updates the hand and its component parts by setting their positions and rotations. */
32 public override void UpdateHand() {
33 SetPositions();
34 }
35
36 protected Vector3 GetPalmCenter() {
37 Vector3 offset = PALM_CENTER_OFFSET * Vector3.Scale(GetPalmDirection(), transform.localScale);
38 return GetPalmPosition() - offset;
39 }
40
41 protected void SetPositions() {
42 for (int f = 0; f < fingers.Length; ++f) {
43 if (fingers[f] != null)
44 fingers[f].UpdateFinger();
45 }
46
47 if (palm != null) {
48 palm.position = GetPalmCenter();
49 palm.rotation = GetPalmRotation();
50 }
51
52 if (wristJoint != null) {
53 wristJoint.position = GetWristPosition();
54 wristJoint.rotation = GetPalmRotation();
55 }
56
57 if (forearm != null) {
58 forearm.position = GetArmCenter();
59 forearm.rotation = GetArmRotation();
60 }
61 }
62 }
63
64