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:
parent
c9fed221a5
commit
5ac6ea9a8d
@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
i<maxNumParticlesToSkip && ((distance2<maxPixelError2) && (nextParticle->getNextParticle()!=Particle::INVALID_INDEX));
|
||||
i<_maxNumberOfParticlesToSkip && ((distance2<maxPixelError2) && (nextParticle->getNextParticle()!=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;
|
||||
i<maxNumParticlesToSkip && ((distance2<maxPixelError2) && (nextParticle->getNextParticle()!=Particle::INVALID_INDEX));
|
||||
i<_maxNumberOfParticlesToSkip && ((distance2<maxPixelError2) && (nextParticle->getNextParticle()!=Particle::INVALID_INDEX));
|
||||
++i)
|
||||
{
|
||||
nextParticle = &_particles[nextParticle->getNextParticle()];
|
||||
@ -216,5 +219,7 @@ void ConnectedParticleSystem::drawImplementation(osg::State& state) const
|
||||
}
|
||||
glEnd();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user