1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
13//osgParticle - Copyright (C) 2002 Marco Jez
15#ifndef OSGPARTICLE_PARTICLESYSTEMUPDATER
16#define OSGPARTICLE_PARTICLESYSTEMUPDATER 1
18#include <osgParticle/Export>
19#include <osgParticle/ParticleSystem>
27#include <osg/NodeVisitor>
29#include <osgUtil/CullVisitor>
34 /** A useful node class for updating particle systems automatically.
35 When a ParticleSystemUpdater is traversed by a cull visitor, it calls the
36 update() method on the specified particle systems. You should place this updater
37 AFTER other nodes like emitters and programs.
39 class OSGPARTICLE_EXPORT ParticleSystemUpdater: public osg::Node {
41 ParticleSystemUpdater();
42 ParticleSystemUpdater(const ParticleSystemUpdater& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
44 META_Node(osgParticle,ParticleSystemUpdater);
46 /// Add a particle system to the list.
47 virtual bool addParticleSystem(ParticleSystem* ps);
49 /// Remove a particle system from the list (by pointer).
50 virtual bool removeParticleSystem(ParticleSystem* ps);
52 /// Remove a particle system(s) from the list (by index).
53 virtual bool removeParticleSystem(unsigned int i, unsigned int numParticleSystemsToRemove=1);
55 /// Replace ParticleSystem with another ParticleSystem.
56 virtual bool replaceParticleSystem(ParticleSystem* origPS, ParticleSystem* newPS);
58 /// set a particle system by index.
59 virtual bool setParticleSystem( unsigned int i, ParticleSystem* ps );
61 /// Return the number of particle systems on the list.
62 inline unsigned int getNumParticleSystems() const;
64 /// Get a particle system from the list.
65 inline ParticleSystem* getParticleSystem(unsigned int i);
67 /// Get a particle system from the list.
68 inline const ParticleSystem* getParticleSystem(unsigned int i) const;
70 /// return true if ParticleSystem is contained within ParticlsSystemUpdater.
71 inline bool containsParticleSystem( const ParticleSystem* ps ) const;
73 /// get index number of ParticleSystem.
74 inline unsigned int getParticleSystemIndex( const ParticleSystem* ps ) const;
76 virtual void traverse(osg::NodeVisitor& nv);
78 virtual osg::BoundingSphere computeBound() const;
81 virtual ~ParticleSystemUpdater() {}
82 ParticleSystemUpdater &operator=(const ParticleSystemUpdater &) { return *this; }
85 typedef std::vector<osg::ref_ptr<ParticleSystem> > ParticleSystem_Vector;
87 ParticleSystem_Vector _psv;
90 //added 1/17/06- bgandere@nps.edu
91 //a var to keep from doing multiple updates per frame
92 unsigned int _frameNumber;
97 inline unsigned int ParticleSystemUpdater::getNumParticleSystems() const
99 return static_cast<int>(_psv.size());
102 inline ParticleSystem* ParticleSystemUpdater::getParticleSystem(unsigned int i)
104 return _psv[i].get();
107 inline const ParticleSystem* ParticleSystemUpdater::getParticleSystem(unsigned int i) const
109 return _psv[i].get();
112 inline bool ParticleSystemUpdater::containsParticleSystem( const ParticleSystem* ps ) const
114 for( ParticleSystem_Vector::const_iterator itr=_psv.begin();
118 if( itr->get() == ps ) return true;
123 inline unsigned int ParticleSystemUpdater::getParticleSystemIndex( const ParticleSystem* ps ) const
125 for( unsigned int particleSystemNum=0; particleSystemNum<_psv.size(); ++particleSystemNum )
127 if( _psv[particleSystemNum] == ps ) return particleSystemNum;
129 return _psv.size(); // node not found.