History

cleanup

Jeffrey Ventrella committed 13 years ago

Commit 0aaeb451 parent 89f36a73 files · +73 −71Browse files

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

Unified · Split

interface/src/ParticleSystem.cpp+59−61
@@ -51,7 +51,7 @@ ParticleSystem::ParticleSystem() { · 50 unmodified lines
5151 _particle[p].age = 0.0f;
5252 _particle[p].radius = 0.0f;
5353 _particle[p].emitterIndex = 0;
54− _particle[p].previousParticle = -1;
54+ _particle[p].previousParticle = NULL_PARTICLE;
5555 _particle[p].position = glm::vec3(0.0f, 0.0f, 0.0f);
5656 _particle[p].velocity = glm::vec3(0.0f, 0.0f, 0.0f);
5757 }
@@ -64,7 +64,7 @@ int ParticleSystem::addEmitter() { · 6 unmodified lines
6464 return _numEmitters - 1;
6565 }
6666
67− return -1;
67+ return NULL_EMITTER;
6868 }
6969
7070
@@ -75,9 +75,9 @@ void ParticleSystem::simulate(float deltaTime) { · 4 unmodified lines
7575 // emit particles
7676 for (int e = 0; e < _numEmitters; e++) {
7777
78− assert( e >= 0 );
79− assert( e <= MAX_EMITTERS );
80− assert( _emitter[e].rate >= 0 );
78+ assert(e >= 0);
79+ assert(e <= MAX_EMITTERS);
80+ assert(_emitter[e].rate >= 0);
8181
8282 _emitter[e].emitReserve += _emitter[e].rate * deltaTime;
8383
@@ -116,10 +116,10 @@ void ParticleSystem::createParticle(int e, float timeFraction) { · 32 unmodified lines
116116 _particle[p].position = _emitter[e].previousPosition + timeFraction * (_emitter[e].position - _emitter[e].previousPosition);
117117 _particle[p].radius = _emitter[e].particleAttributes[0].radius;
118118 _particle[p].color = _emitter[e].particleAttributes[0].color;
119− _particle[p].previousParticle = -1;
119+ _particle[p].previousParticle = NULL_PARTICLE;
120120
121− if ( _particle[_emitter[e].currentParticle].alive) {
122− if (_particle[_emitter[e].currentParticle].emitterIndex == e ) {
121+ if (_particle[_emitter[e].currentParticle].alive) {
122+ if (_particle[_emitter[e].currentParticle].emitterIndex == e) {
123123 _particle[p].previousParticle = _emitter[e].currentParticle;
124124 }
125125 }
@@ -133,15 +133,15 @@ void ParticleSystem::createParticle(int e, float timeFraction) { · 7 unmodified lines
133133
134134 void ParticleSystem::killParticle(int p) {
135135
136− assert( p >= 0);
137− assert( p < MAX_PARTICLES);
136+ assert(p >= 0);
137+ assert(p < MAX_PARTICLES);
138138
139139 _particle[p].alive = false;
140− _particle[p].previousParticle = -1;
140+ _particle[p].previousParticle = NULL_PARTICLE;
141141 _particle[p].position = _emitter[_particle[p].emitterIndex].position;
142142 _particle[p].velocity = glm::vec3(0.0f, 0.0f, 0.0f);
143143 _particle[p].age = 0.0f;
144− _particle[p].emitterIndex = -1;
144+ _particle[p].emitterIndex = NULL_PARTICLE;
145145 }
146146
147147
@@ -153,7 +153,7 @@ void ParticleSystem::setEmitterPosition(int emitterIndex, glm::vec3 position) { · 5 unmodified lines
153153
154154 void ParticleSystem::setParticleAttributes(int emitterIndex, ParticleAttributes attributes) {
155155
156− for (int lifeStage = 0; lifeStage < NUM_PARTICLE_LIFE_STAGES; lifeStage ++ ) {
156+ for (int lifeStage = 0; lifeStage < NUM_PARTICLE_LIFE_STAGES; lifeStage ++) {
157157 setParticleAttributes(emitterIndex, (ParticleLifeStage)lifeStage, attributes);
158158 }
159159 }
@@ -185,8 +185,8 @@ void ParticleSystem::setParticleAttributesToDefault(ParticleAttributes * a) { · 25 unmodified lines
185185
186186 void ParticleSystem::setParticleAttributes(int emitterIndex, ParticleLifeStage lifeStage, ParticleAttributes attributes) {
187187
188− assert(lifeStage >= 0 );
189− assert(lifeStage < NUM_PARTICLE_LIFE_STAGES );
188+ assert(lifeStage >= 0);
189+ assert(lifeStage < NUM_PARTICLE_LIFE_STAGES);
190190
191191 ParticleAttributes * a = &_emitter[emitterIndex].particleAttributes[lifeStage];
192192
@@ -226,8 +226,8 @@ void ParticleSystem::updateParticle(int p, float deltaTime) { · 33 unmodified lines
226226 if (_emitter[_particle[p].emitterIndex].particleLifespan > 0.0) {
227227
228228 ageFraction = _particle[p].age / myEmitter.particleLifespan;
229− lifeStage = (int)( ageFraction * (NUM_PARTICLE_LIFE_STAGES-1) );
230− lifeStageFraction = ageFraction * ( NUM_PARTICLE_LIFE_STAGES - 1 ) - lifeStage;
229+ lifeStage = (int)(ageFraction * (NUM_PARTICLE_LIFE_STAGES - 1));
230+ lifeStageFraction = ageFraction * (NUM_PARTICLE_LIFE_STAGES - 1) - lifeStage;
231231
232232 // adjust radius
233233 _particle[p].radius
@@ -250,18 +250,18 @@ void ParticleSystem::updateParticle(int p, float deltaTime) { · 16 unmodified lines
250250
251251 // apply neighbor attraction
252252 int neighbor = p + 1;
253− if (neighbor == MAX_PARTICLES ) {
253+ if (neighbor == MAX_PARTICLES) {
254254 neighbor = 0;
255255 }
256256
257− if ( _particle[neighbor].emitterIndex == _particle[p].emitterIndex) {
257+ if (_particle[neighbor].emitterIndex == _particle[p].emitterIndex) {
258258 glm::vec3 vectorToNeighbor = _particle[p].position - _particle[neighbor].position;
259259
260260 _particle[p].velocity -= vectorToNeighbor * myEmitter.particleAttributes[lifeStage].neighborAttraction * deltaTime;
261261
262262 float distanceToNeighbor = glm::length(vectorToNeighbor);
263263 if (distanceToNeighbor > 0.0f) {
264− _particle[neighbor].velocity += (vectorToNeighbor / ( 1.0f + distanceToNeighbor * distanceToNeighbor)) * myEmitter.particleAttributes[lifeStage].neighborRepulsion * deltaTime;
264+ _particle[neighbor].velocity += (vectorToNeighbor / (1.0f + distanceToNeighbor * distanceToNeighbor)) * myEmitter.particleAttributes[lifeStage].neighborRepulsion * deltaTime;
265265 }
266266 }
267267
@@ -320,7 +320,7 @@ void ParticleSystem::updateParticle(int p, float deltaTime) { · 52 unmodified lines
320320 float modulation = 0.0f;
321321 float radian = _timer * myEmitter.particleAttributes[lifeStage ].modulationRate * PI_TIMES_TWO;
322322 if (myEmitter.particleAttributes[lifeStage ].modulationStyle == COLOR_MODULATION_STYLE_LIGHNTESS_PULSE) {
323− if ( sinf(radian) > 0.0f ) {
323+ if (sinf(radian) > 0.0f) {
324324 modulation = myEmitter.particleAttributes[lifeStage].modulationAmplitude;
325325 }
326326 } else if (myEmitter.particleAttributes[lifeStage].modulationStyle == COLOR_MODULATION_STYLE_LIGHTNESS_WAVE) {
@@ -347,7 +347,7 @@ void ParticleSystem::updateParticle(int p, float deltaTime) { · 20 unmodified lines
347347 void ParticleSystem::killAllParticles() {
348348
349349 for (int e = 0; e < _numEmitters; e++) {
350− _emitter[e].currentParticle = -1;
350+ _emitter[e].currentParticle = NULL_PARTICLE;
351351 _emitter[e].emitReserve = 0.0f;
352352 _emitter[e].previousPosition = _emitter[e].position;
353353 _emitter[e].rate = 0.0f;
@@ -366,7 +366,7 @@ void ParticleSystem::render() { · 12 unmodified lines
366366 for (int e = 0; e < _numEmitters; e++) {
367367
368368 if (_emitter[e].showingBaseParticle) {
369− glColor4f(_particle[0].color.r, _particle[0].color.g, _particle[0].color.b, _particle[0].color.a );
369+ glColor4f(_particle[0].color.r, _particle[0].color.g, _particle[0].color.b, _particle[0].color.a);
370370 glPushMatrix();
371371 glTranslatef(_emitter[e].position.x, _emitter[e].position.y, _emitter[e].position.z);
372372 glutSolidSphere(_particle[0].radius, _emitter[e].particleResolution, _emitter[e].particleResolution);
@@ -390,7 +390,7 @@ void ParticleSystem::render() { · 17 unmodified lines
390390
391391 void ParticleSystem::renderParticle(int p) {
392392
393− glColor4f(_particle[p].color.r, _particle[p].color.g, _particle[p].color.b, _particle[p].color.a );
393+ glColor4f(_particle[p].color.r, _particle[p].color.g, _particle[p].color.b, _particle[p].color.a);
394394
395395 if (_emitter[_particle[p].emitterIndex].particleRenderStyle == PARTICLE_RENDER_STYLE_BILLBOARD) {
396396 glm::vec3 cameraPosition = Application::getInstance()->getCamera()->getPosition();
@@ -428,66 +428,64 @@ void ParticleSystem::renderParticle(int p) { · 31 unmodified lines
428428
429429 } else if (_emitter[_particle[p].emitterIndex].particleRenderStyle == PARTICLE_RENDER_STYLE_RIBBON) {
430430
431− if (_particle[p].previousParticle != -1) {
431+ if (_particle[p].previousParticle != NULL_PARTICLE) {
432432 if ((_particle[p].alive)
433433 && (_particle[_particle[p].previousParticle].alive)
434− && (_particle[_particle[p].previousParticle].emitterIndex == _particle[p].emitterIndex )) {
434+ && (_particle[_particle[p].previousParticle].emitterIndex == _particle[p].emitterIndex)) {
435435
436− int pp = _particle[p].previousParticle;
437−
438− glm::vec3 v = _particle[p].position - _particle[pp].position;
439− float distance = glm::length(v);
436+ glm::vec3 vectorFromPreviousParticle = _particle[p].position - _particle[_particle[p].previousParticle].position;
437+ float distance = glm::length(vectorFromPreviousParticle);
440438
441439 if (distance > 0.0f) {
442440
443− v /= distance;
441+ vectorFromPreviousParticle /= distance;
444442
445− glm::vec3 up = glm::normalize(glm::cross(v, _upDirection)) * _particle[p].radius;
446− glm::vec3 right = glm::normalize(glm::cross(up, v )) * _particle[p].radius;
443+ glm::vec3 up = glm::normalize(glm::cross(vectorFromPreviousParticle, _upDirection)) * _particle[p].radius;
444+ glm::vec3 right = glm::normalize(glm::cross(up, vectorFromPreviousParticle )) * _particle[p].radius;
447445
448446 glm::vec3 p0Left = _particle[p ].position - right;
449447 glm::vec3 p0Right = _particle[p ].position + right;
450448 glm::vec3 p0Down = _particle[p ].position - up;
451449 glm::vec3 p0Up = _particle[p ].position + up;
452450
453− glm::vec3 ppLeft = _particle[pp].position - right;
454− glm::vec3 ppRight = _particle[pp].position + right;
455− glm::vec3 ppDown = _particle[pp].position - up;
456− glm::vec3 ppUp = _particle[pp].position + up;
451+ glm::vec3 ppLeft = _particle[_particle[p].previousParticle].position - right;
452+ glm::vec3 ppRight = _particle[_particle[p].previousParticle].position + right;
453+ glm::vec3 ppDown = _particle[_particle[p].previousParticle].position - up;
454+ glm::vec3 ppUp = _particle[_particle[p].previousParticle].position + up;
457455
458456 glBegin(GL_TRIANGLES);
459457
460− glVertex3f(p0Left.x, p0Left.y, p0Left.z );
461− glVertex3f(p0Right.x, p0Right.y, p0Right.z );
462− glVertex3f(ppLeft.x, ppLeft.y, ppLeft.z );
458+ glVertex3f(p0Left.x, p0Left.y, p0Left.z );
459+ glVertex3f(p0Right.x, p0Right.y, p0Right.z);
460+ glVertex3f(ppLeft.x, ppLeft.y, ppLeft.z );
463461
464− glVertex3f(p0Right.x, p0Right.y, p0Right.z );
465− glVertex3f(ppLeft.x, ppLeft.y, ppLeft.z );
466− glVertex3f(ppRight.x, ppRight.y, ppRight.z );
462+ glVertex3f(p0Right.x, p0Right.y, p0Right.z);
463+ glVertex3f(ppLeft.x, ppLeft.y, ppLeft.z );
464+ glVertex3f(ppRight.x, ppRight.y, ppRight.z);
467465
468− glVertex3f(p0Up.x, p0Up.y, p0Up.z );
469− glVertex3f(p0Down.x, p0Down.y, p0Down.z );
470− glVertex3f(ppDown.x, ppDown.y, ppDown.z );
466+ glVertex3f(p0Up.x, p0Up.y, p0Up.z );
467+ glVertex3f(p0Down.x, p0Down.y, p0Down.z );
468+ glVertex3f(ppDown.x, ppDown.y, ppDown.z );
471469
472− glVertex3f(p0Up.x, p0Up.y, p0Up.z );
473− glVertex3f(ppUp.x, ppUp.y, ppUp.z );
474− glVertex3f(ppDown.x, ppDown.y, ppDown.z );
470+ glVertex3f(p0Up.x, p0Up.y, p0Up.z );
471+ glVertex3f(ppUp.x, ppUp.y, ppUp.z );
472+ glVertex3f(ppDown.x, ppDown.y, ppDown.z );
475473
476− glVertex3f(p0Up.x, p0Up.y, p0Left.z );
477− glVertex3f(p0Right.x, p0Right.y, p0Right.z );
478− glVertex3f(p0Down.x, p0Down.y, p0Down.z );
474+ glVertex3f(p0Up.x, p0Up.y, p0Left.z );
475+ glVertex3f(p0Right.x, p0Right.y, p0Right.z);
476+ glVertex3f(p0Down.x, p0Down.y, p0Down.z );
479477
480− glVertex3f(p0Up.x, p0Up.y, p0Left.z );
481− glVertex3f(p0Left.x, p0Left.y, p0Left.z );
482− glVertex3f(p0Down.x, p0Down.y, p0Down.z );
478+ glVertex3f(p0Up.x, p0Up.y, p0Left.z );
479+ glVertex3f(p0Left.x, p0Left.y, p0Left.z );
480+ glVertex3f(p0Down.x, p0Down.y, p0Down.z );
483481
484− glVertex3f(ppUp.x, ppUp.y, ppLeft.z );
485− glVertex3f(ppRight.x, ppRight.y, ppRight.z );
486− glVertex3f(ppDown.x, ppDown.y, ppDown.z );
482+ glVertex3f(ppUp.x, ppUp.y, ppLeft.z );
483+ glVertex3f(ppRight.x, ppRight.y, ppRight.z);
484+ glVertex3f(ppDown.x, ppDown.y, ppDown.z );
487485
488− glVertex3f(ppUp.x, ppUp.y, ppLeft.z );
489− glVertex3f(ppLeft.x, ppLeft.y, ppLeft.z );
490− glVertex3f(ppDown.x, ppDown.y, ppDown.z );
486+ glVertex3f(ppUp.x, ppUp.y, ppLeft.z );
487+ glVertex3f(ppLeft.x, ppLeft.y, ppLeft.z );
488+ glVertex3f(ppDown.x, ppDown.y, ppDown.z );
491489
492490 glEnd();
493491 }