Skip to content
This repository
Browse code

added swipe gestures for history fwd-bkwd. fixed mirroring. clamped x…

…yz values to work with JS. changed smoothing in extension. stability issues in the extension are badcd ../..
  • Loading branch information...
commit 05619be808eab0e0cd7ace50ee18ea03989cef80 1 parent f4797a5
authored
7  extension-common/content_script/event_handlers.js
@@ -142,17 +142,18 @@ DepthJS.eventHandlers.onMove = function(data) {
142 142
     return;
143 143
   }
144 144
 
145  
-  data.x = 100-data.x;
  145
+//  data.x = 100-data.x;
146 146
 
147  
-  if (accumulatedX == null) {
  147
+//  if (accumulatedX == null) {
148 148
     accumulatedX = data.x;
149 149
     accumulatedY = data.y;
150 150
     accumulatedZ = data.z;
  151
+    /* //no smoothing!
151 152
   } else {
152 153
     accumulatedX = accumulatedX * smoothing + data.x * (1-smoothing);
153 154
     accumulatedY = accumulatedY * smoothing + data.y * (1-smoothing);
154 155
     accumulatedZ = accumulatedZ * smoothing + data.z * (1-smoothing);
155  
-  }
  156
+  } */
156 157
 
157 158
   if (DepthJS.state == "panner"){
158 159
     DepthJS.panner.move(accumulatedX, accumulatedY, accumulatedZ);
2  extension-common/content_script/selector_box.js
@@ -139,7 +139,7 @@ DepthJS.selectorBoxPopup.move = function(x, y) {
139 139
   if (DepthJS.verbose) console.log("move selector box popup (" + x + ", " + y + ")");
140 140
   y = (y - 50) / 50.0; // -1 to 1
141 141
   // Expode out for a smaller range in Kinect-hand space
142  
-  y *= 4.0;
  142
+//  y *= 4.0;
143 143
   console.log("pre clamp" + y);
144 144
   y = Math.min(1.0, Math.max(-1.0, y)); // clamp to -1 to 1
145 145
   y = (y + 1.0) / 2.0; // shift to 0 to 1
22  webkit-plugin-mac/HandMessageListener.h
@@ -32,10 +32,12 @@ class HandPointControl : public XnVPointControl {
32 32
 	HandPointControl(xn::DepthGenerator depthGenerator, XnVSessionManager* sessionManager):m_DepthGenerator(depthGenerator),m_SessionManager(sessionManager) {
33 33
 //		m_pInnerFlowRouter = new XnVFlowRouter;
34 34
 		m_pPushDetector = new XnVPushDetector;
35  
-//		m_pSwipeDetector = new XnVSwipeDetector;
  35
+		m_pSwipeDetector = new XnVSwipeDetector;
  36
+		m_pSwipeDetector->SetMotionSpeedThreshold(0.8);
36 37
 //		m_pSteadyDetector = new XnVSteadyDetector;		
37 38
 //		m_pWaveDetector = new XnVWaveDetector;
38 39
 		m_pCircleDetector = new XnVCircleDetector;
  40
+		m_pCircleDetector->SetMinRadius(80);
39 41
 		
40 42
 //		m_pInnerFlowRouter->SetActive(m_pPushDetector);
41 43
 		
@@ -47,7 +49,8 @@ class HandPointControl : public XnVPointControl {
47 49
 		m_pPushDetector->RegisterPush(this, &Push_Pushed);
48 50
 		m_pCircleDetector->RegisterCircle(this, &ACircle);
49 51
 		//m_pWaveDetector->RegisterWave(this, &Wave_Waved);
50  
-		
  52
+		m_pSwipeDetector->RegisterSwipeLeft(this, &Swipe_Left);
  53
+		m_pSwipeDetector->RegisterSwipeRight(this, &Swipe_Right);
51 54
 	}
52 55
 	
53 56
 	void Update(XnVMessage* pMessage)
@@ -57,6 +60,14 @@ class HandPointControl : public XnVPointControl {
57 60
 		m_pPushDetector->Update(pMessage);
58 61
 //		m_pWaveDetector->Update(pMessage);
59 62
 		m_pCircleDetector->Update(pMessage);
  63
+		m_pSwipeDetector->Update(pMessage);
  64
+	}
  65
+	
  66
+	static void XN_CALLBACK_TYPE Swipe_Left(XnFloat fVelocity, XnFloat fAngle, void* pUserCxt) {
  67
+		send_event("SwipeLeft", "");
  68
+	}
  69
+	static void XN_CALLBACK_TYPE Swipe_Right(XnFloat fVelocity, XnFloat fAngle, void* pUserCxt) {
  70
+		send_event("SwipeRight", "");
60 71
 	}
61 72
 	
62 73
 	// Push detector
@@ -101,9 +112,10 @@ class HandPointControl : public XnVPointControl {
101 112
 		m_DepthGenerator.ConvertRealWorldToProjective(1, &ptProjective, &ptProjective);
102 113
 //		printf(" -> (%f,%f,%f)\n", ptProjective.X, ptProjective.Y, ptProjective.Z);
103 114
 		
  115
+		//move to [0->100,0->100,0->2048]
104 116
 		stringstream ss;
105  
-		ss  << "\"x\":"  << (int)ptProjective.X
106  
-			<< ",\"y\":" << (int)ptProjective.Y
  117
+		ss  << "\"x\":"  << (int)(100.0*ptProjective.X/640.0)
  118
+			<< ",\"y\":" << (int)(100.0*ptProjective.Y/480.0)
107 119
 			<< ",\"z\":" << (int)ptProjective.Z;
108 120
 		//cout << "move: " << ss.str() << endl;
109 121
 		send_event("Move", ss.str());		
@@ -122,7 +134,7 @@ class HandPointControl : public XnVPointControl {
122 134
 	
123 135
 //	XnVBroadcaster m_Broadcaster;
124 136
 	XnVPushDetector* m_pPushDetector;
125  
-//	XnVSwipeDetector* m_pSwipeDetector;
  137
+	XnVSwipeDetector* m_pSwipeDetector;
126 138
 //	XnVSteadyDetector* m_pSteadyDetector;		
127 139
 //	XnVFlowRouter* m_pInnerFlowRouter;
128 140
 //	
58  webkit-plugin-mac/openni_backend.cpp
@@ -14,6 +14,10 @@
14 14
 #include <XnCppWrapper.h>
15 15
 #include <XnHash.h>
16 16
 #include <XnLog.h>
  17
+#include <XnUSB.h>
  18
+
  19
+#define VID_MICROSOFT 0x45e
  20
+#define PID_NUI_MOTOR 0x02b0
17 21
 
18 22
 // Header for NITE
19 23
 #include "XnVNite.h"
@@ -79,10 +83,11 @@ void XN_CALLBACK_TYPE NoHands(void* UserCxt);
79 83
 
80 84
 class OpenNIBackend {
81 85
 public:
82  
-	OpenNIBackend():g_SessionState(NOT_IN_SESSION),running(true) {}
  86
+	OpenNIBackend():g_SessionState(NOT_IN_SESSION),running(true),terminated(false) {}
83 87
 	
84 88
 	void run() {
85  
-		printf("start openni backend thread");
  89
+		printf("start openni backend thread\n");
  90
+		terminated = false;
86 91
 		while (running) {
87 92
 			XnMapOutputMode mode;
88 93
 			g_DepthGenerator.GetMapOutputMode(mode);
@@ -91,12 +96,48 @@ class OpenNIBackend {
91 96
 			// Update NITE tree
92 97
 			g_pSessionManager->Update(&g_Context);
93 98
 		}
94  
-		printf("end openni backend thread");
  99
+		terminated = true;
  100
+		printf("end openni backend thread\n");
  101
+	}
  102
+	void stop() { printf("stopping openni backend...\n"); running = false;}
  103
+	bool isDead() { return terminated; }
  104
+	
  105
+	int setKinectAngle() {
  106
+		XN_USB_DEV_HANDLE dev;
  107
+		
  108
+		int angle = 20;
  109
+		
  110
+		XnStatus rc = XN_STATUS_OK;
  111
+		
  112
+		rc = xnUSBInit();
  113
+		CHECK_RC(rc,"init usb device");
  114
+		
  115
+		rc = xnUSBOpenDevice(VID_MICROSOFT, PID_NUI_MOTOR, NULL, NULL, &dev);
  116
+		CHECK_RC(rc,"open usb device");
  117
+		
  118
+		uint8_t empty[0x1];
  119
+		angle = angle * 2;
  120
+        
  121
+		rc = xnUSBSendControl(dev,
  122
+							  XN_USB_CONTROL_TYPE_VENDOR,
  123
+							  0x31,
  124
+							  (XnUInt16)angle,
  125
+							  0x0,
  126
+							  empty,
  127
+							  0x0, 0);
  128
+		CHECK_RC(rc,"send usb command");
  129
+		
  130
+		rc = xnUSBCloseDevice(dev);
  131
+		CHECK_RC(rc,"close usb device");
  132
+		
  133
+		return rc;
95 134
 	}
96  
-	void stop() { running = false; }
97  
-	bool isDead() { return !running; }
98  
-	int init() {
99 135
 	
  136
+	int init() {
  137
+		running = true;
  138
+		terminated = false;
  139
+		setKinectAngle();
  140
+		
100 141
 		XnStatus rc = XN_STATUS_OK;
101 142
 		xn::EnumerationErrors errors;
102 143
 		
@@ -144,11 +185,12 @@ class OpenNIBackend {
144 185
 		rc = g_Context.StartGeneratingAll();
145 186
 		CHECK_RC(rc, "StartGenerating");
146 187
 		
  188
+		return rc == XN_STATUS_OK;
147 189
 	}
148 190
 	
149 191
 	SessionState g_SessionState;
150 192
 private:
151  
-	bool running;
  193
+	bool running,terminated;
152 194
 	
153 195
 	// OpenNI objects
154 196
 	xn::Context g_Context;
@@ -188,7 +230,7 @@ void XN_CALLBACK_TYPE NoHands(void* UserCxt)
188 230
 
189 231
 OpenNIBackend onib;
190 232
 
191  
-int openni_backend(void* _arg) { onib.run(); }
  233
+int openni_backend(void* _arg) { onib.run(); return 0; }
192 234
 void kill_openni_backend() { onib.stop(); }
193 235
 bool is_openni_backend_dead() { return onib.isDead(); }
194 236
 int init_openni_backend() { return onib.init(); }

0 notes on commit 05619be

Please sign in to comment.
Something went wrong with that request. Please try again.