示例#1
0
void SimpleSimulator::mouseReleased(float x, float y) {
	//printf("released %f %f\n",x,y);

	TuioCursor *cursor = NULL;
	float distance  = 0.01f;
	for (std::list<TuioCursor*>::iterator iter = stickyCursorList.begin(); iter!=stickyCursorList.end(); iter++) {
		TuioCursor *tcur = (*iter);
		float test = tcur->getDistance(x,y);
		if (test<distance) {
			distance = test;
			cursor = tcur;
		}
	}

	if (cursor!=NULL) {
		activeCursorList.remove(cursor);
		return;
	}

	distance = 0.01f;
	for (std::list<TuioCursor*>::iterator iter = activeCursorList.begin(); iter!=activeCursorList.end(); iter++) {
		TuioCursor *tcur = (*iter);
		float test = tcur->getDistance(x,y);
		if (test<distance) {
			distance = test;
			cursor = tcur;
		}
	}

	if (cursor!=NULL) {
		activeCursorList.remove(cursor);
		tuioServer->removeTuioCursor(cursor);
	}
}
示例#2
0
void SimpleSimulator::mouseDragged(float x, float y) {
	//printf("dragged %f %f\n",x,y);

	TuioCursor *cursor = NULL;
	float distance  = width;
	for (std::list<TuioCursor*>::iterator iter = activeCursorList.begin(); iter!=activeCursorList.end(); iter++) {
		TuioCursor *tcur = (*iter);
		float test = tcur->getDistance(x,y);
		if (test<distance) {
			distance = test;
			cursor = tcur;
		}
	}

	if (cursor==NULL) return;
	if (cursor->getTuioTime()==frameTime) return;

	std::list<TuioCursor*>::iterator joint = std::find( jointCursorList.begin(), jointCursorList.end(), cursor );
	if( joint != jointCursorList.end() ) {
		float dx = x-cursor->getX();
		float dy = y-cursor->getY();
		for (std::list<TuioCursor*>::iterator iter = jointCursorList.begin(); iter!=jointCursorList.end(); iter++) {
			TuioCursor *jointCursor = (*iter);
			 tuioServer->updateTuioCursor(jointCursor,jointCursor->getX()+dx,jointCursor->getY()+dy);
		}
	} else tuioServer->updateTuioCursor(cursor,x,y);
}
示例#3
0
void SimpleSimulator::mousePressed(float x, float y) {
	//printf("pressed %f %f\n",x,y);

	TuioCursor *match = NULL;
	float distance  = 0.01f;
	for (std::list<TuioCursor*>::iterator iter = stickyCursorList.begin(); iter!=stickyCursorList.end(); iter++) {
		TuioCursor *tcur = (*iter);
		float test = tcur->getDistance(x,y);
		if ((test < distance) && (test < 8.0f/width)) {
			distance = test;
			match = tcur;
		}
	}

	Uint8 *keystate = SDL_GetKeyState(NULL);
	if ((keystate[SDLK_LSHIFT]) || (keystate[SDLK_RSHIFT]))  {

		if (match!=NULL) {
			std::list<TuioCursor*>::iterator joint = std::find( jointCursorList.begin(), jointCursorList.end(), match );
			if( joint != jointCursorList.end() ) {
				jointCursorList.erase( joint );
			}
			stickyCursorList.remove(match);
			activeCursorList.remove(match);
			tuioServer->removeTuioCursor(match);
		} else {
			TuioCursor *cursor = tuioServer->addTuioCursor(x,y);
			stickyCursorList.push_back(cursor);
			activeCursorList.push_back(cursor);
		}
	} else if ((keystate[SDLK_LCTRL]) || (keystate[SDLK_RCTRL])) {

		if (match!=NULL) {
			std::list<TuioCursor*>::iterator joint = std::find( jointCursorList.begin(), jointCursorList.end(), match );
			if( joint != jointCursorList.end() ) {
				jointCursorList.remove( match );
			} else jointCursorList.push_back(match);
		}
	} else {
		if (match==NULL) {
			TuioCursor *cursor = tuioServer->addTuioCursor(x,y);
			activeCursorList.push_back(cursor);
		} else activeCursorList.push_back(match);
	}
}
void TuioKinect::updateTuio() {
	TuioTime frameTime = TuioTime::getSessionTime();
	tuioServer->initFrame(frameTime);

	std::vector<ofxCvBlob>::iterator blob;
//	printf("Blobs: %d\n", contourFinder.blobs.size());
	for (blob=contourFinder.blobs.begin(); blob!= contourFinder.blobs.end(); blob++) {
		float xpos = (*blob).centroid.x;
		float ypos = (*blob).centroid.y;

		TuioPoint tp(xpos/kinect.width,ypos/kinect.height);

		//if ((tp.getY() > 0.8) && (tp.getX()>0.25) && (tp.getX()<0.75)) continue;

		TuioCursor *tcur = tuioServer->getClosestTuioCursor(tp.getX(),tp.getY());
		if ((tcur==NULL) || (tcur->getDistance(&tp)>0.2)) {
			tcur = tuioServer->addTuioCursor(tp.getX(), tp.getY());
			updateKalman(tcur->getCursorID(),tcur);

		} else {
			TuioPoint kp = updateKalman(tcur->getCursorID(),tp);
			tuioServer->updateTuioCursor(tcur, kp.getX(), kp.getY());

		}
	}

	tuioServer->stopUntouchedMovingCursors();

	std::list<TuioCursor*> dead_cursor_list = tuioServer->getUntouchedCursors();
	std::list<TuioCursor*>::iterator dead_cursor;
	for (dead_cursor=dead_cursor_list.begin(); dead_cursor!= dead_cursor_list.end(); dead_cursor++) {
		clearKalman((*dead_cursor)->getCursorID());

	}

	tuioServer->removeUntouchedStoppedCursors();
	tuioServer->commitFrame();
}
示例#5
0
//--------------------------------------------------------------
void TuioKinect::update()
{

	ofBackground(10, 10, 10);
	
	//Kinect + Feeds updating
	kinect.update();

	grayImage.setFromPixels(kinect.getDepthPixels(), kinect.width, kinect.height);
	grayImage.mirror(false, true);
	
	unsigned char * pix = grayImage.getPixels();
	int numPixels = grayImage.getWidth() * grayImage.getHeight()-1;
	
	depthImage.setFromPixels(pix, kinect.width, kinect.height);
	depthImage.flagImageChanged();
	
	colorImage.setFromPixels(kinect.getPixels(), kinect.width, kinect.height);
	colorImage.mirror(false, true);
	colorImage.convertToGrayscalePlanarImage(redImage, 0);
	
	for(int i = numPixels; i > 0 ; i--){
		if( pix[i] > nearThreshold && pix[i] < farThreshold ){
			pix[i] = 255;
		}else{
			pix[i] = 0;
		}
	}
	
	//update the cv image
	grayImage.flagImageChanged();
	
	unsigned char * red = redImage.getPixels();
	numPixels = redImage.getWidth() * redImage.getHeight();
	//
	contourFinder.findContours(grayImage, 900, (kinect.width*kinect.height)/8, 20, false);
	
	TuioTime frameTime = TuioTime::getSessionTime();
	tuioServer->initFrame(frameTime);
	
	int numBlobs = contourFinder.blobs.size() ;
	int count = 0 ; 
	
	if ( numBlobs == 0 ) 
		holdingLength = 0 ;
	
	//detect all blobs
	std::vector<ofxCvBlob>::iterator blob;
	for (blob=contourFinder.blobs.begin(); blob!= contourFinder.blobs.end(); blob++) 
	{
		float xpos = (*blob).centroid.x;
		float ypos = (*blob).centroid.y;
		
		TuioPoint tp(xpos/kinect.width,ypos/kinect.height);
		
		TuioCursor *tcur = tuioServer->getClosestTuioCursor(tp.getX(),tp.getY());
		
		//Adjust here to change minumum distance for new points
		if ((tcur==NULL) || (tcur->getDistance(&tp)>0.1)) { 
			tcur = tuioServer->addTuioCursor(tp.getX(), tp.getY());
			updateKalman(tcur->getCursorID(),tcur);
		} else {
			TuioPoint kp = updateKalman(tcur->getCursorID(),tp);
			tuioServer->updateTuioCursor(tcur, kp.getX(), kp.getY());
		}
		
		xpos = tp.getX() * ofGetWidth() ; 
		ypos = tp.getY() * ofGetHeight() ; 
		
		if ( numBlobs < 3 )
		{
			kCursors[count].x = xpos ; 
			kCursors[count].y = ypos ; 
		}
		count++ ;
	}
	
	float strength = 5.0f;
	float damping  = 0.5f;
	
	if ( numBlobs == 2 ) 
	{
		if ( holdingLength < 40 ) 
			holdingLength++ ;

		float holdingRatio = 0.05f + (float)holdingLength/40.0f ;
		float minDis   = 100.0f;
		
		ofPoint c1 = kCursors[1] ; 
		ofPoint c0 = kCursors[0] ; 
		
		for(int i=0; i< customParticles.size() ; i++) 
		{	
			CustomParticle& p = customParticles[i] ; 
			if ( i % 2 == 0 ) 
			{
				p.addAttractionPoint( c0.x, c0.y, (float)holdingLength*1.05 * strength, minDis);
			}
			else 
			{
				p.addAttractionPoint( c1.x, c1.y, (float)holdingLength*1.05 * strength, minDis);
			}

			p.addDamping(damping, damping);
		}
	
	}

	//remove non moving cursors
	tuioServer->stopUntouchedMovingCursors();
	
	std::list<TuioCursor*> dead_cursor_list = tuioServer->getUntouchedCursors();
	std::list<TuioCursor*>::iterator dead_cursor;
	for (dead_cursor=dead_cursor_list.begin(); dead_cursor!= dead_cursor_list.end(); dead_cursor++) 
	{
		clearKalman((*dead_cursor)->getCursorID());
	}
	
	tuioServer->removeUntouchedStoppedCursors();
	tuioServer->commitFrame();

	box2d.update() ; 
}