Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
Roy Shilkrot authored
View
7 extension-common/content_script/event_handlers.js
@@ -142,17 +142,18 @@ DepthJS.eventHandlers.onMove = function(data) {
return;
}
- data.x = 100-data.x;
+// data.x = 100-data.x;
- if (accumulatedX == null) {
+// if (accumulatedX == null) {
accumulatedX = data.x;
accumulatedY = data.y;
accumulatedZ = data.z;
+ /* //no smoothing!
} else {
accumulatedX = accumulatedX * smoothing + data.x * (1-smoothing);
accumulatedY = accumulatedY * smoothing + data.y * (1-smoothing);
accumulatedZ = accumulatedZ * smoothing + data.z * (1-smoothing);
- }
+ } */
if (DepthJS.state == "panner"){
DepthJS.panner.move(accumulatedX, accumulatedY, accumulatedZ);
View
2  extension-common/content_script/selector_box.js
@@ -139,7 +139,7 @@ DepthJS.selectorBoxPopup.move = function(x, y) {
if (DepthJS.verbose) console.log("move selector box popup (" + x + ", " + y + ")");
y = (y - 50) / 50.0; // -1 to 1
// Expode out for a smaller range in Kinect-hand space
- y *= 4.0;
+// y *= 4.0;
console.log("pre clamp" + y);
y = Math.min(1.0, Math.max(-1.0, y)); // clamp to -1 to 1
y = (y + 1.0) / 2.0; // shift to 0 to 1
View
22 webkit-plugin-mac/HandMessageListener.h
@@ -32,10 +32,12 @@ class HandPointControl : public XnVPointControl {
HandPointControl(xn::DepthGenerator depthGenerator, XnVSessionManager* sessionManager):m_DepthGenerator(depthGenerator),m_SessionManager(sessionManager) {
// m_pInnerFlowRouter = new XnVFlowRouter;
m_pPushDetector = new XnVPushDetector;
-// m_pSwipeDetector = new XnVSwipeDetector;
+ m_pSwipeDetector = new XnVSwipeDetector;
+ m_pSwipeDetector->SetMotionSpeedThreshold(0.8);
// m_pSteadyDetector = new XnVSteadyDetector;
// m_pWaveDetector = new XnVWaveDetector;
m_pCircleDetector = new XnVCircleDetector;
+ m_pCircleDetector->SetMinRadius(80);
// m_pInnerFlowRouter->SetActive(m_pPushDetector);
@@ -47,7 +49,8 @@ class HandPointControl : public XnVPointControl {
m_pPushDetector->RegisterPush(this, &Push_Pushed);
m_pCircleDetector->RegisterCircle(this, &ACircle);
//m_pWaveDetector->RegisterWave(this, &Wave_Waved);
-
+ m_pSwipeDetector->RegisterSwipeLeft(this, &Swipe_Left);
+ m_pSwipeDetector->RegisterSwipeRight(this, &Swipe_Right);
}
void Update(XnVMessage* pMessage)
@@ -57,6 +60,14 @@ class HandPointControl : public XnVPointControl {
m_pPushDetector->Update(pMessage);
// m_pWaveDetector->Update(pMessage);
m_pCircleDetector->Update(pMessage);
+ m_pSwipeDetector->Update(pMessage);
+ }
+
+ static void XN_CALLBACK_TYPE Swipe_Left(XnFloat fVelocity, XnFloat fAngle, void* pUserCxt) {
+ send_event("SwipeLeft", "");
+ }
+ static void XN_CALLBACK_TYPE Swipe_Right(XnFloat fVelocity, XnFloat fAngle, void* pUserCxt) {
+ send_event("SwipeRight", "");
}
// Push detector
@@ -101,9 +112,10 @@ class HandPointControl : public XnVPointControl {
m_DepthGenerator.ConvertRealWorldToProjective(1, &ptProjective, &ptProjective);
// printf(" -> (%f,%f,%f)\n", ptProjective.X, ptProjective.Y, ptProjective.Z);
+ //move to [0->100,0->100,0->2048]
stringstream ss;
- ss << "\"x\":" << (int)ptProjective.X
- << ",\"y\":" << (int)ptProjective.Y
+ ss << "\"x\":" << (int)(100.0*ptProjective.X/640.0)
+ << ",\"y\":" << (int)(100.0*ptProjective.Y/480.0)
<< ",\"z\":" << (int)ptProjective.Z;
//cout << "move: " << ss.str() << endl;
send_event("Move", ss.str());
@@ -122,7 +134,7 @@ class HandPointControl : public XnVPointControl {
// XnVBroadcaster m_Broadcaster;
XnVPushDetector* m_pPushDetector;
-// XnVSwipeDetector* m_pSwipeDetector;
+ XnVSwipeDetector* m_pSwipeDetector;
// XnVSteadyDetector* m_pSteadyDetector;
// XnVFlowRouter* m_pInnerFlowRouter;
//
View
58 webkit-plugin-mac/openni_backend.cpp
@@ -14,6 +14,10 @@
#include <XnCppWrapper.h>
#include <XnHash.h>
#include <XnLog.h>
+#include <XnUSB.h>
+
+#define VID_MICROSOFT 0x45e
+#define PID_NUI_MOTOR 0x02b0
// Header for NITE
#include "XnVNite.h"
@@ -79,10 +83,11 @@ void XN_CALLBACK_TYPE NoHands(void* UserCxt);
class OpenNIBackend {
public:
- OpenNIBackend():g_SessionState(NOT_IN_SESSION),running(true) {}
+ OpenNIBackend():g_SessionState(NOT_IN_SESSION),running(true),terminated(false) {}
void run() {
- printf("start openni backend thread");
+ printf("start openni backend thread\n");
+ terminated = false;
while (running) {
XnMapOutputMode mode;
g_DepthGenerator.GetMapOutputMode(mode);
@@ -91,12 +96,48 @@ class OpenNIBackend {
// Update NITE tree
g_pSessionManager->Update(&g_Context);
}
- printf("end openni backend thread");
+ terminated = true;
+ printf("end openni backend thread\n");
+ }
+ void stop() { printf("stopping openni backend...\n"); running = false;}
+ bool isDead() { return terminated; }
+
+ int setKinectAngle() {
+ XN_USB_DEV_HANDLE dev;
+
+ int angle = 20;
+
+ XnStatus rc = XN_STATUS_OK;
+
+ rc = xnUSBInit();
+ CHECK_RC(rc,"init usb device");
+
+ rc = xnUSBOpenDevice(VID_MICROSOFT, PID_NUI_MOTOR, NULL, NULL, &dev);
+ CHECK_RC(rc,"open usb device");
+
+ uint8_t empty[0x1];
+ angle = angle * 2;
+
+ rc = xnUSBSendControl(dev,
+ XN_USB_CONTROL_TYPE_VENDOR,
+ 0x31,
+ (XnUInt16)angle,
+ 0x0,
+ empty,
+ 0x0, 0);
+ CHECK_RC(rc,"send usb command");
+
+ rc = xnUSBCloseDevice(dev);
+ CHECK_RC(rc,"close usb device");
+
+ return rc;
}
- void stop() { running = false; }
- bool isDead() { return !running; }
- int init() {
+ int init() {
+ running = true;
+ terminated = false;
+ setKinectAngle();
+
XnStatus rc = XN_STATUS_OK;
xn::EnumerationErrors errors;
@@ -144,11 +185,12 @@ class OpenNIBackend {
rc = g_Context.StartGeneratingAll();
CHECK_RC(rc, "StartGenerating");
+ return rc == XN_STATUS_OK;
}
SessionState g_SessionState;
private:
- bool running;
+ bool running,terminated;
// OpenNI objects
xn::Context g_Context;
@@ -188,7 +230,7 @@ void XN_CALLBACK_TYPE NoHands(void* UserCxt)
OpenNIBackend onib;
-int openni_backend(void* _arg) { onib.run(); }
+int openni_backend(void* _arg) { onib.run(); return 0; }
void kill_openni_backend() { onib.stop(); }
bool is_openni_backend_dead() { return onib.isDead(); }
int init_openni_backend() { return onib.init(); }
Please sign in to comment.
Something went wrong with that request. Please try again.