void testApp::touchDown(TuioCursor & tcur) { cout << "testApp::touchDown" << endl; touchPoints.push_back( ofPoint(tcur.getX()*ofGetWidth(), tcur.getY()*ofGetHeight()) ); }
TuioCursor* TuioServer::addTuioCursor(float x, float y, float z) { sessionID++; int cursorID = (int)cursorList.size(); if (((int)(cursorList.size())<=maxCursorID) && ((int)(freeCursorList.size())>0)) { std::list<TuioCursor*>::iterator closestCursor = freeCursorList.begin(); for(std::list<TuioCursor*>::iterator iter = freeCursorList.begin(); iter!= freeCursorList.end(); iter++) { if((*iter)->getDistance(x,y,z)<(*closestCursor)->getDistance(x,y,z)) closestCursor = iter; } TuioCursor *freeCursor = (*closestCursor); cursorID = (*closestCursor)->getCursorID(); freeCursorList.erase(closestCursor); delete freeCursor; } else maxCursorID = cursorID; TuioCursor *tcur = new TuioCursor(currentFrameTime, sessionID, cursorID, x, y, z); cursorList.push_back(tcur); updateCursor = true; if (verbose) { if (mode3d) { std::cout << "add cur " << tcur->getCursorID() << " (" << tcur->getSessionID() << ") " << tcur->getX() << " " << tcur->getY() << " " << tcur->getZ() << std::endl; } else { std::cout << "add cur " << tcur->getCursorID() << " (" << tcur->getSessionID() << ") " << tcur->getX() << " " << tcur->getY() << std::endl; } } return tcur; }
//draw them for debug purposes void ofxTuioServer::drawCursors() { char id[3]; // draw the cursors std::list<TuioCursor*> cursorList = tuioServer->getTuioCursors(); for (std::list<TuioCursor*>::iterator tuioCursor = cursorList.begin(); tuioCursor!=cursorList.end(); tuioCursor++) { TuioCursor * tcur = (*tuioCursor); std::list<TuioPoint> path = tcur->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.getX()*ofGetWidth(), last_point.getY()*ofGetHeight(), 0.0f); glVertex3f(point->getX()*ofGetWidth(), point->getY()*ofGetHeight(), 0.0f); last_point.update(point->getX(),point->getY()); } glEnd(); // draw the finger tip glColor3f(0.0, 0.75, 0.75); //float size = tcur->getWidth() + tcur ofCircle(tcur->getX()*ofGetWidth(), tcur->getY()*ofGetHeight(), 10); } } }
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); } }
void IupTuioListener::finishCursorInfo(int cursor_count, int* px, int* py, int* pstate, int w, int h, int use_client_coord, Ihandle* ih_canvas) { std::list<TuioCursor*>& cursorList = this->client->getCursorList(); std::list <TuioCursor*>::iterator iter; std::list <TuioCursor*>::iterator end = cursorList.end(); int i; for (i = 0, iter = cursorList.begin(); i<cursor_count && iter!=end; iter++, i++) { if (pstate[i] == 0) /* if still 0, then it was not updated, must fill it here */ { TuioCursor* tcur = (*iter); int x = tcur->getScreenX(w); int y = tcur->getScreenY(h); if (use_client_coord) iupdrvScreenToClient(ih_canvas, &x, &y); px[i] = x; py[i] = y; pstate[i] = 'M'; /* mark as MOVE */ } } }
TuioCursor* TuioManager::addTuioCursor(float x, float y) { sessionID++; int cursorID = (int)cursorList.size(); if ((int)(cursorList.size())<=maxCursorID) { std::list<TuioCursor*>::iterator closestCursor = freeCursorList.begin(); for(std::list<TuioCursor*>::iterator iter = freeCursorList.begin();iter!= freeCursorList.end(); iter++) { if((*iter)->getDistance(x,y)<(*closestCursor)->getDistance(x,y)) closestCursor = iter; } TuioCursor *freeCursor = (*closestCursor); cursorID = (*closestCursor)->getCursorID(); freeCursorList.erase(closestCursor); delete freeCursor; } else maxCursorID = cursorID; TuioCursor *tcur = new TuioCursor(currentFrameTime, sessionID, cursorID, x, y); cursorList.push_back(tcur); updateCursor = true; for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++) (*listener)->addTuioCursor(tcur); if (verbose) std::cout << "add cur " << tcur->getCursorID() << " (" << tcur->getSessionID() << ") " << tcur->getX() << " " << tcur->getY() << std::endl; return tcur; }
void TuioServer::removeTuioCursor(TuioCursor *tcur) { if (tcur==NULL) return; cursorList.remove(tcur); tcur->remove(currentFrameTime); updateCursor = true; if (verbose) std::cout << "del cur " << tcur->getCursorID() << " (" << tcur->getSessionID() << ")" << std::endl; if (tcur->getCursorID()==maxFingerID) { maxFingerID = -1; delete tcur; if (cursorList.size()>0) { std::list<TuioCursor*>::iterator clist; for (clist=cursorList.begin(); clist != cursorList.end(); clist++) { int fingerID = (*clist)->getCursorID(); if (fingerID>maxFingerID) maxFingerID=fingerID; } std::list<TuioCursor*>::iterator flist; for (flist=freeCursorList.begin(); flist != freeCursorList.end(); flist++) { TuioCursor *freeCursor = (*flist); if (freeCursor->getCursorID()>maxFingerID) delete freeCursor; else freeCursorBuffer.push_back(freeCursor); } freeCursorList = freeCursorBuffer; freeCursorBuffer.clear(); } } else if (tcur->getCursorID()<maxFingerID) freeCursorList.push_back(tcur); }
void testApp::tuioCursorUpdated(TuioCursor & tcur){ /*cout << " cursor updated: " + ofToString(tcur.getCursorID())+ " X: "+ofToString(tcur.getXSpeed())+ " Y: "+ofToString(tcur.getYSpeed()) << endl;*/ //forward the touch events to ofxMultiTouch for the InteractiveObjects ofxMultiTouch.touchMoved(tcur.getX(), tcur.getY(), tcur.getCursorID(), NULL); }
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; }
std::list<TuioCursor*> TuioManager::getUntouchedCursors() { std::list<TuioCursor*> untouched; for (std::list<TuioCursor*>::iterator tuioCursor = cursorList.begin(); tuioCursor!=cursorList.end(); tuioCursor++) { TuioCursor *tcur = (*tuioCursor); if (tcur->getTuioTime()!=currentFrameTime) untouched.push_back(tcur); } return untouched; }
void testApp::tuioCursorRemoved(TuioCursor & tcur){ // cout << " cursor removed: " + ofToString(tcur.getCursorID())+ // " X: "+ofToString(tcur.getX())+ // " Y: "+ofToString(tcur.getY()) // << endl; updateDB(tcur.getCursorID(), time(NULL), tcur.getX(), tcur.getY()); //forward the touch events to ofxMultiTouch for the InteractiveObjects // ofxMultiTouch.touchUp(tcur.getX(), tcur.getY(), tcur.getCursorID(), NULL); }
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); }
void TuioServer::removeUntouchedStoppedCursors() { for (std::list<TuioCursor*>::iterator tuioCursor = cursorList.begin(); tuioCursor!=cursorList.end(); tuioCursor++) { TuioCursor *tcur = (*tuioCursor); if ((tcur->getTuioTime()!=currentFrameTime) && (!tcur->getTuioState()==TUIO_ADDED) && (!tcur->isMoving())) { removeTuioCursor(tcur); removeUntouchedStoppedCursors(); break; } } }
void testApp::cursorUpdateHandler(TuioCursor & tcur) { /*std::cout << "cursorUpdated " << tcur->getCursorID() << " (" << tcur->getSessionID() << ") " << tcur->getX() << " " << tcur->getY() << " " << tcur->getMotionSpeed() << " " << tcur->getMotionAccel() << " " << std::endl;*/ cout << "testApp::cursorUpdateHandler: " << " tcur.getX(): " << tcur.getX() << " tcur.getY(): " << tcur.getY() << endl; touchPoints.push_back(ofPoint(tcur.getX()*ofGetWidth(), tcur.getY()*ofGetHeight())); //touchPoints.push_back( ofPoint(tcur.getX(), tcur.getY()) ); //cout << "tcur.getX(): " << tcur.getX() << " tcur.getY() : " << tcur.getY() << endl; }
void TuioManager::removeUntouchedStoppedCursors() { if (cursorList.size()==0) return; std::list<TuioCursor*>::iterator tuioCursor = cursorList.begin(); while (tuioCursor!=cursorList.end()) { TuioCursor *tcur = (*tuioCursor); if ((tcur->getTuioTime()!=currentFrameTime) && (!tcur->isMoving())) { removeTuioCursor(tcur); tuioCursor = cursorList.begin(); } else tuioCursor++; } }
void IupTuioListener::initCursorInfo(int cursor_count, int* pid, int* pstate) { std::list<TuioCursor*>& cursorList = this->client->getCursorList(); std::list <TuioCursor*>::iterator iter; int i; for (i = 0, iter = cursorList.begin() ; i<cursor_count; iter++, i++) { TuioCursor* tcur = (*iter); pid[i] = (int)tcur->getSessionID(); pstate[i] = 0; /* mark to be updated later */ } }
void moTUIOSystemData::stopUntouchedMovingCursors() { std::list<TuioCursor*> untouched; for (std::list<TuioCursor*>::iterator tuioCursor = cursorList.begin(); tuioCursor!=cursorList.end(); tuioCursor++) { TuioCursor *tcur = (*tuioCursor); if ((tcur->getTuioTime()!=currentFrameTime) && (tcur->isMoving())) { tcur->stop(currentFrameTime); updateCursor = true; /* if (verbose) std::cout << "set cur " << tcur->getCursorID() << " (" << tcur->getSessionID() << ") " << tcur->getX() << " " << tcur->getY() << " " << tcur->getXSpeed() << " " << tcur->getYSpeed()<< " " << tcur->getMotionAccel() << " " << std::endl; */ } } }
int IupTuioListener::GetMainCursor() { std::list<TuioCursor*>& cursorList = this->client->getCursorList(); std::list <TuioCursor*>::iterator iter; std::list <TuioCursor*>::iterator end = cursorList.end(); int min_id = -1; for (iter = cursorList.begin(); iter!=end; iter++) { TuioCursor* tcur = (*iter); int id = (int)tcur->getSessionID(); if (min_id == -1 || id < min_id) min_id = id; } return min_id; }
void testApp::tuioCursorRemoved(TuioCursor & tcur){ /*cout << " cursor removed: " + ofToString(tcur.getCursorID())+ " X: "+ofToString(tcur.getX())+ " Y: "+ofToString(tcur.getY()) << endl;*/ mtActionsHub.touchUp(tcur.getX(), tcur.getY(), tcur.getCursorID(), NULL); mtSliderHub.touchUp(tcur.getX(), tcur.getY(), tcur.getCursorID(), NULL); //draggableRotatableScalableItem.touchUp(tcur.getX(), tcur.getY(), tcur.getCursorID(), NULL); //forward the touch events to ofxMultiTouch for the InteractiveObjects ofxMultiTouch.touchUp(tcur.getX(), tcur.getY(), tcur.getCursorID(), NULL); }
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 TuioManager::removeTuioCursor(TuioCursor *tcur) { if (tcur==NULL) return; if (verbose && tcur->getTuioState()!=TUIO_ADDED) std::cout << "del cur " << tcur->getCursorID() << " (" << tcur->getSessionID() << ")" << std::endl; cursorList.remove(tcur); tcur->remove(currentFrameTime); updateCursor = true; for (std::list<TuioListener*>::iterator listener=listenerList.begin(); listener != listenerList.end(); listener++) (*listener)->removeTuioCursor(tcur); if (tcur->getCursorID()==maxCursorID) { maxCursorID = -1; delete tcur; if (cursorList.size()>0) { std::list<TuioCursor*>::iterator clist; for (clist=cursorList.begin(); clist != cursorList.end(); clist++) { int cursorID = (*clist)->getCursorID(); if (cursorID>maxCursorID) maxCursorID=cursorID; } freeCursorBuffer.clear(); for (std::list<TuioCursor*>::iterator flist=freeCursorList.begin(); flist != freeCursorList.end(); flist++) { TuioCursor *freeCursor = (*flist); if (freeCursor->getCursorID()>maxCursorID) delete freeCursor; else freeCursorBuffer.push_back(freeCursor); } freeCursorList = freeCursorBuffer; } else { for (std::list<TuioCursor*>::iterator flist=freeCursorList.begin(); flist != freeCursorList.end(); flist++) { TuioCursor *freeCursor = (*flist); delete freeCursor; } freeCursorList.clear(); } } else if (tcur->getCursorID()<maxCursorID) { freeCursorList.push_back(tcur); } }
///-------------------------------------------------------------- void Scene2::handleDrag(InteractionSource interactionSource, int x, int y, int cursorId) { if ((x < 0) || (x > ofGetWidth())) return; if ((y < 0) || (y > viewHeight)) return; int pressedObjectIndex; if (interactionSource == InteractionSourceMouse) { pressedObjectIndex = mouseObjectIndex; } else // Coming from TUIO { pressedObjectIndex = getObjectIndexWithCursor(cursorId); if (pressedObjectIndex == -1) { return; } } S2BaseObj *object = objects[pressedObjectIndex]; if (!object->getIsPicked()) return; // Send message to Ableton int pressedClipIndex = getClipIndexAtY(y) + (artistIndex * artistOffset) + SettingsManager::getInstance().abletonFirstClipIndex; if (pressedClipIndex != currentClipIndex) { int track = pressedObjectIndex; AbletonManager::getInstance().stopClip(currentClipIndex, track); currentClipIndex = (unsigned int)pressedClipIndex; // Play Ableton clip AbletonManager::getInstance().playClip(currentClipIndex, track); } // Position object (only if mouse, or if TUIO and cursor is the first one -to avoid crazy repositioning- TuioCursor *firstCursor = object->getFirstCursor(); bool mouseCondition = (interactionSource == InteractionSourceMouse); bool tuioCondition = (interactionSource == InteractionSourceTuio) && ((firstCursor == NULL) || (firstCursor->getCursorID() == cursorId)); if (mouseCondition || tuioCondition) { object->setPositionFromScreenCoords(x, y); } // Update Ableton track int device = 0; int parameter = 1; int value = ofMap(object->getXOffset(), 0, object->getRadius(), 0, 127, true); AbletonManager::getInstance().setDeviceParameter(pressedObjectIndex, device, parameter, value); }
void testApp::tuioCursorUpdated(TuioCursor & tcur){ /*cout << " cursor updated: " + ofToString(tcur.getCursorID())+ " X: "+ofToString(tcur.getXSpeed())+ " Y: "+ofToString(tcur.getYSpeed()) << endl;*/ ofxMultiTouchCustomDataSF multiTouchCustomData; multiTouchCustomData.sessionID = tcur.getSessionID(); mtActionsHub.touchMoved(tcur.getX(), tcur.getY(), tcur.getCursorID(), &multiTouchCustomData); mtSliderHub.touchMoved(tcur.getX(), tcur.getY(), tcur.getCursorID(), &multiTouchCustomData); /* draggableRotatableScalableItem.touchMoved(tcur.getX(), tcur.getY(), tcur.getCursorID(), NULL); if(draggableRotatableScalableItem.ownTouchCursor(tcur.getSessionID())) { return; } */ //forward the touch events to ofxMultiTouch for the InteractiveObjects ofxMultiTouch.touchMoved(tcur.getX(), tcur.getY(), tcur.getCursorID(), NULL); }
void TUIOInputModule::removeTuioCursor(TuioCursor *tcur) { std::vector<TouchInfo> touches; std::list<TuioCursor*> cursorList = tuioClient->getTuioCursors(); tuioClient->lockCursorList(); for (std::list<TuioCursor*>::iterator iter = cursorList.begin(); iter!=cursorList.end(); iter++) { TuioCursor *tuioCursor = (*iter); TouchInfo touch; touch.position.x = tuioCursor->getX(); touch.position.y = tuioCursor->getY(); touch.id= tuioCursor->getCursorID(); touches.push_back(touch); } tuioClient->unlockCursorList(); TUIOEvent event; event.type = InputEvent::EVENT_TOUCHES_ENDED; event.touches = touches; CoreServices::getInstance()->getCore()->lockMutex(eventMutex); events.push_back(event); CoreServices::getInstance()->getCore()->unlockMutex(eventMutex); }
void ofxTuioClient::drawCursors(){ std::list<TuioCursor*> cursorList = client->getTuioCursors(); std::list<TuioCursor*>::iterator tit; client->lockCursorList(); for (tit=cursorList.begin(); tit != cursorList.end(); tit++) { TuioCursor * cur = (*tit); //if(tcur!=0){ //TuioCursor cur = *tcur; glColor3f(0.0,0.0,0.0); ofEllipse(cur->getX()*ofGetWidth(), cur->getY()*ofGetHeight(), 10.0, 10.0); string str = "SessionId: "+ofToString((int)(cur->getSessionID())); ofDrawBitmapString(str, cur->getX()*ofGetWidth()-10.0, cur->getY()*ofGetHeight()+25.0); str = "CursorId: "+ofToString((int)(cur->getCursorID())); ofDrawBitmapString(str, cur->getX()*ofGetWidth()-10.0, cur->getY()*ofGetHeight()+40.0); //} } client->unlockCursorList(); }
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(); }
void testApp::tuioCursorAdded(TuioCursor & tcur){ cout << " cursor added: " + ofToString(tcur.getCursorID())+ " X: "+ofToString(tcur.getX())+ " Y: "+ofToString(tcur.getY()) << endl; // cout << ofToString(touch.id) << ofToString((int)time(NULL)) << ofToString(touch.x) << endl; updateDB(tcur.getCursorID(), time(NULL), tcur.getX(), tcur.getY()); //forward the touch events to ofxMultiTouch for the InteractiveObjects // ofxMultiTouch.touchDown(tcur.getX(), tcur.getY(), tcur.getCursorID(), NULL); }
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(); }
void SimpleSimulator::drawFrame() { if(!running) return; glClear(GL_COLOR_BUFFER_BIT); char id[3]; // draw the cursors std::list<TuioCursor*> cursorList = tuioServer->getTuioCursors(); for (std::list<TuioCursor*>::iterator iter = cursorList.begin(); iter!=cursorList.end(); iter++) { TuioCursor *tcur = (*iter); std::list<TuioPoint> path = tcur->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); std::list<TuioCursor*>::iterator joint = std::find( jointCursorList.begin(), jointCursorList.end(), tcur ); if( joint != jointCursorList.end() ) { glColor3f(0.5, 0.5, 0.5); } glPushMatrix(); glTranslatef(last_point.getScreenX(width), last_point.getScreenY(height), 0.0f); 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(tcur->getScreenX(width),tcur->getScreenY(height)); sprintf(id,"%d",tcur->getCursorID()); drawString(id); } } if (help) { glColor3f(0.0, 0.0, 1.0); glRasterPos2f(10,20); drawString("h - toggle help display"); glRasterPos2f(10,35); if (verbose) drawString("v - disable verbose mode"); else drawString("v - enable verbose mode"); glRasterPos2f(10,50); drawString("r - reset session"); glRasterPos2f(10,65); if (tuioServer->fullUpdateEnabled()) drawString("f - disable full update"); else drawString("f - enable full update"); glRasterPos2f(10,80); if (tuioServer->periodicMessagesEnabled()) drawString("p - disable periodic messages"); else drawString("p - enable periodic messages"); glRasterPos2f(10,95); drawString("SHIFT click - create persistent cursor"); glRasterPos2f(10,110); drawString("CTRL click - add to cursor group"); glRasterPos2f(10,125); if (fullscreen) drawString("F1 - exit fullscreen mode"); else drawString("F1 - enter fullscreen mode"); glRasterPos2f(10,140); drawString("ESC - Quit"); } SDL_GL_SwapBuffers(); }
//-------------------------------------------------------------- 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() ; }