diff --git a/include/osgParticle/ConnectedParticleSystem b/include/osgParticle/ConnectedParticleSystem index 9b0c23ecced..7c1add1121c 100644 --- a/include/osgParticle/ConnectedParticleSystem +++ b/include/osgParticle/ConnectedParticleSystem @@ -44,13 +44,13 @@ namespace osgParticle ///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; + 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; + return (_startParticle != Particle::INVALID_INDEX) ? _particles[_startParticle] : 0; } ///Set the maximum numbers of particles to be skipped during the predraw filtering diff --git a/include/osgParticle/ParticleSystem b/include/osgParticle/ParticleSystem index 35e97ff8967..4a63ae20da7 100644 --- a/include/osgParticle/ParticleSystem +++ b/include/osgParticle/ParticleSystem @@ -173,7 +173,7 @@ namespace osgParticle inline virtual void destroyParticle(int i); /// Reuse the i-th particle. - inline virtual void reuseParticle(int i) { _deadparts.push(&(_particles[i])); } + inline virtual void reuseParticle(int i) { _deadparts.push((_particles[i])); } /// Get the last frame number. inline unsigned int getLastFrameNumber() const; @@ -280,7 +280,12 @@ namespace osgParticle inline void update_bounds(const osg::Vec3& p, float r); - typedef std::vector Particle_vector; + void single_pass_render(osg::RenderInfo& renderInfo, const osg::Matrix& modelview) const; + + void new_drawImplementation(osg::RenderInfo& renderInfo) const; + + typedef std::vector Particle_vector; + typedef std::stack Death_stack; Particle_vector _particles; @@ -436,17 +441,17 @@ namespace osgParticle inline Particle* ParticleSystem::getParticle(int i) { - return &_particles[i]; + return _particles[i]; } inline const Particle* ParticleSystem::getParticle(int i) const { - return &_particles[i]; + return _particles[i]; } inline void ParticleSystem::destroyParticle(int i) { - _particles[i].kill(); + _particles[i]->kill(); } inline unsigned int ParticleSystem::getLastFrameNumber() const diff --git a/src/osgParticle/ConnectedParticleSystem.cpp b/src/osgParticle/ConnectedParticleSystem.cpp index c006e38ea8b..04760fddc4e 100644 --- a/src/osgParticle/ConnectedParticleSystem.cpp +++ b/src/osgParticle/ConnectedParticleSystem.cpp @@ -42,7 +42,8 @@ Particle* ConnectedParticleSystem::createParticle(const Particle* ptemplate) // OSG_NOTICE<setNextParticle(particleIndex); particle->setPreviousParticle(_lastParticleCreated); } @@ -76,7 +77,7 @@ void ConnectedParticleSystem::reuseParticle(int particleIndex) if (particleIndex<0 || particleIndex>=(int)_particles.size()) return; - Particle* particle = &_particles[particleIndex]; + Particle* particle = _particles[particleIndex]; int previous = particle->getPreviousParticle(); int next = particle->getNextParticle(); @@ -95,12 +96,12 @@ void ConnectedParticleSystem::reuseParticle(int particleIndex) // the deletion of the this particle if (previous != Particle::INVALID_INDEX) { - _particles[previous].setNextParticle(next); + _particles[previous]->setNextParticle(next); } if (next != Particle::INVALID_INDEX) { - _particles[next].setPreviousParticle(previous); + _particles[next]->setPreviousParticle(previous); } // reset the next and previous particle entries of this particle @@ -118,7 +119,7 @@ void ConnectedParticleSystem::drawImplementation(osg::RenderInfo& renderInfo) co osg::State& state = *renderInfo.getState(); - const Particle* particle = (_startParticle != Particle::INVALID_INDEX) ? &_particles[_startParticle] : 0; + const Particle* particle = (_startParticle != Particle::INVALID_INDEX) ? _particles[_startParticle] : 0; if (!particle) return; ArrayData& ad = _bufferedArrayData[state.getContextID()]; @@ -158,7 +159,7 @@ void ConnectedParticleSystem::drawImplementation(osg::RenderInfo& renderInfo) co texcoords.push_back(osg::Vec2( particle->getSTexCoord(), 0.5f )); vertices.push_back(pos); - const Particle* nextParticle = (particle->getNextParticle() != Particle::INVALID_INDEX) ? &_particles[particle->getNextParticle()] : 0; + const Particle* nextParticle = (particle->getNextParticle() != Particle::INVALID_INDEX) ? _particles[particle->getNextParticle()] : 0; if (nextParticle) { osg::Vec3 startDelta = nextParticle->getPosition()-pos; @@ -170,8 +171,9 @@ void ConnectedParticleSystem::drawImplementation(osg::RenderInfo& renderInfo) co i<_maxNumberOfParticlesToSkip && ((distance2getNextParticle()!=Particle::INVALID_INDEX)); ++i) { - nextParticle = &_particles[nextParticle->getNextParticle()]; + nextParticle = _particles[nextParticle->getNextParticle()]; osg::Vec3 delta = nextParticle->getPosition()-pos; + distance2 = (delta^startDelta).length2(); } } @@ -194,7 +196,7 @@ void ConnectedParticleSystem::drawImplementation(osg::RenderInfo& renderInfo) co const osg::Vec4& color = particle->getCurrentColor(); const osg::Vec3& pos = particle->getPosition(); - const Particle* nextParticle = (particle->getNextParticle() != Particle::INVALID_INDEX) ? &_particles[particle->getNextParticle()] : 0; + const Particle* nextParticle = (particle->getNextParticle() != Particle::INVALID_INDEX) ? _particles[particle->getNextParticle()] : 0; if (nextParticle) { @@ -208,7 +210,7 @@ void ConnectedParticleSystem::drawImplementation(osg::RenderInfo& renderInfo) co i<_maxNumberOfParticlesToSkip && ((distance2getNextParticle()!=Particle::INVALID_INDEX)); ++i) { - nextParticle = &_particles[nextParticle->getNextParticle()]; + nextParticle = _particles[nextParticle->getNextParticle()]; delta = nextParticle->getPosition()-pos; distance2 = (delta^startDelta).length2(); } diff --git a/src/osgParticle/ParticleSystem.cpp b/src/osgParticle/ParticleSystem.cpp index 7ec7da0c918..3d7fe0a10cc 100644 --- a/src/osgParticle/ParticleSystem.cpp +++ b/src/osgParticle/ParticleSystem.cpp @@ -94,6 +94,9 @@ osgParticle::ParticleSystem::ParticleSystem(const ParticleSystem& copy, const os osgParticle::ParticleSystem::~ParticleSystem() { // OSG_NOTICE<<"ParticleSystem::~ParticleSystem() "<