Showing the changes to interface/src/ParticleSystem.cpp (1 of 4 files). Show all
Unified · Split
| @@ -11,6 +11,7 @@ · 10 unmodified lines | |||
| 11 | #include "ParticleSystem.h" | 11 | #include "ParticleSystem.h" |
| 12 | #include "Application.h" | 12 | #include "Application.h" |
| 13 | 13 | ||
| 14 | const float DEFAULT_PARTICLE_RADIUS = 0.01f; | ||
| 14 | const float DEFAULT_PARTICLE_BOUNCE = 1.0f; | 15 | const float DEFAULT_PARTICLE_BOUNCE = 1.0f; |
| 15 | const float DEFAULT_PARTICLE_AIR_FRICTION = 2.0f; | 16 | const float DEFAULT_PARTICLE_AIR_FRICTION = 2.0f; |
| 16 | 17 | ||
| @@ -19,7 +20,7 @@ ParticleSystem::ParticleSystem() { · 2 unmodified lines | |||
| 19 | _numEmitters = 0; | 20 | _numEmitters = 0; |
| 20 | _numParticles = 0; | 21 | _numParticles = 0; |
| 21 | _upDirection = glm::vec3(0.0f, 1.0f, 0.0f); // default | 22 | _upDirection = glm::vec3(0.0f, 1.0f, 0.0f); // default |
| 22 | 23 | ||
| 23 | for (unsigned int e = 0; e < MAX_EMITTERS; e++) { | 24 | for (unsigned int e = 0; e < MAX_EMITTERS; e++) { |
| 24 | _emitter[e].position = glm::vec3(0.0f, 0.0f, 0.0f); | 25 | _emitter[e].position = glm::vec3(0.0f, 0.0f, 0.0f); |
| 25 | _emitter[e].rotation = glm::quat(); | 26 | _emitter[e].rotation = glm::quat(); |
| @@ -27,8 +28,17 @@ ParticleSystem::ParticleSystem() { · 1 unmodified line | |||
| 27 | _emitter[e].up = IDENTITY_UP; | 28 | _emitter[e].up = IDENTITY_UP; |
| 28 | _emitter[e].front = IDENTITY_FRONT; | 29 | _emitter[e].front = IDENTITY_FRONT; |
| 29 | _emitter[e].visible = false; | 30 | _emitter[e].visible = false; |
| 30 | 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 | |||
| 39 | |||
| 31 | for (int s = 0; s<NUM_PARTICLE_LIFE_STAGES; s++) { | 40 | for (int s = 0; s<NUM_PARTICLE_LIFE_STAGES; s++) { |
| 41 | _emitter[e].particleAttributes[s].radius = DEFAULT_PARTICLE_RADIUS; | ||
| 32 | _emitter[e].particleAttributes[s].bounce = DEFAULT_PARTICLE_BOUNCE; | 42 | _emitter[e].particleAttributes[s].bounce = DEFAULT_PARTICLE_BOUNCE; |
| 33 | _emitter[e].particleAttributes[s].airFriction = DEFAULT_PARTICLE_AIR_FRICTION; | 43 | _emitter[e].particleAttributes[s].airFriction = DEFAULT_PARTICLE_AIR_FRICTION; |
| 34 | _emitter[e].particleAttributes[s].gravity = 0.0f; | 44 | _emitter[e].particleAttributes[s].gravity = 0.0f; |
| @@ -112,9 +122,10 @@ void ParticleSystem::createParticle(int e, glm::vec3 position, glm::vec3 velocit · 77 unmodified lines | |||
| 112 | _particle[p].age = 0.0f; | 122 | _particle[p].age = 0.0f; |
| 113 | _particle[p].position = position; | 123 | _particle[p].position = position; |
| 114 | _particle[p].velocity = velocity; | 124 | _particle[p].velocity = velocity; |
| 115 | _particle[p].radius = radius; | ||
| 116 | _particle[p].color = color; | 125 | _particle[p].color = color; |
| 117 | 126 | ||
| 127 | _particle[p].radius = _emitter[e].particleAttributes[0].radius; | ||
| 128 | |||
| 118 | _numParticles ++; | 129 | _numParticles ++; |
| 119 | 130 | ||
| 120 | assert(_numParticles <= MAX_PARTICLES); | 131 | assert(_numParticles <= MAX_PARTICLES); |
| @@ -163,6 +174,7 @@ void ParticleSystem::setParticleAttributes(int emitterIndex, int lifeStage, Part · 42 unmodified lines | |||
| 163 | 174 | ||
| 164 | ParticleAttributes * a = &_emitter[emitterIndex].particleAttributes[lifeStage]; | 175 | ParticleAttributes * a = &_emitter[emitterIndex].particleAttributes[lifeStage]; |
| 165 | 176 | ||
| 177 | a->radius = attributes.radius; | ||
| 166 | a->bounce = attributes.bounce; | 178 | a->bounce = attributes.bounce; |
| 167 | a->gravity = attributes.gravity; | 179 | a->gravity = attributes.gravity; |
| 168 | a->airFriction = attributes.airFriction; | 180 | a->airFriction = attributes.airFriction; |
| @@ -183,8 +195,16 @@ void ParticleSystem::updateParticle(int p, float deltaTime) { · 14 unmodified lines | |||
| 183 | 195 | ||
| 184 | float ageFraction = _particle[p].age / _particle[p].lifespan; | 196 | float ageFraction = _particle[p].age / _particle[p].lifespan; |
| 185 | 197 | ||
| 198 | |||
| 199 | |||
| 200 | |||
| 186 | int lifeStage = (int)( ageFraction * NUM_PARTICLE_LIFE_STAGES ); | 201 | int lifeStage = (int)( ageFraction * NUM_PARTICLE_LIFE_STAGES ); |
| 187 | 202 | ||
| 203 | |||
| 204 | _particle[p].radius = _emitter[_particle[p].emitterIndex].particleAttributes[lifeStage].radius; | ||
| 205 | |||
| 206 | |||
| 207 | |||
| 188 | Emitter myEmitter = _emitter[_particle[p].emitterIndex]; | 208 | Emitter myEmitter = _emitter[_particle[p].emitterIndex]; |
| 189 | 209 | ||
| 190 | // apply random jitter | 210 | // apply random jitter |
| @@ -272,10 +292,34 @@ void ParticleSystem::setCollisionSphere(int e, glm::vec3 position, float radius) · 81 unmodified lines | |||
| 272 | _emitter[e].particleAttributes[lifeStage].collisionSphereRadius = radius; | 292 | _emitter[e].particleAttributes[lifeStage].collisionSphereRadius = radius; |
| 273 | } | 293 | } |
| 274 | 294 | ||
| 295 | void ParticleSystem::setEmitterParticle(int emitterIndex, bool showing ) { | ||
| 296 | |||
| 297 | _emitter[emitterIndex].baseParticle.alive = true; | ||
| 298 | _emitter[emitterIndex].baseParticle.emitterIndex = emitterIndex; | ||
| 299 | } | ||
| 300 | |||
| 301 | void ParticleSystem::setEmitterParticle(int emitterIndex, bool showing, float radius, glm::vec4 color ) { | ||
| 302 | |||
| 303 | _emitter[emitterIndex].baseParticle.alive = true; | ||
| 304 | _emitter[emitterIndex].baseParticle.emitterIndex = emitterIndex; | ||
| 305 | _emitter[emitterIndex].baseParticle.radius = radius; | ||
| 306 | _emitter[emitterIndex].baseParticle.color = color; | ||
| 307 | } | ||
| 308 | |||
| 309 | |||
| 275 | void ParticleSystem::render() { | 310 | void ParticleSystem::render() { |
| 276 | 311 | ||
| 277 | // render the emitters | 312 | // render the emitters |
| 278 | for (unsigned int e = 0; e < _numEmitters; e++) { | 313 | for (unsigned int e = 0; e < _numEmitters; e++) { |
| 314 | |||
| 315 | if (_emitter[e].baseParticle.alive) { | ||
| 316 | glColor4f(_emitter[e].baseParticle.color.r, _emitter[e].baseParticle.color.g, _emitter[e].baseParticle.color.b, _emitter[e].baseParticle.color.a ); | ||
| 317 | glPushMatrix(); | ||
| 318 | glTranslatef(_emitter[e].position.x, _emitter[e].position.y, _emitter[e].position.z); | ||
| 319 | glutSolidSphere(_emitter[e].baseParticle.radius, 6, 6); | ||
| 320 | glPopMatrix(); | ||
| 321 | } | ||
| 322 | |||
| 279 | if (_emitter[e].visible) { | 323 | if (_emitter[e].visible) { |
| 280 | renderEmitter(e, 0.2f); | 324 | renderEmitter(e, 0.2f); |
| 281 | } | 325 | } |