Mercurial > hg > Game > Games
comparison Orchestland/Assets/Scripts/HandMotionCheck.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 using UnityEngine; | |
2 using System.Collections; | |
3 | |
4 public class HandMotionCheck : MonoBehaviour { | |
5 public HandController hand_controller; | |
6 public TempoCheck tempoCheck; | |
7 public float shakeInterval = 0.2f; | |
8 public NatureSpawner spawner; | |
9 | |
10 GameObject[] hand_ary = new GameObject[2]; | |
11 Vector3[] old_position = new Vector3[2]; | |
12 Vector3 old_speed = new Vector3(); | |
13 float interval_count = 0f; | |
14 // Use this for initialization | |
15 void Start () { | |
16 | |
17 } | |
18 | |
19 // Update is called once per frame | |
20 void Update () { | |
21 Vector3 hand_speed = new Vector3(); | |
22 HandModel[] hands = hand_controller.GetAllPhysicsHands(); | |
23 foreach(HandModel hand in hands){ | |
24 bool find_hand = false; | |
25 for (int i = 0; i < hand_ary.Length; i++) { | |
26 if (hand.gameObject == hand_ary [i]) { | |
27 find_hand = true; | |
28 hand_speed += (hand.GetWristPosition() - old_position[i]); | |
29 hand_ary [i] = hand.gameObject; | |
30 old_position [i] = hand.GetWristPosition(); | |
31 break; | |
32 } | |
33 } | |
34 if (!find_hand) { | |
35 for (int i = 0; i < hand_ary.Length; i++) { | |
36 if (hand_ary[i] == null) { | |
37 hand_ary [i] = hand.gameObject; | |
38 old_position [i] = hand.GetWristPosition(); | |
39 break; | |
40 } | |
41 } | |
42 } | |
43 } | |
44 | |
45 // shake check | |
46 interval_count += Time.deltaTime; | |
47 float move = (hand_speed - old_speed).magnitude; | |
48 if (move > 0.2f && interval_count > shakeInterval) { | |
49 interval_count = 0; | |
50 Shake (); | |
51 tempoCheck.Beat (); | |
52 } | |
53 old_speed = hand_speed; | |
54 } | |
55 | |
56 void OnDrawGizmos(){ | |
57 HandModel[] hands = hand_controller.GetAllPhysicsHands(); | |
58 foreach(HandModel hand in hands){ | |
59 Gizmos.color = Color.red; | |
60 Gizmos.DrawWireSphere (hand.GetPalmPosition (), 1f); | |
61 Gizmos.DrawRay (hand.GetPalmPosition(), old_speed*50); | |
62 } | |
63 } | |
64 | |
65 void Shake(){ | |
66 spawner.OnShake (); | |
67 } | |
68 } |