1: using System;
2: using System.Threading;
3: using ManagedNite;
4:
5: namespace DetectingSwipe
6: {
7: class Program
8: {
9: private static XnMOpenNIContext _context;
10: private static XnMSessionManager _sessionManager;
11: private static XnMSwipeDetector _swipeDetector;
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: _swipeDetector = new XnMSwipeDetector();
36: _swipeDetector.SwipeDown +=SwipeDetectorSwipeDown;
37: _swipeDetector.SwipeLeft += SwipeDetectorSwipeLeft;
38: _swipeDetector.SwipeRight += SwipeDetectorSwipeRight;
39: _swipeDetector.SwipeUp += SwipeDetectorSwipeUp;
40: _swipeDetector.GeneralSwipe += SwipeDetectorGeneralSwipe;
41: _sessionManager.AddListener(_swipeDetector);
42: }
43:
44: static void SwipeDetectorGeneralSwipe(object sender, SwipeDetectorGeneralEventArgs e)
45: {
46: Console.WriteLine("General Swipe. Direction: {0} Angle: {1} Velocity: {2}", e.SelectDirection, e.Angle, e.Velocity);
47: }
48:
49: static void SwipeDetectorSwipeUp(object sender, SwipeDetectorEventArgs e)
50: {
51: Console.WriteLine("SwipeUp. Angle: {0} Velocity: {1}", e.Angle, e.Velocity);
52: }
53:
54: static void SwipeDetectorSwipeRight(object sender, SwipeDetectorEventArgs e)
55: {
56: Console.WriteLine("SwipeRight. Angle: {0} Velocity: {1}", e.Angle, e.Velocity);
57: }
58:
59: static void SwipeDetectorSwipeLeft(object sender, SwipeDetectorEventArgs e)
60: {
61: Console.WriteLine("SwipeLeft. Angle: {0} Velocity: {1}", e.Angle, e.Velocity);
62: }
63:
64: static void SwipeDetectorSwipeDown(object sender, SwipeDetectorEventArgs e)
65: {
66: Console.WriteLine("SwipeDown. Angle: {0} Velocity: {1}", e.Angle, e.Velocity);
67: }
68:
69:
70: #endregion
71:
72: #region Update Thread
73: private static void InitThreadReader()
74: {
75: _readerThread = new Thread(ReaderThread);
76: _readerThread.Start();
77: }
78: private static void ReaderThread()
79: {
80: while (_shouldRun)
81: {
82: var rc = _context.Update();
83: if (rc == 0)
84: _sessionManager.Update(_context);
85: }
86: }
87: #endregion
88: }
89: }