The following repository version could be built without problems or you could also receive directly from openframeworks addon.
First of all, as a Hello World-like sample, try to recognize and display the hand. Only the fingertip could be detected independently! Easy!
There are two ways available for ofxLeapMotion. The first method is to use a simple hand model called ofxLeapMotionSimpleHand defined in ofxLeapMotion. The second method is to access and display functions provided by LeapMotion's SDK.
First of all, I try to draw by using a simple ofxLeapMotionSimpleHand. The way of doing it is very simple, once you have recognized ofxLeapMotionSimpleHand, calling a method called debugDraw () on that instance will display a simple 3D model of the hand.
testApp.cpp
#include "testApp.h"void testApp::setup(){
ofSetFrameRate(60);
ofSetVerticalSync(true);
ofBackground(31);
ofEnableLighting();
light.setPosition(200, 300, 50);
light.enable();
cam.setOrientation(ofPoint(-20, 0, 0));
glEnable(GL_DEPTH_TEST);
glEnable(GL_NORMALIZE);
leap.open();
}
void testApp::update(){
simpleHands = leap.getSimpleHands();
if( leap.isFrameNew() && simpleHands.size() ){
fingerPos.clear();
leap.setMappingX(-230, 230, -ofGetWidth()/2, ofGetWidth()/2);
leap.setMappingY(90, 490, -ofGetHeight()/2, ofGetHeight()/2);
leap.setMappingZ(-150, 150, -200, 200);
for(int i = 0; i < simpleHands.size(); i++){
for(int j = 0; j < simpleHands[i].fingers.size(); j++){
ofVec3f pos = simpleHands[i].fingers[j].pos;
fingerPos.push_back(pos);
}
}
}
leap.markFrameAsOld();
}
void testApp::draw(){
cam.begin();
for(int i = 0; i < fingerPos.size(); i++){
ofBoxPrimitive box;
box.setPosition(fingerPos[i].x, fingerPos[i].y, fingerPos[i].z);
box.set(20);
box.draw();
}
cam.end();
}
#include "ofxLeapMotion.h"
class testApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
void keyPressed (int key);
void keyReleased(int key);
void mouseMoved(int x, int y );
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void windowResized(int w, int h);
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);
void exit();
ofxLeapMotion leap;
vector simpleHands;
ofEasyCam cam;
ofLight light;
vector fingerPos;
};
}
leap.markFrameAsOld();
}
void testApp::draw(){
cam.begin();
for(int i = 0; i < fingerPos.size(); i++){
ofBoxPrimitive box;
box.setPosition(fingerPos[i].x, fingerPos[i].y, fingerPos[i].z);
box.set(20);
box.draw();
}
cam.end();
}
testApp.h
#include "ofMain.h"#include "ofxLeapMotion.h"
class testApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
void keyPressed (int key);
void keyReleased(int key);
void mouseMoved(int x, int y );
void mouseDragged(int x, int y, int button);
void mousePressed(int x, int y, int button);
void mouseReleased(int x, int y, int button);
void windowResized(int w, int h);
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);
void exit();
ofxLeapMotion leap;
vector
ofEasyCam cam;
ofLight light;
vector
};
The output :