OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Operator.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 //osgParticle - Copyright (C) 2002 Marco Jez
14 
15 #ifndef OSGPARTICLE_OPERATOR
16 #define OSGPARTICLE_OPERATOR 1
17 
18 #include <osgParticle/Program>
19 
20 #include <osg/CopyOp>
21 #include <osg/Object>
22 #include <osg/Matrix>
23 
24 namespace osgParticle
25 {
26 
27  // forward declaration to avoid including the whole header file
28  class Particle;
29 
35  class Operator: public osg::Object {
36  public:
37  inline Operator();
38  inline Operator(const Operator& 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 "Operator"; }
42  virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const Operator* >(obj) != 0; }
43 
45  inline bool isEnabled() const;
46 
48  inline void setEnabled(bool v);
49 
55  virtual void operateParticles(ParticleSystem* ps, double dt)
56  {
57  int n = ps->numParticles();
58  for (int i=0; i<n; ++i)
59  {
60  Particle* P = ps->getParticle(i);
61  if (P->isAlive() && isEnabled()) operate(P, dt);
62  }
63  }
64 
70  virtual void operate(Particle* P, double dt) = 0;
71 
77  virtual void beginOperate(Program *) {}
78 
80  virtual void endOperate() {}
81 
82  protected:
83  virtual ~Operator() {}
84  Operator &operator=(const Operator &) { return *this; }
85 
86  private:
87  bool _enabled;
88  };
89 
90  // INLINE FUNCTIONS
91 
93  : osg::Object(), _enabled(true)
94  {
95  }
96 
97  inline Operator::Operator(const Operator& copy, const osg::CopyOp& copyop)
98  : osg::Object(copy, copyop), _enabled(copy._enabled)
99  {
100  }
101 
102  inline bool Operator::isEnabled() const
103  {
104  return _enabled;
105  }
106 
107  inline void Operator::setEnabled(bool v)
108  {
109  _enabled = v;
110  }
111 
112 
113 }
114 
115 #endif
int numParticles() const
Get the number of allocated particles (alive + dead).
virtual bool isSameKindAs(const osg::Object *obj) const
Definition: Operator.h:42
virtual ~Operator()
Definition: Operator.h:83
bool isEnabled() const
Get whether this operator is enabled.
Definition: Operator.h:102
void setEnabled(bool v)
Enable or disable this operator.
Definition: Operator.h:107
virtual void endOperate()
Do something after all particles have been processed.
Definition: Operator.h:80
Operator & operator=(const Operator &)
Definition: Operator.h:84
virtual const char * className() const
Definition: Operator.h:41
bool isAlive() const
Get whether the particle is still alive.
Definition: Particle.h:362
virtual void operate(Particle *P, double dt)=0
virtual void operateParticles(ParticleSystem *ps, double dt)
Definition: Operator.h:55
Definition: AlphaFunc.h:19
Particle * getParticle(int i)
Get a pointer to the i-th particle.
virtual void beginOperate(Program *)
Definition: Operator.h:77
virtual const char * libraryName() const
Definition: Operator.h:40