OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
StandardManipulator.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2010 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  * StandardManipulator code Copyright (C) 2010 PCJohn (Jan Peciva)
14  * while some pieces of code were taken from OSG.
15  * Thanks to company Cadwork (www.cadwork.ch) and
16  * Brno University of Technology (www.fit.vutbr.cz) for open-sourcing this work.
17 */
18 
19 #ifndef OSGGA_CAMERA_MANIPULATOR
20 #define OSGGA_CAMERA_MANIPULATOR 1
21 
22 #include <osgGA/CameraManipulator>
23 
24 
25 namespace osgGA {
26 
27 
31 {
33 
34  public:
35 
36  // flags
38  {
39  UPDATE_MODEL_SIZE = 0x01,
40  COMPUTE_HOME_USING_BBOX = 0x02,
41  PROCESS_MOUSE_WHEEL = 0x04,
42  SET_CENTER_ON_WHEEL_FORWARD_MOVEMENT = 0x08,
43  DEFAULT_SETTINGS = UPDATE_MODEL_SIZE /*| COMPUTE_HOME_USING_BBOX*/ | PROCESS_MOUSE_WHEEL
44  };
45 
46  StandardManipulator( int flags = DEFAULT_SETTINGS );
48  const osg::CopyOp& copyOp = osg::CopyOp::SHALLOW_COPY );
49 
50  // We are not using META_Object as this is abstract class.
51  // Use META_Object(osgGA,YourManipulator); in your descendant non-abstract classes.
52  virtual const char* className() const { return "StandardManipulator"; }
53 
55  virtual void setTransformation( const osg::Vec3d& eye, const osg::Quat& rotation ) = 0;
56 
58  virtual void setTransformation( const osg::Vec3d& eye, const osg::Vec3d& center, const osg::Vec3d& up ) = 0;
59 
61  virtual void getTransformation( osg::Vec3d& eye, osg::Quat& rotation ) const = 0;
62 
64  virtual void getTransformation( osg::Vec3d& eye, osg::Vec3d& center, osg::Vec3d& up ) const = 0;
65 
66  virtual void setNode( osg::Node* );
67  virtual const osg::Node* getNode() const;
68  virtual osg::Node* getNode();
69 
70  virtual void setVerticalAxisFixed( bool value );
71  inline bool getVerticalAxisFixed() const;
72  inline bool getAllowThrow() const;
73  virtual void setAllowThrow( bool allowThrow );
74 
75  virtual void setAnimationTime( const double t );
76  double getAnimationTime() const;
77  bool isAnimating() const;
78  virtual void finishAnimation();
79 
80  virtual void home( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
81  virtual void home( double );
82 
83  virtual void init( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
84  virtual bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
85  virtual void getUsage( osg::ApplicationUsage& usage ) const;
86 
87  protected:
88 
89  virtual bool handleFrame( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
90  virtual bool handleResize( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
91  virtual bool handleMouseMove( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
92  virtual bool handleMouseDrag( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
93  virtual bool handleMousePush( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
94  virtual bool handleMouseRelease( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
95  virtual bool handleKeyDown( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
96  virtual bool handleKeyUp( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
97  virtual bool handleMouseWheel( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
98  virtual bool handleMouseDeltaMovement( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
99 
100  virtual bool performMovement();
101  virtual bool performMovementLeftMouseButton( const double eventTimeDelta, const double dx, const double dy );
102  virtual bool performMovementMiddleMouseButton( const double eventTimeDelta, const double dx, const double dy );
103  virtual bool performMovementRightMouseButton( const double eventTimeDelta, const double dx, const double dy );
104  virtual bool performMouseDeltaMovement( const float dx, const float dy );
105  virtual bool performAnimationMovement( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
106  virtual void applyAnimationStep( const double currentProgress, const double prevProgress );
107 
108  void addMouseEvent( const osgGA::GUIEventAdapter& ea );
109  void flushMouseEventStack();
110  virtual bool isMouseMoving() const;
111  float getThrowScale( const double eventTimeDelta ) const;
112  virtual void centerMousePointer( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
113 
114  static void rotateYawPitch( osg::Quat& rotation, const double yaw, const double pitch,
115  const osg::Vec3d& localUp = osg::Vec3d( 0.,0.,0.) );
116  static void fixVerticalAxis( osg::Quat& rotation, const osg::Vec3d& localUp, bool disallowFlipOver );
117  void fixVerticalAxis( osg::Vec3d& eye, osg::Quat& rotation, bool disallowFlipOver );
118  static void fixVerticalAxis( const osg::Vec3d& forward, const osg::Vec3d& up, osg::Vec3d& newUp,
119  const osg::Vec3d& localUp, bool disallowFlipOver );
120  virtual bool setCenterByMousePointerIntersection( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
121  virtual bool startAnimationByMousePointerIntersection( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
122 
123  // mouse state
124  bool _thrown;
126  float _mouseCenterX, _mouseCenterY;
127 
128  // internal event stack comprising last two mouse events.
131 
137 
142 
143  // scene data
145  double _modelSize;
147 
148  // animation stuff
150  public:
153  double _startTime;
154  double _phase;
155  AnimationData();
156  void start( const double startTime );
157  };
159  virtual void allocAnimationData() { _animationData = new AnimationData(); }
160 
161  // flags
162  int _flags;
163 
164  // flags indicating that a value is relative to model size
166  inline bool getRelativeFlag( int index ) const;
167  inline void setRelativeFlag( int index, bool value );
169  static int allocateRelativeFlag();
170 };
171 
172 
173 //
174 // inline methods
175 //
176 
177 inline bool StandardManipulator::getRelativeFlag( int index ) const
178 {
179  return ( _relativeFlags & (0x01 << index) ) != 0;
180 }
181 
182 inline void StandardManipulator::setRelativeFlag( int index, bool value )
183 {
184  if( value ) _relativeFlags |= (0x01 << index);
185  else _relativeFlags &= (~0x01 << index);
186 }
187 
190 {
191  return _verticalAxisFixed;
192 }
193 
196 {
197  return _allowThrow;
198 }
199 
200 
201 }
202 
203 #endif /* OSGGA_CAMERA_MANIPULATOR */
osg::ref_ptr< osg::Node > _node
osg::ref_ptr< const osgGA::GUIEventAdapter > _ga_t0
osg::ref_ptr< AnimationData > _animationData
#define OSGGA_EXPORT
Definition: Export.h:40
bool getRelativeFlag(int index) const
bool getVerticalAxisFixed() const
Returns whether manipulator preserves camera's "UP" vector.
void setRelativeFlag(int index, bool value)
osg::ref_ptr< const osgGA::GUIEventAdapter > _ga_t1
Definition: Node.h:71
bool getAllowThrow() const
Returns true if the camera can be thrown, false otherwise. It defaults to true.
Definition: Quat.h:29
virtual const char * className() const