openscenegraph
ParticleEffect
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
20namespace osgParticle
21{
22
23 class OSGPARTICLE_EXPORT ParticleEffect : public osg::Group
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
37 ParticleEffect(const ParticleEffect& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
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
78 /// Get whether all particles are dead
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 template<class T> void setParticleSystem(const osg::ref_ptr<T>& ri) { setParticleSystem(ri.get()); }
89
90 inline ParticleSystem* getParticleSystem() { return _particleSystem.get(); }
91 inline const ParticleSystem* getParticleSystem() const { return _particleSystem.get(); }
92
93 virtual void setDefaults();
94
95 virtual void setUpEmitterAndProgram() = 0;
96
97 virtual void buildEffect();
98
99 protected:
100
101 virtual ~ParticleEffect() {}
102
103 bool _automaticSetup;
104
105 osg::ref_ptr<ParticleSystem> _particleSystem;
106
107 bool _useLocalParticleSystem;
108 std::string _textureFileName;
109 Particle _defaultParticleTemplate;
110 osg::Vec3 _position;
111 float _scale;
112 float _intensity;
113 double _startTime;
114 double _emitterDuration;
115 osg::Vec3 _wind;
116 };
117
118}
119
120#endif