1: using System;
2: using System.Threading;
3: using ManagedNite;
4:
5: namespace DetectingPush
6: {
7: class Program
8: {
9: private static XnMOpenNIContext _context;
10: private static XnMSessionManager _sessionManager;
11: private static XnMPushDetector _pushDetector;
12: private static Thread _readerThread;
13: private static bool _shouldRun;
14:
15: static void Main()
16: {
17: Console.WriteLine("Iniciando acceso a Kinect ...");
18: _shouldRun = true;
19:
20: InitSensorInteraction();
21: InitThreadReader();
22:
23: Console.WriteLine("Kinect online. Saluda para comenzar");
24: Console.ReadLine();
25: _shouldRun = false;
26: }
27:
28: #region Sensor Interaction
29: private static void InitSensorInteraction()
30: {
31: _context = new XnMOpenNIContext();
32: _context.Init();
33:
34: _sessionManager = new XnMSessionManager(_context, "Wave", "RaiseHand");
35: _pushDetector = new XnMPushDetector();
36: _pushDetector.Push += PushDetectorPush;
37: _sessionManager.AddListener(_pushDetector);
38: }
39:
40: static void PushDetectorPush(object sender, PushDetectorEventArgs e)
41: {
42: Console.WriteLine("Angle: {0}", e.Angle);
43: Console.WriteLine("Velocity: {0}", e.Velocity);
44: }
45:
46: #endregion
47:
48: #region Update Thread
49: private static void InitThreadReader()
50: {
51: _readerThread = new Thread(ReaderThread);
52: _readerThread.Start();
53: }
54: private static void ReaderThread()
55: {
56: while (_shouldRun)
57: {
58: var rc = _context.Update();
59: if (rc == 0)
60: _sessionManager.Update(_context);
61: }
62: }
63: #endregion
64: }
65: }