From 1cd73f023893eb7d817e8b5beadb29eec2b089e2 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 23 May 2013 18:29:47 +0000 Subject: [PATCH] Added repolation of the _deadparts stack which would otherwise been invalidatd by the depth sort of particles. --- src/osgParticle/ParticleSystem.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/osgParticle/ParticleSystem.cpp b/src/osgParticle/ParticleSystem.cpp index 99fccf2bf..206a36ee3 100644 --- a/src/osgParticle/ParticleSystem.cpp +++ b/src/osgParticle/ParticleSystem.cpp @@ -139,16 +139,33 @@ void osgParticle::ParticleSystem::update(double dt, osg::NodeVisitor& nv) if (cv) { osg::Matrixd modelview = *(cv->getModelViewMatrix()); - float scale = (_sortMode==SORT_FRONT_TO_BACK ? -1.0f : 1.0f); + double scale = (_sortMode==SORT_FRONT_TO_BACK ? -1.0 : 1.0); + double deadDistance = DBL_MAX; for (unsigned int i=0; i<_particles.size(); ++i) { Particle& particle = _particles[i]; if (particle.isAlive()) particle.setDepth(distance(particle.getPosition(), modelview) * scale); else - particle.setDepth(0.0f); + particle.setDepth(deadDistance); } std::sort(_particles.begin(), _particles.end()); + + // Repopulate the death stack as it will have been invalidated by the sort. + unsigned int numDead = _deadparts.size(); + if (numDead>0) + { + // clear the death stack + _deadparts = Death_stack(); + + // copy the tail of the _particles vector as this will contain all the dead Particle thanks to the depth sort against DBL_MAX + Particle* first_dead_ptr = &_particles[_particles.size()-numDead]; + Particle* last_dead_ptr = &_particles[_particles.size()-1]; + for(Particle* dead_ptr = first_dead_ptr; dead_ptr<=last_dead_ptr; ++dead_ptr) + { + _deadparts.push(dead_ptr); + } + } } }