49 //Si il n'y a pas assez de positions dans l'historique local pour vérifier le geste. |
49 //Si il n'y a pas assez de positions dans l'historique local pour vérifier le geste. |
50 if (localHistory.Count < indexesToCheck + 1) |
50 if (localHistory.Count < indexesToCheck + 1) |
51 return Hand.NONE; |
51 return Hand.NONE; |
52 |
52 |
53 //La distance de référence est ici la distance entre le milieu du dos et le milieu des épaules. |
53 //La distance de référence est ici la distance entre le milieu du dos et le milieu des épaules. |
54 refDistance = Math.Abs(localHistory[0][spineID].Position.Y - localHistory[0][shoulderCenterID].Position.Y); |
54 refDistance = Math.Abs(localHistory[0][(int)JointType.Spine].Position.Y - localHistory[0][(int)JointType.ShoulderCenter].Position.Y); |
55 //On commence la position pour les indexesToCheck dernières postures (celle à l'index 0 étant la dernière). |
55 //On commence la position pour les indexesToCheck dernières postures (celle à l'index 0 étant la dernière). |
56 SkeletonPoint startPointLeft = localHistory[localHistory.Count - indexesToCheck][handLeftID].Position; |
56 SkeletonPoint startPointLeft = localHistory[localHistory.Count - indexesToCheck][(int)JointType.HandLeft].Position; |
57 SkeletonPoint startPointRight = localHistory[localHistory.Count - indexesToCheck][handRightID].Position; |
57 SkeletonPoint startPointRight = localHistory[localHistory.Count - indexesToCheck][(int)JointType.HandRight].Position; |
58 |
58 |
59 //Booléens indiquant si le mouvement serait valide pour la main gauche ou droite. |
59 //Booléens indiquant si le mouvement serait valide pour la main gauche ou droite. |
60 bool leftHandOK = true, rightHandOK = true; |
60 bool leftHandOK = true, rightHandOK = true; |
61 |
61 |
62 //De la position p1 à pn, on suit l'algorithme. |
62 //De la position p1 à pn, on suit l'algorithme. |
63 for (int i = localHistory.Count - indexesToCheck + 1; i < localHistory.Count; i++) |
63 for (int i = localHistory.Count - indexesToCheck + 1; i < localHistory.Count; i++) |
64 { |
64 { |
65 if (localHistory[i][handRightID].Position.Y > localHistory[i][headID].Position.Y) |
|
66 debug.R1.Fill = System.Windows.Media.Brushes.Blue; |
|
67 else |
|
68 debug.R1.Fill = System.Windows.Media.Brushes.DarkGray; |
|
69 |
|
70 if (localHistory[i][handRightID].Position.Y < localHistory[i][hipCenterID].Position.Y) |
|
71 debug.R2.Fill = System.Windows.Media.Brushes.Blue; |
|
72 else |
|
73 debug.R2.Fill = System.Windows.Media.Brushes.DarkGray; |
|
74 |
|
75 if (localHistory[i][handRightID].Position.Z < localHistory[i - 1][handRightID].Position.Z) |
|
76 debug.R3.Fill = System.Windows.Media.Brushes.Blue; |
|
77 else |
|
78 debug.R3.Fill = System.Windows.Media.Brushes.DarkGray; |
|
79 |
|
80 //Console.Out.WriteLine(Math.Abs(localHistory[i][handRightID].Position.X - startPointRight.X) + " " + Math.Abs(localHistory[i][handRightID].Position.Y - startPointRight.Y) + " " + refDistance / 10); |
|
81 |
|
82 if (Math.Abs(localHistory[i][handRightID].Position.X - startPointRight.X) < refDistance / 5 && |
|
83 Math.Abs(localHistory[i][handRightID].Position.Y - startPointRight.Y) < refDistance / 5) |
|
84 debug.R4.Fill = System.Windows.Media.Brushes.Blue; |
|
85 else |
|
86 debug.R4.Fill = System.Windows.Media.Brushes.DarkGray; |
|
87 |
|
88 //Si la position Y de la main est plus haute que la tête |
65 //Si la position Y de la main est plus haute que la tête |
89 //OU si la position Y de la main est plus basse que la hanche |
66 //OU si la position Y de la main est plus basse que la hanche |
90 //OU si la nouvelle position Z de la main est moins profonde que la précédente |
67 //OU si la nouvelle position Z de la main est moins profonde que la précédente |
91 //OU si la nouvelle position X de la main est plus éloignée de la distance N par rapport à la première position X |
68 //OU si la nouvelle position X de la main est plus éloignée de la distance N par rapport à la première position X |
92 //OU si la nouvelle position Y de la main est plus éloignée de la distance N par rapport à la première position Y |
69 //OU si la nouvelle position Y de la main est plus éloignée de la distance N par rapport à la première position Y |
93 //Alors la main en question ne fait pas de push. |
70 //Alors la main en question ne fait pas de push. |
94 if (localHistory[i][handLeftID].Position.Y < localHistory[i][headID].Position.Y || |
71 if (localHistory[i][(int)JointType.HandLeft].Position.Y < localHistory[i][(int)JointType.Head].Position.Y || |
95 localHistory[i][handLeftID].Position.Y > localHistory[i][hipCenterID].Position.Y || |
72 localHistory[i][(int)JointType.HandLeft].Position.Y > localHistory[i][(int)JointType.HipCenter].Position.Y || |
96 localHistory[i][handLeftID].Position.Z > localHistory[i - 1][handLeftID].Position.Z || |
73 localHistory[i][(int)JointType.HandLeft].Position.Z > localHistory[i - 1][(int)JointType.HandLeft].Position.Z || |
97 Math.Abs(localHistory[i][handLeftID].Position.X - startPointLeft.X) > refDistance / 5 || |
74 Math.Abs(localHistory[i][(int)JointType.HandLeft].Position.X - startPointLeft.X) > refDistance / 5 || |
98 Math.Abs(localHistory[i][handLeftID].Position.Y - startPointLeft.Y) > refDistance / 5) |
75 Math.Abs(localHistory[i][(int)JointType.HandLeft].Position.Y - startPointLeft.Y) > refDistance / 5) |
99 leftHandOK = false; |
76 leftHandOK = false; |
100 if (localHistory[i][handRightID].Position.Y < localHistory[i][headID].Position.Y || |
77 if (localHistory[i][(int)JointType.HandRight].Position.Y < localHistory[i][(int)JointType.Head].Position.Y || |
101 localHistory[i][handRightID].Position.Y > localHistory[i][hipCenterID].Position.Y || |
78 localHistory[i][(int)JointType.HandRight].Position.Y > localHistory[i][(int)JointType.HipCenter].Position.Y || |
102 localHistory[i][handRightID].Position.Z > localHistory[i - 1][handRightID].Position.Z || |
79 localHistory[i][(int)JointType.HandRight].Position.Z > localHistory[i - 1][(int)JointType.HandRight].Position.Z || |
103 Math.Abs(localHistory[i][handRightID].Position.X - startPointRight.X) > refDistance / 5 || |
80 Math.Abs(localHistory[i][(int)JointType.HandRight].Position.X - startPointRight.X) > refDistance / 5 || |
104 Math.Abs(localHistory[i][handRightID].Position.Y - startPointRight.Y) > refDistance / 5) |
81 Math.Abs(localHistory[i][(int)JointType.HandRight].Position.Y - startPointRight.Y) > refDistance / 5) |
105 rightHandOK = false; |
82 rightHandOK = false; |
106 |
83 |
107 if (!leftHandOK && !rightHandOK) |
84 if (!leftHandOK && !rightHandOK) |
108 return Hand.NONE; |
85 return Hand.NONE; |
109 } |
86 } |
110 |
87 |
111 //Console.Out.WriteLine("OK"); |
|
112 |
|
113 if (Math.Abs(localHistory[localHistory.Count - 1][handRightID].Position.Z - localHistory[localHistory.Count - indexesToCheck][handRightID].Position.Z) * 100 > 20) |
|
114 debug.R5.Fill = System.Windows.Media.Brushes.Blue; |
|
115 else |
|
116 debug.R5.Fill = System.Windows.Media.Brushes.DarkGray; |
|
117 |
|
118 if (localHistory[localHistory.Count - 1][handRightID].Position.X > localHistory[localHistory.Count - 1][hipCenterID].Position.X || |
|
119 localHistory[localHistory.Count - indexesToCheck][handRightID].Position.X > localHistory[localHistory.Count - 1][hipCenterID].Position.X) |
|
120 debug.R6.Fill = System.Windows.Media.Brushes.Blue; |
|
121 else |
|
122 debug.R6.Fill = System.Windows.Media.Brushes.DarkGray; |
|
123 |
|
124 //Si la distance en Z du geste a été plus courte que la distance N |
88 //Si la distance en Z du geste a été plus courte que la distance N |
125 //Alors on retourne faux. |
89 //Alors on retourne faux. |
126 //float dist = (localHistory[localHistory.Count - 1][handRightID].Position.X - localHistory[localHistory.Count - indexesToCheck][handRightID].Position.X); |
90 if (Math.Abs(localHistory[localHistory.Count - 1][(int)JointType.HandLeft].Position.Z - localHistory[localHistory.Count - indexesToCheck][(int)JointType.HandLeft].Position.Z) * 100 < 20) |
127 |
91 leftHandOK = false; |
128 //Console.WriteLine(Math.Abs(localHistory[0][handLeftID].Position.Z - localHistory[localHistory.Count - indexesToCheck][handLeftID].Position.Z) * 100 + " " + refDistance); |
92 if (Math.Abs(localHistory[localHistory.Count - 1][(int)JointType.HandRight].Position.Z - localHistory[localHistory.Count - indexesToCheck][(int)JointType.HandRight].Position.Z) * 100 < 20) |
129 |
93 rightHandOK = false; |
130 if (Math.Abs(localHistory[localHistory.Count - 1][handLeftID].Position.Z - localHistory[localHistory.Count - indexesToCheck][handLeftID].Position.Z) * 100 < 20) |
94 |
131 leftHandOK = false; |
|
132 if (Math.Abs(localHistory[localHistory.Count - 1][handRightID].Position.Z - localHistory[localHistory.Count - indexesToCheck][handRightID].Position.Z) * 100 < 20) |
|
133 rightHandOK = false; |
|
134 |
|
135 /*if(rightHandOK || leftHandOK) |
|
136 Console.Out.WriteLine("000000000");*/ |
|
137 |
|
138 //Si la dernière position de la main droite/gauche est sur le côté gauche/droit du corps |
95 //Si la dernière position de la main droite/gauche est sur le côté gauche/droit du corps |
139 //OU si la première position calculée de la main droite/gauche est sur le côté gauche/droit du corps |
96 //OU si la première position calculée de la main droite/gauche est sur le côté gauche/droit du corps |
140 //Alors on retourne faux. |
97 //Alors on retourne faux. |
141 if (localHistory[localHistory.Count - 1][handLeftID].Position.X > localHistory[localHistory.Count - 1][hipCenterID].Position.X || |
98 if (localHistory[localHistory.Count - 1][(int)JointType.HandLeft].Position.X > localHistory[localHistory.Count - 1][(int)JointType.HipCenter].Position.X || |
142 localHistory[localHistory.Count - indexesToCheck][handLeftID].Position.X > localHistory[localHistory.Count - 1][hipCenterID].Position.X) |
99 localHistory[localHistory.Count - indexesToCheck][(int)JointType.HandLeft].Position.X > localHistory[localHistory.Count - 1][(int)JointType.HipCenter].Position.X) |
143 leftHandOK = false; |
100 leftHandOK = false; |
144 if (localHistory[localHistory.Count - 1][handRightID].Position.X < localHistory[localHistory.Count - 1][hipCenterID].Position.X || |
101 if (localHistory[localHistory.Count - 1][(int)JointType.HandRight].Position.X < localHistory[localHistory.Count - 1][(int)JointType.HipCenter].Position.X || |
145 localHistory[localHistory.Count - indexesToCheck][handRightID].Position.X < localHistory[localHistory.Count - 1][hipCenterID].Position.X) |
102 localHistory[localHistory.Count - indexesToCheck][(int)JointType.HandRight].Position.X < localHistory[localHistory.Count - 1][(int)JointType.HipCenter].Position.X) |
146 rightHandOK = false; |
103 rightHandOK = false; |
147 |
|
148 /*if (rightHandOK || leftHandOK) |
|
149 Console.Out.WriteLine("11111111111");*/ |
|
150 |
104 |
151 if (!leftHandOK && !rightHandOK) |
105 if (!leftHandOK && !rightHandOK) |
152 return Hand.NONE; |
106 return Hand.NONE; |
153 |
|
154 /*if (rightHandOK || leftHandOK) |
|
155 Console.Out.WriteLine("================");*/ |
|
156 |
107 |
157 //On supprime l'historique local. |
108 //On supprime l'historique local. |
158 localHistory.Clear(); |
109 localHistory.Clear(); |
159 |
110 |
160 debug.ExceptionLbl.Background = System.Windows.Media.Brushes.White; |
111 debug.ExceptionLbl.Background = System.Windows.Media.Brushes.White; |
161 //Console.WriteLine("PUSH"); |
|
162 //Console.Read(); |
|
163 |
|
164 //Si on est arrivé jusqu'ici, toutes les conditions pour un push ont été remplies. |
112 //Si on est arrivé jusqu'ici, toutes les conditions pour un push ont été remplies. |
|
113 |
165 if (leftHandOK && rightHandOK) |
114 if (leftHandOK && rightHandOK) |
166 return Hand.BOTH; |
115 return Hand.BOTH; |
167 else if (leftHandOK) |
116 else if (leftHandOK) |
168 return Hand.LEFT; |
117 return Hand.LEFT; |
169 else if (rightHandOK) |
118 else if (rightHandOK) |
205 //OU si la position Y de la main est plus basse que la hanche |
154 //OU si la position Y de la main est plus basse que la hanche |
206 //OU si la nouvelle position Z de la main est plus profonde que la précédente |
155 //OU si la nouvelle position Z de la main est plus profonde que la précédente |
207 //OU si la nouvelle position X de la main est plus éloignée de la distance N par rapport à la première position X |
156 //OU si la nouvelle position X de la main est plus éloignée de la distance N par rapport à la première position X |
208 //OU si la nouvelle position Y de la main est plus éloignée de la distance N par rapport à la première position Y |
157 //OU si la nouvelle position Y de la main est plus éloignée de la distance N par rapport à la première position Y |
209 //Alors la main en question ne fait pas de push. |
158 //Alors la main en question ne fait pas de push. |
210 if (localHistory[i][handLeftID].Position.Y < localHistory[i][headID].Position.Y || |
159 if (localHistory[i][(int)JointType.HandLeft].Position.Y < localHistory[i][(int)JointType.Head].Position.Y || |
211 localHistory[i][handLeftID].Position.Y > localHistory[i][hipCenterID].Position.Y || |
160 localHistory[i][(int)JointType.HandLeft].Position.Y > localHistory[i][(int)JointType.HipCenter].Position.Y || |
212 localHistory[i][handLeftID].Position.Z < localHistory[i - 1][handLeftID].Position.Z || |
161 localHistory[i][(int)JointType.HandLeft].Position.Z < localHistory[i - 1][(int)JointType.HandLeft].Position.Z || |
213 Math.Abs(localHistory[i][handLeftID].Position.X - startPointLeft.X) > refDistance / 5 || |
162 Math.Abs(localHistory[i][(int)JointType.HandLeft].Position.X - startPointLeft.X) > refDistance / 5 || |
214 Math.Abs(localHistory[i][handLeftID].Position.Y - startPointLeft.Y) > refDistance / 5) |
163 Math.Abs(localHistory[i][(int)JointType.HandLeft].Position.Y - startPointLeft.Y) > refDistance / 5) |
215 leftHandOK = false; |
164 leftHandOK = false; |
216 if (localHistory[i][handRightID].Position.Y < localHistory[i][headID].Position.Y || |
165 if (localHistory[i][(int)JointType.HandRight].Position.Y < localHistory[i][(int)JointType.Head].Position.Y || |
217 localHistory[i][handRightID].Position.Y > localHistory[i][hipCenterID].Position.Y || |
166 localHistory[i][(int)JointType.HandRight].Position.Y > localHistory[i][(int)JointType.HipCenter].Position.Y || |
218 localHistory[i][handRightID].Position.Z < localHistory[i - 1][handRightID].Position.Z || |
167 localHistory[i][(int)JointType.HandRight].Position.Z < localHistory[i - 1][(int)JointType.HandRight].Position.Z || |
219 Math.Abs(localHistory[i][handRightID].Position.X - startPointRight.X) > refDistance / 5 || |
168 Math.Abs(localHistory[i][(int)JointType.HandRight].Position.X - startPointRight.X) > refDistance / 5 || |
220 Math.Abs(localHistory[i][handRightID].Position.Y - startPointRight.Y) > refDistance / 5) |
169 Math.Abs(localHistory[i][(int)JointType.HandRight].Position.Y - startPointRight.Y) > refDistance / 5) |
221 rightHandOK = false; |
170 rightHandOK = false; |
222 |
171 |
223 if (!leftHandOK && !rightHandOK) |
172 if (!leftHandOK && !rightHandOK) |
224 return Hand.NONE; |
173 return Hand.NONE; |
225 } |
174 } |
226 |
175 |
227 //Console.Out.WriteLine("OK"); |
|
228 |
|
229 if (Math.Abs(localHistory[localHistory.Count - 1][handRightID].Position.Z - localHistory[localHistory.Count - indexesToCheck][handRightID].Position.Z) * 100 > 20) |
|
230 debug.R5.Fill = System.Windows.Media.Brushes.Blue; |
|
231 else |
|
232 debug.R5.Fill = System.Windows.Media.Brushes.DarkGray; |
|
233 |
|
234 if (localHistory[localHistory.Count - 1][handRightID].Position.X > localHistory[localHistory.Count - 1][hipCenterID].Position.X || |
|
235 localHistory[localHistory.Count - indexesToCheck][handRightID].Position.X > localHistory[localHistory.Count - 1][hipCenterID].Position.X) |
|
236 debug.R6.Fill = System.Windows.Media.Brushes.Blue; |
|
237 else |
|
238 debug.R6.Fill = System.Windows.Media.Brushes.DarkGray; |
|
239 |
|
240 //Si la distance en Z du geste a été plus courte que la distance N |
176 //Si la distance en Z du geste a été plus courte que la distance N |
241 //Alors on retourne faux. |
177 //Alors on retourne faux. |
242 //float dist = (localHistory[localHistory.Count - 1][handRightID].Position.X - localHistory[localHistory.Count - indexesToCheck][handRightID].Position.X); |
178 if (Math.Abs(localHistory[localHistory.Count - 1][(int)JointType.HandLeft].Position.Z - localHistory[localHistory.Count - indexesToCheck][(int)JointType.HandLeft].Position.Z) * 100 < 20) |
243 |
179 leftHandOK = false; |
244 //Console.WriteLine(Math.Abs(localHistory[0][handLeftID].Position.Z - localHistory[localHistory.Count - indexesToCheck][handLeftID].Position.Z) * 100 + " " + refDistance); |
180 if (Math.Abs(localHistory[localHistory.Count - 1][(int)JointType.HandRight].Position.Z - localHistory[localHistory.Count - indexesToCheck][(int)JointType.HandRight].Position.Z) * 100 < 20) |
245 |
181 rightHandOK = false; |
246 if (Math.Abs(localHistory[localHistory.Count - 1][handLeftID].Position.Z - localHistory[localHistory.Count - indexesToCheck][handLeftID].Position.Z) * 100 < 20) |
|
247 leftHandOK = false; |
|
248 if (Math.Abs(localHistory[localHistory.Count - 1][handRightID].Position.Z - localHistory[localHistory.Count - indexesToCheck][handRightID].Position.Z) * 100 < 20) |
|
249 rightHandOK = false; |
|
250 |
|
251 /*if (rightHandOK || leftHandOK) |
|
252 Console.Out.WriteLine("000000000");*/ |
|
253 |
182 |
254 //Si la dernière position de la main droite/gauche est sur le côté gauche/droit du corps |
183 //Si la dernière position de la main droite/gauche est sur le côté gauche/droit du corps |
255 //OU si la première position calculée de la main droite/gauche est sur le côté gauche/droit du corps |
184 //OU si la première position calculée de la main droite/gauche est sur le côté gauche/droit du corps |
256 //Alors on retourne faux. |
185 //Alors on retourne faux. |
257 if (localHistory[localHistory.Count - 1][handLeftID].Position.X > localHistory[localHistory.Count - 1][hipCenterID].Position.X || |
186 if (localHistory[localHistory.Count - 1][(int)JointType.HandLeft].Position.X > localHistory[localHistory.Count - 1][(int)JointType.HipCenter].Position.X || |
258 localHistory[localHistory.Count - indexesToCheck][handLeftID].Position.X > localHistory[localHistory.Count - 1][hipCenterID].Position.X) |
187 localHistory[localHistory.Count - indexesToCheck][(int)JointType.HandLeft].Position.X > localHistory[localHistory.Count - 1][(int)JointType.HipCenter].Position.X) |
259 leftHandOK = false; |
188 leftHandOK = false; |
260 if (localHistory[localHistory.Count - 1][handRightID].Position.X < localHistory[localHistory.Count - 1][hipCenterID].Position.X || |
189 if (localHistory[localHistory.Count - 1][(int)JointType.HandRight].Position.X < localHistory[localHistory.Count - 1][(int)JointType.HipCenter].Position.X || |
261 localHistory[localHistory.Count - indexesToCheck][handRightID].Position.X < localHistory[localHistory.Count - 1][hipCenterID].Position.X) |
190 localHistory[localHistory.Count - indexesToCheck][(int)JointType.HandRight].Position.X < localHistory[localHistory.Count - 1][(int)JointType.HipCenter].Position.X) |
262 rightHandOK = false; |
191 rightHandOK = false; |
263 |
|
264 /*if (rightHandOK || leftHandOK) |
|
265 Console.Out.WriteLine("11111111111");*/ |
|
266 |
192 |
267 if (!leftHandOK && !rightHandOK) |
193 if (!leftHandOK && !rightHandOK) |
268 return Hand.NONE; |
194 return Hand.NONE; |
269 |
|
270 /*if (rightHandOK || leftHandOK) |
|
271 Console.Out.WriteLine("================");*/ |
|
272 |
195 |
273 //On supprime l'historique local. |
196 //On supprime l'historique local. |
274 localHistory.Clear(); |
197 localHistory.Clear(); |
275 |
198 |
276 debug.ExceptionLbl.Background = System.Windows.Media.Brushes.Black; |
199 debug.ExceptionLbl.Background = System.Windows.Media.Brushes.Black; |
277 //Console.WriteLine("PUSH"); |
200 |
278 //Console.Read(); |
|
279 |
|
280 //Si on est arrivé jusqu'ici, toutes les conditions pour un push ont été remplies. |
201 //Si on est arrivé jusqu'ici, toutes les conditions pour un push ont été remplies. |
281 if (leftHandOK && rightHandOK) |
202 if (leftHandOK && rightHandOK) |
282 return Hand.BOTH; |
203 return Hand.BOTH; |
283 else if (leftHandOK) |
204 else if (leftHandOK) |
284 return Hand.LEFT; |
205 return Hand.LEFT; |