コード例 #1
0
ファイル: TuioServer.cpp プロジェクト: nixz/covise
void TuioServer::commitFrame()
{

    if (updateCursor)
    {
        startCursorBundle();
        for (std::list<TuioCursor *>::iterator tuioCursor = cursorList.begin(); tuioCursor != cursorList.end(); tuioCursor++)
        {

            // start a new packet if we exceed the packet capacity
            if ((oscPacket->Capacity() - oscPacket->Size()) < CUR_MESSAGE_SIZE)
            {
                sendCursorBundle(currentFrame);
                startCursorBundle();
            }

            TuioCursor *tcur = (*tuioCursor);
            if ((full_update) || (tcur->getTuioTime() == currentFrameTime))
                addCursorMessage(tcur);
        }
        sendCursorBundle(currentFrame);
    }
    else if ((!periodic_update) && (lastCursorUpdate < currentFrameTime.getSeconds()))
    {
        lastCursorUpdate = currentFrameTime.getSeconds();
        startCursorBundle();
        sendCursorBundle(currentFrame);
    }
    updateCursor = false;

    if (updateObject)
    {
        startObjectBundle();
        for (std::list<TuioObject *>::iterator tuioObject = objectList.begin(); tuioObject != objectList.end(); tuioObject++)
        {

            // start a new packet if we exceed the packet capacity
            if ((oscPacket->Capacity() - oscPacket->Size()) < OBJ_MESSAGE_SIZE)
            {
                sendObjectBundle(currentFrame);
                startObjectBundle();
            }

            TuioObject *tobj = (*tuioObject);
            if ((full_update) || (tobj->getTuioTime() == currentFrameTime))
                addObjectMessage(tobj);
        }
        sendObjectBundle(currentFrame);
    }
    else if ((!periodic_update) && (lastObjectUpdate < currentFrameTime.getSeconds()))
    {
        lastObjectUpdate = currentFrameTime.getSeconds();
        startObjectBundle();
        sendObjectBundle(currentFrame);
    }
    updateObject = false;
}
コード例 #2
0
std::list<TuioObject*> TuioManager::getUntouchedObjects() {
	
	std::list<TuioObject*> untouched;
	for (std::list<TuioObject*>::iterator tuioObject = objectList.begin(); tuioObject!=objectList.end(); tuioObject++) {
		TuioObject *tobj = (*tuioObject);
		if (tobj->getTuioTime()!=currentFrameTime) untouched.push_back(tobj);
	}	
	return untouched;
}
コード例 #3
0
void testApp::tuioObjectUpdated(TuioObject & tobj){
	/*cout << " object updated: " + ofToString(tobj.getSymbolID())+
	" X: "+ofToString(tobj.getX())+
	" Y: "+ofToString(tobj.getY())+
	" angle: "+ofToString(tobj.getAngleDegrees())
	<< endl;*/
	
	//forward the marker events to ofxMarker for the InteractiveObjects
	ofxMarker.markerMoved(tobj.getSymbolID(), tobj.getX(), tobj.getY(), tobj.getAngleDegrees());
}
コード例 #4
0
void TuioManager::removeUntouchedStoppedObjects() {
	
	std::list<TuioObject*>::iterator tuioObject = objectList.begin();
	while (tuioObject!=objectList.end()) {
		TuioObject *tobj = (*tuioObject);
		if ((tobj->getTuioTime()!=currentFrameTime) && (!tobj->isMoving())) {
			removeTuioObject(tobj);
			tuioObject = objectList.begin();
		} else tuioObject++;
	}
}
コード例 #5
0
ファイル: TuioServer.cpp プロジェクト: BlueBrain/TUIO
TuioObject* TuioServer::addTuioObject(int f_id, float x, float y, float a) {
    sessionID++;
    TuioObject *tobj = new TuioObject(currentFrameTime, sessionID, f_id, x, y, a);
    objectList.push_back(tobj);
    updateObject = true;

    if (verbose)
        std::cout << "add obj " << tobj->getSymbolID() << " (" << tobj->getSessionID() << ") "<< tobj->getX() << " " << tobj->getY() << " " << tobj->getAngle() << std::endl;

    return tobj;
}
コード例 #6
0
ファイル: TuioServer.cpp プロジェクト: Ahmedn1/ccv-hand
void TuioServer::removeUntouchedStoppedObjects() {
	
	for (std::list<TuioObject*>::iterator tuioObject = objectList.begin(); tuioObject!=objectList.end(); tuioObject++) {
		
		TuioObject *tobj = (*tuioObject);
		if ((tobj->getTuioTime()!=currentFrameTime) && (!tobj->getTuioState()==TUIO_ADDED) && (!tobj->isMoving())) {
			removeTuioObject(tobj);
			removeUntouchedStoppedObjects();
			break;
		}
	}
}
コード例 #7
0
ファイル: TuioClient.cpp プロジェクト: nixz/covise
void TuioClient::ProcessMessage(const ReceivedMessage &msg, const IpEndpointName &remoteEndpoint)
{
    try
    {
        ReceivedMessageArgumentStream args = msg.ArgumentStream();

        if (strcmp(msg.AddressPattern(), "/tuio/2Dobj") == 0)
        {

            const char *cmd;
            args >> cmd;

            if (strcmp(cmd, "set") == 0)
            {

                int32 s_id, c_id;
                float xpos, ypos, angle, xspeed, yspeed, rspeed, maccel, raccel;
                args >> s_id >> c_id >> xpos >> ypos >> angle >> xspeed >> yspeed >> rspeed >> maccel >> raccel;

                lockObjectList();
                std::list<TuioObject *>::iterator tobj;
                for (tobj = objectList.begin(); tobj != objectList.end(); tobj++)
                    if ((*tobj)->getSessionID() == (long)s_id)
                        break;

                if (tobj == objectList.end())
                {

                    TuioObject *addObject = new TuioObject((long)s_id, (int)c_id, xpos, ypos, angle);
                    frameObjects.push_back(addObject);
                }
                else if (((*tobj)->getX() != xpos) || ((*tobj)->getY() != ypos) || ((*tobj)->getAngle() != angle) || ((*tobj)->getXSpeed() != xspeed) || ((*tobj)->getYSpeed() != yspeed) || ((*tobj)->getRotationSpeed() != rspeed) || ((*tobj)->getMotionAccel() != maccel) || ((*tobj)->getRotationAccel() != raccel))
                {

                    TuioObject *updateObject = new TuioObject((long)s_id, (*tobj)->getSymbolID(), xpos, ypos, angle);
                    updateObject->update(xpos, ypos, angle, xspeed, yspeed, rspeed, maccel, raccel);
                    frameObjects.push_back(updateObject);
                }
                unlockObjectList();
            }
            else if (strcmp(cmd, "alive") == 0)
            {

                int32 s_id;
                aliveObjectList.clear();
                while (!args.Eos())
                {
                    args >> s_id;
                    aliveObjectList.push_back((long)s_id);
                }
            }
コード例 #8
0
TuioObject* TuioManager::addTuioObject(int f_id, float x, float y, float a) {
	sessionID++;
	TuioObject *tobj = new TuioObject(currentFrameTime, sessionID, f_id, x, y, a);
	objectList.push_back(tobj);
	updateObject = true;

	for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
		(*listener)->addTuioObject(tobj);

	if (verbose)
		std::cout << "add obj " << tobj->getSymbolID() << " (" << tobj->getSessionID() << ") "<< tobj->getX() << " " << tobj->getY() << " " << tobj->getAngle() << std::endl;

	return tobj;
}
コード例 #9
0
void moTUIOSystemData::stopUntouchedMovingObjects() {

	std::list<TuioObject*> untouched;
	for (std::list<TuioObject*>::iterator tuioObject = objectList.begin(); tuioObject!=objectList.end(); tuioObject++) {

		TuioObject *tobj = (*tuioObject);
		if ((tobj->getTuioTime()!=currentFrameTime) && (tobj->isMoving())) {
			tobj->stop(currentFrameTime);
			updateObject = true;
			/*if (verbose)
				std::cout << "set obj " << tobj->getSymbolID() << " (" << tobj->getSessionID() << ") "<< tobj->getX() << " " << tobj->getY() << " " << tobj->getAngle()
				<< " " << tobj->getXSpeed() << " " << tobj->getYSpeed() << " " << tobj->getRotationSpeed() << " " << tobj->getMotionAccel() << " " << tobj->getRotationAccel() << std::endl;
				*/
		}
	}
}
コード例 #10
0
ファイル: Tuio2Simulator.cpp プロジェクト: JassiO/TUIO20_CPP
void Tuio2Simulator::mousePressed(float x, float y) {
	//printf("pressed %f %f\n",x,y);

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

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

		if (match!=NULL) {
			std::list<TuioPointer*>::iterator joint = std::find( jointPointerList.begin(), jointPointerList.end(), match );
			if( joint != jointPointerList.end() ) {
				jointPointerList.erase( joint );
			}
			stickyPointerList.remove(match);
			stickyPointerList.remove(match);
			tuioServer->removeTuioPointer(match);
		} else {
			TuioObject *tobj = tuioServer->createTuioPointer(x,y,0,0,0,0);
			stickyPointerList.push_back(tobj->getTuioPointer());
			activePointerList.push_back(tobj->getTuioPointer());
		}
	} else if ((keystate[SDLK_LCTRL]) || (keystate[SDLK_RCTRL])) {

		if (match!=NULL) {
			std::list<TuioPointer*>::iterator joint = std::find( jointPointerList.begin(), jointPointerList.end(), match );
			if( joint != jointPointerList.end() ) {
				jointPointerList.remove( match );
			} else jointPointerList.push_back(match);
		}
	} else {
		if (match==NULL) {
			TuioObject *tobj = tuioServer->createTuioPointer(x,y,0,0,0,0);
			activePointerList.push_back(tobj->getTuioPointer());
        } else {
            activePointerList.push_back(match);
        }
	}
}
コード例 #11
0
ファイル: ofxTuioClient.cpp プロジェクト: BigDTeam/ccv-tbeta
void ofxTuioClient::drawObjects(){
    std::list<TuioObject*> objectList = client->getTuioObjects();
	list<TuioObject*>::iterator tobj;
	client->lockObjectList();
	for (tobj=objectList.begin(); tobj != objectList.end(); tobj++) {
		TuioObject *obj = (*tobj);
		glColor3f(1.0,0.0,0.0);
		glPushMatrix();
		glTranslatef(obj->getX()*ofGetWidth(), obj->getY()*ofGetHeight(), 0.0);
		glRotatef(obj->getAngleDegrees(), 0.0, 0.0, 1.0);
		ofRect(-10.0, -10.0, 20.0, 20.0);
		glColor3f(1.0,1.0,1.0);
		ofLine(0, 0, 0, -10);
		glPopMatrix();
		string str = "SymbolId: "+ofToString((int)(obj->getSymbolID()));
		ofDrawBitmapString(str, obj->getX()*ofGetWidth()-10.0, obj->getY()*ofGetHeight()+25.0);
		str = "SessionId: "+ofToString((int)(obj->getSessionID()));
		ofDrawBitmapString(str, obj->getX()*ofGetWidth()-10.0, obj->getY()*ofGetHeight()+40.0);
	}
	client->unlockObjectList();
}
コード例 #12
0
void TuioClient::ProcessMessage( const ReceivedMessage& msg, const IpEndpointName& remoteEndpoint) {
	try {
		ReceivedMessageArgumentStream args = msg.ArgumentStream();
		ReceivedMessage::const_iterator arg = msg.ArgumentsBegin();
		
		if( strcmp( msg.AddressPattern(), "/tuio/2Dobj" ) == 0 ){
			
			const char* cmd;
			args >> cmd;
			
			if (strcmp(cmd,"set")==0) {	
				
				if (currentTime.getTotalMilliseconds()==0)
					currentTime = TuioTime::getSessionTime();
								
				int32 s_id, c_id;
				float xpos, ypos, angle, xspeed, yspeed, rspeed, maccel, raccel;
				args >> s_id >> c_id >> xpos >> ypos >> angle >> xspeed >> yspeed >> rspeed >> maccel >> raccel;
				
				lockObjectList();
				std::list<TuioObject*>::iterator tobj;
				for (tobj=objectList.begin(); tobj!= objectList.end(); tobj++)
					if((*tobj)->getSessionID()==(long)s_id) break;
				
				if (tobj == objectList.end()) {
					TuioObject *addObject = new TuioObject(currentTime,(long)s_id,(int)c_id,xpos,ypos,angle);
					objectList.push_back(addObject);
					
					for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
						(*listener)->addTuioObject(addObject);
					
				} else if ( ((*tobj)->getX()!=xpos) || ((*tobj)->getY()!=ypos) || ((*tobj)->getAngle()!=angle) || ((*tobj)->getXSpeed()!=xspeed) || ((*tobj)->getYSpeed()!=yspeed) || ((*tobj)->getRotationSpeed()!=rspeed) || ((*tobj)->getMotionAccel()!=maccel) || ((*tobj)->getRotationAccel()!=raccel) ) {

					TuioObject *updateObject = new TuioObject(currentTime,(long)s_id,(*tobj)->getSymbolID(),xpos,ypos,angle);
					updateObject->update(currentTime,xpos,ypos,angle,xspeed,yspeed,rspeed,maccel,raccel);
					frameObjects.push_back(updateObject);
				
					/*(*tobj)->update(currentTime,xpos,ypos,angle,xspeed,yspeed,rspeed,maccel,raccel);
					for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
						(*listener)->updateTuioObject((*tobj));*/
				}
				unlockObjectList();
			} else if (strcmp(cmd,"alive")==0) {
				
				int32 s_id;
				while(!args.Eos()) {
					args >> s_id;
					objectBuffer.push_back((long)s_id);
					
					std::list<long>::iterator iter;
					iter = find(aliveObjectList.begin(), aliveObjectList.end(), (long)s_id); 
					if (iter != aliveObjectList.end()) aliveObjectList.erase(iter);
				}
				
				std::list<long>::iterator alive_iter;
				for (alive_iter=aliveObjectList.begin(); alive_iter != aliveObjectList.end(); alive_iter++) {
					lockObjectList();
					std::list<TuioObject*>::iterator tobj;
					for (tobj=objectList.begin(); tobj!=objectList.end(); tobj++) {
						TuioObject *deleteObject = (*tobj);
						if(deleteObject->getSessionID()==*alive_iter) {
							objectList.erase(tobj);
							deleteObject->remove(currentTime);
							for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
								(*listener)->removeTuioObject(deleteObject);
							delete deleteObject;
							break;
						}
					}
					unlockObjectList();
				}
				aliveObjectList = objectBuffer;
				objectBuffer.clear();
			} else if (strcmp(cmd,"fseq")==0) {
				
				int32 fseq;
				args >> fseq;
				bool lateFrame = false;
				if (fseq>0) {
					if ((fseq>=currentFrame) || ((currentFrame-fseq)>100)) currentFrame = fseq;
					else lateFrame = true;
				}
			
				if (!lateFrame) {
					
					for (std::list<TuioObject*>::iterator iter=frameObjects.begin(); iter != frameObjects.end(); iter++) {
						TuioObject *tobj = (*iter);
						TuioObject *updateObject = getTuioObject(tobj->getSessionID());
						updateObject->update(currentTime,tobj->getX(),tobj->getY(),tobj->getAngle(),tobj->getXSpeed(),tobj->getYSpeed(),tobj->getRotationSpeed(),tobj->getMotionAccel(),tobj->getRotationAccel());
						
						for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
							(*listener)->updateTuioObject(updateObject);
						
						delete tobj;
					}
					
					for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++)
						(*listener)->refresh(currentTime);
					
					if (fseq>0) currentTime.reset();
				} else {
					for (std::list<TuioObject*>::iterator iter=frameObjects.begin(); iter != frameObjects.end(); iter++) {
						TuioObject *tobj = (*iter);
						delete tobj;
					}
				}
				
				frameObjects.clear();
				
				/*TuioTime ftime = TuioTime::getSystemTime();
				long ft = ftime.getSeconds()*1000000 + ftime.getMicroseconds();
				if (currentFrame>0) std:: cout << "received frame " << currentFrame << " " << ft  << std::endl;*/
			}
コード例 #13
0
ファイル: TuioDemo.cpp プロジェクト: crunchytech/TUIO11_CPP
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();
}