diff options
Diffstat (limited to '06_performance/src')
| -rw-r--r-- | 06_performance/src/oni.cpp | 50 | ||||
| -rw-r--r-- | 06_performance/src/oni.h | 29 | ||||
| -rw-r--r-- | 06_performance/src/testApp.cpp | 73 | ||||
| -rw-r--r-- | 06_performance/src/testApp.h | 9 |
4 files changed, 135 insertions, 26 deletions
diff --git a/06_performance/src/oni.cpp b/06_performance/src/oni.cpp index 0cd5efc..099dd87 100644 --- a/06_performance/src/oni.cpp +++ b/06_performance/src/oni.cpp @@ -96,6 +96,34 @@ void syncOniPlayer::drawCloud(int step){ return; } +void syncOniPlayer::drawPoints(float birth,float life,float dx,float dy, float dz){ + if (!drawable) return; + const XnDepthPixel* depthmap=players[0]->getDepthGenerator().GetDepthMap(); + const ofPixels& pixels=players[0]->getImagePixels(); + int range=1700; + int dmw=players[0]->getWidth(); + int dmh=players[0]->getHeight(); + int step=pixels.getWidth()/dmw; + for (int o=0;o<birth;o++) { + int i=ofRandom(dmw); + int j=ofRandom(dmh); + ofPoint p= players[0]->projectiveToWorld(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); + } + std::list<fpoint>::iterator i = points.begin(); + while (i != points.end()) + { + if (i->draw(life,dx,dy,dz)) i = points.erase(i); + else ++i; + ++i; + } +} +int syncOniPlayer::getNumParticles(){ + return points.size(); +} void syncOniPlayer::stop(){ soundplayer.stop(); for (int i=0;i<players.size();i++) { @@ -139,6 +167,9 @@ void oniManager::startPlayer(int newplayer){ players[playing].play(); } } +int oniManager::getNumClips(){ + return players.size(); +} void oniManager::update(){ if (players.size()>playing&&playing>-1) players[playing].update(); } @@ -155,4 +186,23 @@ void oniManager::previous(){ 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) { + glEnable(GL_PROGRAM_POINT_SIZE); + glEnable(GL_POINT_SMOOTH); + glHint(GL_POINT_SMOOTH_HINT, GL_NICEST); + glEnable( GL_BLEND ); + glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); + glPointSize( size); + glBegin(GL_POINTS); + players[playing].drawPoints(birth,life,dx,dy,dz); + glEnd(); + glDisable( GL_BLEND ); + glDisable(GL_PROGRAM_POINT_SIZE); + } }
\ No newline at end of file diff --git a/06_performance/src/oni.h b/06_performance/src/oni.h index 158d513..2492d79 100644 --- a/06_performance/src/oni.h +++ b/06_performance/src/oni.h @@ -2,9 +2,25 @@ #include "ofxXmlSettings.h" #include "ofxOpenNI.h" - - -//in order to play different clips it seems necessary to have a player per clip +//a colour video particle +class fpoint{ + public: + fpoint(float _x,float _y, float _z, unsigned char _r,unsigned char _g,unsigned char _b){ + x=_x;y=_y;z=_z;r=_r;g=_g;b=_b;st=ofGetElapsedTimef(); + } + float x,y,z; + float st; + unsigned char r,g,b; + bool draw(float life,float dx,float dy,float dz){ + float l=ofGetElapsedTimef()-st; + if (life>l) { + glColor4ub(r,g,b,(unsigned char)255); // ((l/life)*255.0f)); + glVertex3f(x-(pow(l,2)*dx),y-(pow(l,2)*dy),z-(pow(l,2)*dz)); + return false; + } + else return true; + } +}; class syncOniPlayer{ public: syncOniPlayer() { @@ -18,8 +34,10 @@ class syncOniPlayer{ void update(); void pause(); int getCurrentFrame(); + int getNumParticles(); void drawWindows(); void drawCloud(int step); + void drawPoints(float birth,float life,float dx,float dy, float dz); void stop(); string audio; @@ -28,16 +46,19 @@ class syncOniPlayer{ vector<string> filenames; ofSoundPlayer soundplayer; bool drawable; - + list<fpoint> points; }; //======================================== class oniManager{ public: void init(const char* filename); void startPlayer(int num); + int getNumClips(); + int getNumParticles(); void update(); void drawWindows(); void drawCloud(int step); + void drawPoints(float size,float birth,float life,float dx,float dy, float dz); void previous(); void next(); int playing; diff --git a/06_performance/src/testApp.cpp b/06_performance/src/testApp.cpp index 6bc31a7..9bba414 100644 --- a/06_performance/src/testApp.cpp +++ b/06_performance/src/testApp.cpp @@ -160,7 +160,7 @@ void testApp::setup(){ for (i=0;i<num;i++) { videoclips.push_back(ofVideoPlayer()); videoclips[i].loadMovie(XML.getAttribute("video","file","",i)); - videoclips.setLoopState(OF_LOOP_NONE); + videoclips[i].setLoopState(OF_LOOP_NONE); } cerr<<"loaded "<<i<<" video clips"<<endl; } @@ -180,13 +180,37 @@ void testApp::update(){ ofxOscMessage m; receiver.getNextMessage(&m); - cerr<<m.getAddress()<<" "<<m.getArgAsInt32(0)<<endl; - - if(m.getAddress() == "/video/"){ - // the arguments is int32 - int clipToPlay = m.getArgAsInt32(0); - - } + + + vector<string> path; + explode(m.getAddress(),'/', back_inserter(path)); + + + + if (path.size()>1) { + string type=path[1]; + int channel=ofToInt(path[2])-1; + int data=m.getArgAsInt32(0); + + cerr<<"type: "<<type<<" channel: "<<channel<<" data: "<<m.getArgAsInt32(0)<<endl; + + if (type=="video"){ + if ((channel > -1)&&videoclips.size()>channel) { + if (data>0) { + cerr<<"playing video "<<channel<<endl; + videoclips[channel].play(); + } + } + } + if (type=="narrator"){ + if ((channel > -1)&&narrator.getNumClips()>channel) { + if (data>0) { + cerr<<"playing narrator "<<channel<<endl; + narrator.startPlayer(channel); + } + } + } + } } @@ -225,7 +249,6 @@ void testApp::draw(){ - static int index=0; float lavg_power = 0.0f; float ravg_power = 0.0f; @@ -383,10 +406,14 @@ void testApp::draw(){ } ofPushMatrix(); - ofTranslate(0,150,-1050); - narrator.drawCloud(2); + ofTranslate(0,-100,-1050); + //narrator.drawCloud(2); + narrator.drawPoints(F_lineWidth,F_particleAmount,F_particleLife,F_particleX,F_particleY,F_particleZ); ofPopMatrix(); + ofSetColor(255,255,255); + + camera.end(); ofPopMatrix(); @@ -514,9 +541,11 @@ void testApp::draw(){ if (showFPS) { - ofDrawBitmapString(ofToString(ofGetFrameRate(), 2),20,20); - ofDrawBitmapString(ofToString(F_xRotation, 4)+" "+ofToString(F_yRotation, 4)+" "+ofToString(F_zRotation, 4),20,30); - ofDrawBitmapString(ofToString(F_yseg, 4),20,40); + string msg=ofToString(ofGetFrameRate(), 2); + msg+="\n"+ofToString(F_xRotation, 4)+" "+ofToString(F_yRotation, 4)+" "+ofToString(F_zRotation, 4); + msg+="\n"+ofToString(F_yseg, 4); + msg+="\n"+ofToString(narrator.getNumParticles()); + ofDrawBitmapString(msg,20,20); } } @@ -624,19 +653,19 @@ void testApp::newMidiMessage(ofxMidiEventArgs& eventArgs){ F_drawAxis=((float) eventArgs.byteTwo-64)*(360.0/127); break; case 4: - F_particleAmount=((float) eventArgs.byteTwo)*(2000.0f/127.0f); + F_particleAmount=((float) eventArgs.byteTwo)*(10000.0f/127.0f); break; case 5: F_particleLife=((float) eventArgs.byteTwo)*(3.0f/127.0f); break; case 6: - F_particleX=(((float) eventArgs.byteTwo)-64)*.1f; + F_particleX=(((float) eventArgs.byteTwo)-64)*10.0f; break; case 7: - F_particleY=(((float) eventArgs.byteTwo)-64)*.1f; + F_particleY=(((float) eventArgs.byteTwo)-64)*10.0f; break; case 8: - F_particleZ=(((float) eventArgs.byteTwo)-64)*.1f; + F_particleZ=(((float) eventArgs.byteTwo)-64)*10.0f; break; //65-80 buttons @@ -812,11 +841,11 @@ void testApp::setMidiState(){ knobs[1]=(F_lineWidth*10); knobs[2]=(F_drawAxis/(360.0/127))+64; - knobs[3]=F_particleAmount/(2000.0f/127); + knobs[3]=F_particleAmount/(10000.0f/127); knobs[4]=F_particleLife/(3.0f/127); - knobs[5]=(F_particleX*10)+64; - knobs[6]=(F_particleY*10)+64; - knobs[7]=(F_particleZ*10)+64; + knobs[5]=(F_particleX*.1)+64; + knobs[6]=(F_particleY*.1)+64; + knobs[7]=(F_particleZ*.1)+64; //radio button set diff --git a/06_performance/src/testApp.h b/06_performance/src/testApp.h index 02ab1ec..bc0b8fb 100644 --- a/06_performance/src/testApp.h +++ b/06_performance/src/testApp.h @@ -33,6 +33,15 @@ average them on the fly? seems likely #define PICTURE 1 #define GRABBER 2 +template <typename OutputIterator> +int explode(const string &s, const char c, OutputIterator output) { + stringstream data(s); + string line; + int i=0; + while(std::getline(data,line,c)) { *output++ = line; i++; } + return i; +} + class testApp : public ofBaseApp, public ofxMidiListener{ |
