BounceOperator 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 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. // Written by Wang Rui, (C) 2010
  14. #ifndef OSGPARTICLE_BOUNCEOPERATOR
  15. #define OSGPARTICLE_BOUNCEOPERATOR
  16. #include <osgParticle/Particle>
  17. #include <osgParticle/DomainOperator>
  18. namespace osgParticle
  19. {
  20. /** A bounce operator can affect the particle's velocity to make it rebound.
  21. Refer to David McAllister's Particle System API (http://www.particlesystems.org)
  22. */
  23. class OSGPARTICLE_EXPORT BounceOperator : public DomainOperator
  24. {
  25. public:
  26. BounceOperator()
  27. : DomainOperator(), _friction(1.0f), _resilience(0.0f), _cutoff(0.0f)
  28. {}
  29. BounceOperator( const BounceOperator& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY )
  30. : DomainOperator(copy, copyop),
  31. _friction(copy._friction), _resilience(copy._resilience), _cutoff(copy._cutoff)
  32. {}
  33. META_Object( osgParticle, BounceOperator );
  34. /// Set the friction
  35. void setFriction( float f ) { _friction = f; }
  36. /// Get the friction
  37. float getFriction() const { return _friction; }
  38. /// Set the resilience
  39. void setResilience( float r ) { _resilience = r; }
  40. /// Get the velocity cutoff factor
  41. float getResilience() const { return _resilience; }
  42. /// Set the velocity cutoff factor
  43. void setCutoff( float v ) { _cutoff = v; }
  44. /// Get the velocity cutoff factor
  45. float getCutoff() const { return _cutoff; }
  46. protected:
  47. virtual ~BounceOperator() {}
  48. BounceOperator& operator=( const BounceOperator& ) { return *this; }
  49. virtual void handleTriangle( const Domain& domain, Particle* P, double dt );
  50. virtual void handleRectangle( const Domain& domain, Particle* P, double dt );
  51. virtual void handlePlane( const Domain& domain, Particle* P, double dt );
  52. virtual void handleSphere( const Domain& domain, Particle* P, double dt );
  53. virtual void handleDisk( const Domain& domain, Particle* P, double dt );
  54. float _friction;
  55. float _resilience;
  56. float _cutoff;
  57. };
  58. }
  59. #endif