Showing the changes to interface/src/ParticleSystem.cpp (1 of 4 files). Show all
Unified · Split
| @@ -30,7 +30,8 @@ ParticleSystem::ParticleSystem() { · 29 unmodified lines | ||
| 30 | 30 | _emitter[emitterIndex].particleLifespan = DEFAULT_PARTICLE_LIFESPAN; |
| 31 | 31 | _emitter[emitterIndex].baseParticle.alive = false; |
| 32 | 32 | _emitter[emitterIndex].baseParticle.age = 0.0f; |
| 33 | − _emitter[emitterIndex].baseParticle.lifespan = 0.0f; | |
| 33 | + _emitter[emitterIndex].thrust = 0.0f; | |
| 34 | + _emitter[emitterIndex].rate = 0.0f; | |
| 34 | 35 | _emitter[emitterIndex].baseParticle.radius = 0.0f; |
| 35 | 36 | _emitter[emitterIndex].baseParticle.emitterIndex = 0; |
| 36 | 37 | _emitter[emitterIndex].baseParticle.position = glm::vec3(0.0f, 0.0f, 0.0f); |
| @@ -59,7 +60,6 @@ ParticleSystem::ParticleSystem() { · 22 unmodified lines | ||
| 59 | 60 | for (unsigned int p = 0; p < MAX_PARTICLES; p++) { |
| 60 | 61 | _particle[p].alive = false; |
| 61 | 62 | _particle[p].age = 0.0f; |
| 62 | − _particle[p].lifespan = 0.0f; | |
| 63 | 63 | _particle[p].radius = 0.0f; |
| 64 | 64 | _particle[p].emitterIndex = 0; |
| 65 | 65 | _particle[p].position = glm::vec3(0.0f, 0.0f, 0.0f); |
| @@ -84,7 +84,7 @@ void ParticleSystem::simulate(float deltaTime) { · 18 unmodified lines | ||
| 84 | 84 | // update particles |
| 85 | 85 | for (unsigned int p = 0; p < _numParticles; p++) { |
| 86 | 86 | if (_particle[p].alive) { |
| 87 | − if (_particle[p].age > _particle[p].lifespan) { | |
| 87 | + if (_particle[p].age > _emitter[_particle[p].emitterIndex].particleLifespan) { | |
| 88 | 88 | killParticle(p); |
| 89 | 89 | } else { |
| 90 | 90 | updateParticle(p, deltaTime); |
| @@ -93,10 +93,10 @@ void ParticleSystem::simulate(float deltaTime) { · 2 unmodified lines | ||
| 93 | 93 | } |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | −void ParticleSystem::emitParticlesNow(int e, int num, float thrust) { | |
| 96 | +void ParticleSystem::emitNow(int e) { | |
| 97 | 97 | |
| 98 | − for (unsigned int p = 0; p < num; p++) { | |
| 99 | − createParticle(e, _emitter[e].direction * thrust); | |
| 98 | + for (unsigned int p = 0; p < _emitter[e].rate; p++) { | |
| 99 | + createParticle(e, _emitter[e].direction); | |
| 100 | 100 | } |
| 101 | 101 | } |
| 102 | 102 | |
| @@ -108,8 +108,7 @@ void ParticleSystem::createParticle(int e, glm::vec3 velocity) { · 5 unmodified lines | ||
| 108 | 108 | _particle[p].emitterIndex = e; |
| 109 | 109 | _particle[p].alive = true; |
| 110 | 110 | _particle[p].age = 0.0f; |
| 111 | − _particle[p].velocity = velocity; | |
| 112 | − _particle[p].lifespan = _emitter[e].particleLifespan; | |
| 111 | + _particle[p].velocity = _emitter[e].direction * _emitter[e].thrust; | |
| 113 | 112 | _particle[p].position = _emitter[e].position; |
| 114 | 113 | _particle[p].radius = _emitter[e].particleAttributes[0].radius; |
| 115 | 114 | _particle[p].color = _emitter[e].particleAttributes[0].color; |
| @@ -163,9 +162,9 @@ void ParticleSystem::setParticleAttributes(int emitterIndex, int lifeStage, Part · 47 unmodified lines | ||
| 163 | 162 | |
| 164 | 163 | void ParticleSystem::updateParticle(int p, float deltaTime) { |
| 165 | 164 | |
| 166 | − assert(_particle[p].age <= _particle[p].lifespan); | |
| 165 | + assert(_particle[p].age <= _emitter[_particle[p].emitterIndex].particleLifespan); | |
| 167 | 166 | |
| 168 | − float ageFraction = _particle[p].age / _particle[p].lifespan; | |
| 167 | + float ageFraction = _particle[p].age / _emitter[_particle[p].emitterIndex].particleLifespan; | |
| 169 | 168 | |
| 170 | 169 | int lifeStage = (int)( ageFraction * (NUM_PARTICLE_LIFE_STAGES-1) ); |
| 171 | 170 | |
| @@ -257,7 +256,7 @@ void ParticleSystem::updateParticle(int p, float deltaTime) { · 85 unmodified lines | ||
| 257 | 256 | _particle[p].age += deltaTime; |
| 258 | 257 | } |
| 259 | 258 | |
| 260 | −void ParticleSystem::setEmitterBaseParticle(int emitterIndex, bool showing ) { | |
| 259 | +void ParticleSystem::setShowingEmitterBaseParticle(int emitterIndex, bool showing ) { | |
| 261 | 260 | |
| 262 | 261 | _emitter[emitterIndex].baseParticle.alive = true; |
| 263 | 262 | _emitter[emitterIndex].baseParticle.emitterIndex = emitterIndex; |
| @@ -271,7 +270,6 @@ void ParticleSystem::killAllParticles() { · 7 unmodified lines | ||
| 271 | 270 | } |
| 272 | 271 | |
| 273 | 272 | |
| 274 | − | |
| 275 | 273 | void ParticleSystem::render() { |
| 276 | 274 | |
| 277 | 275 | // render the emitters |
| @@ -346,8 +344,6 @@ void ParticleSystem::renderParticle(int p) { · 68 unmodified lines | ||
| 346 | 344 | } |
| 347 | 345 | } |
| 348 | 346 | |
| 349 | − | |
| 350 | − | |
| 351 | 347 | void ParticleSystem::renderEmitter(int e, float size) { |
| 352 | 348 | |
| 353 | 349 | glLineWidth(2.0f); |
| @@ -362,5 +358,3 @@ void ParticleSystem::renderEmitter(int e, float size) { · 8 unmodified lines | ||
| 362 | 358 | |
| 363 | 359 | |
| 364 | 360 | |
| 365 | − | |
| 366 | − | |