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_MODULAREMITTER
16#define OSGPARTICLE_MODULAREMITTER 1
17
18#include <osgParticle/Export>
19#include <osgParticle/Emitter>
20#include <osgParticle/Particle>
21#include <osgParticle/RandomRateCounter>
22#include <osgParticle/Placer>
23#include <osgParticle/PointPlacer>
24#include <osgParticle/Shooter>
25#include <osgParticle/RadialShooter>
26#include <osgParticle/ParticleSystem>
27
28#include <osg/ref_ptr>
29#include <osg/CopyOp>
30#include <osg/Object>
31#include <osg/Node>
32#include <osg/NodeVisitor>
33
34namespace osgParticle
35{
36
37    /**    An emitter class that holds three objects to control the creation of particles.
38        These objects are a <I>counter</I>, a <I>placer</I> and a <I>shooter</I>.
39        The counter controls the number of particles to be emitted at each frame;
40        the placer must initialize the particle's position vector, while the shooter initializes
41        its velocity vector.
42        You can use the predefined counter/placer/shooter classes, or you can create your own.
43    */
44    class OSGPARTICLE_EXPORT ModularEmitter: public Emitter {
45    public:
46        ModularEmitter();
47        ModularEmitter(const ModularEmitter& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
48
49        META_Node(osgParticle,ModularEmitter);
50
51        /// Get the counter object.
52        inline Counter* getCounter();
53
54        /// Get the const Counter object.
55        inline const Counter* getCounter() const;
56
57        /// Set the Counter object.
58        inline void setCounter(Counter* c);
59
60        /// Get the ratio between number of particle to create in compensation for movement of the emitter
61        inline float getNumParticlesToCreateMovementCompensationRatio() const;
62
63        /// Set the ratio between number of particle to create in compenstation for movement of the emitter
64        inline void setNumParticlesToCreateMovementCompensationRatio(float r);
65
66
67        /// Get the Placer object.
68        inline Placer* getPlacer();
69
70        /// Get the const Placer object.
71        inline const Placer* getPlacer() const;
72
73        /// Set the Placer object.
74        inline void setPlacer(Placer* p);
75
76        /// Get the Shooter object.
77        inline Shooter *getShooter();
78
79        /// Get the const Shooter object.
80        inline const Shooter *getShooter() const;
81
82        /// Set the Shooter object.
83        inline void setShooter(Shooter *s);
84
85    protected:
86        virtual ~ModularEmitter() {}
87        ModularEmitter &operator=(const ModularEmitter &) { return *this; }
88
89        virtual void emitParticles(double dt);
90
91    private:
92
93        float _numParticleToCreateMovementCompensationRatio;
94        osg::ref_ptr<Counter> _counter;
95        osg::ref_ptr<Placer> _placer;
96        osg::ref_ptr<Shooter> _shooter;
97    };
98
99    // INLINE FUNCTIONS
100
101    inline Counter* ModularEmitter::getCounter()
102    {
103        return _counter.get();
104    }
105
106    inline const Counter* ModularEmitter::getCounter() const
107    {
108        return _counter.get();
109    }
110
111    inline void ModularEmitter::setCounter(Counter* c)
112    {
113        _counter = c;
114    }
115
116    inline float ModularEmitter::getNumParticlesToCreateMovementCompensationRatio() const
117    {
118        return _numParticleToCreateMovementCompensationRatio;
119    }
120
121    inline void ModularEmitter::setNumParticlesToCreateMovementCompensationRatio(float r)
122    {
123        _numParticleToCreateMovementCompensationRatio = r;
124    }
125
126    inline Placer* ModularEmitter::getPlacer()
127    {
128        return _placer.get();
129    }
130
131    inline const Placer* ModularEmitter::getPlacer() const
132    {
133        return _placer.get();
134    }
135
136    inline void ModularEmitter::setPlacer(Placer* p)
137    {
138        _placer = p;
139    }
140
141    inline Shooter *ModularEmitter::getShooter()
142    {
143        return _shooter.get();
144    }
145
146    inline const Shooter *ModularEmitter::getShooter() const
147    {
148        return _shooter.get();
149    }
150
151    inline void ModularEmitter::setShooter(Shooter *s)
152    {
153        _shooter = s;
154    }
155
156}
157
158#endif
159