openscenegraph
Operator
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
24namespace 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
Definition Operator:35
virtual const char * libraryName() const
Definition Operator:40
void setEnabled(bool v)
Enable or disable this operator.
Definition Operator:107
virtual ~Operator()
Definition Operator:83
virtual void endOperate()
Do something after all particles have been processed.
Definition Operator:80
virtual const char * className() const
Definition Operator:41
virtual void operateParticles(ParticleSystem *ps, double dt)
Definition Operator:55
bool isEnabled() const
Get whether this operator is enabled.
Definition Operator:102
Operator & operator=(const Operator &)
Definition Operator:84
virtual void operate(Particle *P, double dt)=0
Operator()
Definition Operator:92
virtual bool isSameKindAs(const osg::Object *obj) const
Definition Operator:42
virtual void beginOperate(Program *)
Definition Operator:77
Definition ParticleSystem:54
Particle * getParticle(int i)
Get a pointer to the i-th particle.
Definition ParticleSystem:437
int numParticles() const
Get the number of allocated particles (alive + dead).
Definition ParticleSystem:427
Definition Particle:47
bool isAlive() const
Get whether the particle is still alive.
Definition Particle:348
Definition osgParticle/Program:36
Definition CopyOp:41
@ SHALLOW_COPY
Definition CopyOp:47
Definition Object:61
Definition AccelOperator:27
author: Julien Valentin 2017 (mp3butcher@hotmail.com)
Definition AlphaFunc:19