diff options
| author | Comment <tim@gray.(none)> | 2013-06-24 13:41:50 +0100 |
|---|---|---|
| committer | Comment <tim@gray.(none)> | 2013-06-24 13:41:50 +0100 |
| commit | ff979a86dc8f031c823cd8806324b0e8c4ca069b (patch) | |
| tree | 73b3e4fa0b6d04f08ae0b64078114a8a36df950e /06_performance | |
| parent | 5f10387ea9eeb5278f4be2c88049041dcc3530b2 (diff) | |
particle scaling
Diffstat (limited to '06_performance')
| -rw-r--r-- | 06_performance/src/oni.cpp | 46 | ||||
| -rw-r--r-- | 06_performance/src/oni.h | 38 | ||||
| -rw-r--r-- | 06_performance/src/testApp.cpp | 9 | ||||
| -rw-r--r-- | 06_performance/src/testApp.h | 16 |
4 files changed, 61 insertions, 48 deletions
diff --git a/06_performance/src/oni.cpp b/06_performance/src/oni.cpp index 024594f..3f028fc 100644 --- a/06_performance/src/oni.cpp +++ b/06_performance/src/oni.cpp @@ -96,8 +96,15 @@ void syncOniPlayer::drawCloud(int step){ return; } -void syncOniPlayer::drawPoints(float birth,float life,float dx,float dy, float dz){ +void syncOniPlayer::drawPoints(float birth,float life,float dx,float dy, float dz,float size){ if (!drawable) return; + 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); const XnDepthPixel* depthmap=players[0]->getDepthGenerator().GetDepthMap(); const ofPixels& pixels=players[0]->getImagePixels(); int range=1700; @@ -110,21 +117,29 @@ void syncOniPlayer::drawPoints(float birth,float life,float dx,float dy, float d 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)); + //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,pixels[((j*step*dmw)+(i*step))*3],pixels[((j*step*dmw)+(i*step))*3]+1,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)); + } } } - 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; + for (int i=0;i<points.size();i++){ + if (!points[i].draw(life,dx,dy,dz,size)) { + pointPool.insert(i); + } } + glEnd(); + glDisable( GL_BLEND ); + glDisable(GL_PROGRAM_POINT_SIZE); } int syncOniPlayer::getNumParticles(){ - return points.size(); + return points.size()-pointPool.size(); } void syncOniPlayer::stop(){ soundplayer.stop(); @@ -195,16 +210,7 @@ int oniManager::getNumParticles(){ } 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); + players[playing].drawPoints(birth,life,dx,dy,dz,size); } } + diff --git a/06_performance/src/oni.h b/06_performance/src/oni.h index 898a7a2..36d216a 100644 --- a/06_performance/src/oni.h +++ b/06_performance/src/oni.h @@ -6,32 +6,33 @@ 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(); + setup(x,y,z,r,g,b); + } + void setup(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();active=true; } float x,y,z; float st; unsigned char r,g,b; - bool draw(float life,float dx,float dy,float dz){ + bool active; + bool draw(float life,float dx,float dy,float dz,float size=5.0f){ + if (!active) { + return true; + } float l=ofGetElapsedTimef()-st; if (life>l) { - glColor4ub(r,g,b,(unsigned char)255); // ((l/life)*255.0f)); + glPointSize((1.0f-(l/life))*size); + glColor3ub(r,g,b); + //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; + return true; + } + else { + active=false; + return false; } - else return true; } }; -class fpointManager{ - void add(float x,float y,float z,uint8_t r,uint8_t g,uint8_t b){ - if (pointPool.size()) {//take 1st dead particle - else {}//make a new one - } - void draw(int life,float dx,float dy,float dz){ - if (p.draw(life,dx,dy,dz)) - } - vector<fpoint> points; - set<int> pointPool; -}; class syncOniPlayer{ public: syncOniPlayer() { @@ -48,7 +49,7 @@ class syncOniPlayer{ int getNumParticles(); void drawWindows(); void drawCloud(int step); - void drawPoints(float birth,float life,float dx,float dy, float dz); + void drawPoints(float birth,float life,float dx,float dy, float dz,float size); void stop(); string audio; @@ -57,7 +58,8 @@ class syncOniPlayer{ vector<string> filenames; ofSoundPlayer soundplayer; bool drawable; - list<fpoint> points; + vector<fpoint> points; + set<int> pointPool; }; //======================================== class oniManager{ diff --git a/06_performance/src/testApp.cpp b/06_performance/src/testApp.cpp index 9bba414..57749b0 100644 --- a/06_performance/src/testApp.cpp +++ b/06_performance/src/testApp.cpp @@ -88,7 +88,7 @@ void testApp::setup(){ F_drawFrames=10; F_drawStep=0; F_drawDecay=0.95; - F_lineWidth=1.0; + F_lineWidth=16.0; //1.0; F_drawAxis=90; //Y @@ -100,8 +100,8 @@ void testApp::setup(){ F_yRotation=180; //was 180 F_zRotation=0; - F_particleAmount=100; - F_particleLife=0.5; + F_particleAmount=2000; //100 + F_particleLife=1.5; //0.5 I_fade1=0; I_fade2=0; @@ -161,6 +161,7 @@ void testApp::setup(){ videoclips.push_back(ofVideoPlayer()); videoclips[i].loadMovie(XML.getAttribute("video","file","",i)); videoclips[i].setLoopState(OF_LOOP_NONE); + videoclips[i].stop(); } cerr<<"loaded "<<i<<" video clips"<<endl; } @@ -544,7 +545,7 @@ void testApp::draw(){ 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()); + msg+="\n"+ofToString(narrator.getNumParticles())+" size "+ofToString(F_lineWidth); ofDrawBitmapString(msg,20,20); } } diff --git a/06_performance/src/testApp.h b/06_performance/src/testApp.h index bc0b8fb..337e05b 100644 --- a/06_performance/src/testApp.h +++ b/06_performance/src/testApp.h @@ -14,12 +14,16 @@ #define BUFFER_FRAMES 512 /* -ok seriously lets make this good - -recording - storage for a bunch of fft - -average them on the fly? seems likely - +alter particle object memory scheme, preallocate +higher res FFT drawing +videos. +1- alter playback speed +2- draw with particles +3- draw seperately in between +4- strategy for drawing split screen - 3 copies + +envelope for particle generation +paticles change size etc during lifetime */ #define OF_ADDON_USING_OFXMIDIIN |
