Showing the changes to interface/src/ParticleSystem.cpp (1 of 4 files). Show all
Unified · Split
| @@ -21,36 +21,35 @@ ParticleSystem::ParticleSystem() { · 20 unmodified lines | ||
| 21 | 21 | _numParticles = 0; |
| 22 | 22 | _upDirection = glm::vec3(0.0f, 1.0f, 0.0f); // default |
| 23 | 23 | |
| 24 | − for (unsigned int e = 0; e < MAX_EMITTERS; e++) { | |
| 25 | − _emitter[e].position = glm::vec3(0.0f, 0.0f, 0.0f); | |
| 26 | − _emitter[e].rotation = glm::quat(); | |
| 27 | − _emitter[e].right = IDENTITY_RIGHT; | |
| 28 | − _emitter[e].up = IDENTITY_UP; | |
| 29 | − _emitter[e].front = IDENTITY_FRONT; | |
| 30 | − _emitter[e].visible = false; | |
| 31 | − _emitter[e].baseParticle.alive = false; | |
| 32 | − _emitter[e].baseParticle.age = 0.0f; | |
| 33 | − _emitter[e].baseParticle.lifespan = 0.0f; | |
| 34 | − _emitter[e].baseParticle.radius = 0.0f; | |
| 35 | − _emitter[e].baseParticle.emitterIndex = 0; | |
| 36 | − _emitter[e].baseParticle.position = glm::vec3(0.0f, 0.0f, 0.0f); | |
| 37 | − _emitter[e].baseParticle.velocity = glm::vec3(0.0f, 0.0f, 0.0f); | |
| 38 | − | |
| 24 | + for (unsigned int emitterIndex = 0; emitterIndex < MAX_EMITTERS; emitterIndex++) { | |
| 25 | + _emitter[emitterIndex].position = glm::vec3(0.0f, 0.0f, 0.0f); | |
| 26 | + _emitter[emitterIndex].rotation = glm::quat(); | |
| 27 | + _emitter[emitterIndex].visible = false; | |
| 28 | + _emitter[emitterIndex].baseParticle.alive = false; | |
| 29 | + _emitter[emitterIndex].baseParticle.age = 0.0f; | |
| 30 | + _emitter[emitterIndex].baseParticle.lifespan = 0.0f; | |
| 31 | + _emitter[emitterIndex].baseParticle.radius = 0.0f; | |
| 32 | + _emitter[emitterIndex].baseParticle.emitterIndex = 0; | |
| 33 | + _emitter[emitterIndex].baseParticle.position = glm::vec3(0.0f, 0.0f, 0.0f); | |
| 34 | + _emitter[emitterIndex].baseParticle.velocity = glm::vec3(0.0f, 0.0f, 0.0f); | |
| 39 | 35 | |
| 40 | − for (int s = 0; s<NUM_PARTICLE_LIFE_STAGES; s++) { | |
| 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); | |
| 43 | − _emitter[e].particleAttributes[s].bounce = DEFAULT_PARTICLE_BOUNCE; | |
| 44 | − _emitter[e].particleAttributes[s].airFriction = DEFAULT_PARTICLE_AIR_FRICTION; | |
| 45 | − _emitter[e].particleAttributes[s].gravity = 0.0f; | |
| 46 | − _emitter[e].particleAttributes[s].jitter = 0.0f; | |
| 47 | − _emitter[e].particleAttributes[s].emitterAttraction = 0.0f; | |
| 48 | − _emitter[e].particleAttributes[s].tornadoForce = 0.0f; | |
| 49 | − _emitter[e].particleAttributes[s].neighborAttraction = 0.0f; | |
| 50 | − _emitter[e].particleAttributes[s].neighborRepulsion = 0.0f; | |
| 51 | − _emitter[e].particleAttributes[s].collisionSphereRadius = 0.0f; | |
| 52 | − _emitter[e].particleAttributes[s].collisionSpherePosition = glm::vec3(0.0f, 0.0f, 0.0f); | |
| 53 | − _emitter[e].particleAttributes[s].usingCollisionSphere = false; | |
| 36 | + for (int lifeStage = 0; lifeStage<NUM_PARTICLE_LIFE_STAGES; lifeStage++) { | |
| 37 | + | |
| 38 | + ParticleAttributes * a = &_emitter[emitterIndex].particleAttributes[lifeStage]; | |
| 39 | + | |
| 40 | + a->radius = DEFAULT_PARTICLE_RADIUS; | |
| 41 | + a->color = glm::vec4(0.0f, 0.0f, 0.0f, 0.0f); | |
| 42 | + a->bounce = DEFAULT_PARTICLE_BOUNCE; | |
| 43 | + a->airFriction = DEFAULT_PARTICLE_AIR_FRICTION; | |
| 44 | + a->gravity = 0.0f; | |
| 45 | + a->jitter = 0.0f; | |
| 46 | + a->emitterAttraction = 0.0f; | |
| 47 | + a->tornadoForce = 0.0f; | |
| 48 | + a->neighborAttraction = 0.0f; | |
| 49 | + a->neighborRepulsion = 0.0f; | |
| 50 | + a->collisionSphereRadius = 0.0f; | |
| 51 | + a->collisionSpherePosition = glm::vec3(0.0f, 0.0f, 0.0f); | |
| 52 | + a->usingCollisionSphere = false; | |
| 54 | 53 | } |
| 55 | 54 | }; |
| 56 | 55 | |
| @@ -79,11 +78,6 @@ int ParticleSystem::addEmitter() { · 22 unmodified lines | ||
| 79 | 78 | |
| 80 | 79 | void ParticleSystem::simulate(float deltaTime) { |
| 81 | 80 | |
| 82 | − // update emitters | |
| 83 | − for (unsigned int e = 0; e < _numEmitters; e++) { | |
| 84 | − updateEmitter(e, deltaTime); | |
| 85 | − } | |
| 86 | − | |
| 87 | 81 | // update particles |
| 88 | 82 | for (unsigned int p = 0; p < _numParticles; p++) { |
| 89 | 83 | if (_particle[p].alive) { |
| @@ -96,23 +90,14 @@ void ParticleSystem::simulate(float deltaTime) { · 6 unmodified lines | ||
| 96 | 90 | } |
| 97 | 91 | } |
| 98 | 92 | |
| 99 | − | |
| 100 | −void ParticleSystem::updateEmitter(int e, float deltaTime) { | |
| 101 | − | |
| 102 | − _emitter[e].front = _emitter[e].rotation * IDENTITY_FRONT; | |
| 103 | − _emitter[e].right = _emitter[e].rotation * IDENTITY_RIGHT; | |
| 104 | − _emitter[e].up = _emitter[e].rotation * IDENTITY_UP; | |
| 105 | −} | |
| 106 | − | |
| 107 | − | |
| 108 | −void ParticleSystem::emitParticlesNow(int e, int num, float radius, glm::vec4 color, glm::vec3 velocity, float lifespan) { | |
| 93 | +void ParticleSystem::emitParticlesNow(int e, int num, glm::vec3 velocity, float lifespan) { | |
| 109 | 94 | |
| 110 | 95 | for (unsigned int p = 0; p < num; p++) { |
| 111 | − createParticle(e, _emitter[e].position, velocity, radius, color, lifespan); | |
| 96 | + createParticle(e, velocity, lifespan); | |
| 112 | 97 | } |
| 113 | 98 | } |
| 114 | 99 | |
| 115 | −void ParticleSystem::createParticle(int e, glm::vec3 position, glm::vec3 velocity, float radius, glm::vec4 color, float lifespan) { | |
| 100 | +void ParticleSystem::createParticle(int e, glm::vec3 velocity, float lifespan) { | |
| 116 | 101 | |
| 117 | 102 | for (unsigned int p = 0; p < MAX_PARTICLES; p++) { |
| 118 | 103 | if (!_particle[p].alive) { |
| @@ -121,12 +106,10 @@ void ParticleSystem::createParticle(int e, glm::vec3 position, glm::vec3 velocit · 2 unmodified lines | ||
| 121 | 106 | _particle[p].lifespan = lifespan; |
| 122 | 107 | _particle[p].alive = true; |
| 123 | 108 | _particle[p].age = 0.0f; |
| 124 | − _particle[p].position = position; | |
| 125 | 109 | _particle[p].velocity = velocity; |
| 126 | − _particle[p].color = color; | |
| 127 | − | |
| 128 | − _particle[p].radius = _emitter[e].particleAttributes[0].radius; | |
| 129 | − _particle[p].color = _emitter[e].particleAttributes[0].color; | |
| 110 | + _particle[p].position = _emitter[e].position; | |
| 111 | + _particle[p].radius = _emitter[e].particleAttributes[0].radius; | |
| 112 | + _particle[p].color = _emitter[e].particleAttributes[0].color; | |
| 130 | 113 | |
| 131 | 114 | _numParticles ++; |
| 132 | 115 | |
| @@ -227,7 +210,11 @@ void ParticleSystem::updateParticle(int p, float deltaTime) { · 94 unmodified lines | ||
| 227 | 210 | } |
| 228 | 211 | |
| 229 | 212 | // apply tornado force |
| 230 | − glm::vec3 tornadoDirection = glm::cross(vectorToHome, myEmitter.up); | |
| 213 | + | |
| 214 | + | |
| 215 | + glm::vec3 emitterUp = myEmitter.rotation * IDENTITY_UP; | |
| 216 | + | |
| 217 | + glm::vec3 tornadoDirection = glm::cross(vectorToHome, emitterUp); | |
| 231 | 218 | _particle[p].velocity += tornadoDirection * myEmitter.particleAttributes[lifeStage].tornadoForce * deltaTime; |
| 232 | 219 | |
| 233 | 220 | // apply air friction |
| @@ -363,10 +350,10 @@ void ParticleSystem::renderParticle(int p) { · 129 unmodified lines | ||
| 363 | 350 | |
| 364 | 351 | |
| 365 | 352 | void ParticleSystem::renderEmitter(int e, float size) { |
| 366 | − | |
| 367 | − glm::vec3 r = _emitter[e].right * size; | |
| 368 | − glm::vec3 u = _emitter[e].up * size; | |
| 369 | − glm::vec3 f = _emitter[e].front * size; | |
| 353 | + | |
| 354 | + glm::vec3 r = _emitter[e].rotation * IDENTITY_FRONT * size; | |
| 355 | + glm::vec3 u = _emitter[e].rotation * IDENTITY_RIGHT * size; | |
| 356 | + glm::vec3 f = _emitter[e].rotation * IDENTITY_UP * size; | |
| 370 | 357 | |
| 371 | 358 | glLineWidth(2.0f); |
| 372 | 359 | |