openscenegraph
Emitter
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//osgParticle - Copyright (C) 2002 Marco Jez
14
15#ifndef OSGPARTICLE_EMITTER
16#define OSGPARTICLE_EMITTER 1
17
18#include <osgParticle/Export>
19#include <osgParticle/ParticleProcessor>
20#include <osgParticle/Particle>
21
22#include <osg/Object>
23#include <osg/Node>
24#include <osg/NodeVisitor>
25#include <osg/CopyOp>
26
27namespace osgParticle
28{
29
30 /** An abstract base class for particle emitters.
31 Descendant classes must override the <CODE>emitParticles()</CODE> method to generate new particles by
32 calling the <CODE>ParticleSystem::createParticle()</CODE> method on the particle system associated
33 to the emitter.
34 */
35 class OSGPARTICLE_EXPORT Emitter: public ParticleProcessor {
36 public:
37 Emitter();
38 Emitter(const Emitter& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
39
40 virtual const char* libraryName() const { return "osgParticle"; }
41 virtual const char* className() const { return "Emitter"; }
42 virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const Emitter*>(obj) != 0; }
43 virtual void accept(osg::NodeVisitor& nv) { if (nv.validNodeMask(*this)) { nv.pushOntoNodePath(this); nv.apply(*this); nv.popFromNodePath(); } }
44
45 void setParticleSystem(ParticleSystem* ps);
46
47 void setEstimatedMaxNumOfParticles(int num);
48 int getEstimatedMaxNumOfParticles() const { return _estimatedMaxNumOfParticles; }
49
50
51 /// Get the particle template.
52 inline const Particle& getParticleTemplate() const;
53
54 /// Set the particle template (particle is copied).
55 inline void setParticleTemplate(const Particle& p);
56
57 /// Return whether the particle system's default template should be used.
58 inline bool getUseDefaultTemplate() const;
59
60 /** Set whether the default particle template should be used.
61 When this flag is true, the particle template is ignored, and the
62 particle system's default template is used instead.
63 */
64 inline void setUseDefaultTemplate(bool v);
65
66 protected:
67 virtual ~Emitter() {}
68 Emitter& operator=(const Emitter&) { return *this; }
69
70 inline void process(double dt);
71
72 virtual void emitParticles(double dt) = 0;
73
74 bool _usedeftemp;
75 Particle _ptemp;
76
77 int _estimatedMaxNumOfParticles;
78 };
79
80 // INLINE FUNCTIONS
81
82 inline const Particle& Emitter::getParticleTemplate() const
83 {
84 return _ptemp;
85 }
86
87 inline void Emitter::setParticleTemplate(const Particle& p)
88 {
89 _ptemp = p;
90 _usedeftemp = false;
91 }
92
93 inline bool Emitter::getUseDefaultTemplate() const
94 {
95 return _usedeftemp;
96 }
97
98 inline void Emitter::setUseDefaultTemplate(bool v)
99 {
100 _usedeftemp = v;
101 }
102
103 inline void Emitter::process(double dt)
104 {
105 emitParticles(dt);
106 }
107
108
109}
110
111
112#endif
113