Showing the changes to interface/src/ParticleSystem.cpp (1 of 2 files). Show all
Unified · Split
| @@ -22,7 +22,6 @@ ParticleSystem::ParticleSystem() { · 21 unmodified lines | ||
| 22 | 22 | |
| 23 | 23 | _timer = 0.0f; |
| 24 | 24 | _numEmitters = 0; |
| 25 | − _numParticles = 0; | |
| 26 | 25 | _upDirection = glm::vec3(0.0f, 1.0f, 0.0f); // default |
| 27 | 26 | |
| 28 | 27 | for (unsigned int emitterIndex = 0; emitterIndex < MAX_EMITTERS; emitterIndex++) { |
| @@ -94,9 +93,9 @@ void ParticleSystem::simulate(float deltaTime) { · 65 unmodified lines | ||
| 94 | 93 | |
| 95 | 94 | // update particles |
| 96 | 95 | |
| 97 | − for (unsigned int p = 0; p < _numParticles; p++) { | |
| 96 | + for (int p = 0; p < MAX_PARTICLES; p++) { | |
| 98 | 97 | if (_particle[p].alive) { |
| 99 | − if (_particle[p].age > _emitter[_particle[p].emitterIndex].particleLifespan) { | |
| 98 | + if (_particle[p].age > _emitter[_particle[p].emitterIndex].particleLifespan) { | |
| 100 | 99 | killParticle(p); |
| 101 | 100 | } else { |
| 102 | 101 | updateParticle(p, deltaTime); |
| @@ -114,10 +113,7 @@ void ParticleSystem::createParticle(int e, float timeFraction) { · 11 unmodified lines | ||
| 114 | 113 | _particle[p].alive = true; |
| 115 | 114 | _particle[p].age = 0.0f; |
| 116 | 115 | _particle[p].velocity = _emitter[e].direction * _emitter[e].thrust; |
| 117 | − | |
| 118 | −//_particle[p].position = _emitter[e].position; | |
| 119 | −_particle[p].position = _emitter[e].previousPosition + timeFraction * (_emitter[e].position - _emitter[e].previousPosition); | |
| 120 | − | |
| 116 | + _particle[p].position = _emitter[e].previousPosition + timeFraction * (_emitter[e].position - _emitter[e].previousPosition); | |
| 121 | 117 | _particle[p].radius = _emitter[e].particleAttributes[0].radius; |
| 122 | 118 | _particle[p].color = _emitter[e].particleAttributes[0].color; |
| 123 | 119 | _particle[p].previousParticle = -1; |
| @@ -130,10 +126,6 @@ _particle[p].position = _emitter[e].previousPosition + timeFraction * (_emitter[ · 6 unmodified lines | ||
| 130 | 126 | |
| 131 | 127 | _emitter[e].currentParticle = p; |
| 132 | 128 | |
| 133 | − _numParticles ++; | |
| 134 | − | |
| 135 | − assert(_numParticles <= MAX_PARTICLES); | |
| 136 | − | |
| 137 | 129 | break; |
| 138 | 130 | } |
| 139 | 131 | } |
| @@ -143,7 +135,6 @@ void ParticleSystem::killParticle(int p) { · 3 unmodified lines | ||
| 143 | 135 | |
| 144 | 136 | assert( p >= 0); |
| 145 | 137 | assert( p < MAX_PARTICLES); |
| 146 | − assert( _numParticles > 0); | |
| 147 | 138 | |
| 148 | 139 | _particle[p].alive = false; |
| 149 | 140 | _particle[p].previousParticle = -1; |
| @@ -151,8 +142,6 @@ void ParticleSystem::killParticle(int p) { · 1 unmodified line | ||
| 151 | 142 | _particle[p].velocity = glm::vec3(0.0f, 0.0f, 0.0f); |
| 152 | 143 | _particle[p].age = 0.0f; |
| 153 | 144 | _particle[p].emitterIndex = -1; |
| 154 | − | |
| 155 | − _numParticles --; | |
| 156 | 145 | } |
| 157 | 146 | |
| 158 | 147 | |
| @@ -196,6 +185,9 @@ void ParticleSystem::setParticleAttributesToDefault(ParticleAttributes * a) { · 37 unmodified lines | ||
| 196 | 185 | |
| 197 | 186 | void ParticleSystem::setParticleAttributes(int emitterIndex, ParticleLifeStage lifeStage, ParticleAttributes attributes) { |
| 198 | 187 | |
| 188 | + assert(lifeStage >= 0 ); | |
| 189 | + assert(lifeStage < NUM_PARTICLE_LIFE_STAGES ); | |
| 190 | + | |
| 199 | 191 | ParticleAttributes * a = &_emitter[emitterIndex].particleAttributes[lifeStage]; |
| 200 | 192 | |
| 201 | 193 | a->radius = attributes.radius; |
| @@ -258,7 +250,7 @@ void ParticleSystem::updateParticle(int p, float deltaTime) { · 56 unmodified lines | ||
| 258 | 250 | |
| 259 | 251 | // apply neighbor attraction |
| 260 | 252 | int neighbor = p + 1; |
| 261 | − if (neighbor == _numParticles ) { | |
| 253 | + if (neighbor == MAX_PARTICLES ) { | |
| 262 | 254 | neighbor = 0; |
| 263 | 255 | } |
| 264 | 256 | |
| @@ -355,11 +347,15 @@ void ParticleSystem::updateParticle(int p, float deltaTime) { · 90 unmodified lines | ||
| 355 | 347 | void ParticleSystem::killAllParticles() { |
| 356 | 348 | |
| 357 | 349 | for (int e = 0; e < _numEmitters; e++) { |
| 358 | − _emitter[e].currentParticle = -1; | |
| 359 | − _emitter[e].emitReserve = 0.0f; | |
| 350 | + _emitter[e].currentParticle = -1; | |
| 351 | + _emitter[e].emitReserve = 0.0f; | |
| 352 | + _emitter[e].previousPosition = _emitter[e].position; | |
| 353 | + _emitter[e].rate = 0.0f; | |
| 354 | + _emitter[e].currentParticle = 0; | |
| 355 | + _emitter[e].numParticlesEmittedThisTime = 0; | |
| 360 | 356 | } |
| 361 | 357 | |
| 362 | − for (unsigned int p = 0; p < _numParticles; p++) { | |
| 358 | + for (int p = 0; p < MAX_PARTICLES; p++) { | |
| 363 | 359 | killParticle(p); |
| 364 | 360 | } |
| 365 | 361 | } |
| @@ -383,7 +379,7 @@ void ParticleSystem::render() { · 17 unmodified lines | ||
| 383 | 379 | }; |
| 384 | 380 | |
| 385 | 381 | // render the particles |
| 386 | − for (unsigned int p = 0; p < _numParticles; p++) { | |
| 382 | + for (int p = 0; p < MAX_PARTICLES; p++) { | |
| 387 | 383 | if (_particle[p].alive) { |
| 388 | 384 | if (_emitter[_particle[p].emitterIndex].particleLifespan > 0.0) { |
| 389 | 385 | renderParticle(p); |