diff --git a/include/osgParticle/ConnectedParticleSystem b/include/osgParticle/ConnectedParticleSystem index 044021b48..9187722f3 100644 --- a/include/osgParticle/ConnectedParticleSystem +++ b/include/osgParticle/ConnectedParticleSystem @@ -40,16 +40,39 @@ namespace osgParticle /// Draw the connected particles as either a line or a quad strip, depending upon viewing distance. . virtual void drawImplementation(osg::State& state) const; - + + ///Get the (const) particle from where the line or quadstrip starts to be drawn + const osgParticle::Particle* getStartParticle() const + { + return (_startParticle != Particle::INVALID_INDEX) ? &_particles[_startParticle] : 0; + } + + ///Get the particle from where the line or quadstrip starts to be drawn + osgParticle::Particle* getStartParticle() + { + return (_startParticle != Particle::INVALID_INDEX) ? &_particles[_startParticle] : 0; + } + + ///Set the maximum numbers of particles to be skipped during the predraw filtering + void setMaxNumberOfParticlesToSkip(unsigned int maxNumberofParticlesToSkip){_maxNumberOfParticlesToSkip = maxNumberofParticlesToSkip;} + + ///Get the maximum numbers of particles to be skipped during the predraw filtering + unsigned int getMaxNumberOfParticlesToSkip(){ return _maxNumberOfParticlesToSkip;} + protected: virtual ~ConnectedParticleSystem(); ConnectedParticleSystem& operator=(const ConnectedParticleSystem&) { return *this; } - - int _startParticle; + int _lastParticleCreated; - }; + unsigned int _maxNumberOfParticlesToSkip; + + int _startParticle; + + }; + + } diff --git a/src/osgParticle/ConnectedParticleSystem.cpp b/src/osgParticle/ConnectedParticleSystem.cpp index 218199b34..f8823b79a 100644 --- a/src/osgParticle/ConnectedParticleSystem.cpp +++ b/src/osgParticle/ConnectedParticleSystem.cpp @@ -20,14 +20,16 @@ using namespace osgParticle; ConnectedParticleSystem::ConnectedParticleSystem(): _startParticle(Particle::INVALID_INDEX), - _lastParticleCreated(Particle::INVALID_INDEX) + _lastParticleCreated(Particle::INVALID_INDEX), + _maxNumberOfParticlesToSkip(200) { } ConnectedParticleSystem::ConnectedParticleSystem(const ConnectedParticleSystem& copy, const osg::CopyOp& copyop): ParticleSystem(copy,copyop), _startParticle(copy._startParticle), - _lastParticleCreated(copy._lastParticleCreated) + _lastParticleCreated(copy._lastParticleCreated), + _maxNumberOfParticlesToSkip(200) { } @@ -105,8 +107,9 @@ void ConnectedParticleSystem::reuseParticle(int particleIndex) particle->setPreviousParticle(Particle::INVALID_INDEX); particle->setNextParticle(Particle::INVALID_INDEX); - // do the actual destroy of the particle - ParticleSystem::destroyParticle(particleIndex); + // put the particle on the death stack + ParticleSystem::reuseParticle(particleIndex); + } void ConnectedParticleSystem::drawImplementation(osg::State& state) const @@ -119,7 +122,7 @@ void ConnectedParticleSystem::drawImplementation(osg::State& state) const float pixelSizeOfFirstParticle = unitPixelSize * particle->getCurrentSize(); //float desiredGapBetweenDrawnParticles = 50.0f/unitPixelSize; //float desiredGapBetweenDrawnParticles2 = desiredGapBetweenDrawnParticles*desiredGapBetweenDrawnParticles; - unsigned int maxNumParticlesToSkip = 200; + float maxPixelError2 = osg::square(1.0f/unitPixelSize); if (pixelSizeOfFirstParticle<1.0) @@ -145,7 +148,7 @@ void ConnectedParticleSystem::drawImplementation(osg::State& state) const // now skip particles of required for(unsigned int i=0; - igetNextParticle()!=Particle::INVALID_INDEX)); + i<_maxNumberOfParticlesToSkip && ((distance2getNextParticle()!=Particle::INVALID_INDEX)); ++i) { nextParticle = &_particles[nextParticle->getNextParticle()]; @@ -185,7 +188,7 @@ void ConnectedParticleSystem::drawImplementation(osg::State& state) const // now skip particles of required for(unsigned int i=0; - igetNextParticle()!=Particle::INVALID_INDEX)); + i<_maxNumberOfParticlesToSkip && ((distance2getNextParticle()!=Particle::INVALID_INDEX)); ++i) { nextParticle = &_particles[nextParticle->getNextParticle()]; @@ -216,5 +219,7 @@ void ConnectedParticleSystem::drawImplementation(osg::State& state) const } glEnd(); } - } + + +