From 5ac6ea9a8d0b29f9e04cf491839ff6122e381ba9 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 7 Nov 2006 13:48:20 +0000 Subject: [PATCH] Ben van Basten, "1 Bug fix in reuseParticle where originally an old particle that was already killed would be killed again, but instead should have been placed on the dead stack for future reuse. 2 Getter/setter for _maxNumberOfParticlesToSkip that is used for filtering of particles during draw. This enables you to turn the filtering of by setting this value to zero. 3 Getter for retrieval of the first particle in the trail. This allows you to directly manipulate the trail from your application by walking from the start particle towards the end of the trail." Submitted on Ben's behalf by Roland Smeenk. --- include/osgParticle/ConnectedParticleSystem | 31 ++++++++++++++++++--- src/osgParticle/ConnectedParticleSystem.cpp | 21 ++++++++------ 2 files changed, 40 insertions(+), 12 deletions(-) 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(); } - } + + +