Ejemplo n.º 1
0
//
// Create a new instance of the XBoard object:
// - no logging
// - start sending features to the XBoard GUI
//
XBoard::XBoard()
{
	cout.setf(ios::unitbuf);
	pulchess_log_off();
	sendFeatures();
}
Ejemplo n.º 2
0
//--------------------------------------------------------------
void testApp::update(){

	fingersFound.clear();
	
	//here is a simple example of getting the hands and using them to draw trails from the fingertips. 
	//the leap data is delivered in a threaded callback - so it can be easier to work with this copied hand data
	
	//if instead you want to get the data as it comes in then you can inherit ofxLeapMotion and implement the onFrame method. 
	//there you can work with the frame data directly. 



    //Option 1: Use the simple ofxLeapMotionSimpleHand - this gives you quick access to fingers and palms. 
    
    simpleHands = leap.getSimpleHands();
    
    if( leap.isFrameNew() && simpleHands.size() ){
    
        screenStr = "";
        
        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++){
        
            screenStr += "Hand " + ofToString(i) + ":: " +
            ofToString(simpleHands[i].handPos.x,3) + "," +
            ofToString(simpleHands[i].handPos.y,3) + "," +
            ofToString(simpleHands[i].handPos.z,3) + "," + " :: " +
            ofToString(simpleHands[i].handNormal.x,3) + "," +
            ofToString(simpleHands[i].handNormal.y,3) + "," +
            ofToString(simpleHands[i].handNormal.z,3) +
            "\n";
            
            for(int j = 0; j < simpleHands[i].fingers.size(); j++){
                
                
                
                int id = simpleHands[i].fingers[j].id;
                ofPolyline & polyline = fingerTrails[id];
                ofPoint pt = simpleHands[i].fingers[j].pos;
                ofPoint vl = simpleHands[i].fingers[j].vel;
                
                screenStr += "  Finger " + ofToString(id) + "    pos: " +
                            ofToString(pt.x, 3) + ","
                            + ofToString(pt.y, 3) + ","
                            + ofToString(pt.z, 3) + "    vel: " 
                            + ofToString(vl.x, 3) + ","
                            + ofToString(vl.y, 3) + ","
                            + ofToString(vl.z, 3) +"\n";
                
            
           
                
                //if the distance between the last point and the current point is too big - lets clear the line
                //this stops us connecting to an old drawing
                if( polyline.size() && (pt-polyline[polyline.size()-1] ).length() > 50 ){
                    polyline.clear(); 
                }
                
                //add our point to our trail
                polyline.addVertex(pt); 
                
                //store fingers seen this frame for drawing
                fingersFound.push_back(id);
            }
        }
    }


    // Option 2: Work with the leap data / sdk directly - gives you access to more properties than the simple approach  
    // uncomment code below and comment the code above to use this approach. You can also inhereit ofxLeapMotion and get the data directly via the onFrame callback. 
    
	/*vector <Hand> hands = leap.getLeapHands();
	if( leap.isFrameNew() && hands.size() ){

		//leap returns data in mm - lets set a mapping to our world space. 
		//you can get back a mapped point by using ofxLeapMotion::getMappedofPoint with the Leap::Vector that tipPosition returns  
		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 < hands.size(); i++){
            for(int j = 0; j < hands[i].fingers().count(); j++){
				ofPoint pt; 
			
				const Finger & finger = hands[i].fingers()[j];
								
				//here we convert the Leap point to an ofPoint - with mapping of coordinates
				//if you just want the raw point - use ofxLeapMotion::getofPoint 
				pt = leap.getMappedofPoint( finger.tipPosition() );
                								
				//lets get the correct trail (ofPolyline) out of our map - using the finger id as the key 
				ofPolyline & polyline = fingerTrails[finger.id()]; 
				
				//if the distance between the last point and the current point is too big - lets clear the line 
				//this stops us connecting to an old drawing
				if( polyline.size() && (pt-polyline[polyline.size()-1] ).length() > 50 ){
					polyline.clear(); 
				}
				
				//add our point to our trail
				polyline.addVertex(pt); 
				
				//store fingers seen this frame for drawing
				fingersFound.push_back(finger.id());
			}
		}	
	}*/

	//IMPORTANT! - tell ofxLeapMotion that the frame is no longer new. 
	leap.markFrameAsOld();
    sendFeatures();
}