History

added particle life stages

Jeffrey Ventrella committed 13 years ago

Commit 1f1259c1 parent d572fee4 files · +59 −39Browse files

Showing the changes to interface/src/ParticleSystem.cpp (1 of 4 files). Show all

Unified · Split

interface/src/ParticleSystem.cpp+32−21
@@ -39,6 +39,7 @@ ParticleSystem::ParticleSystem() { · 38 unmodified lines
3939
4040 for (int s = 0; s<NUM_PARTICLE_LIFE_STAGES; s++) {
4141 _emitter[e].particleAttributes[s].radius = DEFAULT_PARTICLE_RADIUS;
42+ _emitter[e].particleAttributes[s].color = glm::vec4(0.0f, 0.0f, 0.0f, 0.0f);
4243 _emitter[e].particleAttributes[s].bounce = DEFAULT_PARTICLE_BOUNCE;
4344 _emitter[e].particleAttributes[s].airFriction = DEFAULT_PARTICLE_AIR_FRICTION;
4445 _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
125126 _particle[p].color = color;
126127
127128 _particle[p].radius = _emitter[e].particleAttributes[0].radius;
129+ _particle[p].color = _emitter[e].particleAttributes[0].color;
128130
129131 _numParticles ++;
130132
@@ -175,6 +177,7 @@ void ParticleSystem::setParticleAttributes(int emitterIndex, int lifeStage, Part · 44 unmodified lines
175177 ParticleAttributes * a = &_emitter[emitterIndex].particleAttributes[lifeStage];
176178
177179 a->radius = attributes.radius;
180+ a->color = attributes.color;
178181 a->bounce = attributes.bounce;
179182 a->gravity = attributes.gravity;
180183 a->airFriction = attributes.airFriction;
@@ -192,19 +195,27 @@ void ParticleSystem::setParticleAttributes(int emitterIndex, int lifeStage, Part · 11 unmodified lines
192195 void ParticleSystem::updateParticle(int p, float deltaTime) {
193196
194197 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;
205198
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;
206204
205+ /*
206+ if ( p == 0 ) {
207+ printf( "lifespan = %f ageFraction = %f lifeStage = %d lifeStageFraction = %f\n", _particle[p].lifespan, ageFraction, lifeStage, lifeStageFraction );
208+ }
209+ */
207210
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+
208219 Emitter myEmitter = _emitter[_particle[p].emitterIndex];
209220
210221 // apply random jitter
@@ -292,13 +303,13 @@ void ParticleSystem::setCollisionSphere(int e, glm::vec3 position, float radius) · 81 unmodified lines
292303 _emitter[e].particleAttributes[lifeStage].collisionSphereRadius = radius;
293304 }
294305
295−void ParticleSystem::setEmitterParticle(int emitterIndex, bool showing ) {
306+void ParticleSystem::setEmitterBaseParticle(int emitterIndex, bool showing ) {
296307
297308 _emitter[emitterIndex].baseParticle.alive = true;
298309 _emitter[emitterIndex].baseParticle.emitterIndex = emitterIndex;
299310 }
300311
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 ) {
302313
303314 _emitter[emitterIndex].baseParticle.alive = true;
304315 _emitter[emitterIndex].baseParticle.emitterIndex = emitterIndex;
@@ -310,7 +321,7 @@ void ParticleSystem::setEmitterParticle(int emitterIndex, bool showing, float ra · 5 unmodified lines
310321 void ParticleSystem::render() {
311322
312323 // render the emitters
313− for (unsigned int e = 0; e < _numEmitters; e++) {
324+ for (int e = 0; e < _numEmitters; e++) {
314325
315326 if (_emitter[e].baseParticle.alive) {
316327 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
370381 glutSolidSphere(_particle[p].radius, 6, 6);
371382 glPopMatrix();
372383
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+ }
381392 }
382393 }
383394