void ParticleSystem::killAllParticles() { for (int e = 0; e < _numEmitters; e++) { _emitter[e].currentParticle = NULL_PARTICLE; _emitter[e].emitReserve = 0.0f; _emitter[e].previousPosition = _emitter[e].position; _emitter[e].rate = 0.0f; _emitter[e].currentParticle = 0; _emitter[e].numParticlesEmittedThisTime = 0; } for (int p = 0; p < MAX_PARTICLES; p++) { killParticle(p); } }
/// Updates particles ages and removes any particles that have expired void ParticleEffect::killParticles() { // By starting from the back, we do less work. See ParticleEffect::killParticle // for details. for(int i=m_nLiveParticleCount-1; i>=0; i--) { m_Particles[m_drawOrder[i]].lifeleft -= m_fElapsedTime; if(m_Particles[m_drawOrder[i]].lifeleft < 0.0f) { killParticle(i); } } // if we're not cycling and there are none left if(m_IsDying && m_nLiveParticleCount == 0) m_bIsDead = true; // we're dead }
void ParticleSystem::simulate(float deltaTime) { _timer += deltaTime; // update emitters for (int emitterIndex = 0; emitterIndex < _numEmitters; emitterIndex++) { assert(emitterIndex <= MAX_EMITTERS); if (_emitter[emitterIndex].active) { updateEmitter(emitterIndex, deltaTime); } } // update particles for (int p = 0; p < MAX_PARTICLES; p++) { if (_particle[p].alive) { if (_particle[p].age > _emitter[_particle[p].emitterIndex].particleLifespan) { killParticle(p); } else { updateParticle(p, deltaTime); } } } }
//-------------------------------------------------------------- void testApp::update(){ while( receiver.hasWaitingMessages() ){ ofxOscMessage m; receiver.getNextMessage( &m ); if( m.getAddress() == "/particle/new" ){ int x = m.getArgAsInt32( 0 ); int y = m.getArgAsInt32( 1 ); int n = m.getArgAsInt32( 2 ); int h = m.getArgAsInt32( 3 ); insertParticle(x, y, n, h); } } tuioClient.getMessage(); //------------------------------- if (timer <= standBy){ nucle.mass = 10; nucle.maxDistance = screenHeight*0.07; if ( timer >= (standBy-standBy/3)){ universe.mass = 10; universe.proportional= false; universe.clockwise = false; universe.impulse = timer - (standBy - standBy/3); universe.angle = -40; universe.density = 0.8; blur.setRadius(1); fboAlpha = 200; } else { universe.mass = 0.75; universe.proportional= true; universe.clockwise = true; universe.impulse = 0.3; universe.angle = 0; universe.density = 0.7; blur.setRadius(0.5); fboAlpha = 150; } } else { nucle.maxDistance = screenHeight*0.01; nucle.mass = 0.7; blur.setRadius(2); fboAlpha = 255; } for (int i=0; i < pAct.size() ; i++) if (universe.onSpace(pAct[i]->loc) && (pAct[i]->alpha > 5) ){ pAct[i]->update(); if (nucle.onSpace(pAct[i]->loc)) if (pAct[i]->bArrive) killParticle(i); } else killParticle(i); for (int i=0; i < pInact.size() ; i++) if (!universe.onSpace(pInact[i]->loc) || (pInact[i]->alpha < 5) ) pInact.erase(pInact.begin()+i); else pInact[i]->update(); timer += 1/ofGetFrameRate(); }