ParticleEffect 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. #ifndef OSGPARTICLE_PARTICLEEFFECT
  14. #define OSGPARTICLE_PARTICLEEFFECT
  15. #include <osgParticle/Emitter>
  16. #include <osgParticle/Program>
  17. namespace osgParticle
  18. {
  19. class OSGPARTICLE_EXPORT ParticleEffect : public osg::Group
  20. {
  21. public:
  22. explicit ParticleEffect(bool automaticSetup=true):
  23. _automaticSetup(automaticSetup),
  24. _useLocalParticleSystem(true),
  25. _scale(1.0f),
  26. _intensity(1.0f),
  27. _startTime(0.0),
  28. _emitterDuration(1.0),
  29. _wind(0.0f,0.0f,0.0f)
  30. {}
  31. ParticleEffect(const ParticleEffect& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
  32. virtual const char* libraryName() const { return "osgParticle"; }
  33. virtual const char* className() const { return "ParticleEffect"; }
  34. virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const ParticleEffect*>(obj) != 0; }
  35. virtual void accept(osg::NodeVisitor& nv) { if (nv.validNodeMask(*this)) { nv.pushOntoNodePath(this); nv.apply(*this); nv.popFromNodePath(); } }
  36. void setAutomaticSetup(bool flag) { _automaticSetup = flag; }
  37. bool getAutomaticSetup() const { return _automaticSetup; }
  38. void setUseLocalParticleSystem(bool local);
  39. bool getUseLocalParticleSystem() const { return _useLocalParticleSystem; }
  40. void setTextureFileName(const std::string& filename);
  41. const std::string& getTextureFileName() const { return _textureFileName; }
  42. void setDefaultParticleTemplate(const Particle& p);
  43. const Particle& getDefaultParticleTemplate() const { return _defaultParticleTemplate; }
  44. void setPosition(const osg::Vec3& position);
  45. const osg::Vec3& getPosition() const { return _position; }
  46. void setScale(float scale);
  47. float getScale() const { return _scale; }
  48. void setIntensity(float intensity);
  49. float getIntensity() const { return _intensity; }
  50. void setStartTime(double startTime);
  51. double getStartTime() const { return _startTime; }
  52. void setEmitterDuration(double duration);
  53. double getEmitterDuration() const { return _emitterDuration; }
  54. void setParticleDuration(double duration);
  55. double getParticleDuration() const { return _defaultParticleTemplate.getLifeTime(); }
  56. void setWind(const osg::Vec3& wind);
  57. const osg::Vec3& getWind() const { return _wind; }
  58. /// Get whether all particles are dead
  59. bool areAllParticlesDead() const { return _particleSystem.valid()?_particleSystem->areAllParticlesDead():true; }
  60. virtual Emitter* getEmitter() = 0;
  61. virtual const Emitter* getEmitter() const = 0;
  62. virtual Program* getProgram() = 0;
  63. virtual const Program* getProgram() const = 0;
  64. void setParticleSystem(ParticleSystem* ps);
  65. template<class T> void setParticleSystem(const osg::ref_ptr<T>& ri) { setParticleSystem(ri.get()); }
  66. inline ParticleSystem* getParticleSystem() { return _particleSystem.get(); }
  67. inline const ParticleSystem* getParticleSystem() const { return _particleSystem.get(); }
  68. virtual void setDefaults();
  69. virtual void setUpEmitterAndProgram() = 0;
  70. virtual void buildEffect();
  71. protected:
  72. virtual ~ParticleEffect() {}
  73. bool _automaticSetup;
  74. osg::ref_ptr<ParticleSystem> _particleSystem;
  75. bool _useLocalParticleSystem;
  76. std::string _textureFileName;
  77. Particle _defaultParticleTemplate;
  78. osg::Vec3 _position;
  79. float _scale;
  80. float _intensity;
  81. double _startTime;
  82. double _emitterDuration;
  83. osg::Vec3 _wind;
  84. };
  85. }
  86. #endif