Showing the changes to interface/src/ParticleSystem.cpp (1 of 3 files). Show all
Unified · Split
| @@ -29,6 +29,7 @@ ParticleSystem::ParticleSystem() { · 28 unmodified lines | ||
| 29 | 29 | |
| 30 | 30 | Emitter * e = &_emitter[emitterIndex]; |
| 31 | 31 | e->position = glm::vec3(0.0f, 0.0f, 0.0f); |
| 32 | + e->previousPosition = glm::vec3(0.0f, 0.0f, 0.0f); | |
| 32 | 33 | e->direction = glm::vec3(0.0f, 1.0f, 0.0f); |
| 33 | 34 | e->visible = false; |
| 34 | 35 | e->particleResolution = DEFAULT_PARTICLE_SPHERE_RESOLUTION; |
| @@ -39,6 +40,7 @@ ParticleSystem::ParticleSystem() { · 4 unmodified lines | ||
| 39 | 40 | e->rate = 0.0f; |
| 40 | 41 | e->currentParticle = 0; |
| 41 | 42 | e->particleRenderStyle = PARTICLE_RENDER_STYLE_SPHERE; |
| 43 | + e->numParticlesEmittedThisTime = 0; | |
| 42 | 44 | |
| 43 | 45 | for (int lifeStage = 0; lifeStage<NUM_PARTICLE_LIFE_STAGES; lifeStage++) { |
| 44 | 46 | setParticleAttributesToDefault(&_emitter[emitterIndex].particleAttributes[lifeStage]); |
| @@ -80,12 +82,13 @@ void ParticleSystem::simulate(float deltaTime) { · 35 unmodified lines | ||
| 80 | 82 | |
| 81 | 83 | _emitter[e].emitReserve += _emitter[e].rate * deltaTime; |
| 82 | 84 | |
| 83 | − int numParticlesEmittedThisTime = (int)_emitter[e].emitReserve; | |
| 85 | + _emitter[e].numParticlesEmittedThisTime = (int)_emitter[e].emitReserve; | |
| 84 | 86 | |
| 85 | − _emitter[e].emitReserve -= numParticlesEmittedThisTime; | |
| 87 | + _emitter[e].emitReserve -= _emitter[e].numParticlesEmittedThisTime; | |
| 86 | 88 | |
| 87 | − for (int p = 0; p < numParticlesEmittedThisTime; p++) { | |
| 88 | − createParticle(e); | |
| 89 | + for (int p = 0; p < _emitter[e].numParticlesEmittedThisTime; p++) { | |
| 90 | + float timeFraction = (float)p / (float)_emitter[e].numParticlesEmittedThisTime; | |
| 91 | + createParticle(e, timeFraction); | |
| 89 | 92 | } |
| 90 | 93 | } |
| 91 | 94 | |
| @@ -102,7 +105,7 @@ void ParticleSystem::simulate(float deltaTime) { · 10 unmodified lines | ||
| 102 | 105 | } |
| 103 | 106 | } |
| 104 | 107 | |
| 105 | −void ParticleSystem::createParticle(int e) { | |
| 108 | +void ParticleSystem::createParticle(int e, float timeFraction) { | |
| 106 | 109 | |
| 107 | 110 | for (unsigned int p = 0; p < MAX_PARTICLES; p++) { |
| 108 | 111 | if (!_particle[p].alive) { |
| @@ -111,7 +114,10 @@ void ParticleSystem::createParticle(int e) { · 2 unmodified lines | ||
| 111 | 114 | _particle[p].alive = true; |
| 112 | 115 | _particle[p].age = 0.0f; |
| 113 | 116 | _particle[p].velocity = _emitter[e].direction * _emitter[e].thrust; |
| 114 | − _particle[p].position = _emitter[e].position; | |
| 117 | + | |
| 118 | +//_particle[p].position = _emitter[e].position; | |
| 119 | +_particle[p].position = _emitter[e].previousPosition + timeFraction * (_emitter[e].position - _emitter[e].previousPosition); | |
| 120 | + | |
| 115 | 121 | _particle[p].radius = _emitter[e].particleAttributes[0].radius; |
| 116 | 122 | _particle[p].color = _emitter[e].particleAttributes[0].color; |
| 117 | 123 | _particle[p].previousParticle = -1; |
| @@ -150,6 +156,12 @@ void ParticleSystem::killParticle(int p) { · 32 unmodified lines | ||
| 150 | 156 | } |
| 151 | 157 | |
| 152 | 158 | |
| 159 | +void ParticleSystem::setEmitterPosition(int emitterIndex, glm::vec3 position) { | |
| 160 | + _emitter[emitterIndex].previousPosition = _emitter[emitterIndex].position; | |
| 161 | + _emitter[emitterIndex].position = position; | |
| 162 | +} | |
| 163 | + | |
| 164 | + | |
| 153 | 165 | void ParticleSystem::setParticleAttributes(int emitterIndex, ParticleAttributes attributes) { |
| 154 | 166 | |
| 155 | 167 | for (int lifeStage = 0; lifeStage < NUM_PARTICLE_LIFE_STAGES; lifeStage ++ ) { |