VariableRateCounter 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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_VARIABLERATE_COUNTER
  15. #define OSGPARTICLE_VARIABLERATE_COUNTER 1
  16. #include <osgParticle/Counter>
  17. #include <osgParticle/range>
  18. #include <osg/CopyOp>
  19. #include <osg/Object>
  20. namespace osgParticle
  21. {
  22. class VariableRateCounter: public Counter {
  23. public:
  24. inline VariableRateCounter();
  25. inline VariableRateCounter(const VariableRateCounter& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
  26. virtual const char* libraryName() const { return "osgParticle"; }
  27. virtual const char* className() const { return "VariableRateCounter"; }
  28. virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const VariableRateCounter *>(obj) != 0; }
  29. inline const rangef& getRateRange() const;
  30. inline void setRateRange(const rangef& r);
  31. inline void setRateRange(float minrange, float maxrange);
  32. virtual int getEstimatedMaxNumOfParticles(double lifeTime) const { return static_cast<int>(_rate_range.maximum * lifeTime); }
  33. protected:
  34. virtual ~VariableRateCounter() {}
  35. private:
  36. rangef _rate_range;
  37. };
  38. // INLINE FUNCTIONS
  39. inline VariableRateCounter::VariableRateCounter()
  40. : Counter(), _rate_range(1, 1)
  41. {
  42. }
  43. inline VariableRateCounter::VariableRateCounter(const VariableRateCounter& copy, const osg::CopyOp& copyop)
  44. : Counter(copy, copyop), _rate_range(copy._rate_range)
  45. {
  46. }
  47. inline const rangef &VariableRateCounter::getRateRange() const
  48. {
  49. return _rate_range;
  50. }
  51. inline void VariableRateCounter::setRateRange(const rangef& r)
  52. {
  53. _rate_range = r;
  54. }
  55. inline void VariableRateCounter::setRateRange(float minrange, float maxrange)
  56. {
  57. _rate_range.set(minrange, maxrange);
  58. }
  59. }
  60. #endif