From 97d1c5bcbf9c48c99182fefd8e687d10df363c76 Mon Sep 17 00:00:00 2001 From: Eric Johnston Date: Wed, 7 Aug 2013 18:03:59 -0700 Subject: [PATCH] =?UTF-8?q?Rave=20tweak:=20noise=20reduction=20=E2=80=A6by?= =?UTF-8?q?=20putting=20a=20smart=20cap=20on=20particle=20chain=20distance?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- interface/src/ParticleSystem.cpp | 16 ++++++++++++---- interface/src/ParticleSystem.h | 1 + 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/interface/src/ParticleSystem.cpp b/interface/src/ParticleSystem.cpp index 5aed606191..48a27c4fd1 100644 --- a/interface/src/ParticleSystem.cpp +++ b/interface/src/ParticleSystem.cpp @@ -17,6 +17,7 @@ const float DEFAULT_PARTICLE_AIR_FRICTION = 2.0f; const float DEFAULT_PARTICLE_LIFESPAN = 1.0f; const int DEFAULT_PARTICLE_SPHERE_RESOLUTION = 6; const float DEFAULT_EMITTER_RENDER_LENGTH = 0.2f; +const float DEFAULT_PARTICLE_CONNECT_DISTANCE = 0.03f; ParticleSystem::ParticleSystem() { @@ -41,7 +42,8 @@ ParticleSystem::ParticleSystem() { e->currentParticle = 0; e->particleRenderStyle = PARTICLE_RENDER_STYLE_SPHERE; e->numParticlesEmittedThisTime = 0; - + e->maxParticleConnectDistance = DEFAULT_PARTICLE_CONNECT_DISTANCE; + for (int lifeStage = 0; lifeStage < NUM_PARTICLE_LIFE_STAGES; lifeStage++) { setParticleAttributesToDefault(&_emitter[emitterIndex].particleAttributes[lifeStage]); } @@ -110,6 +112,7 @@ void ParticleSystem::updateEmitter(int emitterIndex, float deltaTime) { void ParticleSystem::createParticle(int e, float timeFraction) { + float maxConnectDistSqr = _emitter[e].maxParticleConnectDistance * _emitter[e].maxParticleConnectDistance; for (unsigned int p = 0; p < MAX_PARTICLES; p++) { if (!_particle[p].alive) { @@ -122,9 +125,14 @@ void ParticleSystem::createParticle(int e, float timeFraction) { _particle[p].color = _emitter[e].particleAttributes[PARTICLE_LIFESTAGE_0].color; _particle[p].previousParticle = NULL_PARTICLE; - if (_particle[_emitter[e].currentParticle].alive) { - if (_particle[_emitter[e].currentParticle].emitterIndex == e) { - _particle[p].previousParticle = _emitter[e].currentParticle; + Particle& prev = _particle[_emitter[e].currentParticle]; + if (prev.alive) { + if (prev.emitterIndex == e) { + glm::vec3 diff = prev.position - _particle[p].position; + float sqrDist = glm::dot(diff, diff); + if (sqrDist < maxConnectDistSqr) { + _particle[p].previousParticle = _emitter[e].currentParticle; + } } } diff --git a/interface/src/ParticleSystem.h b/interface/src/ParticleSystem.h index 60bd0f91d4..8b83d6606a 100644 --- a/interface/src/ParticleSystem.h +++ b/interface/src/ParticleSystem.h @@ -122,6 +122,7 @@ private: int currentParticle; // the index of the most recently-emitted particle ParticleAttributes particleAttributes[NUM_PARTICLE_LIFE_STAGES]; // the attributes of particles emitted from this emitter ParticleRenderStyle particleRenderStyle; + float maxParticleConnectDistance; // past this, don't connect the particles. }; glm::vec3 _upDirection;