Created
October 5, 2011 13:40
-
-
Save johnschimmel/1264451 to your computer and use it in GitHub Desktop.
Hand with Red Dot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* -------------------------------------------------------------------------- | |
* SimpleOpenNI Hands3d Test | |
* -------------------------------------------------------------------------- | |
* Processing Wrapper for the OpenNI/Kinect library | |
* http://code.google.com/p/simple-openni | |
* -------------------------------------------------------------------------- | |
* prog: Max Rheiner / Interaction Design / zhdk / http://iad.zhdk.ch/ | |
* date: 02/27/2011 (m/d/y) | |
* ---------------------------------------------------------------------------- | |
* This demos shows how to use the gesture/hand generator. | |
* It's not the most reliable yet, a two hands example will follow | |
* ---------------------------------------------------------------------------- | |
*/ | |
import SimpleOpenNI.*; | |
//import processing.opengl.*; | |
SimpleOpenNI context; | |
float zoomF =0.5f; | |
float rotX = radians(180); // by default rotate the hole scene 180deg around the x-axis, | |
// the data from openni comes upside down | |
float rotY = radians(0); | |
boolean handsTrackFlag = false; | |
PVector handVec = new PVector(); | |
ArrayList handVecList = new ArrayList(); | |
int handVecListSize = 30; | |
String lastGesture = ""; | |
void setup() | |
{ | |
size(600, 480); // strange, get drawing error in the cameraFrustum if i use P3D, in opengl there is no problem | |
//size(1024,768,OPENGL); | |
context = new SimpleOpenNI(this); | |
// disable mirror | |
context.setMirror(true); | |
// enable depthMap generation | |
context.enableDepth(); | |
// enable hands + gesture generation | |
context.enableGesture(); | |
context.enableHands(); | |
// add focus gestures / here i do have some problems on the mac, i only recognize raiseHand ? Maybe cpu performance ? | |
context.addGesture("Wave"); | |
context.addGesture("Click"); | |
context.addGesture("RaiseHand"); | |
// set how smooth the hand capturing should be | |
context.setSmoothingHands(.5); | |
stroke(255, 255, 255); | |
smooth(); | |
perspective(95.0f, | |
float(width)/float(height), | |
10.0f, 150000.0f); | |
} | |
void draw() | |
{ | |
context.update(); | |
image(context.depthImage(), 0, 0); | |
//red point | |
stroke(255, 0, 0); | |
strokeWeight(20); | |
context.convertRealWorldToProjective(handVec, handVec); | |
point(handVec.x, handVec.y); | |
} | |
// ----------------------------------------------------------------- | |
// hand events | |
void onCreateHands(int handId, PVector pos, float time) | |
{ | |
println("onCreateHands - handId: " + handId + ", pos: " + pos + ", time:" + time); | |
handVec = pos; | |
} | |
void onUpdateHands(int handId, PVector pos, float time) | |
{ | |
println("onUpdateHandsCb - handId: " + handId + ", pos: " + pos + ", time:" + time); | |
handVec = pos; | |
} | |
void onDestroyHands(int handId, float time) | |
{ | |
println("onDestroyHandsCb - handId: " + handId + ", time:" + time); | |
} | |
// ----------------------------------------------------------------- | |
// gesture events | |
void onRecognizeGesture(String strGesture, PVector idPosition, PVector endPosition) | |
{ | |
println("onRecognizeGesture - strGesture: " + strGesture + ", idPosition: " + idPosition + ", endPosition:" + endPosition); | |
lastGesture = strGesture; | |
context.removeGesture(strGesture); | |
context.startTrackingHands(endPosition); | |
} | |
void onProgressGesture(String strGesture, PVector position, float progress) | |
{ | |
//println("onProgressGesture - strGesture: " + strGesture + ", position: " + position + ", progress:" + progress); | |
} | |
// ----------------------------------------------------------------- | |
// Keyboard event | |
void keyPressed() | |
{ | |
switch(key) | |
{ | |
case ' ': | |
context.setMirror(!context.mirror()); | |
break; | |
} | |
switch(keyCode) | |
{ | |
case LEFT: | |
rotY += 0.1f; | |
break; | |
case RIGHT: | |
rotY -= 0.1f; | |
break; | |
case UP: | |
if (keyEvent.isShiftDown()) | |
zoomF += 0.01f; | |
else | |
rotX += 0.1f; | |
break; | |
case DOWN: | |
if (keyEvent.isShiftDown()) | |
{ | |
zoomF -= 0.01f; | |
if (zoomF < 0.01) | |
zoomF = 0.01; | |
} | |
else | |
rotX -= 0.1f; | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment