source: other-projects/fft-ddr/open-day-2015/trunk/FFTDDR/SkeletonManager.cs@ 29911

Last change on this file since 29911 was 29911, checked in by cct9, 9 years ago

Reworked version of the project undertaken for open day 2015

File size: 5.9 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6using Microsoft.Kinect;
7using System.Drawing;
8using System.Windows.Forms;
9
10namespace FFTDDR
11{
12 class SkeletonManager
13 {
14 public Skeleton[] skeletons;
15 public bool[] calibrated, calibrating, currentlyTracked;
16 public Vector4[] centre;
17 public Vector4[] leftFoot;
18 public Vector4[] rightFoot;
19 public Vector4[] deadSpot;
20 public float deadSpotRadius = 0.2f;
21 public bool previousLeftHandRaised = false;
22 public float previousRightHandY = 0;
23
24
25 public SkeletonManager(int numSkeletons)
26 {
27 skeletons = new Skeleton[numSkeletons];
28 calibrated = new bool[numSkeletons];
29 calibrating = new bool[numSkeletons];
30 currentlyTracked = new bool[numSkeletons];
31 centre = new Vector4[numSkeletons];
32 leftFoot = new Vector4[numSkeletons];
33 rightFoot = new Vector4[numSkeletons];
34 deadSpot = new Vector4[numSkeletons];
35
36
37 for (int i = 0; i < numSkeletons; i++)
38 {
39 calibrated[i] = false;
40 calibrating[i] = false;
41 currentlyTracked[i] = false;
42
43 }
44 }
45 public void Update(Skeleton[] newSkeletons)
46 {
47 skeletons = newSkeletons;
48
49 for (int i = 0; i < skeletons.Length; i++)
50 {
51 if(calibrated[i] == true){
52 leftFoot[i].X = skeletons[i].Joints[JointType.AnkleLeft].Position.X;
53 leftFoot[i].Y = skeletons[i].Joints[JointType.AnkleLeft].Position.Y;
54 leftFoot[i].Z = skeletons[i].Joints[JointType.AnkleLeft].Position.Z;
55 rightFoot[i].X = skeletons[i].Joints[JointType.AnkleRight].Position.X;
56 rightFoot[i].Y = skeletons[i].Joints[JointType.AnkleRight].Position.Y;
57 rightFoot[i].Z = skeletons[i].Joints[JointType.AnkleRight].Position.Z;
58
59
60 }
61 }
62
63 }
64
65 public int temp = 0;
66
67 public string Calibrate(int skeletonNo)
68 {
69
70 if (calibrating[skeletonNo] == false &&
71 skeletons[skeletonNo].Joints[JointType.HandLeft].Position.Y > skeletons[skeletonNo].Joints[JointType.Head].Position.Y
72 && skeletons[skeletonNo].Joints[JointType.HandRight].Position.Y > skeletons[skeletonNo].Joints[JointType.Head].Position.Y)
73 {
74 return "menu";
75 }
76
77 if (calibrating[skeletonNo] == false &&
78 skeletons[skeletonNo].Joints[JointType.HandLeft].Position.X > skeletons[skeletonNo].Joints[JointType.HandRight].Position.X)
79 {
80
81 calibrating[skeletonNo] = true;
82 centre[skeletonNo] = calculateCentre(skeletons[skeletonNo]);
83
84 deadSpot[skeletonNo].X = centre[skeletonNo].X - deadSpotRadius / 2;
85 deadSpot[skeletonNo].Z = centre[skeletonNo].Z - deadSpotRadius / 2;
86
87 calibrating[skeletonNo] = false;
88 calibrated[skeletonNo] = true;
89
90 return "continue";
91 }
92
93 // If right hand is above collarbone, only if noncalibrated.
94
95 if (calibrating[skeletonNo] == false &&
96 skeletons[skeletonNo].Joints[JointType.HandLeft].Position.Y > skeletons[skeletonNo].Joints[JointType.ShoulderCenter].Position.Y)
97 {
98 if (previousLeftHandRaised == false)
99 {
100 previousLeftHandRaised = true;
101 previousRightHandY = skeletons[skeletonNo].Joints[JointType.HandRight].Position.Y;
102 }
103 float heightChange = previousRightHandY - skeletons[skeletonNo].Joints[JointType.HandRight].Position.Y;
104 if (heightChange < 0)
105 {
106 return heightChange.ToString();
107
108 }
109 return heightChange.ToString();
110
111 }
112 else if (calibrated[skeletonNo] == false && calibrating[skeletonNo] == false &&
113 skeletons[skeletonNo].Joints[JointType.HandLeft].Position.Y < skeletons[skeletonNo].Joints[JointType.ShoulderCenter].Position.Y)
114 {
115 previousLeftHandRaised = false;
116 }
117
118
119
120 return "";
121
122
123 }
124
125 private Vector4 calculateCentre(Skeleton skel)
126 {
127 Vector4 temp = new Vector4();
128 temp.X = (skel.Joints[JointType.FootLeft].Position.X + skel.Joints[JointType.FootRight].Position.X) / 2;
129 temp.Y = (skel.Joints[JointType.FootLeft].Position.Y + skel.Joints[JointType.FootRight].Position.Y) / 2;
130 temp.Z = (skel.Joints[JointType.FootLeft].Position.Z + skel.Joints[JointType.FootRight].Position.Z) / 2;
131
132 return temp;
133 }
134
135 public int FindQuadrant(float Z, float X, Vector4 center)
136 {
137 if (Z < (center.Z + 0.8) && Z > (center.Z - 0.8) && X < (center.X + 0.8) && X > (center.X - 0.8))
138 {
139 if (Z > center.Z)
140 {
141 if (X < center.X)
142 {
143 return 4;
144 }
145 else
146 {
147 return 3;
148 }
149 }
150 else
151 {
152 if (X < center.X)
153 {
154 return 1;
155 }
156 else
157 {
158 return 2;
159 }
160 }
161 }
162 else return 0;
163 }
164 }
165}
Note: See TracBrowser for help on using the repository browser.