OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ParticleEffect.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2  *
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.
7  *
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.
12 */
13 
14 #ifndef OSGPARTICLE_PARTICLEEFFECT
15 #define OSGPARTICLE_PARTICLEEFFECT
16 
17 #include <osgParticle/Emitter>
18 #include <osgParticle/Program>
19 
20 namespace osgParticle
21 {
22 
24  {
25  public:
26 
27  explicit ParticleEffect(bool automaticSetup=true):
28  _automaticSetup(automaticSetup),
29  _useLocalParticleSystem(true),
30  _scale(1.0f),
31  _intensity(1.0f),
32  _startTime(0.0),
33  _emitterDuration(1.0),
34  _wind(0.0f,0.0f,0.0f)
35  {}
36 
38 
39 
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(); } }
44 
45  void setAutomaticSetup(bool flag) { _automaticSetup = flag; }
46  bool getAutomaticSetup() const { return _automaticSetup; }
47 
48  void setUseLocalParticleSystem(bool local);
49  bool getUseLocalParticleSystem() const { return _useLocalParticleSystem; }
50 
51  void setTextureFileName(const std::string& filename);
52  const std::string& getTextureFileName() const { return _textureFileName; }
53 
54  void setDefaultParticleTemplate(const Particle& p);
55  const Particle& getDefaultParticleTemplate() const { return _defaultParticleTemplate; }
56 
57  void setPosition(const osg::Vec3& position);
58  const osg::Vec3& getPosition() const { return _position; }
59 
60  void setScale(float scale);
61  float getScale() const { return _scale; }
62 
63  void setIntensity(float intensity);
64  float getIntensity() const { return _intensity; }
65 
66  void setStartTime(double startTime);
67  double getStartTime() const { return _startTime; }
68 
69  void setEmitterDuration(double duration);
70  double getEmitterDuration() const { return _emitterDuration; }
71 
72  void setParticleDuration(double duration);
73  double getParticleDuration() const { return _defaultParticleTemplate.getLifeTime(); }
74 
75  void setWind(const osg::Vec3& wind);
76  const osg::Vec3& getWind() const { return _wind; }
77 
79  bool areAllParticlesDead() const { return _particleSystem.valid()?_particleSystem->areAllParticlesDead():true; }
80 
81  virtual Emitter* getEmitter() = 0;
82  virtual const Emitter* getEmitter() const = 0;
83 
84  virtual Program* getProgram() = 0;
85  virtual const Program* getProgram() const = 0;
86 
87  void setParticleSystem(ParticleSystem* ps);
88  inline ParticleSystem* getParticleSystem() { return _particleSystem.get(); }
89  inline const ParticleSystem* getParticleSystem() const { return _particleSystem.get(); }
90 
91  virtual void setDefaults();
92 
93  virtual void setUpEmitterAndProgram() = 0;
94 
95  virtual void buildEffect();
96 
97  protected:
98 
99  virtual ~ParticleEffect() {}
100 
102 
104 
106  std::string _textureFileName;
109  float _scale;
110  float _intensity;
111  double _startTime;
114  };
115 
116 }
117 
118 #endif
double getEmitterDuration() const
bool areAllParticlesDead() const
Get whether all particles are dead.
ParticleSystem * getParticleSystem()
const Particle & getDefaultParticleTemplate() const
bool getUseLocalParticleSystem() const
const osg::Vec3 & getPosition() const
void popFromNodePath()
Definition: NodeVisitor.h:204
void setAutomaticSetup(bool flag)
bool validNodeMask(const osg::Node &node) const
Definition: NodeVisitor.h:166
const std::string & getTextureFileName() const
virtual void accept(osg::NodeVisitor &nv)
const osg::Vec3 & getWind() const
double getParticleDuration() const
#define OSGPARTICLE_EXPORT
Definition: Export.h:40
ParticleEffect(bool automaticSetup=true)
osg::ref_ptr< ParticleSystem > _particleSystem
const ParticleSystem * getParticleSystem() const
virtual void apply(Drawable &drawable)
virtual const char * libraryName() const
void pushOntoNodePath(Node *node)
Definition: NodeVisitor.h:198
virtual const char * className() const
double getStartTime() const
virtual bool isSameKindAs(const osg::Object *obj) const