bool CC3ParticleEmitter::emitParticle( CC3Particle* aParticle ) { if ( !aParticle || isFull() ) return false; // Can't add particles if there's no space /*CC3Assert([aParticle conformsToProtocol: self.requiredParticleProtocol], @"%@ does not conform to the %@ protocol. All particles emitted by %@ must conform to that protocol.", aParticle, [NSString stringWithUTF8String: protocol_getName(self.requiredParticleProtocol)], self); CC3Assert(!_particleNavigator || [aParticle conformsToProtocol: _particleNavigator.requiredParticleProtocol], @"%@ does not conform to the %@ protocol. All particles configured by %@ must conform to that protocol.", aParticle, [NSString stringWithUTF8String: protocol_getName(_particleNavigator.requiredParticleProtocol)], _particleNavigator);*/ // Ensure that we have capacity for this particle, and add the particle to the living // particles, which also attaches the emitter to the particle. if ( !ensureParticleCapacityFor( aParticle ) ) return false; addNewParticle( aParticle ); aParticle->setIsAlive( true ); initializeParticle( aParticle ); if ( aParticle->isAlive() ) m_particleNavigator->initializeParticle( aParticle ); if ( aParticle->isAlive() ) aParticle->initializeParticle(); // If particle not aborted during initialization, accept it. if ( aParticle->isAlive() ) acceptParticle( aParticle ); return aParticle->isAlive(); }
/************************************************************************** * Name: initialize() * Description: Method used to initialize the particle system. * Inputs: none * Returns: none **************************************************************************/ void ParticleSystem::initialize() { LogManager::pushEvent(LogEventType::LogEventType_ALL_LOG_EVENT, LogLevel::LogLevel_INFO, "Initializing ParticleSystem..."); /* Gets the shader */ m_shader = ShaderBank::getShader("Shaders/Particle/fade_in_out"); LogManager::pushEvent(LogEventType::LogEventType_ALL_LOG_EVENT, LogLevel::LogLevel_DEBUG, "Registering variables..."); /* Registers the uniform variables W, V, P matrixes along with the time t.*/ m_shader->registerUniform("W"); m_shader->registerUniform("V"); m_shader->registerUniform("P"); m_shader->registerUniform("t"); /* Registers the in attributes for tjhe particle. */ m_shader->registerAttribute("position"); m_shader->registerAttribute("speed"); m_shader->registerAttribute("acceleration"); m_shader->registerAttribute("color"); m_shader->registerAttribute("spawnTime"); m_shader->registerAttribute("ttl"); LogManager::pushEvent(LogEventType::LogEventType_ALL_LOG_EVENT, LogLevel::LogLevel_DEBUG, "Creating "+ Helpers::uint32ToString(m_particleCount) +" particles..."); /* Initializes all particles of the system. */ m_particles = new Particle[m_particleCount]; for (uint32 i = 0; i < m_particleCount; ++i) initializeParticle(m_particles[i]); LogManager::pushEvent(LogEventType::LogEventType_ALL_LOG_EVENT, LogLevel::LogLevel_INFO, "ParticleSystem initialized."); }
/************************************************************************** * Name: update(float32 _dt) * Description: Method used to update the particle system and so resets * all dead particles. * Inputs: * -_dt : float32, time difference when the last update occured. * Returns: none **************************************************************************/ void ParticleSystem::update(float32 _dt) { /* Adds update time to the global time. */ m_globalTime += _dt; /* For all Particles, if they are dead, they are re-initialized. */ for (uint32 i = 0; i < m_particleCount; ++i) if (m_particles[i].ttl + m_particles[i].spawnTime <= m_globalTime) initializeParticle(m_particles[i]); }
void ParticleSystem::initialize() { int i; int maxParticles = (int)particleGroup.getMaxParticles(); Particle *p; for (i=0; i<maxParticles; i++) { p = new Particle(); initializeParticle(p); particleGroup.add(p); } }