ModularEmitter 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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_MODULAREMITTER
  15. #define OSGPARTICLE_MODULAREMITTER 1
  16. #include <osgParticle/Export>
  17. #include <osgParticle/Emitter>
  18. #include <osgParticle/Particle>
  19. #include <osgParticle/RandomRateCounter>
  20. #include <osgParticle/Placer>
  21. #include <osgParticle/PointPlacer>
  22. #include <osgParticle/Shooter>
  23. #include <osgParticle/RadialShooter>
  24. #include <osgParticle/ParticleSystem>
  25. #include <osg/ref_ptr>
  26. #include <osg/CopyOp>
  27. #include <osg/Object>
  28. #include <osg/Node>
  29. #include <osg/NodeVisitor>
  30. namespace osgParticle
  31. {
  32. /** An emitter class that holds three objects to control the creation of particles.
  33. These objects are a <I>counter</I>, a <I>placer</I> and a <I>shooter</I>.
  34. The counter controls the number of particles to be emitted at each frame;
  35. the placer must initialize the particle's position vector, while the shooter initializes
  36. its velocity vector.
  37. You can use the predefined counter/placer/shooter classes, or you can create your own.
  38. */
  39. class OSGPARTICLE_EXPORT ModularEmitter: public Emitter {
  40. public:
  41. ModularEmitter();
  42. ModularEmitter(const ModularEmitter& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
  43. META_Node(osgParticle,ModularEmitter);
  44. /// Get the counter object.
  45. inline Counter* getCounter();
  46. /// Get the const Counter object.
  47. inline const Counter* getCounter() const;
  48. /// Set the Counter object.
  49. inline void setCounter(Counter* c);
  50. /// Get the ratio between number of particle to create in compensation for movement of the emitter
  51. inline float getNumParticlesToCreateMovementCompensationRatio() const;
  52. /// Set the ratio between number of particle to create in compenstation for movement of the emitter
  53. inline void setNumParticlesToCreateMovementCompensationRatio(float r);
  54. /// Get the Placer object.
  55. inline Placer* getPlacer();
  56. /// Get the const Placer object.
  57. inline const Placer* getPlacer() const;
  58. /// Set the Placer object.
  59. inline void setPlacer(Placer* p);
  60. /// Get the Shooter object.
  61. inline Shooter *getShooter();
  62. /// Get the const Shooter object.
  63. inline const Shooter *getShooter() const;
  64. /// Set the Shooter object.
  65. inline void setShooter(Shooter *s);
  66. protected:
  67. virtual ~ModularEmitter() {}
  68. ModularEmitter &operator=(const ModularEmitter &) { return *this; }
  69. virtual void emitParticles(double dt);
  70. private:
  71. float _numParticleToCreateMovementCompensationRatio;
  72. osg::ref_ptr<Counter> _counter;
  73. osg::ref_ptr<Placer> _placer;
  74. osg::ref_ptr<Shooter> _shooter;
  75. };
  76. // INLINE FUNCTIONS
  77. inline Counter* ModularEmitter::getCounter()
  78. {
  79. return _counter.get();
  80. }
  81. inline const Counter* ModularEmitter::getCounter() const
  82. {
  83. return _counter.get();
  84. }
  85. inline void ModularEmitter::setCounter(Counter* c)
  86. {
  87. _counter = c;
  88. }
  89. inline float ModularEmitter::getNumParticlesToCreateMovementCompensationRatio() const
  90. {
  91. return _numParticleToCreateMovementCompensationRatio;
  92. }
  93. inline void ModularEmitter::setNumParticlesToCreateMovementCompensationRatio(float r)
  94. {
  95. _numParticleToCreateMovementCompensationRatio = r;
  96. }
  97. inline Placer* ModularEmitter::getPlacer()
  98. {
  99. return _placer.get();
  100. }
  101. inline const Placer* ModularEmitter::getPlacer() const
  102. {
  103. return _placer.get();
  104. }
  105. inline void ModularEmitter::setPlacer(Placer* p)
  106. {
  107. _placer = p;
  108. }
  109. inline Shooter *ModularEmitter::getShooter()
  110. {
  111. return _shooter.get();
  112. }
  113. inline const Shooter *ModularEmitter::getShooter() const
  114. {
  115. return _shooter.get();
  116. }
  117. inline void ModularEmitter::setShooter(Shooter *s)
  118. {
  119. _shooter = s;
  120. }
  121. }
  122. #endif