Skip to content

Commit

Permalink
added missing vector clear to particle manager clear(); renamed Parti…
Browse files Browse the repository at this point in the history
…cle lifespan functions to default to ms; added particle constructors for ofPoint and ofRectangle
  • Loading branch information
danomatika committed Nov 27, 2011
1 parent d1f7e25 commit e170455
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
20 changes: 16 additions & 4 deletions src/ofxParticle.cpp
Expand Up @@ -13,7 +13,7 @@
unsigned int ofxParticle::_frameTimeout = 500;

//--------------------------------------------------------------
ofxParticle::ofxParticle() : ofRectangle(), bAlive(false), lifespan(5000), age(0) {
ofxParticle::ofxParticle() : ofRectangle(), bAlive(false), lifespan(0), age(0) {
reset();
}

Expand All @@ -23,6 +23,18 @@ ofxParticle::ofxParticle(float x, float y, float w, float h) :
reset();
}

//--------------------------------------------------------------
ofxParticle::ofxParticle(ofPoint pos, float w, float h) :
ofRectangle(pos.x, pos.y, w, h), bAlive(false), lifespan(0), age(0) {
reset();
}

//--------------------------------------------------------------
ofxParticle::ofxParticle(ofRectangle rect) :
ofRectangle(rect), bAlive(false), lifespan(0), age(0) {
reset();
}

//--------------------------------------------------------------
ofxParticle::~ofxParticle() {}

Expand Down Expand Up @@ -58,13 +70,13 @@ void ofxParticle::updateAge() {
}

//--------------------------------------------------------------
double ofxParticle::getAge() {
double ofxParticle::getAgeN() {
if(lifespan == 0)
return 0;
return age/lifespan;
}

//--------------------------------------------------------------
double ofxParticle::getRemaingLife() {
return ((getAge()*-1.0) + 1.0);
double ofxParticle::getRemainingLifeN() {
return ((getAgeN()*-1.0) + 1.0);
}
27 changes: 17 additions & 10 deletions src/ofxParticle.h
Expand Up @@ -23,6 +23,8 @@ class ofxParticle : public ofRectangle

ofxParticle();
ofxParticle(float x, float y, float w, float h);
ofxParticle(ofPoint pos, float w, float h);
ofxParticle(ofRectangle rect);
virtual ~ofxParticle();

/// copy constructor
Expand All @@ -34,7 +36,12 @@ class ofxParticle : public ofRectangle

/// \section Main

/// update the particles age, ignores time between frames longer then the frame timeout
/// update the particles age, ignores time between frames longer then
/// the frame timeout
///
/// note: make sure to call this in your update() or the age will not
/// change
///
void updateAge();

/// do the update calculations
Expand All @@ -49,17 +56,17 @@ class ofxParticle : public ofRectangle
/// bring this particle to life
void reset() {bAlive = true; lifeTimer.set();}

/// get the age normalized between 0 and 1: 0 is birth, 1 is death
double getAge();

/// get the age in ms
double getAgeMS() {return age;}
double getAge() {return age;}

/// get the remaing life normalized between 0 and 1, 1 being death
double getRemaingLife();
/// get the age normalized between 0 and 1: 0 is birth, 1 is death
double getAgeN();

/// get the remaining life in ms
double getRemaingLifeMS() {return lifespan - age;}
double getRemainingLife() {return lifespan - age;}

/// get the remaing life normalized between 0 and 1, 1 being death
double getRemainingLifeN();

/// is this particle alive?
inline bool isAlive() {return bAlive;}
Expand All @@ -74,8 +81,8 @@ class ofxParticle : public ofRectangle
inline unsigned int getLifespan() {return lifespan;}
inline void setLifespan(unsigned int span) {lifespan = span;}

/// set how long to wait between frames (ms) before throwing out a time calculation
/// default is 500 ms
/// set how long to wait between frames (ms) before throwing out a time
/// calculation, default is 500 ms
static void setFrameTimeout(unsigned int timeout) {_frameTimeout = timeout;}
static unsigned int getFrameTimeout() {return _frameTimeout;}

Expand Down
4 changes: 3 additions & 1 deletion src/ofxParticleManager.h
Expand Up @@ -38,9 +38,11 @@ class ofxParticleManager {
void clear() {
std::vector<ofxParticle*> ::iterator iter;
for(iter = particleList.begin(); iter != particleList.end(); ++iter) {
if((*iter) != NULL)
if((*iter) != NULL) {
delete (*iter);
}
}
particleList.clear();
}

/// automatically remove (delete) dead particles?
Expand Down

0 comments on commit e170455

Please sign in to comment.