Showing the changes to interface/src/ParticleSystem.cpp (1 of 5 files). Show all
Unified · Split
| @@ -14,6 +14,7 @@ · 13 unmodified lines | |||
| 14 | const float DEFAULT_PARTICLE_RADIUS = 0.01f; | 14 | const float DEFAULT_PARTICLE_RADIUS = 0.01f; |
| 15 | const float DEFAULT_PARTICLE_BOUNCE = 1.0f; | 15 | const float DEFAULT_PARTICLE_BOUNCE = 1.0f; |
| 16 | const float DEFAULT_PARTICLE_AIR_FRICTION = 2.0f; | 16 | const float DEFAULT_PARTICLE_AIR_FRICTION = 2.0f; |
| 17 | const float DEFAULT_PARTICLE_LIFESPAN = 1.0f; | ||
| 17 | 18 | ||
| 18 | ParticleSystem::ParticleSystem() { | 19 | ParticleSystem::ParticleSystem() { |
| 19 | 20 | ||
| @@ -26,6 +27,7 @@ ParticleSystem::ParticleSystem() { · 6 unmodified lines | |||
| 26 | _emitter[emitterIndex].position = glm::vec3(0.0f, 0.0f, 0.0f); | 27 | _emitter[emitterIndex].position = glm::vec3(0.0f, 0.0f, 0.0f); |
| 27 | _emitter[emitterIndex].direction = glm::vec3(0.0f, 1.0f, 0.0f); | 28 | _emitter[emitterIndex].direction = glm::vec3(0.0f, 1.0f, 0.0f); |
| 28 | _emitter[emitterIndex].visible = false; | 29 | _emitter[emitterIndex].visible = false; |
| 30 | _emitter[emitterIndex].particleLifespan = DEFAULT_PARTICLE_LIFESPAN; | ||
| 29 | _emitter[emitterIndex].baseParticle.alive = false; | 31 | _emitter[emitterIndex].baseParticle.alive = false; |
| 30 | _emitter[emitterIndex].baseParticle.age = 0.0f; | 32 | _emitter[emitterIndex].baseParticle.age = 0.0f; |
| 31 | _emitter[emitterIndex].baseParticle.lifespan = 0.0f; | 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 | for (unsigned int p = 0; p < num; p++) { | 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 | for (unsigned int p = 0; p < MAX_PARTICLES; p++) { | 105 | for (unsigned int p = 0; p < MAX_PARTICLES; p++) { |
| 104 | if (!_particle[p].alive) { | 106 | if (!_particle[p].alive) { |
| 105 | 107 | ||
| 106 | _particle[p].emitterIndex = e; | 108 | _particle[p].emitterIndex = e; |
| 107 | _particle[p].lifespan = lifespan; | ||
| 108 | _particle[p].alive = true; | 109 | _particle[p].alive = true; |
| 109 | _particle[p].age = 0.0f; | 110 | _particle[p].age = 0.0f; |
| 110 | _particle[p].velocity = velocity; | 111 | _particle[p].velocity = velocity; |
| 112 | _particle[p].lifespan = _emitter[e].particleLifespan; | ||
| 111 | _particle[p].position = _emitter[e].position; | 113 | _particle[p].position = _emitter[e].position; |
| 112 | _particle[p].radius = _emitter[e].particleAttributes[0].radius; | 114 | _particle[p].radius = _emitter[e].particleAttributes[0].radius; |
| 113 | _particle[p].color = _emitter[e].particleAttributes[0].color; | 115 | _particle[p].color = _emitter[e].particleAttributes[0].color; |
| @@ -261,15 +263,15 @@ void ParticleSystem::setEmitterBaseParticle(int emitterIndex, bool showing ) { · 147 unmodified lines | |||
| 261 | _emitter[emitterIndex].baseParticle.emitterIndex = emitterIndex; | 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; | 268 | for (unsigned int p = 0; p < _numParticles; p++) { |
| 267 | _emitter[emitterIndex].baseParticle.emitterIndex = emitterIndex; | 269 | killParticle(p); |
| 268 | _emitter[emitterIndex].baseParticle.radius = radius; | 270 | } |
| 269 | _emitter[emitterIndex].baseParticle.color = color; | ||
| 270 | } | 271 | } |
| 271 | 272 | ||
| 272 | 273 | ||
| 274 | |||
| 273 | void ParticleSystem::render() { | 275 | void ParticleSystem::render() { |
| 274 | 276 | ||
| 275 | // render the emitters | 277 | // render the emitters |