Emitter 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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_EMITTER
  15. #define OSGPARTICLE_EMITTER 1
  16. #include <osgParticle/Export>
  17. #include <osgParticle/ParticleProcessor>
  18. #include <osgParticle/Particle>
  19. #include <osg/Object>
  20. #include <osg/Node>
  21. #include <osg/NodeVisitor>
  22. #include <osg/CopyOp>
  23. namespace osgParticle
  24. {
  25. /** An abstract base class for particle emitters.
  26. Descendant classes must override the <CODE>emitParticles()</CODE> method to generate new particles by
  27. calling the <CODE>ParticleSystem::createParticle()</CODE> method on the particle system associated
  28. to the emitter.
  29. */
  30. class OSGPARTICLE_EXPORT Emitter: public ParticleProcessor {
  31. public:
  32. Emitter();
  33. Emitter(const Emitter& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
  34. virtual const char* libraryName() const { return "osgParticle"; }
  35. virtual const char* className() const { return "Emitter"; }
  36. virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const Emitter*>(obj) != 0; }
  37. virtual void accept(osg::NodeVisitor& nv) { if (nv.validNodeMask(*this)) { nv.pushOntoNodePath(this); nv.apply(*this); nv.popFromNodePath(); } }
  38. void setParticleSystem(ParticleSystem* ps);
  39. void setEstimatedMaxNumOfParticles(int num);
  40. int getEstimatedMaxNumOfParticles() const { return _estimatedMaxNumOfParticles; }
  41. /// Get the particle template.
  42. inline const Particle& getParticleTemplate() const;
  43. /// Set the particle template (particle is copied).
  44. inline void setParticleTemplate(const Particle& p);
  45. /// Return whether the particle system's default template should be used.
  46. inline bool getUseDefaultTemplate() const;
  47. /** Set whether the default particle template should be used.
  48. When this flag is true, the particle template is ignored, and the
  49. particle system's default template is used instead.
  50. */
  51. inline void setUseDefaultTemplate(bool v);
  52. protected:
  53. virtual ~Emitter() {}
  54. Emitter& operator=(const Emitter&) { return *this; }
  55. inline void process(double dt);
  56. virtual void emitParticles(double dt) = 0;
  57. bool _usedeftemp;
  58. Particle _ptemp;
  59. int _estimatedMaxNumOfParticles;
  60. };
  61. // INLINE FUNCTIONS
  62. inline const Particle& Emitter::getParticleTemplate() const
  63. {
  64. return _ptemp;
  65. }
  66. inline void Emitter::setParticleTemplate(const Particle& p)
  67. {
  68. _ptemp = p;
  69. _usedeftemp = false;
  70. }
  71. inline bool Emitter::getUseDefaultTemplate() const
  72. {
  73. return _usedeftemp;
  74. }
  75. inline void Emitter::setUseDefaultTemplate(bool v)
  76. {
  77. _usedeftemp = v;
  78. }
  79. inline void Emitter::process(double dt)
  80. {
  81. emitParticles(dt);
  82. }
  83. }
  84. #endif