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.
14#ifndef OSGPARTICLE_PARTICLEEFFECT
15#define OSGPARTICLE_PARTICLEEFFECT
17#include <osgParticle/Emitter>
18#include <osgParticle/Program>
23 class OSGPARTICLE_EXPORT ParticleEffect : public osg::Group
27 explicit ParticleEffect(bool automaticSetup=true):
28 _automaticSetup(automaticSetup),
29 _useLocalParticleSystem(true),
33 _emitterDuration(1.0),
37 ParticleEffect(const ParticleEffect& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
40 virtual const char* libraryName() const { return "osgParticle"; }
41 virtual const char* className() const { return "ParticleEffect"; }
42 virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const ParticleEffect*>(obj) != 0; }
43 virtual void accept(osg::NodeVisitor& nv) { if (nv.validNodeMask(*this)) { nv.pushOntoNodePath(this); nv.apply(*this); nv.popFromNodePath(); } }
45 void setAutomaticSetup(bool flag) { _automaticSetup = flag; }
46 bool getAutomaticSetup() const { return _automaticSetup; }
48 void setUseLocalParticleSystem(bool local);
49 bool getUseLocalParticleSystem() const { return _useLocalParticleSystem; }
51 void setTextureFileName(const std::string& filename);
52 const std::string& getTextureFileName() const { return _textureFileName; }
54 void setDefaultParticleTemplate(const Particle& p);
55 const Particle& getDefaultParticleTemplate() const { return _defaultParticleTemplate; }
57 void setPosition(const osg::Vec3& position);
58 const osg::Vec3& getPosition() const { return _position; }
60 void setScale(float scale);
61 float getScale() const { return _scale; }
63 void setIntensity(float intensity);
64 float getIntensity() const { return _intensity; }
66 void setStartTime(double startTime);
67 double getStartTime() const { return _startTime; }
69 void setEmitterDuration(double duration);
70 double getEmitterDuration() const { return _emitterDuration; }
72 void setParticleDuration(double duration);
73 double getParticleDuration() const { return _defaultParticleTemplate.getLifeTime(); }
75 void setWind(const osg::Vec3& wind);
76 const osg::Vec3& getWind() const { return _wind; }
78 /// Get whether all particles are dead
79 bool areAllParticlesDead() const { return _particleSystem.valid()?_particleSystem->areAllParticlesDead():true; }
81 virtual Emitter* getEmitter() = 0;
82 virtual const Emitter* getEmitter() const = 0;
84 virtual Program* getProgram() = 0;
85 virtual const Program* getProgram() const = 0;
87 void setParticleSystem(ParticleSystem* ps);
88 template<class T> void setParticleSystem(const osg::ref_ptr<T>& ri) { setParticleSystem(ri.get()); }
90 inline ParticleSystem* getParticleSystem() { return _particleSystem.get(); }
91 inline const ParticleSystem* getParticleSystem() const { return _particleSystem.get(); }
93 virtual void setDefaults();
95 virtual void setUpEmitterAndProgram() = 0;
97 virtual void buildEffect();
101 virtual ~ParticleEffect() {}
103 bool _automaticSetup;
105 osg::ref_ptr<ParticleSystem> _particleSystem;
107 bool _useLocalParticleSystem;
108 std::string _textureFileName;
109 Particle _defaultParticleTemplate;
114 double _emitterDuration;