ModularProgram 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. #ifndef OSGPARTICLE_MODULARPROGRAM
  15. #define OSGPARTICLE_MODULARPROGRAM 1
  16. #include <osgParticle/Export>
  17. #include <osgParticle/Program>
  18. #include <osgParticle/Operator>
  19. #include <osg/CopyOp>
  20. #include <osg/Object>
  21. #include <osg/Node>
  22. #include <osg/NodeVisitor>
  23. namespace osgParticle
  24. {
  25. /** A program class for performing operations on particles using a sequence of <I>operators</I>.
  26. To use a <CODE>ModularProgram</CODE> you have to create some <CODE>Operator</CODE> objects and
  27. add them to the program.
  28. All operators will be applied to each particle in the same order they've been added to the program.
  29. */
  30. class OSGPARTICLE_EXPORT ModularProgram: public Program {
  31. public:
  32. ModularProgram();
  33. ModularProgram(const ModularProgram& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
  34. META_Node(osgParticle,ModularProgram);
  35. /// Get the number of operators.
  36. inline int numOperators() const;
  37. /// Add an operator to the list.
  38. inline void addOperator(Operator* o);
  39. /// Get a pointer to an operator in the list.
  40. inline Operator* getOperator(int i);
  41. /// Get a const pointer to an operator in the list.
  42. inline const Operator* getOperator(int i) const;
  43. /// Remove an operator from the list.
  44. inline void removeOperator(int i);
  45. protected:
  46. virtual ~ModularProgram() {}
  47. ModularProgram& operator=(const ModularProgram&) { return *this; }
  48. void execute(double dt);
  49. private:
  50. typedef std::vector<osg::ref_ptr<Operator> > Operator_vector;
  51. Operator_vector _operators;
  52. };
  53. // INLINE FUNCTIONS
  54. inline int ModularProgram::numOperators() const
  55. {
  56. return static_cast<int>(_operators.size());
  57. }
  58. inline void ModularProgram::addOperator(Operator* o)
  59. {
  60. _operators.push_back(o);
  61. }
  62. inline Operator* ModularProgram::getOperator(int i)
  63. {
  64. return _operators[i].get();
  65. }
  66. inline const Operator* ModularProgram::getOperator(int i) const
  67. {
  68. return _operators[i].get();
  69. }
  70. inline void ModularProgram::removeOperator(int i)
  71. {
  72. _operators.erase(_operators.begin()+i);
  73. }
  74. }
  75. #endif