Showing the changes to interface/src/ParticleSystem.cpp (1 of 3 files). Show all
Unified · Split
| @@ -51,7 +51,7 @@ ParticleSystem::ParticleSystem() { · 50 unmodified lines | ||
| 51 | 51 | _particle[p].age = 0.0f; |
| 52 | 52 | _particle[p].radius = 0.0f; |
| 53 | 53 | _particle[p].emitterIndex = 0; |
| 54 | − _particle[p].previousParticle = -1; | |
| 54 | + _particle[p].previousParticle = NULL_PARTICLE; | |
| 55 | 55 | _particle[p].position = glm::vec3(0.0f, 0.0f, 0.0f); |
| 56 | 56 | _particle[p].velocity = glm::vec3(0.0f, 0.0f, 0.0f); |
| 57 | 57 | } |
| @@ -64,7 +64,7 @@ int ParticleSystem::addEmitter() { · 6 unmodified lines | ||
| 64 | 64 | return _numEmitters - 1; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | − return -1; | |
| 67 | + return NULL_EMITTER; | |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | |
| @@ -75,9 +75,9 @@ void ParticleSystem::simulate(float deltaTime) { · 4 unmodified lines | ||
| 75 | 75 | // emit particles |
| 76 | 76 | for (int e = 0; e < _numEmitters; e++) { |
| 77 | 77 | |
| 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); | |
| 81 | 81 | |
| 82 | 82 | _emitter[e].emitReserve += _emitter[e].rate * deltaTime; |
| 83 | 83 | |
| @@ -116,10 +116,10 @@ void ParticleSystem::createParticle(int e, float timeFraction) { · 32 unmodified lines | ||
| 116 | 116 | _particle[p].position = _emitter[e].previousPosition + timeFraction * (_emitter[e].position - _emitter[e].previousPosition); |
| 117 | 117 | _particle[p].radius = _emitter[e].particleAttributes[0].radius; |
| 118 | 118 | _particle[p].color = _emitter[e].particleAttributes[0].color; |
| 119 | − _particle[p].previousParticle = -1; | |
| 119 | + _particle[p].previousParticle = NULL_PARTICLE; | |
| 120 | 120 | |
| 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) { | |
| 123 | 123 | _particle[p].previousParticle = _emitter[e].currentParticle; |
| 124 | 124 | } |
| 125 | 125 | } |
| @@ -133,15 +133,15 @@ void ParticleSystem::createParticle(int e, float timeFraction) { · 7 unmodified lines | ||
| 133 | 133 | |
| 134 | 134 | void ParticleSystem::killParticle(int p) { |
| 135 | 135 | |
| 136 | − assert( p >= 0); | |
| 137 | − assert( p < MAX_PARTICLES); | |
| 136 | + assert(p >= 0); | |
| 137 | + assert(p < MAX_PARTICLES); | |
| 138 | 138 | |
| 139 | 139 | _particle[p].alive = false; |
| 140 | − _particle[p].previousParticle = -1; | |
| 140 | + _particle[p].previousParticle = NULL_PARTICLE; | |
| 141 | 141 | _particle[p].position = _emitter[_particle[p].emitterIndex].position; |
| 142 | 142 | _particle[p].velocity = glm::vec3(0.0f, 0.0f, 0.0f); |
| 143 | 143 | _particle[p].age = 0.0f; |
| 144 | − _particle[p].emitterIndex = -1; | |
| 144 | + _particle[p].emitterIndex = NULL_PARTICLE; | |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | |
| @@ -153,7 +153,7 @@ void ParticleSystem::setEmitterPosition(int emitterIndex, glm::vec3 position) { · 5 unmodified lines | ||
| 153 | 153 | |
| 154 | 154 | void ParticleSystem::setParticleAttributes(int emitterIndex, ParticleAttributes attributes) { |
| 155 | 155 | |
| 156 | − for (int lifeStage = 0; lifeStage < NUM_PARTICLE_LIFE_STAGES; lifeStage ++ ) { | |
| 156 | + for (int lifeStage = 0; lifeStage < NUM_PARTICLE_LIFE_STAGES; lifeStage ++) { | |
| 157 | 157 | setParticleAttributes(emitterIndex, (ParticleLifeStage)lifeStage, attributes); |
| 158 | 158 | } |
| 159 | 159 | } |
| @@ -185,8 +185,8 @@ void ParticleSystem::setParticleAttributesToDefault(ParticleAttributes * a) { · 25 unmodified lines | ||
| 185 | 185 | |
| 186 | 186 | void ParticleSystem::setParticleAttributes(int emitterIndex, ParticleLifeStage lifeStage, ParticleAttributes attributes) { |
| 187 | 187 | |
| 188 | − assert(lifeStage >= 0 ); | |
| 189 | − assert(lifeStage < NUM_PARTICLE_LIFE_STAGES ); | |
| 188 | + assert(lifeStage >= 0); | |
| 189 | + assert(lifeStage < NUM_PARTICLE_LIFE_STAGES); | |
| 190 | 190 | |
| 191 | 191 | ParticleAttributes * a = &_emitter[emitterIndex].particleAttributes[lifeStage]; |
| 192 | 192 | |
| @@ -226,8 +226,8 @@ void ParticleSystem::updateParticle(int p, float deltaTime) { · 33 unmodified lines | ||
| 226 | 226 | if (_emitter[_particle[p].emitterIndex].particleLifespan > 0.0) { |
| 227 | 227 | |
| 228 | 228 | 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; | |
| 231 | 231 | |
| 232 | 232 | // adjust radius |
| 233 | 233 | _particle[p].radius |
| @@ -250,18 +250,18 @@ void ParticleSystem::updateParticle(int p, float deltaTime) { · 16 unmodified lines | ||
| 250 | 250 | |
| 251 | 251 | // apply neighbor attraction |
| 252 | 252 | int neighbor = p + 1; |
| 253 | − if (neighbor == MAX_PARTICLES ) { | |
| 253 | + if (neighbor == MAX_PARTICLES) { | |
| 254 | 254 | neighbor = 0; |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | − if ( _particle[neighbor].emitterIndex == _particle[p].emitterIndex) { | |
| 257 | + if (_particle[neighbor].emitterIndex == _particle[p].emitterIndex) { | |
| 258 | 258 | glm::vec3 vectorToNeighbor = _particle[p].position - _particle[neighbor].position; |
| 259 | 259 | |
| 260 | 260 | _particle[p].velocity -= vectorToNeighbor * myEmitter.particleAttributes[lifeStage].neighborAttraction * deltaTime; |
| 261 | 261 | |
| 262 | 262 | float distanceToNeighbor = glm::length(vectorToNeighbor); |
| 263 | 263 | 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; | |
| 265 | 265 | } |
| 266 | 266 | } |
| 267 | 267 | |
| @@ -320,7 +320,7 @@ void ParticleSystem::updateParticle(int p, float deltaTime) { · 52 unmodified lines | ||
| 320 | 320 | float modulation = 0.0f; |
| 321 | 321 | float radian = _timer * myEmitter.particleAttributes[lifeStage ].modulationRate * PI_TIMES_TWO; |
| 322 | 322 | if (myEmitter.particleAttributes[lifeStage ].modulationStyle == COLOR_MODULATION_STYLE_LIGHNTESS_PULSE) { |
| 323 | − if ( sinf(radian) > 0.0f ) { | |
| 323 | + if (sinf(radian) > 0.0f) { | |
| 324 | 324 | modulation = myEmitter.particleAttributes[lifeStage].modulationAmplitude; |
| 325 | 325 | } |
| 326 | 326 | } 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 | ||
| 347 | 347 | void ParticleSystem::killAllParticles() { |
| 348 | 348 | |
| 349 | 349 | for (int e = 0; e < _numEmitters; e++) { |
| 350 | − _emitter[e].currentParticle = -1; | |
| 350 | + _emitter[e].currentParticle = NULL_PARTICLE; | |
| 351 | 351 | _emitter[e].emitReserve = 0.0f; |
| 352 | 352 | _emitter[e].previousPosition = _emitter[e].position; |
| 353 | 353 | _emitter[e].rate = 0.0f; |
| @@ -366,7 +366,7 @@ void ParticleSystem::render() { · 12 unmodified lines | ||
| 366 | 366 | for (int e = 0; e < _numEmitters; e++) { |
| 367 | 367 | |
| 368 | 368 | 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); | |
| 370 | 370 | glPushMatrix(); |
| 371 | 371 | glTranslatef(_emitter[e].position.x, _emitter[e].position.y, _emitter[e].position.z); |
| 372 | 372 | glutSolidSphere(_particle[0].radius, _emitter[e].particleResolution, _emitter[e].particleResolution); |
| @@ -390,7 +390,7 @@ void ParticleSystem::render() { · 17 unmodified lines | ||
| 390 | 390 | |
| 391 | 391 | void ParticleSystem::renderParticle(int p) { |
| 392 | 392 | |
| 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); | |
| 394 | 394 | |
| 395 | 395 | if (_emitter[_particle[p].emitterIndex].particleRenderStyle == PARTICLE_RENDER_STYLE_BILLBOARD) { |
| 396 | 396 | glm::vec3 cameraPosition = Application::getInstance()->getCamera()->getPosition(); |
| @@ -428,66 +428,64 @@ void ParticleSystem::renderParticle(int p) { · 31 unmodified lines | ||
| 428 | 428 | |
| 429 | 429 | } else if (_emitter[_particle[p].emitterIndex].particleRenderStyle == PARTICLE_RENDER_STYLE_RIBBON) { |
| 430 | 430 | |
| 431 | − if (_particle[p].previousParticle != -1) { | |
| 431 | + if (_particle[p].previousParticle != NULL_PARTICLE) { | |
| 432 | 432 | if ((_particle[p].alive) |
| 433 | 433 | && (_particle[_particle[p].previousParticle].alive) |
| 434 | − && (_particle[_particle[p].previousParticle].emitterIndex == _particle[p].emitterIndex )) { | |
| 434 | + && (_particle[_particle[p].previousParticle].emitterIndex == _particle[p].emitterIndex)) { | |
| 435 | 435 | |
| 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); | |
| 440 | 438 | |
| 441 | 439 | if (distance > 0.0f) { |
| 442 | 440 | |
| 443 | − v /= distance; | |
| 441 | + vectorFromPreviousParticle /= distance; | |
| 444 | 442 | |
| 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; | |
| 447 | 445 | |
| 448 | 446 | glm::vec3 p0Left = _particle[p ].position - right; |
| 449 | 447 | glm::vec3 p0Right = _particle[p ].position + right; |
| 450 | 448 | glm::vec3 p0Down = _particle[p ].position - up; |
| 451 | 449 | glm::vec3 p0Up = _particle[p ].position + up; |
| 452 | 450 | |
| 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; | |
| 457 | 455 | |
| 458 | 456 | glBegin(GL_TRIANGLES); |
| 459 | 457 | |
| 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 ); | |
| 463 | 461 | |
| 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); | |
| 467 | 465 | |
| 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 ); | |
| 471 | 469 | |
| 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 ); | |
| 475 | 473 | |
| 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 ); | |
| 479 | 477 | |
| 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 ); | |
| 483 | 481 | |
| 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 ); | |
| 487 | 485 | |
| 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 ); | |
| 491 | 489 | |
| 492 | 490 | glEnd(); |
| 493 | 491 | } |