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 | const float DEFAULT_PARTICLE_LIFESPAN = 1.0f; | 17 | const float DEFAULT_PARTICLE_LIFESPAN = 1.0f; |
| 18 | const int DEFAULT_PARTICLE_SPHERE_RESOLUTION = 6; | 18 | const int DEFAULT_PARTICLE_SPHERE_RESOLUTION = 6; |
| 19 | const float DEFAULT_EMITTER_RENDER_LENGTH = 0.2f; | 19 | const float DEFAULT_EMITTER_RENDER_LENGTH = 0.2f; |
| 20 | const float DEFAULT_PARTICLE_CONNECT_DISTANCE = 0.03f; | ||
| 20 | 21 | ||
| 21 | ParticleSystem::ParticleSystem() { | 22 | ParticleSystem::ParticleSystem() { |
| 22 | 23 | ||
| @@ -41,7 +42,8 @@ ParticleSystem::ParticleSystem() { · 18 unmodified lines | |||
| 41 | e->currentParticle = 0; | 42 | e->currentParticle = 0; |
| 42 | e->particleRenderStyle = PARTICLE_RENDER_STYLE_SPHERE; | 43 | e->particleRenderStyle = PARTICLE_RENDER_STYLE_SPHERE; |
| 43 | e->numParticlesEmittedThisTime = 0; | 44 | e->numParticlesEmittedThisTime = 0; |
| 44 | 45 | e->maxParticleConnectDistance = DEFAULT_PARTICLE_CONNECT_DISTANCE; | |
| 46 | |||
| 45 | for (int lifeStage = 0; lifeStage < NUM_PARTICLE_LIFE_STAGES; lifeStage++) { | 47 | for (int lifeStage = 0; lifeStage < NUM_PARTICLE_LIFE_STAGES; lifeStage++) { |
| 46 | setParticleAttributesToDefault(&_emitter[emitterIndex].particleAttributes[lifeStage]); | 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 | void ParticleSystem::createParticle(int e, float timeFraction) { | 113 | void ParticleSystem::createParticle(int e, float timeFraction) { |
| 112 | 114 | ||
| 115 | float maxConnectDistSqr = _emitter[e].maxParticleConnectDistance * _emitter[e].maxParticleConnectDistance; | ||
| 113 | for (unsigned int p = 0; p < MAX_PARTICLES; p++) { | 116 | for (unsigned int p = 0; p < MAX_PARTICLES; p++) { |
| 114 | if (!_particle[p].alive) { | 117 | if (!_particle[p].alive) { |
| 115 | 118 | ||
| @@ -122,9 +125,14 @@ void ParticleSystem::createParticle(int e, float timeFraction) { · 6 unmodified lines | |||
| 122 | _particle[p].color = _emitter[e].particleAttributes[PARTICLE_LIFESTAGE_0].color; | 125 | _particle[p].color = _emitter[e].particleAttributes[PARTICLE_LIFESTAGE_0].color; |
| 123 | _particle[p].previousParticle = NULL_PARTICLE; | 126 | _particle[p].previousParticle = NULL_PARTICLE; |
| 124 | 127 | ||
| 125 | if (_particle[_emitter[e].currentParticle].alive) { | 128 | Particle& prev = _particle[_emitter[e].currentParticle]; |
| 126 | if (_particle[_emitter[e].currentParticle].emitterIndex == e) { | 129 | if (prev.alive) { |
| 127 | _particle[p].previousParticle = _emitter[e].currentParticle; | 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 | ||