Exemplo n.º 1
0
TuioBlob* TuioManager::addTuioBlob(float x, float y, float a, float w, float h, float f) {
	sessionID++;
	
	int blobID = (int)blobList.size();
	if ((int)(blobList.size())<=maxBlobID) {
		std::list<TuioBlob*>::iterator closestBlob = freeBlobList.begin();
		
		for(std::list<TuioBlob*>::iterator iter = freeBlobList.begin();iter!= freeBlobList.end(); iter++) {
			if((*iter)->getDistance(x,y)<(*closestBlob)->getDistance(x,y)) closestBlob = iter;
		}
		
		TuioBlob *freeBlob = (*closestBlob);
		blobID = (*closestBlob)->getBlobID();
		freeBlobList.erase(closestBlob);
		delete freeBlob;
	} else maxBlobID = blobID;	
	
	TuioBlob *tblb = new TuioBlob(currentFrameTime, sessionID, blobID, x, y, a, w, h, f);
	blobList.push_back(tblb);
	updateBlob = true;
	
	for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
		(*listener)->addTuioBlob(tblb);
	
	if (verbose) 
		std::cout << "add blb " << tblb->getBlobID() << " (" <<  tblb->getSessionID() << ") " << tblb->getX() << " " << tblb->getY()  << tblb->getAngle() << " " << tblb->getWidth() << tblb->getHeight() << " " << tblb->getArea() << std::endl;
	
	return tblb;
}
Exemplo n.º 2
0
std::list<TuioBlob*> TuioManager::getUntouchedBlobs() {
	
	std::list<TuioBlob*> untouched;
	for (std::list<TuioBlob*>::iterator tuioBlob = blobList.begin(); tuioBlob!=blobList.end(); tuioBlob++) {
		TuioBlob *tblb = (*tuioBlob);
		if (tblb->getTuioTime()!=currentFrameTime) untouched.push_back(tblb);
	}	
	return untouched;
}
Exemplo n.º 3
0
void TuioManager::removeUntouchedStoppedBlobs() {
	
	std::list<TuioBlob*>::iterator tuioBlob = blobList.begin();
	while (tuioBlob!=blobList.end()) {
		TuioBlob *tblb = (*tuioBlob);
		if ((tblb->getTuioTime()!=currentFrameTime) && (!tblb->isMoving())) {
			removeTuioBlob(tblb);
			tuioBlob = blobList.begin();
		} else tuioBlob++;
	}	
}
Exemplo n.º 4
0
void TuioManager::stopUntouchedMovingBlobs() {
	
	std::list<TuioBlob*> untouched;
	for (std::list<TuioBlob*>::iterator tuioBlob = blobList.begin(); tuioBlob!=blobList.end(); tuioBlob++) {
		TuioBlob *tblb = (*tuioBlob);
		if ((tblb->getTuioTime()!=currentFrameTime) && (tblb->isMoving())) {
			tblb->stop(currentFrameTime);
			updateBlob = true;
			if (verbose) 	
				std::cout << "set blb " << tblb->getSessionID() << tblb->getX() << " " << tblb->getY() << " " << tblb->getWidth() << " " << tblb->getHeight() << " " << tblb->getAngle()
				<< " " << tblb->getXSpeed() << " " << tblb->getYSpeed()<< " " << tblb->getMotionAccel() << " " << std::endl;							
		}
	}	
}
Exemplo n.º 5
0
void TuioManager::removeTuioBlob(TuioBlob *tblb) {
	if (tblb==NULL) return;
	
	blobList.remove(tblb);
	tblb->remove(currentFrameTime);
	updateBlob = true;

	for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
		(*listener)->removeTuioBlob(tblb);
	
	if (verbose)
		std::cout << "del blb " << tblb->getBlobID() << " (" <<  tblb->getSessionID() << ")" << std::endl;
	
	if (tblb->getBlobID()==maxBlobID) {
		maxBlobID = -1;
		delete tblb;
		
		if (blobList.size()>0) {
			std::list<TuioBlob*>::iterator clist;
			for (clist=blobList.begin(); clist != blobList.end(); clist++) {
				int blobID = (*clist)->getBlobID();
				if (blobID>maxBlobID) maxBlobID=blobID;
			}
			
			freeBlobBuffer.clear();
			for (std::list<TuioBlob*>::iterator flist=freeBlobList.begin(); flist != freeBlobList.end(); flist++) {
				TuioBlob *freeBlob = (*flist);
				if (freeBlob->getBlobID()>maxBlobID) delete freeBlob;
				else freeBlobBuffer.push_back(freeBlob);
			}
			
			freeBlobList = freeBlobBuffer;
			
		} else {
			for (std::list<TuioBlob*>::iterator flist=freeBlobList.begin(); flist != freeBlobList.end(); flist++) {
				TuioBlob *freeBlob = (*flist);
				delete freeBlob;
			}
			freeBlobList.clear();
		}
	} else if (tblb->getBlobID()<maxBlobID) {
		freeBlobList.push_back(tblb);	
	}
	
}
Exemplo n.º 6
0
void TuioDemo::drawObjects() {
	glClear(GL_COLOR_BUFFER_BIT);
	char id[3];
	
	// draw the cursors
	std::list<TuioCursor*> cursorList = tuioClient->getTuioCursors();
	tuioClient->lockCursorList();
	for (std::list<TuioCursor*>::iterator iter = cursorList.begin(); iter!=cursorList.end(); iter++) {
		TuioCursor *tuioCursor = (*iter);
		std::list<TuioPoint> path = tuioCursor->getPath();
		if (path.size()>0) {
			
			TuioPoint last_point = path.front();
			glBegin(GL_LINES);
			glColor3f(0.0, 0.0, 1.0);
			
			for (std::list<TuioPoint>::iterator point = path.begin(); point!=path.end(); point++) {
				glVertex3f(last_point.getScreenX(width), last_point.getScreenY(height), 0.0f);
				glVertex3f(point->getScreenX(width), point->getScreenY(height), 0.0f);
				last_point.update(point->getX(),point->getY());
			} glEnd();
			
			// draw the finger tip
			glColor3f(0.75, 0.75, 0.75);
			glPushMatrix();
			glTranslatef(last_point.getScreenX(width), last_point.getScreenY(height), 0.0);
			glBegin(GL_TRIANGLE_FAN);
			for(double a = 0.0f; a <= 2*M_PI; a += 0.2f) {
				glVertex2d(cos(a) * height/100.0f, sin(a) * height/100.0f);
			} glEnd();
			glPopMatrix();
			
			glColor3f(0.0, 0.0, 0.0);
			glRasterPos2f(tuioCursor->getScreenX(width),tuioCursor->getScreenY(height));
			sprintf(id,"%d",tuioCursor->getCursorID());
			drawString(id);
		}
	}
	tuioClient->unlockCursorList();
	
	// draw the objects
	std::list<TuioObject*> objectList = tuioClient->getTuioObjects();
	tuioClient->lockObjectList();
	for (std::list<TuioObject*>::iterator iter = objectList.begin(); iter!=objectList.end(); iter++) {
		TuioObject *tuioObject = (*iter);
		int pos_size = height/25.0f;
		int neg_size = -1*pos_size;
		float xpos  = tuioObject->getScreenX(width);
		float ypos  = tuioObject->getScreenY(height);
		float angle = tuioObject->getAngleDegrees();
		
		glColor3f(0.0, 0.0, 0.0);
		glPushMatrix();
		glTranslatef(xpos, ypos, 0.0);
		glRotatef(angle, 0.0, 0.0, 1.0);
		glBegin(GL_QUADS);
		glVertex2f(neg_size, neg_size);
		glVertex2f(neg_size, pos_size);
		glVertex2f(pos_size, pos_size);
		glVertex2f(pos_size, neg_size);
		glEnd();
		glPopMatrix();
		
		glColor3f(1.0, 1.0, 1.0);
		glRasterPos2f(xpos,ypos+5);
		sprintf(id,"%d",tuioObject->getSymbolID());
		drawString(id);
	}
	tuioClient->unlockObjectList();
	
	// draw the blobs
	std::list<TuioBlob*> blobList = tuioClient->getTuioBlobs();
	tuioClient->lockBlobList();
	for (std::list<TuioBlob*>::iterator iter = blobList.begin(); iter!=blobList.end(); iter++) {
		TuioBlob *tuioBlob = (*iter);
		float blob_width = tuioBlob->getScreenWidth(width)/2;
		float blob_height = tuioBlob->getScreenHeight(height)/2;
		float xpos  = tuioBlob->getScreenX(width);
		float ypos  = tuioBlob->getScreenY(height);
		float angle = tuioBlob->getAngleDegrees();
		
		glColor3f(0.25, 0.25, 0.25);
		glPushMatrix();
		glTranslatef(xpos, ypos, 0.0);
		glRotatef(angle, 0.0, 0.0, 1.0);
		
		/*glBegin(GL_QUADS);
		 glVertex2f(blob_width/-2, blob_height/-2);
		 glVertex2f(blob_width/-2, blob_height/2);
		 glVertex2f(blob_width/2, blob_height/2);
		 glVertex2f(blob_width/2, blob_height/-2);
		 glEnd();*/
		
		glBegin(GL_TRIANGLE_FAN);
		for(double a = 0.0f; a <= 2*M_PI; a += 0.2f) {
			glVertex2d(cos(a) * blob_width, sin(a) * blob_height);
		} glEnd();
		
		glPopMatrix();
		
		glColor3f(1.0, 1.0, 1.0);
		glRasterPos2f(xpos,ypos+5);
		sprintf(id,"%d",tuioBlob->getBlobID());
		drawString(id);
	}
	tuioClient->unlockBlobList();
	
	SDL_GL_SwapBuffers();
}