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 | _emitter[emitterIndex].particleLifespan = DEFAULT_PARTICLE_LIFESPAN; | 30 | _emitter[emitterIndex].particleLifespan = DEFAULT_PARTICLE_LIFESPAN; |
| 31 | _emitter[emitterIndex].baseParticle.alive = false; | 31 | _emitter[emitterIndex].baseParticle.alive = false; |
| 32 | _emitter[emitterIndex].baseParticle.age = 0.0f; | 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 | _emitter[emitterIndex].baseParticle.radius = 0.0f; | 35 | _emitter[emitterIndex].baseParticle.radius = 0.0f; |
| 35 | _emitter[emitterIndex].baseParticle.emitterIndex = 0; | 36 | _emitter[emitterIndex].baseParticle.emitterIndex = 0; |
| 36 | _emitter[emitterIndex].baseParticle.position = glm::vec3(0.0f, 0.0f, 0.0f); | 37 | _emitter[emitterIndex].baseParticle.position = glm::vec3(0.0f, 0.0f, 0.0f); |
| @@ -59,7 +60,6 @@ ParticleSystem::ParticleSystem() { · 22 unmodified lines | |||
| 59 | for (unsigned int p = 0; p < MAX_PARTICLES; p++) { | 60 | for (unsigned int p = 0; p < MAX_PARTICLES; p++) { |
| 60 | _particle[p].alive = false; | 61 | _particle[p].alive = false; |
| 61 | _particle[p].age = 0.0f; | 62 | _particle[p].age = 0.0f; |
| 62 | _particle[p].lifespan = 0.0f; | ||
| 63 | _particle[p].radius = 0.0f; | 63 | _particle[p].radius = 0.0f; |
| 64 | _particle[p].emitterIndex = 0; | 64 | _particle[p].emitterIndex = 0; |
| 65 | _particle[p].position = glm::vec3(0.0f, 0.0f, 0.0f); | 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 | // update particles | 84 | // update particles |
| 85 | for (unsigned int p = 0; p < _numParticles; p++) { | 85 | for (unsigned int p = 0; p < _numParticles; p++) { |
| 86 | if (_particle[p].alive) { | 86 | if (_particle[p].alive) { |
| 87 | if (_particle[p].age > _particle[p].lifespan) { | 87 | if (_particle[p].age > _emitter[_particle[p].emitterIndex].particleLifespan) { |
| 88 | killParticle(p); | 88 | killParticle(p); |
| 89 | } else { | 89 | } else { |
| 90 | updateParticle(p, deltaTime); | 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++) { | 98 | for (unsigned int p = 0; p < _emitter[e].rate; p++) { |
| 99 | createParticle(e, _emitter[e].direction * thrust); | 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 | _particle[p].emitterIndex = e; | 108 | _particle[p].emitterIndex = e; |
| 109 | _particle[p].alive = true; | 109 | _particle[p].alive = true; |
| 110 | _particle[p].age = 0.0f; | 110 | _particle[p].age = 0.0f; |
| 111 | _particle[p].velocity = velocity; | 111 | _particle[p].velocity = _emitter[e].direction * _emitter[e].thrust; |
| 112 | _particle[p].lifespan = _emitter[e].particleLifespan; | ||
| 113 | _particle[p].position = _emitter[e].position; | 112 | _particle[p].position = _emitter[e].position; |
| 114 | _particle[p].radius = _emitter[e].particleAttributes[0].radius; | 113 | _particle[p].radius = _emitter[e].particleAttributes[0].radius; |
| 115 | _particle[p].color = _emitter[e].particleAttributes[0].color; | 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 | void ParticleSystem::updateParticle(int p, float deltaTime) { | 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 | int lifeStage = (int)( ageFraction * (NUM_PARTICLE_LIFE_STAGES-1) ); | 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 | _particle[p].age += deltaTime; | 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 | _emitter[emitterIndex].baseParticle.alive = true; | 261 | _emitter[emitterIndex].baseParticle.alive = true; |
| 263 | _emitter[emitterIndex].baseParticle.emitterIndex = emitterIndex; | 262 | _emitter[emitterIndex].baseParticle.emitterIndex = emitterIndex; |
| @@ -271,7 +270,6 @@ void ParticleSystem::killAllParticles() { · 7 unmodified lines | |||
| 271 | } | 270 | } |
| 272 | 271 | ||
| 273 | 272 | ||
| 274 | |||
| 275 | void ParticleSystem::render() { | 273 | void ParticleSystem::render() { |
| 276 | 274 | ||
| 277 | // render the emitters | 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 | void ParticleSystem::renderEmitter(int e, float size) { | 347 | void ParticleSystem::renderEmitter(int e, float size) { |
| 352 | 348 | ||
| 353 | glLineWidth(2.0f); | 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 | |||