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.
This commit is contained in:
Robert Osfield 2006-11-07 13:48:20 +00:00
parent c9fed221a5
commit 5ac6ea9a8d
2 changed files with 40 additions and 12 deletions

View File

@ -41,16 +41,39 @@ namespace osgParticle
/// Draw the connected particles as either a line or a quad strip, depending upon viewing distance. . /// Draw the connected particles as either a line or a quad strip, depending upon viewing distance. .
virtual void drawImplementation(osg::State& state) const; 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: protected:
virtual ~ConnectedParticleSystem(); virtual ~ConnectedParticleSystem();
ConnectedParticleSystem& operator=(const ConnectedParticleSystem&) { return *this; } ConnectedParticleSystem& operator=(const ConnectedParticleSystem&) { return *this; }
int _startParticle;
int _lastParticleCreated; int _lastParticleCreated;
unsigned int _maxNumberOfParticlesToSkip;
int _startParticle;
}; };
} }
#endif #endif

View File

@ -20,14 +20,16 @@ using namespace osgParticle;
ConnectedParticleSystem::ConnectedParticleSystem(): ConnectedParticleSystem::ConnectedParticleSystem():
_startParticle(Particle::INVALID_INDEX), _startParticle(Particle::INVALID_INDEX),
_lastParticleCreated(Particle::INVALID_INDEX) _lastParticleCreated(Particle::INVALID_INDEX),
_maxNumberOfParticlesToSkip(200)
{ {
} }
ConnectedParticleSystem::ConnectedParticleSystem(const ConnectedParticleSystem& copy, const osg::CopyOp& copyop): ConnectedParticleSystem::ConnectedParticleSystem(const ConnectedParticleSystem& copy, const osg::CopyOp& copyop):
ParticleSystem(copy,copyop), ParticleSystem(copy,copyop),
_startParticle(copy._startParticle), _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->setPreviousParticle(Particle::INVALID_INDEX);
particle->setNextParticle(Particle::INVALID_INDEX); particle->setNextParticle(Particle::INVALID_INDEX);
// do the actual destroy of the particle // put the particle on the death stack
ParticleSystem::destroyParticle(particleIndex); ParticleSystem::reuseParticle(particleIndex);
} }
void ConnectedParticleSystem::drawImplementation(osg::State& state) const void ConnectedParticleSystem::drawImplementation(osg::State& state) const
@ -119,7 +122,7 @@ void ConnectedParticleSystem::drawImplementation(osg::State& state) const
float pixelSizeOfFirstParticle = unitPixelSize * particle->getCurrentSize(); float pixelSizeOfFirstParticle = unitPixelSize * particle->getCurrentSize();
//float desiredGapBetweenDrawnParticles = 50.0f/unitPixelSize; //float desiredGapBetweenDrawnParticles = 50.0f/unitPixelSize;
//float desiredGapBetweenDrawnParticles2 = desiredGapBetweenDrawnParticles*desiredGapBetweenDrawnParticles; //float desiredGapBetweenDrawnParticles2 = desiredGapBetweenDrawnParticles*desiredGapBetweenDrawnParticles;
unsigned int maxNumParticlesToSkip = 200;
float maxPixelError2 = osg::square(1.0f/unitPixelSize); float maxPixelError2 = osg::square(1.0f/unitPixelSize);
if (pixelSizeOfFirstParticle<1.0) if (pixelSizeOfFirstParticle<1.0)
@ -145,7 +148,7 @@ void ConnectedParticleSystem::drawImplementation(osg::State& state) const
// now skip particles of required // now skip particles of required
for(unsigned int i=0; for(unsigned int i=0;
i<maxNumParticlesToSkip && ((distance2<maxPixelError2) && (nextParticle->getNextParticle()!=Particle::INVALID_INDEX)); i<_maxNumberOfParticlesToSkip && ((distance2<maxPixelError2) && (nextParticle->getNextParticle()!=Particle::INVALID_INDEX));
++i) ++i)
{ {
nextParticle = &_particles[nextParticle->getNextParticle()]; nextParticle = &_particles[nextParticle->getNextParticle()];
@ -185,7 +188,7 @@ void ConnectedParticleSystem::drawImplementation(osg::State& state) const
// now skip particles of required // now skip particles of required
for(unsigned int i=0; for(unsigned int i=0;
i<maxNumParticlesToSkip && ((distance2<maxPixelError2) && (nextParticle->getNextParticle()!=Particle::INVALID_INDEX)); i<_maxNumberOfParticlesToSkip && ((distance2<maxPixelError2) && (nextParticle->getNextParticle()!=Particle::INVALID_INDEX));
++i) ++i)
{ {
nextParticle = &_particles[nextParticle->getNextParticle()]; nextParticle = &_particles[nextParticle->getNextParticle()];
@ -216,5 +219,7 @@ void ConnectedParticleSystem::drawImplementation(osg::State& state) const
} }
glEnd(); glEnd();
} }
} }