Scale1DDragger 3.8 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. //osgManipulator - Copyright (C) 2007 Fugro-Jason B.V.
  14. #ifndef OSGMANIPULATOR_SCALE1DDRAGGER
  15. #define OSGMANIPULATOR_SCALE1DDRAGGER 1
  16. #include <osgManipulator/Dragger>
  17. #include <osgManipulator/Projector>
  18. namespace osgManipulator {
  19. /**
  20. * Dragger for performing 1D scaling.
  21. */
  22. class OSGMANIPULATOR_EXPORT Scale1DDragger : public Dragger
  23. {
  24. public:
  25. enum ScaleMode
  26. {
  27. SCALE_WITH_ORIGIN_AS_PIVOT = 0,
  28. SCALE_WITH_OPPOSITE_HANDLE_AS_PIVOT
  29. };
  30. Scale1DDragger(ScaleMode scaleMode=SCALE_WITH_ORIGIN_AS_PIVOT);
  31. META_OSGMANIPULATOR_Object(osgManipulator,Scale1DDragger)
  32. /**
  33. * Handle pick events on dragger and generate TranslateInLine commands.
  34. */
  35. virtual bool handle(const PointerInfo& pi, const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us);
  36. /** Setup default geometry for dragger. */
  37. void setupDefaultGeometry();
  38. /** Set/Get min scale for dragger. */
  39. inline void setMinScale(double min) { _minScale = min; }
  40. inline double getMinScale() const { return _minScale; }
  41. /** Set/Get color for dragger. */
  42. inline void setColor(const osg::Vec4& color) { _color = color; setMaterialColor(_color,*this); }
  43. inline const osg::Vec4& getColor() const { return _color; }
  44. /**
  45. * Set/Get pick color for dragger. Pick color is color of the dragger
  46. * when picked. It gives a visual feedback to show that the dragger has
  47. * been picked.
  48. */
  49. inline void setPickColor(const osg::Vec4& color) { _pickColor = color; }
  50. inline const osg::Vec4& getPickColor() const { return _pickColor; }
  51. /** Set/Get left and right handle nodes for dragger. */
  52. inline void setLeftHandleNode (osg::Node& node) { _leftHandleNode = &node; }
  53. inline void setRightHandleNode(osg::Node& node) { _rightHandleNode = &node; }
  54. inline osg::Node* getLeftHandleNode() { return _leftHandleNode.get(); }
  55. inline const osg::Node* getLeftHandleNode() const { return _leftHandleNode.get(); }
  56. inline osg::Node* getRightHandleNode() { return _rightHandleNode.get(); }
  57. inline const osg::Node* getRightHandleNode() const { return _rightHandleNode.get(); }
  58. /** Set left/right handle position. */
  59. inline void setLeftHandlePosition(double pos) { _projector->getLineStart() = osg::Vec3d(pos,0.0,0.0); }
  60. inline double getLeftHandlePosition() const { return _projector->getLineStart()[0]; }
  61. inline void setRightHandlePosition(double pos) { _projector->getLineEnd() = osg::Vec3d(pos,0.0,0.0); }
  62. inline double getRightHandlePosition() const { return _projector->getLineEnd()[0]; }
  63. protected:
  64. virtual ~Scale1DDragger();
  65. osg::ref_ptr< LineProjector > _projector;
  66. osg::Vec3d _startProjectedPoint;
  67. double _scaleCenter;
  68. double _minScale;
  69. osg::ref_ptr< osg::Node > _leftHandleNode;
  70. osg::ref_ptr< osg::Node > _rightHandleNode;
  71. osg::Vec4 _color;
  72. osg::Vec4 _pickColor;
  73. ScaleMode _scaleMode;
  74. };
  75. }
  76. #endif