-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomController3.cs
218 lines (190 loc) · 8.69 KB
/
CustomController3.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows.Controls;
using Microsoft.Research.Kinect.Nui;
using Coding4Fun.Kinect.Wpf;
namespace SkeletalTracking
{
// Controller 1: Shoulder-tracking of user orientation
class CustomController3 : SkeletonController
{
private MainWindow window;
// Variables to keep "time"
public int selectCount = 0;
public CustomController3(MainWindow win)
: base(win)
{
window = win;
}
public override void processSkeletonFrame(SkeletonData skeleton, Dictionary<int, Target> targets)
{
if (targets[4].isSelected())
{
// Birdwatcher Menu (targets 4, 5) is displayed
Joint rightHand = skeleton.Joints[JointID.HandRight].ScaleTo(640, 480, window.k_xMaxJointScale, window.k_yMaxJointScale);
//Calculate how far our right hand is from target 5 in both x and y directions
double deltaX_right = Math.Abs(rightHand.Position.X - targets[5].getXPosition());
double deltaY_right = Math.Abs(rightHand.Position.Y - targets[5].getYPosition());
//If we have a hit in a reasonable range, highlight the target5
if (deltaX_right < 20 && deltaY_right < 20)
{
targets[5].setTargetSelected();
selectCount++;
if (selectCount > 10)
{
// target 5 selected, clear menu and return to Navigation (Targets 1,2,3)
// hide Targets 4,5
targets[4].setTargetUnselected();
targets[4].hideTarget();
targets[5].setTargetUnselected();
targets[5].hideTarget();
// show Targets 1,2,3
//targets[1].setTargetUnselected();
//targets[2].setTargetUnselected();
//targets[3].setTargetUnselected();
targets[1].showTarget();
targets[2].showTarget();
targets[3].showTarget();
targets[6].showTarget();
targets[7].showTarget();
// reset the count
selectCount = 0;
}
}
else
{
targets[5].setTargetUnselected();
selectCount = 0; // reset the count
}
}
else
{
// Birdwatcher Menu is NOT up. Detect Navigation.
// Get right foot position
Point rightFootPosition;
Joint rightFoot = skeleton.Joints[JointID.FootRight];
rightFootPosition = new Point(rightFoot.Position.X, rightFoot.Position.Z);
// Get left foot position
Point leftFootPosition;
Joint leftFoot = skeleton.Joints[JointID.FootLeft];
leftFootPosition = new Point(leftFoot.Position.X, leftFoot.Position.Z);
double feetDifferential = leftFootPosition.Y - rightFootPosition.Y;
if (feetDifferential > 0.1)
{
// move forward (select 1)
targets[2].setTargetUnselected();
targets[3].setTargetUnselected();
targets[1].setTargetSelected();
}
else if (feetDifferential < -0.1)
{
// move backward (select 3)
targets[1].setTargetUnselected();
targets[2].setTargetUnselected();
targets[3].setTargetSelected();
}
else
{
// stay put (select 2)
targets[1].setTargetUnselected();
targets[3].setTargetUnselected();
targets[2].setTargetSelected();
}
// Detect left-right shoulder navigation
// Gets right shoulder position
Joint rightShoulder = skeleton.Joints[JointID.ShoulderRight];
Point rightNav = new Point(rightShoulder.Position.X, rightShoulder.Position.Z);
Joint leftShoulder = skeleton.Joints[JointID.ShoulderLeft];
Point leftNav = new Point(leftShoulder.Position.X, leftShoulder.Position.Z);
double shoulderDifferential = leftNav.Y - rightNav.Y;
if (shoulderDifferential > 0.05) // Right
{
targets[6].setTargetSelected();
targets[7].setTargetUnselected();
}
else if (shoulderDifferential < -0.05) // Left
{
targets[6].setTargetUnselected();
targets[7].setTargetSelected();
}
else
{
targets[6].setTargetUnselected();
targets[7].setTargetUnselected();
}
// Detect Birdwatcher Gesture
// Get head position
Point headPosition;
Joint head = skeleton.Joints[JointID.Head];
headPosition = new Point(head.Position.X, head.Position.Y);
// Get right hand position
Point rightHandPosition;
Joint rightHand = skeleton.Joints[JointID.HandRight];
rightHandPosition = new Point(rightHand.Position.X, rightHand.Position.Y);
Point rightElbowPosition;
Joint rightElbow = skeleton.Joints[JointID.ElbowRight];
rightElbowPosition = new Point(rightElbow.Position.X, rightElbow.Position.Y);
// Get right shoulder position
Point rightShoulderPosition;
//Joint rightShoulder = skeleton.Joints[JointID.ShoulderRight];
rightShoulderPosition = new Point(rightShoulder.Position.X, rightShoulder.Position.Y);
//Calculate how far our right hand is from target 5 in both x and y directions
double deltaX = Math.Abs(rightHandPosition.X - headPosition.X);
double deltaY = Math.Abs(rightHandPosition.Y - headPosition.Y);
double headelbowXDifferential = rightElbowPosition.X - headPosition.X;
// y increases towards top
// hand > elbow > shoulder
if (deltaY < 0.03
&& rightHandPosition.Y > rightElbowPosition.Y
&& rightElbowPosition.Y > rightShoulderPosition.Y
&& deltaX < 0.3
&& headelbowXDifferential > 0.2)
{
// Birdwatcher! (highlight 4 and show 5)
targets[4].showTarget();
targets[4].setTargetSelected();
targets[5].showTarget();
// hide navigation targets 1,2,3
targets[1].setTargetUnselected();
targets[2].setTargetUnselected();
targets[3].setTargetUnselected();
targets[1].hideTarget();
targets[2].hideTarget();
targets[3].hideTarget();
targets[6].setTargetUnselected();
targets[7].setTargetUnselected();
targets[6].hideTarget();
targets[7].hideTarget();
}
}
}
public override void controllerActivated(Dictionary<int, Target> targets)
{
targets[1].setTargetUnselected();
targets[1].showTarget();
targets[1].setTargetPosition(262, 30);
targets[2].setTargetUnselected();
targets[2].showTarget();
targets[2].setTargetPosition(262, 150);
targets[3].setTargetUnselected();
targets[3].showTarget();
targets[3].setTargetPosition(262, 270);
targets[4].setTargetUnselected();
targets[4].hideTarget();
targets[4].setTargetPosition(400, 30);
targets[5].setTargetUnselected();
targets[5].hideTarget();
targets[5].setTargetPosition(400, 150);
// show left-right directional targets
targets[6].setTargetUnselected();
targets[6].showTarget();
targets[7].setTargetUnselected();
targets[7].showTarget();
}
}
}