FlightManipulator 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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_FLIGHT_MANIPULATOR
  14. #define OSGGA_FLIGHT_MANIPULATOR 1
  15. #include <osgGA/FirstPersonManipulator>
  16. namespace osgGA {
  17. /** FlightManipulator is a CameraManipulator which provides flight simulator-like
  18. * updating of the camera position & orientation. By default, the left mouse
  19. * button accelerates, the right mouse button decelerates, and the middle mouse
  20. * button (or left and right simultaneously) stops dead.
  21. */
  22. class OSGGA_EXPORT FlightManipulator : public FirstPersonManipulator
  23. {
  24. typedef FirstPersonManipulator inherited;
  25. public:
  26. enum YawControlMode
  27. {
  28. YAW_AUTOMATICALLY_WHEN_BANKED,
  29. NO_AUTOMATIC_YAW
  30. };
  31. FlightManipulator( int flags = UPDATE_MODEL_SIZE | COMPUTE_HOME_USING_BBOX );
  32. FlightManipulator( const FlightManipulator& fpm,
  33. const osg::CopyOp& copyOp = osg::CopyOp::SHALLOW_COPY );
  34. META_Object( osgGA, FlightManipulator );
  35. virtual void setYawControlMode( YawControlMode ycm );
  36. inline YawControlMode getYawControlMode() const;
  37. virtual void home( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
  38. virtual void init( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
  39. virtual void getUsage( osg::ApplicationUsage& usage ) const;
  40. protected:
  41. virtual bool handleFrame( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
  42. virtual bool handleMouseMove( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
  43. virtual bool handleMouseDrag( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
  44. virtual bool handleMousePush( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
  45. virtual bool handleMouseRelease( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
  46. virtual bool handleKeyDown( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
  47. virtual bool flightHandleEvent( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
  48. virtual bool performMovement();
  49. virtual bool performMovementLeftMouseButton( const double eventTimeDelta, const double dx, const double dy );
  50. virtual bool performMovementMiddleMouseButton( const double eventTimeDelta, const double dx, const double dy );
  51. virtual bool performMovementRightMouseButton( const double eventTimeDelta, const double dx, const double dy );
  52. YawControlMode _yawMode;
  53. };
  54. //
  55. // inline methods
  56. //
  57. /// Returns the Yaw control for the flight model.
  58. inline FlightManipulator::YawControlMode FlightManipulator::getYawControlMode() const { return _yawMode; }
  59. }
  60. #endif /* OSGGA_FLIGHT_MANIPULATOR */