├── .gitattributes
├── .gitignore
├── App.config
├── App.xaml
├── App.xaml.cs
├── FiveTwoFiveTwo
├── KinectMathHelpers.cs
└── XAMLValueConverters.cs
├── Images
├── JackOLantern.png
├── Kinect.ico
├── ScreenshotHover.png
├── ScreenshotNormal.png
└── Status.png
├── K4WJointVisualizer.csproj
├── K4WJointVisualizer.sln
├── LICENSE
├── MainWindow.xaml
├── MainWindow.xaml.cs
├── Properties
├── AssemblyInfo.cs
├── Resources.Designer.cs
├── Resources.resx
├── Settings.Designer.cs
└── Settings.settings
├── README.md
├── Settings.cs
├── ViewModels
├── KinectBaseViewModel.cs
└── ViewModelBase.cs
├── packages.config
└── packages
└── Microsoft.Kinect.Tools.x64.2.0.1409-publicpreview-10000
└── lib
└── net45
├── Microsoft.Kinect.Tools.dll
└── Microsoft.Kinect.Tools.xml
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.sln.docstates
8 |
9 | # Build results
10 | [Dd]ebug/
11 | [Dd]ebugPublic/
12 | [Rr]elease/
13 | [Rr]eleases/
14 | x64/
15 | x86/
16 | build/
17 | bld/
18 | [Bb]in/
19 | [Oo]bj/
20 |
21 | # Roslyn cache directories
22 | *.ide/
23 |
24 | # MSTest test Results
25 | [Tt]est[Rr]esult*/
26 | [Bb]uild[Ll]og.*
27 |
28 | #NUNIT
29 | *.VisualState.xml
30 | TestResult.xml
31 |
32 | # Build Results of an ATL Project
33 | [Dd]ebugPS/
34 | [Rr]eleasePS/
35 | dlldata.c
36 |
37 | *_i.c
38 | *_p.c
39 | *_i.h
40 | *.ilk
41 | *.meta
42 | *.obj
43 | *.pch
44 | *.pdb
45 | *.pgc
46 | *.pgd
47 | *.rsp
48 | *.sbr
49 | *.tlb
50 | *.tli
51 | *.tlh
52 | *.tmp
53 | *.tmp_proj
54 | *.log
55 | *.vspscc
56 | *.vssscc
57 | .builds
58 | *.pidb
59 | *.svclog
60 | *.scc
61 |
62 | # Chutzpah Test files
63 | _Chutzpah*
64 |
65 | # Visual C++ cache files
66 | ipch/
67 | *.aps
68 | *.ncb
69 | *.opensdf
70 | *.sdf
71 | *.cachefile
72 |
73 | # Visual Studio profiler
74 | *.psess
75 | *.vsp
76 | *.vspx
77 |
78 | # TFS 2012 Local Workspace
79 | $tf/
80 |
81 | # Guidance Automation Toolkit
82 | *.gpState
83 |
84 | # ReSharper is a .NET coding add-in
85 | _ReSharper*/
86 | *.[Rr]e[Ss]harper
87 | *.DotSettings.user
88 |
89 | # JustCode is a .NET coding addin-in
90 | .JustCode
91 |
92 | # TeamCity is a build add-in
93 | _TeamCity*
94 |
95 | # DotCover is a Code Coverage Tool
96 | *.dotCover
97 |
98 | # NCrunch
99 | _NCrunch_*
100 | .*crunch*.local.xml
101 |
102 | # MightyMoose
103 | *.mm.*
104 | AutoTest.Net/
105 |
106 | # Web workbench (sass)
107 | .sass-cache/
108 |
109 | # Installshield output folder
110 | [Ee]xpress/
111 |
112 | # DocProject is a documentation generator add-in
113 | DocProject/buildhelp/
114 | DocProject/Help/*.HxT
115 | DocProject/Help/*.HxC
116 | DocProject/Help/*.hhc
117 | DocProject/Help/*.hhk
118 | DocProject/Help/*.hhp
119 | DocProject/Help/Html2
120 | DocProject/Help/html
121 |
122 | # Click-Once directory
123 | publish/
124 |
125 | # Publish Web Output
126 | *.[Pp]ublish.xml
127 | *.azurePubxml
128 | # TODO: Comment the next line if you want to checkin your web deploy settings
129 | # but database connection strings (with potential passwords) will be unencrypted
130 | *.pubxml
131 | *.publishproj
132 |
133 | # NuGet Packages
134 | *.nupkg
135 | # The packages folder can be ignored because of Package Restore
136 | **/packages/*
137 | # except build/, which is used as an MSBuild target.
138 | !**/packages/build/
139 | # If using the old MSBuild-Integrated Package Restore, uncomment this:
140 | #!**/packages/repositories.config
141 |
142 | # Windows Azure Build Output
143 | csx/
144 | *.build.csdef
145 |
146 | # Windows Store app package directory
147 | AppPackages/
148 |
149 | # Others
150 | sql/
151 | *.Cache
152 | ClientBin/
153 | [Ss]tyle[Cc]op.*
154 | ~$*
155 | *~
156 | *.dbmdl
157 | *.dbproj.schemaview
158 | *.pfx
159 | *.publishsettings
160 | node_modules/
161 |
162 | # RIA/Silverlight projects
163 | Generated_Code/
164 |
165 | # Backup & report files from converting an old project file
166 | # to a newer Visual Studio version. Backup files are not needed,
167 | # because we have git ;-)
168 | _UpgradeReport_Files/
169 | Backup*/
170 | UpgradeLog*.XML
171 | UpgradeLog*.htm
172 |
173 | # SQL Server files
174 | *.mdf
175 | *.ldf
176 |
177 | # Business Intelligence projects
178 | *.rdl.data
179 | *.bim.layout
180 | *.bim_*.settings
181 |
182 | # Microsoft Fakes
183 | FakesAssemblies/
184 |
--------------------------------------------------------------------------------
/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/App.xaml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Configuration;
4 | using System.Data;
5 | using System.Linq;
6 | using System.Threading.Tasks;
7 | using System.Windows;
8 |
9 | namespace K4WJointVisualizer
10 | {
11 | ///
12 | /// Interaction logic for App.xaml
13 | ///
14 | public partial class App : Application
15 | {
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/FiveTwoFiveTwo/KinectMathHelpers.cs:
--------------------------------------------------------------------------------
1 |
2 | using System;
3 | using System.Windows;
4 | using Microsoft.Kinect;
5 |
6 |
7 | namespace FiveTwoFiveTwo.KinectMathHelpers
8 | {
9 |
10 | public static class MathHelpers
11 | {
12 | public struct Vector3
13 | {
14 | public double X { get; set; }
15 | public double Y { get; set; }
16 | public double Z { get; set; }
17 | public static Vector3 Zero
18 | {
19 | get
20 | {
21 | return new Vector3() { X = 0, Y = 0, Z = 0 };
22 | }
23 | }
24 | }
25 | ///
26 | /// The function converts a Quaternion into a Vector3
27 | ///
28 | /// The Quaternion to convert
29 | /// An equivalent Vector3
30 | ///
31 | /// This function was extrapolated by reading the work of Martin John Baker.
32 | /// All credit for this function goes to Martin John.
33 | /// http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/index.htm
34 | ///
35 | public static Vector3 QuaternionToEuler(Vector4 q)
36 | {
37 | Vector3 v = Vector3.Zero;
38 | v.X = Math.Atan2(2 * q.Y * q.W - 2 * q.X * q.Z,
39 | 1 - 2 * Math.Pow(q.Y, 2) - 2 * Math.Pow(q.Z, 2));
40 |
41 | v.Z = Math.Asin(2 * q.X * q.Y + 2 * q.Z * q.W);
42 |
43 | v.Y = Math.Atan2(2 * q.X * q.W - 2 * q.Y * q.Z,
44 | 1 - 2 * Math.Pow(q.X, 2) - 2 * Math.Pow(q.Z, 2));
45 |
46 | if (q.X * q.Y + q.Z * q.W == 0.5)
47 | {
48 | v.X = (2 * Math.Atan2(q.X, q.W));
49 | v.Y = 0;
50 | }
51 | else if (q.X * q.Y + q.Z * q.W == -0.5)
52 | {
53 | v.X = (-2 * Math.Atan2(q.X, q.W));
54 | v.Y = 0;
55 | }
56 |
57 | v.X = RadianToDegree(v.X);
58 | v.Y = RadianToDegree(v.Y);
59 | v.Z = RadianToDegree(v.Z);
60 | return v;
61 | }
62 |
63 | ///
64 | /// Converts a Vector4 quaternion to a Vector3 CameraSpacePoint.
65 | ///
66 | /// The Vector4 quaternion.
67 | /// A Vector3 representation of the quaternion.
68 | public static CameraSpacePoint QuaternionToEuler3(this Vector4 orientation)
69 | {
70 | CameraSpacePoint point = new CameraSpacePoint();
71 |
72 | point.X = (float)Math.Atan2
73 | (
74 | 2 * orientation.Y * orientation.W - 2 * orientation.X * orientation.Z,
75 | 1 - 2 * Math.Pow(orientation.Y, 2) - 2 * Math.Pow(orientation.Z, 2)
76 | );
77 |
78 | point.Y = (float)Math.Asin
79 | (
80 | 2 * orientation.X * orientation.Y + 2 * orientation.Z * orientation.W
81 | );
82 |
83 | point.Z = (float)Math.Atan2
84 | (
85 | 2 * orientation.X * orientation.W - 2 * orientation.Y * orientation.Z,
86 | 1 - 2 * Math.Pow(orientation.X, 2) - 2 * Math.Pow(orientation.Z, 2)
87 | );
88 |
89 | if (orientation.X * orientation.Y + orientation.Z * orientation.W == 0.5)
90 | {
91 | point.X = (float)(2 * Math.Atan2(orientation.X, orientation.W));
92 | point.Z = 0;
93 | }
94 |
95 | else if (orientation.X * orientation.Y + orientation.Z * orientation.W == -0.5)
96 | {
97 | point.X = (float)(-2 * Math.Atan2(orientation.X, orientation.W));
98 | point.Z = 0;
99 | }
100 |
101 | point.X = (float)RadianToDegree(point.X);
102 | point.Y = (float)RadianToDegree(point.Y);
103 | point.Z = (float)RadianToDegree(point.Z);
104 | return point;
105 | }
106 |
107 |
108 | private static double RadianToDegree(double angle)
109 | {//Return degrees (0->360) from radians
110 | return angle * (180.0 / Math.PI) + 180;
111 | }
112 | public static Vector3 QuaternionToYawPitchRoll(Vector4 q)
113 | {
114 | const double Epsilon = 0.0009765625f;
115 | const double Threshold = 0.5f - Epsilon;
116 |
117 | double yaw;
118 | double pitch;
119 | double roll;
120 |
121 | double XY = q.X * q.Y;
122 | double ZW = q.Z * q.W;
123 |
124 | double TEST = XY + ZW;
125 |
126 | if (TEST < -Threshold || TEST > Threshold)
127 | {
128 |
129 | int sign = Math.Sign(TEST);
130 |
131 | yaw = sign * 2 * (double)Math.Atan2(q.X, q.W);
132 |
133 | pitch = sign * (Math.PI / 2.0d);
134 |
135 | roll = 0;
136 |
137 | }
138 | else
139 | {
140 |
141 | double XX = q.X * q.X;
142 | double XZ = q.X * q.Z;
143 | double XW = q.X * q.W;
144 |
145 | double YY = q.Y * q.Y;
146 | double YW = q.Y * q.W;
147 | double YZ = q.Y * q.Z;
148 |
149 | double ZZ = q.Z * q.Z;
150 |
151 | yaw = (double)Math.Atan2(2 * YW - 2 * XZ, 1 - 2 * YY - 2 * ZZ);
152 |
153 | pitch = (double)Math.Atan2(2 * XW - 2 * YZ, 1 - 2 * XX - 2 * ZZ);
154 |
155 | roll = (double)Math.Asin(2 * TEST);
156 |
157 | }//if
158 |
159 | return new Vector3() { X = yaw, Y = pitch, Z = roll };
160 |
161 | }//method
162 | public static double AngleBetweenPoints(Point p1, Point p2)
163 | {
164 | double retval;
165 | double xDiff = p1.X - p2.X;
166 | double yDiff = p1.Y - p2.Y;
167 | retval = (double)Math.Atan2(yDiff, xDiff) * (double)(180 / Math.PI);
168 | return retval;
169 | }
170 |
171 |
172 | }
173 | public class Quaternion
174 | {
175 | public Quaternion(float w_, float xi, float yj, float zk)
176 | {
177 | w = w_;
178 | x = xi;
179 | y = yj;
180 | z = zk;
181 | }
182 | private float w;
183 | public float W
184 | {
185 | set
186 | { w = value; }
187 | get
188 | { return w; }
189 | }
190 | private float x;
191 | public float X
192 | {
193 | set { x = value; }
194 | get { return x; }
195 | }
196 | private float y;
197 | public float Y
198 | {
199 | set { y = value; }
200 | get { return y; }
201 | }
202 | private float z;
203 | public float Z
204 | {
205 | set { z = value; }
206 | get { return z; }
207 | }
208 | ///
209 | /// Euclidean norm
210 | ///
211 | public float Norm
212 | {
213 | get { return (float)Math.Sqrt(w * w + x * x + y * y + z * z); }
214 | }
215 | ///
216 | /// Conjugate
217 | ///
218 | public Quaternion Conj
219 | {
220 | get { return new Quaternion(w, -x, -y, -z); }
221 | }
222 | public static Quaternion operator +(Quaternion q1, Quaternion q2)
223 | {
224 | return new Quaternion(q1.W + q2.W, q1.X + q2.X, q1.Y + q2.Y, q1.Z + q2.Z);
225 | }
226 | public static Quaternion operator -(Quaternion q1, Quaternion q2)
227 | {
228 | return new Quaternion(q1.W - q2.W, q1.X - q2.X, q1.Y - q2.Y, q1.Z - q2.Z);
229 | }
230 | ///
231 | /// product of two quaterions
232 | ///
233 | /// Quaternion1
234 | /// Quaternion2
235 | /// Quaternion1*Quaternion2
236 | public static Quaternion operator *(Quaternion q1, Quaternion q2)
237 | {
238 | return new Quaternion(q1.w * q2.w - q1.x * q2.x - q1.y * q2.y - q1.z * q2.z
239 | , q1.w * q2.x + q1.x * q2.w + q1.y * q2.z - q1.z * q2.y
240 | , q1.w * q2.y + q1.y * q2.w + q1.z * q2.x - q1.x * q2.z
241 | , q1.w * q2.z + q1.z * q2.w + q1.x * q2.y - q1.y * q2.x);
242 | }
243 | public static Quaternion operator *(float f, Quaternion q)
244 | {
245 | return new Quaternion(f * q.w, f * q.x, f * q.y, f * q.z);
246 | }
247 | public static Quaternion operator *(Quaternion q, float f)
248 | {
249 | return new Quaternion(f * q.w, f * q.x, f * q.y, f * q.z);
250 | }
251 | public static Quaternion operator /(Quaternion q, float f)
252 | {
253 | if (f == 0.0f) { throw new DivideByZeroException(); }
254 | return new Quaternion(1 / f * q.w, 1 / f * q.x, 1 / f * q.y, 1 / f * q.z);
255 | }
256 | public static Quaternion operator /(float f, Quaternion q)
257 | {
258 | if (q.Norm == 0.0f) { throw new DivideByZeroException(); }
259 | return f / (q.Norm * q.Norm) * q.Conj;
260 | }
261 | public static Quaternion operator /(Quaternion q1, Quaternion q2)
262 | {
263 | return q1 * q2.Conj / (q2.Norm * q2.Norm);
264 | }
265 | public static bool operator ==(Quaternion q1, Quaternion q2)
266 | {
267 | if (Math.Abs(q1.w - q2.w) < 0.00001f
268 | && Math.Abs(q1.x - q2.x) < 0.00001f
269 | && Math.Abs(q1.y - q2.y) < 0.00001f
270 | && Math.Abs(q1.z - q2.z) < 0.00001f)
271 | {
272 | return true;
273 | }
274 | return false;
275 | }
276 | public static bool operator !=(Quaternion q1, Quaternion q2)
277 | {
278 | if (q1.w == q2.w && q1.x == q2.x && q1.y == q2.y && q1.z == q2.z)
279 | {
280 | return false;
281 | }
282 | return true;
283 | }
284 | public override bool Equals(object obj)
285 | {
286 | Quaternion q = obj as Quaternion;
287 | return q == this;
288 | }
289 | public override int GetHashCode()
290 | {
291 | return this.w.GetHashCode() ^ (this.x.GetHashCode() * this.y.GetHashCode() * this.z.GetHashCode());
292 | }
293 | public float[] Rotate(float x1, float y1, float z1)
294 | {
295 | Quaternion q = new Quaternion(0.0f, x1, y1, z1);
296 | Quaternion r = this * q * this.Conj;
297 | return new float[3] { r.X, r.Y, r.Z };
298 | }
299 | }
300 |
301 | public static class KinectHelpers
302 | {
303 | // returns the parent joint of the given joint
304 | public static JointType GetParentJoint(JointType joint)
305 | {
306 | switch (joint)
307 | {
308 | case JointType.SpineBase:
309 | return JointType.SpineBase;
310 |
311 | case JointType.Neck:
312 | return JointType.SpineShoulder;
313 |
314 | case JointType.SpineShoulder:
315 | return JointType.SpineBase;
316 |
317 | case JointType.ShoulderLeft:
318 | case JointType.ShoulderRight:
319 | return JointType.SpineShoulder;
320 |
321 | case JointType.HipLeft:
322 | case JointType.HipRight:
323 | return JointType.SpineBase;
324 |
325 | case JointType.HandTipLeft:
326 | case JointType.ThumbLeft:
327 | return JointType.HandLeft;
328 |
329 | case JointType.HandTipRight:
330 | case JointType.ThumbRight:
331 | return JointType.HandRight;
332 | }
333 |
334 | return (JointType)((int)joint - 1);
335 | }
336 | }
337 | }
338 |
339 |
340 |
341 |
--------------------------------------------------------------------------------
/FiveTwoFiveTwo/XAMLValueConverters.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows.Data;
7 | using System.Windows.Markup;
8 |
9 | namespace FiveTwoFiveTwo.XAMLHelpers
10 | {
11 | public abstract class BaseConverter : MarkupExtension
12 | {
13 | public override object ProvideValue(IServiceProvider serviceProvider)
14 | {
15 | return this;
16 | }
17 | }
18 | [ValueConversion(typeof(object), typeof(string))]
19 | public class StringFormatConverter : BaseConverter, IValueConverter
20 | {
21 | public object Convert(object value, Type targetType, object parameter,
22 | System.Globalization.CultureInfo culture)
23 | {
24 | string format = parameter as string;
25 | if (!string.IsNullOrEmpty(format))
26 | {
27 | return string.Format(culture, format, value);
28 | }
29 | else
30 | {
31 | return value.ToString();
32 | }
33 | }
34 |
35 | public object ConvertBack(object value, Type targetType, object parameter,
36 | System.Globalization.CultureInfo culture)
37 | {
38 | return null;
39 | }
40 | }
41 | [ValueConversion(typeof(double), typeof(double))]
42 | public class SubtractConverter : BaseConverter, IValueConverter
43 | {
44 | public object Convert(object value, Type targetType, object parameter,
45 | System.Globalization.CultureInfo culture)
46 | {
47 | double param = System.Convert.ToDouble(parameter);
48 | return (double)value - param;
49 | }
50 |
51 | public object ConvertBack(object value, Type targetType, object parameter,
52 | System.Globalization.CultureInfo culture)
53 | {
54 | return null;
55 | }
56 | }
57 | [ValueConversion(typeof(Decimal), typeof(Double))]
58 | public class D2PConverter : BaseConverter, IMultiValueConverter
59 | {
60 | public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
61 | {
62 | Double foo = System.Convert.ToDouble(values[0]);
63 | Double bar = System.Convert.ToDouble(values[1]);
64 | if(foo > bar)
65 | {
66 | return 100.0d;
67 | }
68 | if(foo < 0 || bar < 0)
69 | {
70 | return 0.0d;
71 | }
72 |
73 |
74 | return ((foo / bar) * 100.0d);
75 | }
76 |
77 | public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
78 | {
79 | throw new NotImplementedException();
80 | }
81 | }
82 |
83 |
84 | [ValueConversion(typeof(double), typeof(double))]
85 | public class DoubleDividerConverter : BaseConverter, IValueConverter
86 | {
87 | public object Convert(object value, Type targetType, object parameter,
88 | System.Globalization.CultureInfo culture)
89 | {
90 | try
91 | {
92 | double doubleParam = System.Convert.ToDouble(parameter);
93 | double doubleValue = System.Convert.ToDouble(value);
94 | return doubleValue / doubleParam;
95 |
96 | }
97 | catch (Exception)
98 | {
99 |
100 | throw;
101 | }
102 |
103 | }
104 |
105 | public object ConvertBack(object value, Type targetType, object parameter,
106 | System.Globalization.CultureInfo culture)
107 | {
108 | return null;
109 | }
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/Images/JackOLantern.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IntStarFoo/KinectJointVisualizer/3839e37fa446e5e2c396b36dc5994b9a167a02e8/Images/JackOLantern.png
--------------------------------------------------------------------------------
/Images/Kinect.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IntStarFoo/KinectJointVisualizer/3839e37fa446e5e2c396b36dc5994b9a167a02e8/Images/Kinect.ico
--------------------------------------------------------------------------------
/Images/ScreenshotHover.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IntStarFoo/KinectJointVisualizer/3839e37fa446e5e2c396b36dc5994b9a167a02e8/Images/ScreenshotHover.png
--------------------------------------------------------------------------------
/Images/ScreenshotNormal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IntStarFoo/KinectJointVisualizer/3839e37fa446e5e2c396b36dc5994b9a167a02e8/Images/ScreenshotNormal.png
--------------------------------------------------------------------------------
/Images/Status.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/IntStarFoo/KinectJointVisualizer/3839e37fa446e5e2c396b36dc5994b9a167a02e8/Images/Status.png
--------------------------------------------------------------------------------
/K4WJointVisualizer.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {F1E8B2C6-6FE2-4FD5-A9FE-EED3572B9250}
8 | WinExe
9 | Properties
10 | K4WJointVisualizer
11 | K4WJointVisualizer
12 | v4.5
13 | 512
14 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
15 | 4
16 |
17 |
18 | x64
19 | true
20 | full
21 | false
22 | bin\Debug\
23 | DEBUG;TRACE
24 | prompt
25 | 4
26 | false
27 |
28 |
29 | AnyCPU
30 | pdbonly
31 | true
32 | bin\Release\
33 | TRACE
34 | prompt
35 | 4
36 |
37 |
38 |
39 | False
40 | C:\Program Files\Microsoft SDKs\Kinect\v2.0-PublicPreview1409\Assemblies\Microsoft.Kinect.dll
41 |
42 |
43 | ..\packages\Microsoft.Kinect.Tools.x64.2.0.1409-publicpreview-10000\lib\net45\Microsoft.Kinect.Tools.dll
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 | 4.0
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 | MSBuild:Compile
63 | Designer
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 | MSBuild:Compile
72 | Designer
73 |
74 |
75 | App.xaml
76 | Code
77 |
78 |
79 | MainWindow.xaml
80 | Code
81 |
82 |
83 |
84 |
85 | Code
86 |
87 |
88 | True
89 | True
90 | Resources.resx
91 |
92 |
93 | True
94 | Settings.settings
95 | True
96 |
97 |
98 | PublicResXFileCodeGenerator
99 | Resources.Designer.cs
100 |
101 |
102 |
103 | PublicSettingsSingleFileGenerator
104 | Settings.Designer.cs
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
128 |
--------------------------------------------------------------------------------
/K4WJointVisualizer.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.30723.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "K4WJointVisualizer", "K4WJointVisualizer.csproj", "{F1E8B2C6-6FE2-4FD5-A9FE-EED3572B9250}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {F1E8B2C6-6FE2-4FD5-A9FE-EED3572B9250}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {F1E8B2C6-6FE2-4FD5-A9FE-EED3572B9250}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {F1E8B2C6-6FE2-4FD5-A9FE-EED3572B9250}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {F1E8B2C6-6FE2-4FD5-A9FE-EED3572B9250}.Release|Any CPU.Build.0 = Release|Any CPU
18 | EndGlobalSection
19 | GlobalSection(SolutionProperties) = preSolution
20 | HideSolutionNode = FALSE
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 John A. Berry
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
25 |
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 |
78 |
81 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
--------------------------------------------------------------------------------
/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Windows;
7 | using System.Windows.Controls;
8 | using System.Windows.Data;
9 | using System.Windows.Documents;
10 | using System.Windows.Input;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 | using System.Windows.Navigation;
14 | using System.Windows.Shapes;
15 |
16 | namespace K4WJointVisualizer
17 | {
18 | ///
19 | /// Interaction logic for MainWindow.xaml
20 | ///
21 | public partial class MainWindow : Window
22 | {
23 | public MainWindow()
24 | {
25 | InitializeComponent();
26 | this.DataContext = K4WJointVisualizer.ViewModels.KinectBaseViewModel.Instance;
27 | }
28 |
29 | private void CheckBox_Checked(object sender, RoutedEventArgs e)
30 | {
31 |
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 | using System.Windows;
6 |
7 | // General Information about an assembly is controlled through the following
8 | // set of attributes. Change these attribute values to modify the information
9 | // associated with an assembly.
10 | [assembly: AssemblyTitle("K4WJointVisualizer")]
11 | [assembly: AssemblyDescription("")]
12 | [assembly: AssemblyConfiguration("")]
13 | [assembly: AssemblyCompany("")]
14 | [assembly: AssemblyProduct("K4WJointVisualizer")]
15 | [assembly: AssemblyCopyright("Copyright © 2014")]
16 | [assembly: AssemblyTrademark("")]
17 | [assembly: AssemblyCulture("")]
18 |
19 | // Setting ComVisible to false makes the types in this assembly not visible
20 | // to COM components. If you need to access a type in this assembly from
21 | // COM, set the ComVisible attribute to true on that type.
22 | [assembly: ComVisible(false)]
23 |
24 | //In order to begin building localizable applications, set
25 | //CultureYouAreCodingWith in your .csproj file
26 | //inside a . For example, if you are using US english
27 | //in your source files, set the to en-US. Then uncomment
28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in
29 | //the line below to match the UICulture setting in the project file.
30 |
31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32 |
33 |
34 | [assembly: ThemeInfo(
35 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
36 | //(used if a resource is not found in the page,
37 | // or application resource dictionaries)
38 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
39 | //(used if a resource is not found in the page,
40 | // app, or any theme specific resource dictionaries)
41 | )]
42 |
43 |
44 | // Version information for an assembly consists of the following four values:
45 | //
46 | // Major Version
47 | // Minor Version
48 | // Build Number
49 | // Revision
50 | //
51 | // You can specify all the values or you can default the Build and Revision Numbers
52 | // by using the '*' as shown below:
53 | // [assembly: AssemblyVersion("1.0.*")]
54 | [assembly: AssemblyVersion("1.0.0.0")]
55 | [assembly: AssemblyFileVersion("1.0.0.0")]
56 |
--------------------------------------------------------------------------------
/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.34014
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace K4WJointVisualizer.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | public class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// Returns the cached ResourceManager instance used by this class.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | public static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("K4WJointVisualizer.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | public static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 |
63 | ///
64 | /// Looks up a localized string similar to Failed to write screenshot to {0}.
65 | ///
66 | public static string FailedScreenshotStatusTextFormat {
67 | get {
68 | return ResourceManager.GetString("FailedScreenshotStatusTextFormat", resourceCulture);
69 | }
70 | }
71 |
72 | ///
73 | /// Looks up a localized string similar to No Kinect Sensor Available..
74 | ///
75 | public static string NoSensorStatusText {
76 | get {
77 | return ResourceManager.GetString("NoSensorStatusText", resourceCulture);
78 | }
79 | }
80 |
81 | ///
82 | /// Looks up a localized string similar to Kinect Connected..
83 | ///
84 | public static string RunningStatusText {
85 | get {
86 | return ResourceManager.GetString("RunningStatusText", resourceCulture);
87 | }
88 | }
89 |
90 | ///
91 | /// Looks up a localized string similar to Saved screenshot to {0}.
92 | ///
93 | public static string SavedScreenshotStatusTextFormat {
94 | get {
95 | return ResourceManager.GetString("SavedScreenshotStatusTextFormat", resourceCulture);
96 | }
97 | }
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 | Failed to write screenshot to {0}
122 |
123 |
124 | No Kinect Sensor Available.
125 |
126 |
127 | Kinect Connected.
128 |
129 |
130 | Saved screenshot to {0}
131 |
132 |
--------------------------------------------------------------------------------
/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.34014
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace K4WJointVisualizer.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")]
16 | public sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | KinectJointVisualizer
2 | =====================
3 |
4 | A WPF application that visually demonstrates Kinect for Windows 2 SDK JointOrientation data.
5 |
6 |
7 | Video Demo
8 | http://youtu.be/E11PhEHLlP0
9 |
--------------------------------------------------------------------------------
/Settings.cs:
--------------------------------------------------------------------------------
1 | namespace K4WJointVisualizer.Properties
2 | {
3 |
4 |
5 | // This class allows you to handle specific events on the settings class:
6 | // The SettingChanging event is raised before a setting's value is changed.
7 | // The PropertyChanged event is raised after a setting's value is changed.
8 | // The SettingsLoaded event is raised after the setting values are loaded.
9 | // The SettingsSaving event is raised before the setting values are saved.
10 | public sealed partial class Settings
11 | {
12 |
13 | public Settings()
14 | {
15 | // // To add event handlers for saving and changing settings, uncomment the lines below:
16 | //
17 | // this.SettingChanging += this.SettingChangingEventHandler;
18 | //
19 | // this.SettingsSaving += this.SettingsSavingEventHandler;
20 | //
21 | }
22 |
23 | private void SettingChangingEventHandler(object sender, System.Configuration.SettingChangingEventArgs e)
24 | {
25 | // Add code to handle the SettingChangingEvent event here.
26 | }
27 |
28 | private void SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e)
29 | {
30 | // Add code to handle the SettingsSaving event here.
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/ViewModels/KinectBaseViewModel.cs:
--------------------------------------------------------------------------------
1 | using FiveTwoFiveTwo.KinectMathHelpers;
2 | using Microsoft.Kinect;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Globalization;
6 | using System.IO;
7 | using System.Linq;
8 | using System.Text;
9 | using System.Threading.Tasks;
10 | using System.Windows;
11 | using System.Windows.Media;
12 | using System.Windows.Media.Imaging;
13 |
14 | namespace K4WJointVisualizer.ViewModels
15 | {
16 | public class KinectBaseViewModel : ViewModelBase
17 | {
18 |
19 | #region class variables
20 |
21 | ///
22 | /// Size of the RGB pixel in the _kinectColorBitmap
23 | ///
24 | private readonly int bytesPerPixel = (PixelFormats.Bgr32.BitsPerPixel + 7) / 8;
25 |
26 | ///
27 | /// Active Kinect sensor
28 | ///
29 | private KinectSensor kinectSensor = null;
30 |
31 | ///
32 | /// Coordinate mapper to map one type of point to another
33 | ///
34 | private CoordinateMapper coordinateMapper = null;
35 |
36 | ///
37 | /// Reader for depth/color/body index frames
38 | ///
39 | private MultiSourceFrameReader multiFrameSourceReader = null;
40 |
41 | ///
42 | /// Bitmap to display
43 | ///
44 | private WriteableBitmap _kinectColorBitmap = null;
45 |
46 | ///
47 | /// The size in bytes of the _kinectColorBitmap back buffer
48 | ///
49 | private uint bitmapBackBufferSize = 0;
50 |
51 | ///
52 | /// Intermediate storage for the color to depth mapping
53 | ///
54 | private DepthSpacePoint[] colorMappedToDepthPoints = null;
55 |
56 | ///
57 | /// Constant for clamping Z values of camera space points from being negative
58 | ///
59 | private const float InferredZPositionClamp = 0.1f;
60 |
61 |
62 | ///
63 | /// Gets the _kinectColorBitmap to display
64 | ///
65 | public ImageSource ImageSource
66 | {
67 | get
68 | {
69 | return this._kinectColorBitmap;
70 | }
71 | }
72 |
73 |
74 | private int _displayWidth;
75 | private int _displayHeight;
76 | ///
77 | /// Gets the bitmap to display
78 | ///
79 | public ImageSource ImageSource2
80 | {
81 | get
82 | {
83 | return this._imageSource;
84 | }
85 | }
86 | private ImageSource _imageSource;
87 | ///
88 | /// Drawing group for body rendering output
89 | ///
90 | private DrawingGroup drawingGroup;
91 |
92 |
93 | ///
94 | /// Current status text to display
95 | ///
96 | private string statusText = null;
97 |
98 | ///
99 | /// Gets or sets the current status text to display
100 | ///
101 | public string StatusText
102 | {
103 | get
104 | {
105 | return this.statusText;
106 | }
107 |
108 | set
109 | {
110 | if (this.statusText != value)
111 | {
112 | this.SetProperty(ref statusText, value, () => this.StatusText);
113 | }
114 | }
115 | }
116 |
117 |
118 | ///
119 | /// List of colors for each body tracked
120 | ///
121 | private List bodyColors;
122 |
123 |
124 | ///
125 | /// definition of bones
126 | ///
127 | private List> bones;
128 |
129 |
130 | ///
131 | /// Radius of drawn hand circles
132 | ///
133 | private const double HandSize = 30;
134 |
135 | ///
136 | /// Thickness of drawn joint lines
137 | ///
138 | private const double JointThickness = 1;
139 |
140 | ///
141 | /// Brush used for drawing hands that are currently tracked as closed
142 | ///
143 | private readonly Brush handClosedBrush = new SolidColorBrush(Color.FromArgb(128, 255, 0, 0));
144 |
145 | ///
146 | /// Brush used for drawing hands that are currently tracked as opened
147 | ///
148 | private readonly Brush handOpenBrush = new SolidColorBrush(Color.FromArgb(128, 0, 255, 0));
149 |
150 | ///
151 | /// Brush used for drawing hands that are currently tracked as in lasso (pointer) position
152 | ///
153 | private readonly Brush handLassoBrush = new SolidColorBrush(Color.FromArgb(128, 0, 0, 255));
154 |
155 | ///
156 | /// Brush used for drawing joints that are currently tracked
157 | ///
158 | private readonly Brush trackedJointBrush = new SolidColorBrush(Color.FromArgb(255, 1, 1, 68));
159 |
160 | ///
161 | /// Brush used for drawing joints that are currently inferred
162 | ///
163 | private readonly Brush inferredJointBrush = Brushes.Yellow;
164 |
165 | ///
166 | /// Pen used for drawing bones that are currently inferred
167 | ///
168 | private readonly Pen inferredBonePen = new Pen(Brushes.Gray, 1);
169 |
170 |
171 |
172 |
173 | private bool _drawOrientationVectors;
174 | public bool DrawOrientationVectors
175 | {
176 | get
177 | {
178 | return _drawOrientationVectors;
179 | }
180 | set
181 | {
182 |
183 | this.SetProperty(ref _drawOrientationVectors, value, () => this.DrawOrientationVectors);
184 | }
185 | }
186 |
187 | private bool _drawOrientationAnglesX;
188 | public bool DrawOrientationAnglesX
189 | {
190 | get
191 | {
192 | return _drawOrientationAnglesX;
193 | }
194 | set
195 | {
196 |
197 | this.SetProperty(ref _drawOrientationAnglesX, value, () => this.DrawOrientationAnglesX);
198 | }
199 | }
200 | private bool _drawOrientationAnglesY;
201 | public bool DrawOrientationAnglesY
202 | {
203 | get
204 | {
205 | return _drawOrientationAnglesY;
206 | }
207 | set
208 | {
209 |
210 | this.SetProperty(ref _drawOrientationAnglesY, value, () => this.DrawOrientationAnglesY);
211 | }
212 | }
213 | private bool _drawOrientationAnglesZ;
214 | public bool DrawOrientationAnglesZ
215 | {
216 | get
217 | {
218 | return _drawOrientationAnglesZ;
219 | }
220 | set
221 | {
222 |
223 | this.SetProperty(ref _drawOrientationAnglesZ, value, () => this.DrawOrientationAnglesZ);
224 | }
225 | }
226 |
227 |
228 | #endregion
229 |
230 |
231 | #region ViewModel Commands
232 |
233 |
234 |
235 |
236 | private CommandBase _screenshotCommand { get; set; }
237 | public CommandBase ScreenshotCommand
238 | {
239 | get
240 | {
241 | if (_screenshotCommand == null)
242 | {
243 | _screenshotCommand = new CommandBase(i => ScreenshotCommandExecute(), null);
244 | }
245 | return _screenshotCommand;
246 | }
247 | }
248 |
249 | #endregion
250 |
251 | #region constructor singleton instance
252 |
253 |
254 | private KinectBaseViewModel()
255 | {
256 |
257 | }
258 |
259 |
260 |
261 | private static KinectBaseViewModel _instance;
262 | ///
263 | /// Singleton instance of this VM.
264 | ///
265 | public static KinectBaseViewModel Instance
266 | {
267 |
268 | get
269 | {
270 | if (_instance == null)
271 | {
272 | _instance = new KinectBaseViewModel();
273 |
274 | // for Alpha (and public beta!!! boo.) one sensor is supported
275 | _instance.kinectSensor = KinectSensor.GetDefault();
276 |
277 | if (_instance.kinectSensor != null)
278 | {
279 | _instance.multiFrameSourceReader = _instance.kinectSensor.OpenMultiSourceFrameReader(FrameSourceTypes.Depth | FrameSourceTypes.Color | FrameSourceTypes.BodyIndex | FrameSourceTypes.Body);
280 |
281 | _instance.multiFrameSourceReader.MultiSourceFrameArrived += _instance.Reader_MultiSourceFrameArrived;
282 |
283 | _instance.coordinateMapper = _instance.kinectSensor.CoordinateMapper;
284 |
285 | FrameDescription depthFrameDescription = _instance.kinectSensor.DepthFrameSource.FrameDescription;
286 |
287 | int depthWidth = depthFrameDescription.Width;
288 | int depthHeight = depthFrameDescription.Height;
289 |
290 | FrameDescription colorFrameDescription = _instance.kinectSensor.ColorFrameSource.FrameDescription;
291 |
292 | int colorWidth = colorFrameDescription.Width;
293 | int colorHeight = colorFrameDescription.Height;
294 |
295 | _instance.colorMappedToDepthPoints = new DepthSpacePoint[colorWidth * colorHeight];
296 |
297 |
298 | _instance._displayWidth = depthWidth;
299 | _instance._displayHeight = depthHeight;
300 | _instance.InitializeBodyVisuals();
301 |
302 | _instance.DrawOrientationVectors = false;
303 |
304 |
305 | _instance.DrawOrientationAnglesX = false;
306 |
307 | _instance.DrawOrientationAnglesY = false;
308 | _instance.DrawOrientationAnglesZ = false;
309 |
310 | // Create the drawing group we'll use for drawing
311 | _instance.drawingGroup = new DrawingGroup();
312 | // Create an image source that we can use in our image control
313 | _instance._imageSource = new DrawingImage(_instance.drawingGroup);
314 |
315 | _instance._kinectColorBitmap = new WriteableBitmap(colorWidth, colorHeight, 96.0, 96.0, PixelFormats.Bgra32, null);
316 |
317 | // Calculate the WriteableBitmap back buffer size
318 | _instance.bitmapBackBufferSize = (uint)((_instance._kinectColorBitmap.BackBufferStride * (_instance._kinectColorBitmap.PixelHeight - 1)) + (_instance._kinectColorBitmap.PixelWidth * _instance.bytesPerPixel));
319 |
320 | _instance.kinectSensor.IsAvailableChanged += _instance.Sensor_IsAvailableChanged;
321 |
322 | _instance.kinectSensor.Open();
323 |
324 | _instance.StatusText = _instance.kinectSensor.IsAvailable ? Properties.Resources.RunningStatusText
325 | : Properties.Resources.NoSensorStatusText;
326 |
327 |
328 | }
329 | else
330 | {
331 | }
332 |
333 |
334 |
335 | }
336 |
337 | return _instance;
338 | }
339 | }
340 |
341 |
342 | private void InitializeBodyVisuals()
343 | {
344 | // populate body colors, one for each BodyIndex
345 | Instance.bodyColors = new List();
346 |
347 | Instance.bodyColors.Add(new Pen(Brushes.Violet, 2));
348 | Instance.bodyColors.Add(new Pen(Brushes.Orange, 2));
349 | Instance.bodyColors.Add(new Pen(Brushes.Green, 2));
350 | Instance.bodyColors.Add(new Pen(Brushes.Blue, 2));
351 | Instance.bodyColors.Add(new Pen(Brushes.Indigo, 2));
352 | Instance.bodyColors.Add(new Pen(Brushes.Red, 2));
353 | // a bone defined as a line between two joints
354 | Instance.bones = new List>();
355 | // Torso
356 | Instance.bones.Add(new Tuple(JointType.Head, JointType.Neck));
357 | Instance.bones.Add(new Tuple(JointType.Neck, JointType.SpineShoulder));
358 | Instance.bones.Add(new Tuple(JointType.SpineShoulder, JointType.SpineMid));
359 | Instance.bones.Add(new Tuple(JointType.SpineMid, JointType.SpineBase));
360 | Instance.bones.Add(new Tuple(JointType.SpineShoulder, JointType.ShoulderRight));
361 | Instance.bones.Add(new Tuple(JointType.SpineShoulder, JointType.ShoulderLeft));
362 | Instance.bones.Add(new Tuple(JointType.SpineBase, JointType.HipRight));
363 | Instance.bones.Add(new Tuple(JointType.SpineBase, JointType.HipLeft));
364 |
365 | // Right Arm
366 | Instance.bones.Add(new Tuple(JointType.ShoulderRight, JointType.ElbowRight));
367 | Instance.bones.Add(new Tuple(JointType.ElbowRight, JointType.WristRight));
368 | Instance.bones.Add(new Tuple(JointType.WristRight, JointType.HandRight));
369 | Instance.bones.Add(new Tuple(JointType.HandRight, JointType.HandTipRight));
370 | Instance.bones.Add(new Tuple(JointType.WristRight, JointType.ThumbRight));
371 |
372 | // Left Arm
373 | Instance.bones.Add(new Tuple(JointType.ShoulderLeft, JointType.ElbowLeft));
374 | Instance.bones.Add(new Tuple(JointType.ElbowLeft, JointType.WristLeft));
375 | Instance.bones.Add(new Tuple(JointType.WristLeft, JointType.HandLeft));
376 | Instance.bones.Add(new Tuple(JointType.HandLeft, JointType.HandTipLeft));
377 | Instance.bones.Add(new Tuple(JointType.WristLeft, JointType.ThumbLeft));
378 |
379 | // Right Leg
380 | Instance.bones.Add(new Tuple(JointType.HipRight, JointType.KneeRight));
381 | Instance.bones.Add(new Tuple(JointType.KneeRight, JointType.AnkleRight));
382 | Instance.bones.Add(new Tuple(JointType.AnkleRight, JointType.FootRight));
383 |
384 | // Left Leg
385 | Instance.bones.Add(new Tuple(JointType.HipLeft, JointType.KneeLeft));
386 | Instance.bones.Add(new Tuple(JointType.KneeLeft, JointType.AnkleLeft));
387 | Instance.bones.Add(new Tuple(JointType.AnkleLeft, JointType.FootLeft));
388 |
389 | }
390 |
391 |
392 |
393 | #endregion
394 |
395 | #region viewmodel event handlers
396 | private void Sensor_IsAvailableChanged(object sender, IsAvailableChangedEventArgs e)
397 | {
398 | Instance.StatusText = Instance.kinectSensor.IsAvailable ? Properties.Resources.RunningStatusText
399 | : Properties.Resources.NoSensorStatusText;
400 | }
401 |
402 | ///
403 | /// Handles the depth/color/body index frame data arriving from the sensor
404 | ///
405 | /// object sending the event
406 | /// event arguments
407 | private void Reader_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e)
408 | {
409 |
410 | DepthFrame depthFrame = null;
411 | ColorFrame colorFrame = null;
412 | BodyIndexFrame bodyIndexFrame = null;
413 | BodyFrame bodyFrame = null;
414 |
415 | bool isBitmapLocked = false;
416 |
417 | MultiSourceFrame multiSourceFrame = e.FrameReference.AcquireFrame();
418 |
419 | // If the Frame has expired by the time we process this event, return.
420 | if (multiSourceFrame == null)
421 | {
422 | return;
423 | }
424 |
425 | // We use a try/finally to ensure that we clean up before we exit the function.
426 | // This includes calling Dispose on any Frame objects that we may have and unlocking the _kinectColorBitmap back buffer.
427 | try
428 | {
429 | depthFrame = multiSourceFrame.DepthFrameReference.AcquireFrame();
430 | colorFrame = multiSourceFrame.ColorFrameReference.AcquireFrame();
431 | bodyIndexFrame = multiSourceFrame.BodyIndexFrameReference.AcquireFrame();
432 |
433 | bodyFrame = multiSourceFrame.BodyFrameReference.AcquireFrame();
434 | if (bodyFrame != null)
435 | {
436 | this.RenderBodyFrame(bodyFrame);
437 | }
438 |
439 | // If any frame has expired by the time we process this event, return.
440 | // The "finally" statement will Dispose any that are not null.
441 | if ((depthFrame == null) || (colorFrame == null) || (bodyIndexFrame == null))
442 | {
443 | return;
444 | }
445 | }
446 | finally
447 | {
448 | if (isBitmapLocked)
449 | {
450 | this._kinectColorBitmap.Unlock();
451 | }
452 |
453 | if (depthFrame != null)
454 | {
455 | depthFrame.Dispose();
456 | }
457 |
458 | if (bodyFrame != null)
459 | {
460 | bodyFrame.Dispose();
461 | }
462 |
463 | if (colorFrame != null)
464 | {
465 | colorFrame.Dispose();
466 | }
467 |
468 | if (bodyIndexFrame != null)
469 | {
470 | bodyIndexFrame.Dispose();
471 | }
472 | }
473 | }
474 |
475 | ///
476 | /// Handles the user invoking the screenshot command
477 | /// Creates a .png file in Environment.SpecialFolder.MyPictures
478 | /// with the contents of the ImageSource
479 | ///
480 | private void ScreenshotCommandExecute()
481 | {
482 | // Create a render target to which we'll render our composite image
483 | RenderTargetBitmap renderBitmap = new RenderTargetBitmap((int)_kinectColorBitmap.Width, (int)_kinectColorBitmap.Height, 96.0, 96.0, PixelFormats.Pbgra32);
484 |
485 | DrawingVisual dv = new DrawingVisual();
486 | using (DrawingContext dc = dv.RenderOpen())
487 | {
488 | dc.DrawImage(ImageSource, new Rect(new Point(), new Size(_kinectColorBitmap.Width, _kinectColorBitmap.Height)));
489 | }
490 |
491 | renderBitmap.Render(dv);
492 |
493 | BitmapEncoder encoder = new PngBitmapEncoder();
494 | encoder.Frames.Add(BitmapFrame.Create(renderBitmap));
495 |
496 | string time = System.DateTime.Now.ToString("hh'-'mm'-'ss", CultureInfo.CurrentUICulture.DateTimeFormat);
497 |
498 | string myPhotos = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
499 |
500 | string path = Path.Combine(myPhotos, "KinectScreenshot-" + time + ".png");
501 |
502 | // Write the new file to disk
503 | try
504 | {
505 | using (FileStream fs = new FileStream(path, FileMode.Create))
506 | {
507 | encoder.Save(fs);
508 | }
509 |
510 | this.StatusText = string.Format(Properties.Resources.SavedScreenshotStatusTextFormat, path);
511 | }
512 | catch (IOException)
513 | {
514 | this.StatusText = string.Format(Properties.Resources.FailedScreenshotStatusTextFormat, path);
515 | }
516 | }
517 |
518 | private void RenderBodyFrame(BodyFrame bodyFrame)
519 | {
520 | bool dataReceived = false;
521 |
522 | Body[] bodies = null;
523 | if (bodyFrame != null)
524 | {
525 | if (bodies == null)
526 | {
527 | bodies = new Body[bodyFrame.BodyCount];
528 | }
529 |
530 | // The first time GetAndRefreshBodyData is called, Kinect will allocate each Body in the array.
531 | // As long as those body objects are not disposed and not set to null in the array,
532 | // those body objects will be re-used.
533 | bodyFrame.GetAndRefreshBodyData(bodies);
534 | dataReceived = true;
535 | }
536 |
537 | if (dataReceived)
538 | {
539 |
540 | using (DrawingContext dc = this.drawingGroup.Open())
541 | {
542 | // Draw a transparent background to set the render size
543 | dc.DrawRectangle(Brushes.Black, null, new Rect(0.0, 0.0, Instance._displayWidth, Instance._displayHeight));
544 |
545 | int penIndex = 0;
546 | foreach (Body body in bodies)
547 | {
548 | Pen drawPen = this.bodyColors[penIndex++];
549 |
550 | if (body.IsTracked)
551 | {
552 |
553 | IReadOnlyDictionary joints = body.Joints;
554 |
555 | // convert the joint points to depth (display) space
556 | Dictionary jointPoints = new Dictionary();
557 |
558 | foreach (JointType jointType in joints.Keys)
559 | {
560 | // sometimes the depth(Z) of an inferred joint may show as negative
561 | // clamp down to 0.1f to prevent coordinatemapper from returning (-Infinity, -Infinity)
562 | CameraSpacePoint position = joints[jointType].Position;
563 | if (position.Z < 0)
564 | {
565 | position.Z = InferredZPositionClamp;
566 | }
567 |
568 | DepthSpacePoint depthSpacePoint = this.coordinateMapper.MapCameraPointToDepthSpace(position);
569 | jointPoints[jointType] = new Point(depthSpacePoint.X, depthSpacePoint.Y);
570 | }
571 |
572 | this.DrawBody(joints, jointPoints, dc, drawPen, body.JointOrientations);
573 | if (Instance.DrawOrientationVectors == true)
574 | {
575 | this.DrawLocalCoordinates(body.JointOrientations, joints, jointPoints, dc);
576 | }
577 | }
578 | }
579 |
580 | // prevent drawing outside of our render area
581 | this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, Instance._displayWidth, Instance._displayHeight));
582 | }
583 |
584 |
585 | }
586 | }
587 |
588 |
589 |
590 |
591 | private void DrawLocalCoordinates(IReadOnlyDictionary jointOrientations
592 | , IReadOnlyDictionary joints
593 | , IDictionary jointPoints
594 | , DrawingContext drawingContext)
595 | {
596 | Pen xCoordPen = new Pen(Brushes.Red, 2);
597 | Pen yCoordPen = new Pen(Brushes.Green, 2);
598 | Pen zCoordPen = new Pen(Brushes.Blue, 2);
599 | //Draw the local coordinates
600 | foreach (JointType jointType in jointOrientations.Keys)
601 | {
602 | Vector4 vec = jointOrientations[jointType].Orientation;
603 | Quaternion qOrientation = new Quaternion(vec.W, vec.X, vec.Y, vec.Z);
604 | CameraSpacePoint csX = CreateEndPoint(joints[jointType].Position, qOrientation.Rotate(0.1f, 0.0f, 0.0f));
605 | CameraSpacePoint csY = CreateEndPoint(joints[jointType].Position, qOrientation.Rotate(0.0f, 0.1f, 0.0f));
606 | CameraSpacePoint csZ = CreateEndPoint(joints[jointType].Position, qOrientation.Rotate(0.0f, 0.0f, 0.1f));
607 |
608 | DepthSpacePoint dsX = this.coordinateMapper.MapCameraPointToDepthSpace(csX);
609 | DepthSpacePoint dsY = this.coordinateMapper.MapCameraPointToDepthSpace(csY);
610 | DepthSpacePoint dsZ = this.coordinateMapper.MapCameraPointToDepthSpace(csZ);
611 |
612 | drawingContext.DrawLine(xCoordPen, jointPoints[jointType], new Point(dsX.X, dsX.Y));
613 | drawingContext.DrawLine(yCoordPen, jointPoints[jointType], new Point(dsY.X, dsY.Y));
614 | drawingContext.DrawLine(zCoordPen, jointPoints[jointType], new Point(dsZ.X, dsZ.Y));
615 |
616 | if (Instance.DrawOrientationAnglesX == true
617 | || Instance.DrawOrientationAnglesY == true
618 | || Instance.DrawOrientationAnglesZ == true)
619 | {
620 |
621 | JointType parentJoint = KinectHelpers.GetParentJoint(jointType);
622 | double AngleBetweenParentChildY = 0;
623 | double AngleBetweenParentChildX = 0;
624 | double AngleBetweenParentChildZ = 0;
625 |
626 | //For each vector in the DepthSpacePoint, compute the angle between
627 | // parent and child (only if the joint has a parent)
628 | if (parentJoint != jointType)
629 | {
630 |
631 | Vector4 vecParent = jointOrientations[parentJoint].Orientation;
632 | Quaternion qOrientationParent = new Quaternion(vecParent.W, vecParent.X, vecParent.Y, vecParent.Z);
633 | //(only compute if requested)
634 | if (DrawOrientationAnglesX == true)
635 | {
636 | CameraSpacePoint csXParent = CreateEndPoint(joints[parentJoint].Position, qOrientationParent.Rotate(0.1f, 0.0f, 0.0f));
637 | DepthSpacePoint dsXParent = this.coordinateMapper.MapCameraPointToDepthSpace(csXParent);
638 | AngleBetweenParentChildX = MathHelpers.AngleBetweenPoints(new Point(dsX.X, dsX.Y), new Point(dsXParent.X, dsXParent.Y));
639 | }
640 | if (DrawOrientationAnglesY == true)
641 | {
642 | CameraSpacePoint csYParent = CreateEndPoint(joints[parentJoint].Position, qOrientationParent.Rotate(0.0f, 0.1f, 0.0f));
643 | DepthSpacePoint dsYParent = this.coordinateMapper.MapCameraPointToDepthSpace(csYParent);
644 | AngleBetweenParentChildY = MathHelpers.AngleBetweenPoints(new Point(dsY.X, dsY.Y), new Point(dsYParent.X, dsYParent.Y));
645 | }
646 | if (DrawOrientationAnglesZ == true)
647 | {
648 | CameraSpacePoint csZParent = CreateEndPoint(joints[parentJoint].Position, qOrientationParent.Rotate(0.0f, 0.0f, 0.1f));
649 | DepthSpacePoint dsZParent = this.coordinateMapper.MapCameraPointToDepthSpace(csZParent);
650 | AngleBetweenParentChildZ = MathHelpers.AngleBetweenPoints(new Point(dsZ.X, dsY.Y), new Point(dsZParent.X, dsZParent.Y));
651 | }
652 | }
653 |
654 | if (DrawOrientationAnglesY == true)
655 | {
656 | //Fun With Formatted Text
657 | ///http://msdn.microsoft.com/en-us/library/system.windows.media.formattedtext(v=vs.110).aspx
658 | FormattedText fteY = new FormattedText(String.Format("{0,0:F0}°", AngleBetweenParentChildY),
659 | CultureInfo.GetCultureInfo("en-us"),
660 | FlowDirection.LeftToRight,
661 | new Typeface("Verdana"),
662 | 8, yCoordPen.Brush);
663 |
664 | drawingContext.DrawText(fteY, GetTextTopLeft(fteY, new Point(dsY.X, dsY.Y), jointPoints[jointType]));
665 |
666 | }
667 | if (DrawOrientationAnglesZ == true)
668 | {
669 | FormattedText fteZ = new FormattedText(String.Format("{0,0:F0}°", AngleBetweenParentChildZ),
670 | CultureInfo.GetCultureInfo("en-us"),
671 | FlowDirection.LeftToRight,
672 | new Typeface("Verdana"),
673 | 8, zCoordPen.Brush);
674 |
675 | drawingContext.DrawText(fteZ, GetTextTopLeft(fteZ, new Point(dsZ.X, dsZ.Y), jointPoints[jointType]));
676 | }
677 | if (DrawOrientationAnglesX == true)
678 | {
679 | FormattedText fteX = new FormattedText(String.Format("{0,0:F0}°", AngleBetweenParentChildX),
680 | CultureInfo.GetCultureInfo("en-us"),
681 | FlowDirection.LeftToRight,
682 | new Typeface("Verdana"),
683 | 8, xCoordPen.Brush);
684 |
685 | drawingContext.DrawText(fteX, GetTextTopLeft(fteX, new Point(dsX.X, dsX.Y), jointPoints[jointType]));
686 | }
687 | }
688 | }
689 | }
690 | ///
691 | /// Computes a good position for drawing text next to a line
692 | /// If the line goes from X+ -> X-, The END of the text ends at X-
693 | /// If the line goes from X- -> X+, the BEGINNING of the text starts at X+
694 | /// // like this<------ ------>or this
695 | ///
696 | /// Formatted Text to be displayed
697 | /// End of line
698 | /// Start of line
699 | ///
700 | private Point GetTextTopLeft(FormattedText ftxt, Point lineTo, Point lineFrom)
701 | {
702 | Point retval = lineTo;
703 | // Try to place the text outside of the body but connected to the line...
704 | if (lineFrom.X > lineTo.X + 10)
705 | {
706 | retval.X = lineTo.X - ftxt.Width;
707 | }
708 | return retval;
709 | }
710 |
711 | private CameraSpacePoint CreateEndPoint(CameraSpacePoint startP, float[] vec)
712 | {
713 | CameraSpacePoint point = new CameraSpacePoint();
714 | point.X = startP.X + vec[0];
715 | point.Y = startP.Y + vec[1];
716 | point.Z = startP.Z + vec[2];
717 | return point;
718 | }
719 |
720 |
721 |
722 | ///
723 | /// Draws a body
724 | ///
725 | /// joints to draw
726 | /// translated positions of joints to draw
727 | /// drawing context to draw to
728 | /// specifies color to draw a specific body
729 | private void DrawBody(IReadOnlyDictionary joints, IDictionary jointPoints, DrawingContext drawingContext, Pen drawingPen, IReadOnlyDictionary JointOrientations)
730 | {
731 | // Draw the bones
732 | foreach (var bone in this.bones)
733 | {
734 | this.DrawBone(joints, jointPoints, bone.Item1, bone.Item2, drawingContext, drawingPen);
735 | }
736 |
737 | // Draw the joints
738 | foreach (JointType jointType in joints.Keys)
739 | {
740 | Brush drawBrush = null;
741 |
742 | TrackingState trackingState = joints[jointType].TrackingState;
743 |
744 | if (trackingState == TrackingState.Tracked)
745 | {
746 | drawBrush = this.trackedJointBrush;
747 | }
748 | else if (trackingState == TrackingState.Inferred)
749 | {
750 | drawBrush = this.inferredJointBrush;
751 | }
752 |
753 | if (drawBrush != null)
754 | {
755 | drawingContext.DrawEllipse(drawBrush, null, jointPoints[jointType], JointThickness, JointThickness);
756 |
757 | }
758 | }
759 | }
760 |
761 | ///
762 | /// Draws one bone of a body (joint to joint)
763 | ///
764 | /// joints to draw
765 | /// translated positions of joints to draw
766 | /// first joint of bone to draw
767 | /// second joint of bone to draw
768 | /// drawing context to draw to
769 | /// /// specifies color to draw a specific bone
770 | private void DrawBone(IReadOnlyDictionary joints, IDictionary jointPoints, JointType jointType0, JointType jointType1, DrawingContext drawingContext, Pen drawingPen)
771 | {
772 | Joint joint0 = joints[jointType0];
773 | Joint joint1 = joints[jointType1];
774 |
775 | // If we can't find either of these joints, exit
776 | if (joint0.TrackingState == TrackingState.NotTracked ||
777 | joint1.TrackingState == TrackingState.NotTracked)
778 | {
779 | return;
780 | }
781 |
782 | // We assume all drawn bones are inferred unless BOTH joints are tracked
783 | Pen drawPen = this.inferredBonePen;
784 | if ((joint0.TrackingState == TrackingState.Tracked) && (joint1.TrackingState == TrackingState.Tracked))
785 | {
786 | drawPen = drawingPen;
787 | }
788 |
789 | drawingContext.DrawLine(drawPen, jointPoints[jointType0], jointPoints[jointType1]);
790 | }
791 |
792 | ///
793 | /// Draws a hand symbol if the hand is tracked: red circle = closed, green circle = opened; blue circle = lasso
794 | ///
795 | /// state of the hand
796 | /// position of the hand
797 | /// drawing context to draw to
798 | private void DrawHand(HandState handState, Point handPosition, DrawingContext drawingContext)
799 | {
800 | switch (handState)
801 | {
802 | case HandState.Closed:
803 | drawingContext.DrawEllipse(this.handClosedBrush, null, handPosition, HandSize, HandSize);
804 | break;
805 |
806 | case HandState.Open:
807 | drawingContext.DrawEllipse(this.handOpenBrush, null, handPosition, HandSize, HandSize);
808 | break;
809 |
810 | case HandState.Lasso:
811 | drawingContext.DrawEllipse(this.handLassoBrush, null, handPosition, HandSize, HandSize);
812 | break;
813 | }
814 | }
815 |
816 |
817 | #endregion
818 |
819 |
820 |
821 | }
822 | }
--------------------------------------------------------------------------------
/ViewModels/ViewModelBase.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Linq.Expressions;
5 | using System.Windows;
6 | using System.Windows.Input;
7 |
8 |
9 | ///
10 | /// MVVM uses commands instead of UI events
11 | /// http://blog.magnusmontin.net/2013/06/30/handling-events-in-an-mvvm-wpf-application/
12 | ///
13 |
14 | public class CommandBase : ICommand
15 | {
16 | readonly Action