From ff979a86dc8f031c823cd8806324b0e8c4ca069b Mon Sep 17 00:00:00 2001 From: Comment Date: Mon, 24 Jun 2013 13:41:50 +0100 Subject: particle scaling --- 06_performance/src/oni.cpp | 46 ++++++++++++++++++++++++------------------ 06_performance/src/oni.h | 38 +++++++++++++++++----------------- 06_performance/src/testApp.cpp | 9 +++++---- 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::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;iplaying&&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 points; - set 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 filenames; ofSoundPlayer soundplayer; bool drawable; - list points; + vector points; + set 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 "<