AngularAccelOperator 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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_ANGULARACCELOPERATOR
  15. #define OSGPARTICLE_ANGULARACCELOPERATOR 1
  16. #include <osgParticle/ModularProgram>
  17. #include <osgParticle/Operator>
  18. #include <osgParticle/Particle>
  19. #include <osg/CopyOp>
  20. #include <osg/Object>
  21. #include <osg/Vec3>
  22. namespace osgParticle
  23. {
  24. /** An operator class that applies a constant angular acceleration to
  25. * the particles.
  26. */
  27. class AngularAccelOperator: public Operator {
  28. public:
  29. inline AngularAccelOperator();
  30. inline AngularAccelOperator(const AngularAccelOperator& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY);
  31. META_Object(osgParticle, AngularAccelOperator);
  32. /// Get the angular acceleration vector.
  33. inline const osg::Vec3& getAngularAcceleration() const;
  34. /// Set the angular acceleration vector.
  35. inline void setAngularAcceleration(const osg::Vec3& v);
  36. /// Apply the angular acceleration to a particle. Do not call this method manually.
  37. inline void operate(Particle* P, double dt);
  38. /// Perform some initializations. Do not call this method manually.
  39. inline void beginOperate(Program *prg);
  40. protected:
  41. virtual ~AngularAccelOperator() {}
  42. AngularAccelOperator& operator=(const AngularAccelOperator& ) { return *this; }
  43. private:
  44. osg::Vec3 _angul_araccel;
  45. osg::Vec3 _xf_angul_araccel;
  46. };
  47. // INLINE FUNCTIONS
  48. inline AngularAccelOperator::AngularAccelOperator()
  49. : Operator(), _angul_araccel(0, 0, 0)
  50. {
  51. }
  52. inline AngularAccelOperator::AngularAccelOperator(const AngularAccelOperator& copy, const osg::CopyOp& copyop)
  53. : Operator(copy, copyop), _angul_araccel(copy._angul_araccel)
  54. {
  55. }
  56. inline const osg::Vec3& AngularAccelOperator::getAngularAcceleration() const
  57. {
  58. return _angul_araccel;
  59. }
  60. inline void AngularAccelOperator::setAngularAcceleration(const osg::Vec3& v)
  61. {
  62. _angul_araccel = v;
  63. }
  64. inline void AngularAccelOperator::operate(Particle* P, double dt)
  65. {
  66. P->addAngularVelocity(_xf_angul_araccel * dt);
  67. }
  68. inline void AngularAccelOperator::beginOperate(Program *prg)
  69. {
  70. if (prg->getReferenceFrame() == ModularProgram::RELATIVE_RF) {
  71. _xf_angul_araccel = prg->rotateLocalToWorld(_angul_araccel);
  72. } else {
  73. _xf_angul_araccel = _angul_araccel;
  74. }
  75. }
  76. }
  77. #endif