Showing the changes to interface/src/ParticleSystem.cpp (1 of 4 files). Show all
Unified · Split
| @@ -39,6 +39,7 @@ ParticleSystem::ParticleSystem() { · 38 unmodified lines | ||
| 39 | 39 | |
| 40 | 40 | for (int s = 0; s<NUM_PARTICLE_LIFE_STAGES; s++) { |
| 41 | 41 | _emitter[e].particleAttributes[s].radius = DEFAULT_PARTICLE_RADIUS; |
| 42 | + _emitter[e].particleAttributes[s].color = glm::vec4(0.0f, 0.0f, 0.0f, 0.0f); | |
| 42 | 43 | _emitter[e].particleAttributes[s].bounce = DEFAULT_PARTICLE_BOUNCE; |
| 43 | 44 | _emitter[e].particleAttributes[s].airFriction = DEFAULT_PARTICLE_AIR_FRICTION; |
| 44 | 45 | _emitter[e].particleAttributes[s].gravity = 0.0f; |
| @@ -125,6 +126,7 @@ void ParticleSystem::createParticle(int e, glm::vec3 position, glm::vec3 velocit · 80 unmodified lines | ||
| 125 | 126 | _particle[p].color = color; |
| 126 | 127 | |
| 127 | 128 | _particle[p].radius = _emitter[e].particleAttributes[0].radius; |
| 129 | + _particle[p].color = _emitter[e].particleAttributes[0].color; | |
| 128 | 130 | |
| 129 | 131 | _numParticles ++; |
| 130 | 132 | |
| @@ -175,6 +177,7 @@ void ParticleSystem::setParticleAttributes(int emitterIndex, int lifeStage, Part · 44 unmodified lines | ||
| 175 | 177 | ParticleAttributes * a = &_emitter[emitterIndex].particleAttributes[lifeStage]; |
| 176 | 178 | |
| 177 | 179 | a->radius = attributes.radius; |
| 180 | + a->color = attributes.color; | |
| 178 | 181 | a->bounce = attributes.bounce; |
| 179 | 182 | a->gravity = attributes.gravity; |
| 180 | 183 | a->airFriction = attributes.airFriction; |
| @@ -192,19 +195,27 @@ void ParticleSystem::setParticleAttributes(int emitterIndex, int lifeStage, Part · 11 unmodified lines | ||
| 192 | 195 | void ParticleSystem::updateParticle(int p, float deltaTime) { |
| 193 | 196 | |
| 194 | 197 | assert(_particle[p].age <= _particle[p].lifespan); |
| 195 | − | |
| 196 | − float ageFraction = _particle[p].age / _particle[p].lifespan; | |
| 197 | − | |
| 198 | − | |
| 199 | − | |
| 200 | − | |
| 201 | − int lifeStage = (int)( ageFraction * NUM_PARTICLE_LIFE_STAGES ); | |
| 202 | − | |
| 203 | − | |
| 204 | − _particle[p].radius = _emitter[_particle[p].emitterIndex].particleAttributes[lifeStage].radius; | |
| 205 | 198 | |
| 199 | + float ageFraction = _particle[p].age / _particle[p].lifespan; | |
| 200 | + | |
| 201 | + int lifeStage = (int)( ageFraction * (NUM_PARTICLE_LIFE_STAGES-1) ); | |
| 202 | + | |
| 203 | + float lifeStageFraction = ageFraction * ( NUM_PARTICLE_LIFE_STAGES - 1 ) - lifeStage; | |
| 206 | 204 | |
| 205 | + /* | |
| 206 | + if ( p == 0 ) { | |
| 207 | + printf( "lifespan = %f ageFraction = %f lifeStage = %d lifeStageFraction = %f\n", _particle[p].lifespan, ageFraction, lifeStage, lifeStageFraction ); | |
| 208 | + } | |
| 209 | + */ | |
| 207 | 210 | |
| 211 | + _particle[p].radius | |
| 212 | + = _emitter[_particle[p].emitterIndex].particleAttributes[lifeStage ].radius * (1.0f - lifeStageFraction) | |
| 213 | + + _emitter[_particle[p].emitterIndex].particleAttributes[lifeStage+1].radius * lifeStageFraction; | |
| 214 | + | |
| 215 | + _particle[p].color | |
| 216 | + = _emitter[_particle[p].emitterIndex].particleAttributes[lifeStage ].color * (1.0f - lifeStageFraction) | |
| 217 | + + _emitter[_particle[p].emitterIndex].particleAttributes[lifeStage+1].color * lifeStageFraction; | |
| 218 | + | |
| 208 | 219 | Emitter myEmitter = _emitter[_particle[p].emitterIndex]; |
| 209 | 220 | |
| 210 | 221 | // apply random jitter |
| @@ -292,13 +303,13 @@ void ParticleSystem::setCollisionSphere(int e, glm::vec3 position, float radius) · 81 unmodified lines | ||
| 292 | 303 | _emitter[e].particleAttributes[lifeStage].collisionSphereRadius = radius; |
| 293 | 304 | } |
| 294 | 305 | |
| 295 | −void ParticleSystem::setEmitterParticle(int emitterIndex, bool showing ) { | |
| 306 | +void ParticleSystem::setEmitterBaseParticle(int emitterIndex, bool showing ) { | |
| 296 | 307 | |
| 297 | 308 | _emitter[emitterIndex].baseParticle.alive = true; |
| 298 | 309 | _emitter[emitterIndex].baseParticle.emitterIndex = emitterIndex; |
| 299 | 310 | } |
| 300 | 311 | |
| 301 | −void ParticleSystem::setEmitterParticle(int emitterIndex, bool showing, float radius, glm::vec4 color ) { | |
| 312 | +void ParticleSystem::setEmitterBaseParticle(int emitterIndex, bool showing, float radius, glm::vec4 color ) { | |
| 302 | 313 | |
| 303 | 314 | _emitter[emitterIndex].baseParticle.alive = true; |
| 304 | 315 | _emitter[emitterIndex].baseParticle.emitterIndex = emitterIndex; |
| @@ -310,7 +321,7 @@ void ParticleSystem::setEmitterParticle(int emitterIndex, bool showing, float ra · 5 unmodified lines | ||
| 310 | 321 | void ParticleSystem::render() { |
| 311 | 322 | |
| 312 | 323 | // render the emitters |
| 313 | − for (unsigned int e = 0; e < _numEmitters; e++) { | |
| 324 | + for (int e = 0; e < _numEmitters; e++) { | |
| 314 | 325 | |
| 315 | 326 | if (_emitter[e].baseParticle.alive) { |
| 316 | 327 | glColor4f(_emitter[e].baseParticle.color.r, _emitter[e].baseParticle.color.g, _emitter[e].baseParticle.color.b, _emitter[e].baseParticle.color.a ); |
| @@ -370,14 +381,14 @@ void ParticleSystem::renderParticle(int p) { · 53 unmodified lines | ||
| 370 | 381 | glutSolidSphere(_particle[p].radius, 6, 6); |
| 371 | 382 | glPopMatrix(); |
| 372 | 383 | |
| 373 | − // render velocity lines | |
| 374 | − glColor4f( _particle[p].color.x, _particle[p].color.y, _particle[p].color.z, 0.5f); | |
| 375 | − glm::vec3 end = _particle[p].position - _particle[p].velocity * 2.0f; | |
| 376 | − glBegin(GL_LINES); | |
| 377 | − glVertex3f(_particle[p].position.x, _particle[p].position.y, _particle[p].position.z); | |
| 378 | − glVertex3f(end.x, end.y, end.z); | |
| 379 | − | |
| 380 | − glEnd(); | |
| 384 | + if (SHOW_VELOCITY_TAILS) { | |
| 385 | + glColor4f( _particle[p].color.x, _particle[p].color.y, _particle[p].color.z, 0.5f); | |
| 386 | + glm::vec3 end = _particle[p].position - _particle[p].velocity * 2.0f; | |
| 387 | + glBegin(GL_LINES); | |
| 388 | + glVertex3f(_particle[p].position.x, _particle[p].position.y, _particle[p].position.z); | |
| 389 | + glVertex3f(end.x, end.y, end.z); | |
| 390 | + glEnd(); | |
| 391 | + } | |
| 381 | 392 | } |
| 382 | 393 | } |
| 383 | 394 | |