Showing the changes to interface/src/ParticleSystem.cpp (1 of 5 files). Show all
Unified · Split
| @@ -14,6 +14,7 @@ · 13 unmodified lines | ||
| 14 | 14 | const float DEFAULT_PARTICLE_RADIUS = 0.01f; |
| 15 | 15 | const float DEFAULT_PARTICLE_BOUNCE = 1.0f; |
| 16 | 16 | const float DEFAULT_PARTICLE_AIR_FRICTION = 2.0f; |
| 17 | +const float DEFAULT_PARTICLE_LIFESPAN = 1.0f; | |
| 17 | 18 | |
| 18 | 19 | ParticleSystem::ParticleSystem() { |
| 19 | 20 | |
| @@ -26,6 +27,7 @@ ParticleSystem::ParticleSystem() { · 6 unmodified lines | ||
| 26 | 27 | _emitter[emitterIndex].position = glm::vec3(0.0f, 0.0f, 0.0f); |
| 27 | 28 | _emitter[emitterIndex].direction = glm::vec3(0.0f, 1.0f, 0.0f); |
| 28 | 29 | _emitter[emitterIndex].visible = false; |
| 30 | + _emitter[emitterIndex].particleLifespan = DEFAULT_PARTICLE_LIFESPAN; | |
| 29 | 31 | _emitter[emitterIndex].baseParticle.alive = false; |
| 30 | 32 | _emitter[emitterIndex].baseParticle.age = 0.0f; |
| 31 | 33 | _emitter[emitterIndex].baseParticle.lifespan = 0.0f; |
| @@ -91,23 +93,23 @@ void ParticleSystem::simulate(float deltaTime) { · 59 unmodified lines | ||
| 91 | 93 | } |
| 92 | 94 | } |
| 93 | 95 | |
| 94 | −void ParticleSystem::emitParticlesNow(int e, int num, float thrust, float lifespan) { | |
| 96 | +void ParticleSystem::emitParticlesNow(int e, int num, float thrust) { | |
| 95 | 97 | |
| 96 | 98 | for (unsigned int p = 0; p < num; p++) { |
| 97 | − createParticle(e, _emitter[e].direction * thrust, lifespan); | |
| 99 | + createParticle(e, _emitter[e].direction * thrust); | |
| 98 | 100 | } |
| 99 | 101 | } |
| 100 | 102 | |
| 101 | −void ParticleSystem::createParticle(int e, glm::vec3 velocity, float lifespan) { | |
| 103 | +void ParticleSystem::createParticle(int e, glm::vec3 velocity) { | |
| 102 | 104 | |
| 103 | 105 | for (unsigned int p = 0; p < MAX_PARTICLES; p++) { |
| 104 | 106 | if (!_particle[p].alive) { |
| 105 | 107 | |
| 106 | 108 | _particle[p].emitterIndex = e; |
| 107 | − _particle[p].lifespan = lifespan; | |
| 108 | 109 | _particle[p].alive = true; |
| 109 | 110 | _particle[p].age = 0.0f; |
| 110 | 111 | _particle[p].velocity = velocity; |
| 112 | + _particle[p].lifespan = _emitter[e].particleLifespan; | |
| 111 | 113 | _particle[p].position = _emitter[e].position; |
| 112 | 114 | _particle[p].radius = _emitter[e].particleAttributes[0].radius; |
| 113 | 115 | _particle[p].color = _emitter[e].particleAttributes[0].color; |
| @@ -261,15 +263,15 @@ void ParticleSystem::setEmitterBaseParticle(int emitterIndex, bool showing ) { · 147 unmodified lines | ||
| 261 | 263 | _emitter[emitterIndex].baseParticle.emitterIndex = emitterIndex; |
| 262 | 264 | } |
| 263 | 265 | |
| 264 | −void ParticleSystem::setEmitterBaseParticle(int emitterIndex, bool showing, float radius, glm::vec4 color ) { | |
| 266 | +void ParticleSystem::killAllParticles() { | |
| 265 | 267 | |
| 266 | − _emitter[emitterIndex].baseParticle.alive = true; | |
| 267 | − _emitter[emitterIndex].baseParticle.emitterIndex = emitterIndex; | |
| 268 | − _emitter[emitterIndex].baseParticle.radius = radius; | |
| 269 | − _emitter[emitterIndex].baseParticle.color = color; | |
| 268 | + for (unsigned int p = 0; p < _numParticles; p++) { | |
| 269 | + killParticle(p); | |
| 270 | + } | |
| 270 | 271 | } |
| 271 | 272 | |
| 272 | 273 | |
| 274 | + | |
| 273 | 275 | void ParticleSystem::render() { |
| 274 | 276 | |
| 275 | 277 | // render the emitters |