Exemplo n.º 1
0
void MyTuioServer::send_blobs(std::vector<cBlob>& blobs, std::vector<Area>& areas, cv::Rect& roi){

	currentTime = TuioTime::getSessionTime();
	initFrame(currentTime);

	cBlob *pb;
	Area *pa;
//	printf("Area size: %i\n", areas.size());
	float lx,ly;
	for (int i = 0; i < blobs.size(); i++) {
		pb = &blobs[i];
		pa = &areas[pb->areaid-1];
		switch( pb->event ){
			case BLOB_UP:
				{
					printf("Remove cursor\n");
					//assert( pb->cursor != NULL );
					if( pb->cursor == NULL ) break;
					removeTuioCursor(pb->cursor);
				}
				break;
			case BLOB_DOWN:
				{
					//assert( pb->cursor == NULL );
					localCoords(pb,pa,&roi,&lx,&ly);
					if( pb->cursor == NULL ){
						pb->cursor = addTuioCursor(lx,ly,tuioSessionId(pb));
						printf("Add cursor %i \n", (int)tuioSessionId(pb));
					}else{
						updateTuioCursor(pb->cursor,lx,ly);
					}
				}
				break;
			case BLOB_MOVE:
			default:
				{
					localCoords(pb,pa,&roi,&lx,&ly);
					//assert( pb->cursor != NULL );
					if( pb->cursor == NULL ){
						pb->cursor = addTuioCursor(lx,ly,tuioSessionId(pb));
					}else{
						printf("Move cursor %i to %f %f \n", (int)tuioSessionId(pb),lx,ly );
						updateTuioCursor(pb->cursor,lx,ly);
					}
				}
				break;
		}
	}
	//processEvents();
	stopUntouchedMovingCursors();//?
	commitFrame();

/*
	if (cursor->getTuioTime()==currentTime) return;
	tuioServer->updateTuioCursor(cursor,x,y);
			cursor = tuioServer->addTuioCursor(x,y);
		tuioServer->removeTuioCursor(cursor);
	std::list<TuioCursor*> cursorList = tuioServer->getTuioCursors();
	*/
}
Exemplo n.º 2
0
void TouchServer::updateLeftCursor(const unsigned int user, const float xp, const float yp)
{
    //printf("Left cursor at: %f, %f.\n", xp, yp);
    
    // user not in map, add user and add cursor
    if(cursorMap_.count(user) == 0)
    {
        CursorPair cpair;
        cpair.leftCursor_ = addTuioCursor(xp, yp);
        cpair.rightCursor_ = NULL;
        cursorMap_.insert(std::pair<unsigned int, CursorPair>(user, cpair));
    }
    
    // user is in map, update cursor
    if(cursorMap_[user].leftCursor_ != NULL)
        updateTuioCursor(cursorMap_[user].leftCursor_, xp, yp);
    else
        cursorMap_[user].leftCursor_ = addTuioCursor(xp, yp);  
}