2005-04-15 05:41:28 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2005 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2002-06-05 20:44:55 +08:00
|
|
|
//osgParticle - Copyright (C) 2002 Marco Jez
|
|
|
|
|
2005-04-29 17:47:57 +08:00
|
|
|
#ifndef OSGPARTICLE_MODULARPROGRAM
|
|
|
|
#define OSGPARTICLE_MODULARPROGRAM 1
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
#include <osgParticle/Export>
|
|
|
|
#include <osgParticle/Program>
|
|
|
|
#include <osgParticle/Operator>
|
|
|
|
|
|
|
|
#include <osg/CopyOp>
|
|
|
|
#include <osg/Object>
|
|
|
|
#include <osg/Node>
|
|
|
|
#include <osg/NodeVisitor>
|
|
|
|
|
|
|
|
namespace osgParticle
|
|
|
|
{
|
|
|
|
|
|
|
|
/** A program class for performing operations on particles using a sequence of <I>operators</I>.
|
|
|
|
To use a <CODE>ModularProgram</CODE> you have to create some <CODE>Operator</CODE> objects and
|
|
|
|
add them to the program.
|
|
|
|
All operators will be applied to each particle in the same order they've been added to the program.
|
|
|
|
*/
|
|
|
|
class OSGPARTICLE_EXPORT ModularProgram: public Program {
|
|
|
|
public:
|
|
|
|
ModularProgram();
|
2005-04-29 17:47:57 +08:00
|
|
|
ModularProgram(const ModularProgram& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
|
2002-06-05 20:44:55 +08:00
|
|
|
|
2002-06-06 21:25:36 +08:00
|
|
|
META_Node(osgParticle,ModularProgram);
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
/// Get the number of operators.
|
|
|
|
inline int numOperators() const;
|
|
|
|
|
|
|
|
/// Add an operator to the list.
|
2005-04-29 17:47:57 +08:00
|
|
|
inline void addOperator(Operator* o);
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
/// Get a pointer to an operator in the list.
|
2005-04-29 17:47:57 +08:00
|
|
|
inline Operator* getOperator(int i);
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
/// Get a const pointer to an operator in the list.
|
2005-04-29 17:47:57 +08:00
|
|
|
inline const Operator* getOperator(int i) const;
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
/// Remove an operator from the list.
|
|
|
|
inline void removeOperator(int i);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~ModularProgram() {}
|
2005-04-29 17:47:57 +08:00
|
|
|
ModularProgram& operator=(const ModularProgram&) { return *this; }
|
2002-06-05 20:44:55 +08:00
|
|
|
|
|
|
|
void execute(double dt);
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef std::vector<osg::ref_ptr<Operator> > Operator_vector;
|
|
|
|
|
2005-04-29 17:47:57 +08:00
|
|
|
Operator_vector _operators;
|
2002-06-05 20:44:55 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// INLINE FUNCTIONS
|
|
|
|
|
|
|
|
inline int ModularProgram::numOperators() const
|
|
|
|
{
|
2005-04-29 17:47:57 +08:00
|
|
|
return static_cast<int>(_operators.size());
|
2002-06-05 20:44:55 +08:00
|
|
|
}
|
|
|
|
|
2005-04-29 17:47:57 +08:00
|
|
|
inline void ModularProgram::addOperator(Operator* o)
|
2002-06-05 20:44:55 +08:00
|
|
|
{
|
2005-04-29 17:47:57 +08:00
|
|
|
_operators.push_back(o);
|
2002-06-05 20:44:55 +08:00
|
|
|
}
|
|
|
|
|
2005-04-29 17:47:57 +08:00
|
|
|
inline Operator* ModularProgram::getOperator(int i)
|
2002-06-05 20:44:55 +08:00
|
|
|
{
|
2005-04-29 17:47:57 +08:00
|
|
|
return _operators[i].get();
|
2002-06-05 20:44:55 +08:00
|
|
|
}
|
|
|
|
|
2005-04-29 17:47:57 +08:00
|
|
|
inline const Operator* ModularProgram::getOperator(int i) const
|
2002-06-05 20:44:55 +08:00
|
|
|
{
|
2005-04-29 17:47:57 +08:00
|
|
|
return _operators[i].get();
|
2002-06-05 20:44:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void ModularProgram::removeOperator(int i)
|
|
|
|
{
|
2005-04-29 17:47:57 +08:00
|
|
|
_operators.erase(_operators.begin()+i);
|
2002-06-05 20:44:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|