source: other-projects/fft-ddr/summer-2014/trunk/FFDDR/SkeletonManager.cs@ 29735

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

Initial set of files for the FFT-Dance-Dance-Revolution project

  • Property svn:executable set to *
File size: 4.1 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 FFDDR
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
22
23 public SkeletonManager(int numSkeletons)
24 {
25 skeletons = new Skeleton[numSkeletons];
26 calibrated = new bool[numSkeletons];
27 calibrating = new bool[numSkeletons];
28 currentlyTracked = new bool[numSkeletons];
29 centre = new Vector4[numSkeletons];
30 leftFoot = new Vector4[numSkeletons];
31 rightFoot = new Vector4[numSkeletons];
32 deadSpot = new Vector4[numSkeletons];
33
34
35 for (int i = 0; i < numSkeletons; i++)
36 {
37 calibrated[i] = false;
38 calibrating[i] = false;
39 currentlyTracked[i] = false;
40
41 }
42 }
43 public void Update(Skeleton[] newSkeletons)
44 {
45 skeletons = newSkeletons;
46
47 for (int i = 0; i < skeletons.Length; i++)
48 {
49 if(calibrated[i] == true){
50 leftFoot[i].X = skeletons[i].Joints[JointType.AnkleLeft].Position.X;
51 leftFoot[i].Y = skeletons[i].Joints[JointType.AnkleLeft].Position.Y;
52 leftFoot[i].Z = skeletons[i].Joints[JointType.AnkleLeft].Position.Z;
53 rightFoot[i].X = skeletons[i].Joints[JointType.AnkleRight].Position.X;
54 rightFoot[i].Y = skeletons[i].Joints[JointType.AnkleRight].Position.Y;
55 rightFoot[i].Z = skeletons[i].Joints[JointType.AnkleRight].Position.Z;
56
57
58 }
59 }
60
61 }
62
63 public void Calibrate(int skeletonNo)
64 {
65 if(calibrated[skeletonNo] == false && calibrating[skeletonNo] == false &&
66 skeletons[skeletonNo].Joints[JointType.HandLeft].Position.Y > skeletons[skeletonNo].Joints[JointType.Head].Position.Y)
67 {
68 calibrating[skeletonNo] = true;
69 centre[skeletonNo] = calculateCentre(skeletons[skeletonNo]);
70
71 deadSpot[skeletonNo].X = centre[skeletonNo].X - deadSpotRadius/2;
72 deadSpot[skeletonNo].Z = centre[skeletonNo].Z - deadSpotRadius/2;
73
74 calibrating[skeletonNo] = false;
75 calibrated[skeletonNo] = true;
76 }
77 }
78
79 private Vector4 calculateCentre(Skeleton skel)
80 {
81 Vector4 temp = new Vector4();
82 temp.X = (skel.Joints[JointType.FootLeft].Position.X + skel.Joints[JointType.FootRight].Position.X) / 2;
83 temp.Y = (skel.Joints[JointType.FootLeft].Position.Y + skel.Joints[JointType.FootRight].Position.Y) / 2;
84 temp.Z = (skel.Joints[JointType.FootLeft].Position.Z + skel.Joints[JointType.FootRight].Position.Z) / 2;
85
86 return temp;
87 }
88
89 public int FindQuadrant(float Z, float X, Vector4 center)
90 {
91 if (Z < (center.Z + 0.8) && Z > (center.Z - 0.8) && X < (center.X + 0.8) && X > (center.X - 0.8))
92 {
93 if (Z > center.Z)
94 {
95 if (X < center.X)
96 {
97 return 4;
98 }
99 else
100 {
101 return 3;
102 }
103 }
104 else
105 {
106 if (X < center.X)
107 {
108 return 1;
109 }
110 else
111 {
112 return 2;
113 }
114 }
115 }
116 else return 0;
117 }
118 }
119}
Note: See TracBrowser for help on using the repository browser.