#include "oni.h" void syncOniPlayer::addPlayer(string name){ //ofxOpenNI *o=new ofxOpenNI; //o->setupFromONI(name,true); //o->setPaused(true); //players.push_back(o); players.push_back(NULL); filenames.push_back(name); soundplayer.setLoop(false); //players[players.size()-1]->setSpeed(0.0f); //players[players.size()-1]->setup(true); //players[players.size()-1]->start(); //players[players.size()-1]->startPlayer(name); } void syncOniPlayer::play(){ for (int i=0;isetSafeThreading(true); players[i]->setupFromONI(filenames[i],true); //players[i]->addDepthGenerator(); //players[i]->addImageGenerator(); //players[i]->setRegister(true); players[i]->setLooped(false); //players[i]->setBaseUserClass(user); players[i]->start(); //players[players.size()-1]->setSpeed(1.0f); if (audio!="") { soundplayer.loadSound(audio); soundplayer.play(); }; //sleep(2); drawable=true; startTime=ofGetElapsedTimef(); playerActive=true; } } void syncOniPlayer::update(){ for (int i=0;iupdate(); } } void syncOniPlayer::pause(){ for (int i=0;isetSpeed(0.0f); players[i]->setPaused(true); } } int syncOniPlayer::getCurrentFrame(){ if (players.size()) return players[0]->getCurrentFrame(); else return -1; } float syncOniPlayer::getPosition(){ if (players.size()) return players[0]->getPosition(); else return -1.0f; } void syncOniPlayer::drawWindows(){ if (!drawable) return; for (int i=0;idrawDepth(50, 0,520,390); players[i]->drawImage(600, 0,520,390); } } void syncOniPlayer::drawCloud(int step){ int count; for (int n=0;ngetDepthGenerator().GetDepthMap(); //uint16_t* depthpixels=depthmap.getPixels(); int range=1700; int depthW=players[n]->getWidth(); int depthH=players[n]->getHeight(); for (int i=0;iprojectiveToWorld(ofPoint(i,j,(float)(depthmap[j*depthW+i]))); //ofPoint p= projectiveToWorld(ofPoint(i,j,(float)depthmap[j*dmw+i])); if (p.z == 0 || p.z>range) continue; // gets rid of background glColor4ub((unsigned char)255, (unsigned char)255, (unsigned char)255, (unsigned char)255); glVertex3f(p.x, p.y, p.z); //if (i==320&&j==160) cerr<<"world point: "<getPosition()>playOutFraction) { //cerr<<"playing out!"<getPosition()-playOutFraction)/(1.0f-playOutFraction))); //if it reaches the end stop creating points but allow old points to play out if (players[0]->getPosition()>0.99) playerActive=false; } else birth=_birth; //cerr<getPosition()<getDepthGenerator().GetDepthMap(); const ofPixels& pixels=players[0]->getImagePixels(); int range=1700; int dmw=players[0]->getWidth(); int dmh=players[0]->getHeight(); if (dmw&&dmh){ int step=pixels.getWidth()/dmw; for (int o=0;oprojectiveToWorld(ofPoint(i,j,(float)depthmap[j*dmw+i])); if (p.z <100 || p.z>range) continue; //points.push_back(fpoint(p.x, p.y, p.z,pixels[((j*step*dmw)+(i*step))*3],pixels[((j*step*dmw)+(i*step))*3]+1,pixels[((j*step*dmw)+(i*step))*3]+2)); //fpoint f=fpoint(p.x, p.y, p.z,pixels[((j*step*dmw)+(i*step))*3],pixels[((j*step*dmw)+(i*step))*3]+1,pixels[((j*step*dmw)+(i*step))*3]+2); //f.draw(life,dx,dy,dz); if (pointPool.size()) {//take 1st dead particle points[(*pointPool.begin())].setup(p.x, p.y, p.z, LUT[pixels[((j*step*dmw)+(i*step))*3]], LUT[pixels[((j*step*dmw)+(i*step))*3]+1], LUT[pixels[((j*step*dmw)+(i*step))*3]+2] ); pointPool.erase(pointPool.begin()); } else {//make a new one points.push_back(fpoint(p.x, p.y, p.z,pixels[((j*step*dmw)+(i*step))*3],pixels[((j*step*dmw)+(i*step))*3]+1,pixels[((j*step*dmw)+(i*step))*3]+2)); } } } } for (int i=0;istop(); delete players[i]; players[i]=NULL; } } drawable=false; playerActive=false; } //================= void oniManager::init(const char* filename){ playing=-1; int numDevices=1; string f=string(filename); if( !XML.loadFile(f) ){ printf("unable to load recordings, check data/ folder\n"); }else{ if(XML.pushTag("TRSS")) { int num=XML.getNumTags("rec"); if(num) { for (int i=0;inewplayer){ if (playing>-1) players[playing].stop(); usleep(500000); playing=newplayer; players[playing].play(); } } int oniManager::getNumClips(){ return players.size(); } void oniManager::update(){ if (players.size()>playing&&playing>-1) players[playing].update(); } void oniManager::drawWindows(){ if (players.size()>playing&&playing>-1) players[playing].drawWindows(); } void oniManager::drawCloud(int step){ if (players.size()>playing&&playing>-1) players[playing].drawCloud(step); } void oniManager::previous(){ int newp=(playing+1)%players.size(); startPlayer(newp); } void oniManager::next(){ int newp=playing-1<0?players.size()-1:playing-1; startPlayer(newp); } int oniManager::getNumParticles(){ if (players.size()>playing&&playing>-1) return players[playing].getNumParticles(); else return 0; } void oniManager::drawPoints(float size,float birth,float life,float dx,float dy, float dz){ if (players.size()>playing&&playing>-1) { players[playing].drawPoints(birth,life,dx,dy,dz,size); } } syncOniPlayer* oniManager::getCurrentPlayer(){ if (players.size()>playing&&playing>-1) return &players[playing]; else return NULL; }