NodeTrackerManipulator 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 OSGGA_NODE_TRACKER_MANIPULATOR
  14. #define OSGGA_NODE_TRACKER_MANIPULATOR 1
  15. #include <osgGA/OrbitManipulator>
  16. #include <osg/ObserverNodePath>
  17. namespace osgGA {
  18. class OSGGA_EXPORT NodeTrackerManipulator : public OrbitManipulator
  19. {
  20. typedef OrbitManipulator inherited;
  21. public:
  22. NodeTrackerManipulator( int flags = DEFAULT_SETTINGS );
  23. NodeTrackerManipulator( const NodeTrackerManipulator& om,
  24. const osg::CopyOp& copyOp = osg::CopyOp::SHALLOW_COPY );
  25. META_Object( osgGA, NodeTrackerManipulator );
  26. void setTrackNodePath(const osg::NodePath& nodePath);
  27. void setTrackNodePath(const osg::ObserverNodePath& nodePath) { _trackNodePath = nodePath; }
  28. osg::ObserverNodePath& getTrackNodePath() { return _trackNodePath; }
  29. void setTrackNode(osg::Node* node);
  30. osg::Node* getTrackNode() { osg::NodePath nodePath; return _trackNodePath.getNodePath(nodePath) && !nodePath.empty() ? nodePath.back() : 0; }
  31. const osg::Node* getTrackNode() const { osg::NodePath nodePath; return _trackNodePath.getNodePath(nodePath) && !nodePath.empty() ? nodePath.back() : 0; }
  32. enum TrackerMode
  33. {
  34. /** Track the center of the node's bounding sphere, but not rotations of the node.
  35. * For databases which have a CoordinateSystemNode, the orientation is kept relative the coordinate frame if the center of the node.
  36. */
  37. NODE_CENTER,
  38. /** Track the center of the node's bounding sphere, and the azimuth rotation (about the z axis of the current coordinate frame).
  39. * For databases which have a CoordinateSystemNode, the orientation is kept relative the coordinate frame if the center of the node.
  40. */
  41. NODE_CENTER_AND_AZIM,
  42. /** Tack the center of the node's bounding sphere, and the all rotations of the node.
  43. */
  44. NODE_CENTER_AND_ROTATION
  45. };
  46. void setTrackerMode(TrackerMode mode);
  47. TrackerMode getTrackerMode() const { return _trackerMode; }
  48. enum RotationMode
  49. {
  50. /** Use a trackball style manipulation of the view direction w.r.t the tracked orientation.
  51. */
  52. TRACKBALL,
  53. /** Allow the elevation and azimuth angles to be adjust w.r.t the tracked orientation.
  54. */
  55. ELEVATION_AZIM
  56. };
  57. void setRotationMode(RotationMode mode);
  58. RotationMode getRotationMode() const;
  59. virtual void setByMatrix(const osg::Matrixd& matrix);
  60. virtual osg::Matrixd getMatrix() const;
  61. virtual osg::Matrixd getInverseMatrix() const;
  62. virtual void setNode(osg::Node*);
  63. virtual void computeHomePosition();
  64. protected:
  65. virtual bool performMovementLeftMouseButton(const double eventTimeDelta, const double dx, const double dy);
  66. virtual bool performMovementMiddleMouseButton(const double eventTimeDelta, const double dx, const double dy);
  67. virtual bool performMovementRightMouseButton(const double eventTimeDelta, const double dx, const double dy);
  68. void computeNodeWorldToLocal(osg::Matrixd& worldToLocal) const;
  69. void computeNodeLocalToWorld(osg::Matrixd& localToWorld) const;
  70. void computeNodeCenterAndRotation(osg::Vec3d& center, osg::Quat& rotation) const;
  71. void computePosition(const osg::Vec3d& eye,const osg::Vec3d& lv,const osg::Vec3d& up);
  72. osg::ObserverNodePath _trackNodePath;
  73. TrackerMode _trackerMode;
  74. };
  75. }
  76. #endif /* OSGGA_NODE_TRACKER_MANIPULATOR */