Showing the changes to interface/src/ParticleSystem.cpp (1 of 2 files). Show all
Unified · Split
| @@ -17,6 +17,7 @@ const float DEFAULT_PARTICLE_AIR_FRICTION = 2.0f; · 16 unmodified lines | ||
| 17 | 17 | const float DEFAULT_PARTICLE_LIFESPAN = 1.0f; |
| 18 | 18 | const int DEFAULT_PARTICLE_SPHERE_RESOLUTION = 6; |
| 19 | 19 | const float DEFAULT_EMITTER_RENDER_LENGTH = 0.2f; |
| 20 | +const float DEFAULT_PARTICLE_CONNECT_DISTANCE = 0.03f; | |
| 20 | 21 | |
| 21 | 22 | ParticleSystem::ParticleSystem() { |
| 22 | 23 | |
| @@ -41,7 +42,8 @@ ParticleSystem::ParticleSystem() { · 18 unmodified lines | ||
| 41 | 42 | e->currentParticle = 0; |
| 42 | 43 | e->particleRenderStyle = PARTICLE_RENDER_STYLE_SPHERE; |
| 43 | 44 | e->numParticlesEmittedThisTime = 0; |
| 44 | − | |
| 45 | + e->maxParticleConnectDistance = DEFAULT_PARTICLE_CONNECT_DISTANCE; | |
| 46 | + | |
| 45 | 47 | for (int lifeStage = 0; lifeStage < NUM_PARTICLE_LIFE_STAGES; lifeStage++) { |
| 46 | 48 | setParticleAttributesToDefault(&_emitter[emitterIndex].particleAttributes[lifeStage]); |
| 47 | 49 | } |
| @@ -110,6 +112,7 @@ void ParticleSystem::updateEmitter(int emitterIndex, float deltaTime) { · 62 unmodified lines | ||
| 110 | 112 | |
| 111 | 113 | void ParticleSystem::createParticle(int e, float timeFraction) { |
| 112 | 114 | |
| 115 | + float maxConnectDistSqr = _emitter[e].maxParticleConnectDistance * _emitter[e].maxParticleConnectDistance; | |
| 113 | 116 | for (unsigned int p = 0; p < MAX_PARTICLES; p++) { |
| 114 | 117 | if (!_particle[p].alive) { |
| 115 | 118 | |
| @@ -122,9 +125,14 @@ void ParticleSystem::createParticle(int e, float timeFraction) { · 6 unmodified lines | ||
| 122 | 125 | _particle[p].color = _emitter[e].particleAttributes[PARTICLE_LIFESTAGE_0].color; |
| 123 | 126 | _particle[p].previousParticle = NULL_PARTICLE; |
| 124 | 127 | |
| 125 | − if (_particle[_emitter[e].currentParticle].alive) { | |
| 126 | − if (_particle[_emitter[e].currentParticle].emitterIndex == e) { | |
| 127 | − _particle[p].previousParticle = _emitter[e].currentParticle; | |
| 128 | + Particle& prev = _particle[_emitter[e].currentParticle]; | |
| 129 | + if (prev.alive) { | |
| 130 | + if (prev.emitterIndex == e) { | |
| 131 | + glm::vec3 diff = prev.position - _particle[p].position; | |
| 132 | + float sqrDist = glm::dot(diff, diff); | |
| 133 | + if (sqrDist < maxConnectDistSqr) { | |
| 134 | + _particle[p].previousParticle = _emitter[e].currentParticle; | |
| 135 | + } | |
| 128 | 136 | } |
| 129 | 137 | } |
| 130 | 138 | |