//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield //Distributed under the terms of the GNU Library General Public License (LGPL) //as published by the Free Software Foundation. //osgParticle - Copyright (C) 2002 Marco Jez #ifndef OSGPARTICLE_PARTICLESYSTEMUPDATER_ #define OSGPARTICLE_PARTICLESYSTEMUPDATER_ 1 #include #include #include #include #include #include #include #include #include namespace osgParticle { /** A useful node class for updating particle systems automatically. When a ParticleSystemUpdater is traversed by a cull visitor, it calls the update() method on the specified particle systems. You should place this updater AFTER other nodes like emitters and programs. */ class OSGPARTICLE_EXPORT ParticleSystemUpdater: public osg::Node { public: ParticleSystemUpdater(); ParticleSystemUpdater(const ParticleSystemUpdater ©, const osg::CopyOp ©op = osg::CopyOp::SHALLOW_COPY); META_Node(osgParticle,ParticleSystemUpdater); /// Return the number of particle systems on the list. inline int numParticleSystems() const; /// Add a particle system to the list. inline void addParticleSystem(ParticleSystem *ps); /// Get a const particle system from the list. inline const ParticleSystem *getParticleSystem(int i) const; /// Get a particle system from the list. inline ParticleSystem *getParticleSystem(int i); /// Find a particle system. inline int findParticleSystem(ParticleSystem *ps) const; /// Remove a particle system from the list (by index). inline void removeParticleSystem(int i); /// Remove a particle system from the list (by pointer). inline bool removeParticleSystem(ParticleSystem *ps); virtual void traverse(osg::NodeVisitor &nv); protected: virtual ~ParticleSystemUpdater() {} ParticleSystemUpdater &operator=(const ParticleSystemUpdater &) { return *this; } inline virtual const bool computeBound() const; private: typedef std::vector > ParticleSystem_Vector; ParticleSystem_Vector psv_; double t0_; }; // INLINE FUNCTIONS inline const bool ParticleSystemUpdater::computeBound() const { _bsphere.init(); _bsphere_computed = true; return true; } inline int ParticleSystemUpdater::numParticleSystems() const { return static_cast(psv_.size()); } inline void ParticleSystemUpdater::addParticleSystem(ParticleSystem *ps) { psv_.push_back(ps); } inline const ParticleSystem *ParticleSystemUpdater::getParticleSystem(int i) const { return psv_[i].get(); } inline ParticleSystem *ParticleSystemUpdater::getParticleSystem(int i) { return psv_[i].get(); } inline void ParticleSystemUpdater::removeParticleSystem(int i) { psv_.erase(psv_.begin()+i); } inline int ParticleSystemUpdater::findParticleSystem(ParticleSystem *ps) const { ParticleSystem_Vector::const_iterator i; int j = 0; for (i=psv_.begin(); i!=psv_.end(); ++i, ++j) { if (i->get() == ps) return j; } return -1; } inline bool ParticleSystemUpdater::removeParticleSystem(ParticleSystem *ps) { int i = findParticleSystem(ps); if (i == -1) return false; removeParticleSystem(i); return true; } } #endif