48 //Si il n'y a pas assez de positions dans l'historique local pour vérifier le geste. |
48 //Si il n'y a pas assez de positions dans l'historique local pour vérifier le geste. |
49 if (localHistory.Count < indexesToCheck+1) |
49 if (localHistory.Count < indexesToCheck+1) |
50 return false; |
50 return false; |
51 |
51 |
52 //La distance de référence est ici la distance entre le milieu du dos et le milieu des épaules. |
52 //La distance de référence est ici la distance entre le milieu du dos et le milieu des épaules. |
53 refDistance = Math.Abs(localHistory[0][spineID].Position.Y - localHistory[0][shoulderCenterID].Position.Y); |
53 refDistance = Math.Abs(localHistory[0][(int)JointType.Spine].Position.Y - localHistory[0][(int)JointType.ShoulderCenter].Position.Y); |
54 //On commence la position pour les indexesToCheck dernières postures (celle à l'index 0 étant la dernière). |
54 //On commence la position pour les indexesToCheck dernières postures (celle à l'index 0 étant la dernière). |
55 startPoint = localHistory[localHistory.Count - indexesToCheck][handRightID].Position; |
55 startPoint = localHistory[localHistory.Count - indexesToCheck][(int)JointType.HandRight].Position; |
56 |
56 |
57 //De la position p1 à pn, on suit l'algorithme. |
57 //De la position p1 à pn, on suit l'algorithme. |
58 for (int i = localHistory.Count - indexesToCheck + 1; i < localHistory.Count; i++) |
58 for (int i = localHistory.Count - indexesToCheck + 1; i < localHistory.Count; i++) |
59 { |
59 { |
60 //Debug temporaire pour vérifier la validité de certaines contraintes durant la gesture. |
|
61 /*if (localHistory[i][handRightID].Position.Y > localHistory[i][headID].Position.Y) |
|
62 debug.R1.Fill = System.Windows.Media.Brushes.Blue; |
|
63 else |
|
64 debug.R1.Fill = System.Windows.Media.Brushes.DarkGray; |
|
65 |
|
66 if(localHistory[i][handRightID].Position.Y < localHistory[i][hipCenterID].Position.Y) |
|
67 debug.R2.Fill = System.Windows.Media.Brushes.Blue; |
|
68 else |
|
69 debug.R2.Fill = System.Windows.Media.Brushes.DarkGray; |
|
70 |
|
71 if(localHistory[i][handRightID].Position.X < localHistory[i - 1][handRightID].Position.X) |
|
72 debug.R3.Fill = System.Windows.Media.Brushes.Blue; |
|
73 else |
|
74 debug.R3.Fill = System.Windows.Media.Brushes.DarkGray; |
|
75 |
|
76 if(Math.Abs(localHistory[i][handRightID].Position.Y - startPoint.Y) < refDistance/2) |
|
77 debug.R4.Fill = System.Windows.Media.Brushes.Blue; |
|
78 else |
|
79 debug.R4.Fill = System.Windows.Media.Brushes.DarkGray;*/ |
|
80 |
|
81 //Si la position Y de la main est plus haute que la tête |
60 //Si la position Y de la main est plus haute que la tête |
82 //OU si la position Y de la main est plus basse que la hanche |
61 //OU si la position Y de la main est plus basse que la hanche |
83 //OU si la nouvelle position X de la main est à droite de la précédente |
62 //OU si la nouvelle position X de la main est à droite de la précédente |
84 //OU si la nouvelle position Y de la main est plus éloignée de la distance N par rapport à la première position Y |
63 //OU si la nouvelle position Y de la main est plus éloignée de la distance N par rapport à la première position Y |
85 //Alors on retourne faux. |
64 //Alors on retourne faux. |
86 if (localHistory[i][handRightID].Position.Y < localHistory[i][headID].Position.Y || |
65 if (localHistory[i][(int)JointType.HandRight].Position.Y < localHistory[i][(int)JointType.Head].Position.Y || |
87 localHistory[i][handRightID].Position.Y > localHistory[i][hipCenterID].Position.Y || |
66 localHistory[i][(int)JointType.HandRight].Position.Y > localHistory[i][(int)JointType.HipCenter].Position.Y || |
88 localHistory[i][handRightID].Position.X > localHistory[i - 1][handRightID].Position.X || |
67 localHistory[i][(int)JointType.HandRight].Position.X > localHistory[i - 1][(int)JointType.HandRight].Position.X || |
89 Math.Abs(localHistory[i][handRightID].Position.Y - startPoint.Y) > refDistance/2) |
68 Math.Abs(localHistory[i][(int)JointType.HandRight].Position.Y - startPoint.Y) > refDistance / 2) |
90 return false; |
69 return false; |
91 } |
70 } |
92 |
71 |
93 //Si la distance horizontale du geste a été plus courte que la distance N |
72 //Si la distance horizontale du geste a été plus courte que la distance N |
94 //Alors on retourne faux. |
73 //Alors on retourne faux. |
95 //float dist = (localHistory[localHistory.Count - 1][handRightID].Position.X - localHistory[localHistory.Count - indexesToCheck][handRightID].Position.X); |
74 if (Math.Abs(localHistory[0][(int)JointType.HandRight].Position.X - localHistory[localHistory.Count - indexesToCheck][(int)JointType.HandRight].Position.X) < refDistance / 2) |
96 |
|
97 if (Math.Abs(localHistory[0][handRightID].Position.X - localHistory[localHistory.Count - indexesToCheck][handRightID].Position.X) < refDistance/2) |
|
98 return false; |
75 return false; |
99 |
76 |
100 //Si la dernière position de la main droite est sur le côté droit du corps |
77 //Si la dernière position de la main droite est sur le côté droit du corps |
101 //OU si la première position calculée de la main droite est sur le côté gauche du corps |
78 //OU si la première position calculée de la main droite est sur le côté gauche du corps |
102 //Alors on retourne faux. |
79 //Alors on retourne faux. |
103 if(localHistory[localHistory.Count - 1][handRightID].Position.X > localHistory[localHistory.Count - 1][hipCenterID].Position.X || |
80 if (localHistory[localHistory.Count - 1][(int)JointType.HandRight].Position.X > localHistory[localHistory.Count - 1][(int)JointType.HipCenter].Position.X || |
104 localHistory[localHistory.Count - indexesToCheck][handRightID].Position.X < localHistory[localHistory.Count - 1][hipCenterID].Position.X) |
81 localHistory[localHistory.Count - indexesToCheck][(int)JointType.HandRight].Position.X < localHistory[localHistory.Count - 1][(int)JointType.HipCenter].Position.X) |
105 return false; |
82 return false; |
106 |
83 |
107 //System.Console.Out.WriteLine(Math.Abs(localHistory[0][handRightID].Position.X - localHistory[localHistory.Count - indexesToCheck][handRightID].Position.X) + " < " + refDistance/2); |
|
108 //On supprime l'historique local. |
84 //On supprime l'historique local. |
109 localHistory.Clear(); |
85 localHistory.Clear(); |
110 //Si on est arrivé jusqu'ici, toutes les conditions pour un swipe left ont été remplies. |
86 //Si on est arrivé jusqu'ici, toutes les conditions pour un swipe left ont été remplies. |
111 return true; |
87 return true; |
112 } |
88 } |
127 //Si il n'y a pas assez de positions dans l'historique local pour vérifier le geste. |
103 //Si il n'y a pas assez de positions dans l'historique local pour vérifier le geste. |
128 if (localHistory.Count < indexesToCheck + 1) |
104 if (localHistory.Count < indexesToCheck + 1) |
129 return false; |
105 return false; |
130 |
106 |
131 //La distance de référence est ici la distance entre le milieu du dos et le milieu des épaules. |
107 //La distance de référence est ici la distance entre le milieu du dos et le milieu des épaules. |
132 refDistance = Math.Abs(localHistory[0][spineID].Position.Y - localHistory[0][shoulderCenterID].Position.Y); |
108 refDistance = Math.Abs(localHistory[0][(int)JointType.Spine].Position.Y - localHistory[0][(int)JointType.ShoulderCenter].Position.Y); |
133 //On commence la position pour les indexesToCheck dernières postures (celle à l'index 0 étant la dernière). |
109 //On commence la position pour les indexesToCheck dernières postures (celle à l'index 0 étant la dernière). |
134 startPoint = localHistory[localHistory.Count - indexesToCheck][handLeftID].Position; |
110 startPoint = localHistory[localHistory.Count - indexesToCheck][(int)JointType.HandLeft].Position; |
135 |
111 |
136 //De la position p1 à pn, on suit l'algorithme. |
112 //De la position p1 à pn, on suit l'algorithme. |
137 for (int i = localHistory.Count - indexesToCheck + 1; i < localHistory.Count; i++) |
113 for (int i = localHistory.Count - indexesToCheck + 1; i < localHistory.Count; i++) |
138 { |
114 { |
139 //Debug temporaire pour vérifier la validité de certaines contraintes durant la gesture. |
|
140 /*if (localHistory[i][handLeftID].Position.Y > localHistory[i][headID].Position.Y) |
|
141 debug.R1.Fill = System.Windows.Media.Brushes.Cyan; |
|
142 else |
|
143 debug.R1.Fill = System.Windows.Media.Brushes.DarkGray; |
|
144 |
|
145 if (localHistory[i][handLeftID].Position.Y < localHistory[i][hipCenterID].Position.Y) |
|
146 debug.R2.Fill = System.Windows.Media.Brushes.Cyan; |
|
147 else |
|
148 debug.R2.Fill = System.Windows.Media.Brushes.DarkGray; |
|
149 |
|
150 if (localHistory[i][handLeftID].Position.X > localHistory[i - 1][handLeftID].Position.X) |
|
151 debug.R3.Fill = System.Windows.Media.Brushes.Cyan; |
|
152 else |
|
153 debug.R3.Fill = System.Windows.Media.Brushes.DarkGray; |
|
154 |
|
155 if (Math.Abs(localHistory[i][handLeftID].Position.Y - startPoint.Y) < refDistance / 2) |
|
156 debug.R4.Fill = System.Windows.Media.Brushes.Cyan; |
|
157 else |
|
158 debug.R4.Fill = System.Windows.Media.Brushes.DarkGray;*/ |
|
159 |
|
160 //Si la position Y de la main est plus haute que la tête |
115 //Si la position Y de la main est plus haute que la tête |
161 //OU si la position Y de la main est plus basse que la hanche |
116 //OU si la position Y de la main est plus basse que la hanche |
162 //OU si la nouvelle position X de la main est à gauche de la précédente |
117 //OU si la nouvelle position X de la main est à gauche de la précédente |
163 //OU si la nouvelle position Y de la main est plus éloignée de la distance N par rapport à la première position Y |
118 //OU si la nouvelle position Y de la main est plus éloignée de la distance N par rapport à la première position Y |
164 //Alors on retourne faux. |
119 //Alors on retourne faux. |
165 if (localHistory[i][handLeftID].Position.Y < localHistory[i][headID].Position.Y || |
120 if (localHistory[i][(int)JointType.HandLeft].Position.Y < localHistory[i][(int)JointType.Head].Position.Y || |
166 localHistory[i][handLeftID].Position.Y > localHistory[i][hipCenterID].Position.Y || |
121 localHistory[i][(int)JointType.HandLeft].Position.Y > localHistory[i][(int)JointType.HipCenter].Position.Y || |
167 localHistory[i][handLeftID].Position.X < localHistory[i - 1][handLeftID].Position.X || |
122 localHistory[i][(int)JointType.HandLeft].Position.X < localHistory[i - 1][(int)JointType.HandLeft].Position.X || |
168 Math.Abs(localHistory[i][handLeftID].Position.Y - startPoint.Y) > refDistance / 2) |
123 Math.Abs(localHistory[i][(int)JointType.HandLeft].Position.Y - startPoint.Y) > refDistance / 2) |
169 return false; |
124 return false; |
170 } |
125 } |
171 |
126 |
172 //Si la distance horizontale du geste a été plus courte que la distance N |
127 //Si la distance horizontale du geste a été plus courte que la distance N |
173 //Alors on retourne faux. |
128 //Alors on retourne faux. |
174 //float dist = (localHistory[localHistory.Count - 1][handLeftID].Position.X - localHistory[localHistory.Count - indexesToCheck][handLeftID].Position.X); |
129 if (Math.Abs(localHistory[0][(int)JointType.HandLeft].Position.X - localHistory[localHistory.Count - indexesToCheck][(int)JointType.HandLeft].Position.X) < refDistance / 2) |
175 |
|
176 if (Math.Abs(localHistory[0][handLeftID].Position.X - localHistory[localHistory.Count - indexesToCheck][handLeftID].Position.X) < refDistance / 2) |
|
177 return false; |
130 return false; |
178 |
131 |
179 //Si la dernière position de la main droite est sur le côté gauche du corps |
132 //Si la dernière position de la main droite est sur le côté gauche du corps |
180 //OU si la première position calculée de la main droite est sur le côté droit du corps |
133 //OU si la première position calculée de la main droite est sur le côté droit du corps |
181 //Alors on retourne faux. |
134 //Alors on retourne faux. |
182 if (localHistory[localHistory.Count - 1][handLeftID].Position.X < localHistory[localHistory.Count - 1][hipCenterID].Position.X || |
135 if (localHistory[localHistory.Count - 1][(int)JointType.HandLeft].Position.X < localHistory[localHistory.Count - 1][(int)JointType.HipCenter].Position.X || |
183 localHistory[localHistory.Count - indexesToCheck][handLeftID].Position.X > localHistory[localHistory.Count - 1][hipCenterID].Position.X) |
136 localHistory[localHistory.Count - indexesToCheck][(int)JointType.HandLeft].Position.X > localHistory[localHistory.Count - 1][(int)JointType.HipCenter].Position.X) |
184 return false; |
137 return false; |
185 |
138 |
186 //System.Console.Out.WriteLine(Math.Abs(localHistory[0][handLeftID].Position.X - localHistory[localHistory.Count - indexesToCheck][handLeftID].Position.X) + " < " + refDistance / 2); |
|
187 //On supprime l'historique local. |
139 //On supprime l'historique local. |
188 localHistory.Clear(); |
140 localHistory.Clear(); |
189 //Si on est arrivé jusqu'ici, toutes les conditions pour un swipe right ont été remplies. |
141 //Si on est arrivé jusqu'ici, toutes les conditions pour un swipe right ont été remplies. |
190 return true; |
142 return true; |
191 } |
143 } |