1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
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.
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.
13//osgParticle - Copyright (C) 2002 Marco Jez
15#ifndef OSGPARTICLE_OPERATOR
16#define OSGPARTICLE_OPERATOR 1
18#include <osgParticle/Program>
27 // forward declaration to avoid including the whole header file
30 /** An abstract base class used by <CODE>ModularProgram</CODE> to perform operations on particles before they are updated.
31 To implement a new operator, derive from this class and override the <CODE>operate()</CODE> method.
32 You should also override the <CODE>beginOperate()</CODE> method to query the calling program for the reference frame
33 used, and initialize the right transformations if needed.
35 class Operator: public osg::Object {
38 inline Operator(const Operator& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
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; }
44 /// Get whether this operator is enabled.
45 inline bool isEnabled() const;
47 /// Enable or disable this operator.
48 inline void setEnabled(bool v);
50 /** Do something on all emitted particles.
51 This method is called by <CODE>ModularProgram</CODE> objects to perform some operations
52 on the particles. By default, it will call the <CODE>operate()</CODE> method for each particle.
53 You must override it in descendant classes.
55 virtual void operateParticles(ParticleSystem* ps, double dt)
57 int n = ps->numParticles();
58 for (int i=0; i<n; ++i)
60 Particle* P = ps->getParticle(i);
61 if (P->isAlive() && isEnabled()) operate(P, dt);
65 /** Do something on a particle.
66 You must override it in descendant classes. Common operations
67 consist of modifying the particle's velocity vector. The <CODE>dt</CODE> parameter is
68 the time elapsed from last operation.
70 virtual void operate(Particle* P, double dt) = 0;
72 /** Do something before processing particles via the <CODE>operate()</CODE> method.
73 Overriding this method could be necessary to query the calling <CODE>Program</CODE> object
74 for the current reference frame. If the reference frame is RELATIVE_RF, then your
75 class should prepare itself to do all operations in local coordinates.
77 virtual void beginOperate(Program *) {}
79 /// Do something after all particles have been processed.
80 virtual void endOperate() {}
83 virtual ~Operator() {}
84 Operator &operator=(const Operator &) { return *this; }
92 inline Operator::Operator()
93 : osg::Object(), _enabled(true)
97 inline Operator::Operator(const Operator& copy, const osg::CopyOp& copyop)
98 : osg::Object(copy, copyop), _enabled(copy._enabled)
102 inline bool Operator::isEnabled() const
107 inline void Operator::setEnabled(bool v)