DOFTransform 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 OSGSIM_DOFTRANSFORM
  14. #define OSGSIM_DOFTRANSFORM 1
  15. //base class:
  16. #include <osg/Transform>
  17. #include <osgSim/Export>
  18. namespace osgSim {
  19. /** DOFTransform - encapsulates Multigen DOF behavior*/
  20. class OSGSIM_EXPORT DOFTransform : public osg::Transform
  21. {
  22. public:
  23. /** constructor*/
  24. DOFTransform();
  25. /**copy constructor*/
  26. DOFTransform(const DOFTransform& dof, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
  27. META_Node(osgSim, DOFTransform);
  28. virtual void traverse(osg::NodeVisitor& nv);
  29. void setMinHPR(const osg::Vec3& hpr) { _minHPR = hpr;}
  30. const osg::Vec3& getMinHPR() const { return _minHPR;}
  31. void setMaxHPR(const osg::Vec3& hpr) {_maxHPR = hpr;}
  32. const osg::Vec3& getMaxHPR() const { return _maxHPR;}
  33. void setIncrementHPR(const osg::Vec3& hpr) {_incrementHPR = hpr;}
  34. const osg::Vec3& getIncrementHPR() const { return _incrementHPR;}
  35. void setCurrentHPR(const osg::Vec3& hpr) {_currentHPR = hpr; dirtyBound(); }
  36. const osg::Vec3& getCurrentHPR() const {return _currentHPR;}
  37. void updateCurrentHPR(const osg::Vec3& hpr);
  38. void setMinTranslate(const osg::Vec3& translate) {_minTranslate = translate; }
  39. const osg::Vec3& getMinTranslate() const { return _minTranslate;}
  40. void setMaxTranslate(const osg::Vec3& translate) {_maxTranslate = translate; }
  41. const osg::Vec3& getMaxTranslate() const { return _maxTranslate;}
  42. void setIncrementTranslate(const osg::Vec3& translate) { _incrementTranslate = translate; }
  43. const osg::Vec3& getIncrementTranslate() const { return _incrementTranslate;}
  44. void setCurrentTranslate(const osg::Vec3& translate){ _currentTranslate = translate; dirtyBound(); }
  45. inline const osg::Vec3& getCurrentTranslate() const { return _currentTranslate;}
  46. void updateCurrentTranslate(const osg::Vec3& translate);
  47. void setMinScale(const osg::Vec3& scale) { _minScale = scale;}
  48. const osg::Vec3& getMinScale() const { return _minScale;}
  49. void setMaxScale(const osg::Vec3& scale) { _maxScale = scale;}
  50. const osg::Vec3& getMaxScale() const { return _maxScale;}
  51. void setIncrementScale(const osg::Vec3& scale) { _incrementScale = scale;}
  52. const osg::Vec3& getIncrementScale() const { return _incrementScale;}
  53. void setCurrentScale(const osg::Vec3& scale) { _currentScale = scale; dirtyBound(); }
  54. inline const osg::Vec3& getCurrentScale() const { return _currentScale;}
  55. void updateCurrentScale(const osg::Vec3& scale);
  56. void setPutMatrix(const osg::Matrix& put) { _Put = put; dirtyBound(); }
  57. inline const osg::Matrix& getPutMatrix() const {return _Put;}
  58. void setInversePutMatrix(const osg::Matrix& inversePut) { _inversePut = inversePut; dirtyBound(); }
  59. inline const osg::Matrix& getInversePutMatrix() const {return _inversePut;}
  60. void setLimitationFlags(unsigned long flags) { _limitationFlags = flags;}
  61. inline unsigned long getLimitationFlags() const {return _limitationFlags;}
  62. enum MultOrder
  63. {
  64. PRH,
  65. PHR,
  66. HPR,
  67. HRP,
  68. RPH,
  69. RHP
  70. };
  71. void setHPRMultOrder(MultOrder order) { _multOrder = order; }
  72. inline MultOrder getHPRMultOrder() const { return _multOrder;}
  73. void setAnimationOn(bool do_animate);
  74. inline bool getAnimationOn() const { return _animationOn; }
  75. void animate(float deltaTime);
  76. virtual bool computeLocalToWorldMatrix(osg::Matrix& matrix,osg::NodeVisitor* nv) const;
  77. virtual bool computeWorldToLocalMatrix(osg::Matrix& matrix,osg::NodeVisitor* nv) const;
  78. protected:
  79. virtual ~DOFTransform() {}
  80. unsigned int _previousTraversalNumber;
  81. double _previousTime;
  82. osg::Vec3 _minHPR;
  83. osg::Vec3 _maxHPR;
  84. osg::Vec3 _currentHPR;
  85. osg::Vec3 _incrementHPR;
  86. osg::Vec3 _minTranslate;
  87. osg::Vec3 _maxTranslate;
  88. osg::Vec3 _currentTranslate;
  89. osg::Vec3 _incrementTranslate;
  90. osg::Vec3 _minScale;
  91. osg::Vec3 _maxScale;
  92. osg::Vec3 _currentScale;
  93. osg::Vec3 _incrementScale;
  94. osg::Matrix _Put;
  95. osg::Matrix _inversePut;
  96. unsigned long _limitationFlags;
  97. /* bits from left to right
  98. 0 = x translation limited (2^31)
  99. 1 = y translation limited (2^30)
  100. 2 = z translation limited (2^29)
  101. 3 = pitch limited (2^28)
  102. 4 = roll limited (2^27)
  103. 5 = yaw limited (2^26)
  104. 6 = x scale limited (2^25)
  105. 7 = y scale limited (2^24)
  106. 8 = z scale limited (2^23)
  107. else reserved
  108. */
  109. bool _animationOn;
  110. /** flags indicating whether value is incerasing or decreasing in animation
  111. bits form right to left, 1 means increasing while 0 is decreasing
  112. 0 = x translation
  113. 1 = y translation
  114. 2 = z translation
  115. 3 = pitch
  116. 4 = roll
  117. 5 = yaw
  118. 6 = x scale
  119. 7 = y scale
  120. 8 = z scale
  121. */
  122. unsigned short _increasingFlags;
  123. MultOrder _multOrder;
  124. };
  125. }
  126. #endif