OpenWalnut  1.5.0dev
WGEZoomTrackballManipulator.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WGEZOOMTRACKBALLMANIPULATOR_H
26 #define WGEZOOMTRACKBALLMANIPULATOR_H
27 
28 #include <osgGA/TrackballManipulator>
29 
30 #include "WGEZoomTrackballNodeVisitor.h"
31 
32 
33 /**
34  * New OSG manipulator: TrackballManipulator with added mouse wheel zoom.
35  */
36 class WGEZoomTrackballManipulator: public osgGA::TrackballManipulator
37 {
38 public:
39  /**
40  * Default constructor
41  */
43 
44  /**
45  * Set the position of the manipulator using a 4x4 matrix.
46  * \param matrix position of the manipulator
47  */
48  virtual void setByMatrix( const osg::Matrixd& matrix );
49 
50  /**
51  * Get the position of the manipulator as 4x4 matrix.
52  *
53  * \return the matrix representing the transformation
54  */
55  virtual osg::Matrixd getMatrix() const;
56 
57  /**
58  * Get the manipulator only containing rotation and translation.
59  *
60  * \return the matrix with translation and rotation.
61  */
62  virtual osg::Matrixd getMatrixWithoutZoom() const;
63 
64  /**
65  * Get the position of the manipulator as a inverse matrix of the
66  * manipulator, typically used as a model view matrix.
67  *
68  * \return the inverse matrix
69  */
70  virtual osg::Matrixd getInverseMatrix() const;
71 
72  /**
73  * Move the camera to the default position.
74  * May be ignored by manipulators if home functionality is not appropriate.
75  * \param currentTime Variable specified in osg class but not used.
76  */
77  virtual void home( double currentTime );
78 
79  /**
80  * Handle events, return true if handled, false otherwise.
81  * \param ea Event class for storing Keyboard, mouse and window events.
82  * \param us Interface by which GUIEventHandlers may request actions of the GUI system
83  *
84  * \return true if event was handled
85  */
86  virtual bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
87 
88  /**
89  * Get zoom factor.
90  *
91  * \return the current zoom factor
92  */
93  double getZoom() const;
94 
95  /**
96  * Set zoom factor.
97  * \param zoom the zoom factor to be set.
98  */
99  void setZoom( double zoom );
100 
101  /**
102  * setter for paint mode
103  * when set to something different from 0, a left drag should move the scene
104  *
105  * \param mode the mode
106  */
107  void setPaintMode( int mode );
108 
109  /**
110  * En-/Disables throwing.
111  *
112  * \param allowThrow if true, throwing is enabled.
113  */
114  void setThrow( bool allowThrow = true );
115 
116  /**
117  * Checks whether throwing is active.
118  *
119  * \return true if active
120  */
121  bool getThrow() const;
122 
123  /**
124  * Computes the home position.
125  * \param camera The camera from which to compute.
126  * \param useBoundingBox if boundingboxes should be used.
127  */
128  virtual void computeHomePosition( const osg::Camera* camera, bool useBoundingBox );
129 
130  /**
131  * Zooms and centers to fit screen.
132  * \param camera The camera to zoom.
133  */
134  void fitToScreen( const osg::Camera* camera );
135 
136 protected:
137 private:
138  /**
139  * Handles events related to zooming.
140  * \param ea Event class for storing Keyboard, mouse and window events.
141  * \param us Interface by which GUIEventHandlers may request actions of the GUI system
142  *
143  * \return true if event was handled
144  */
145  bool zoom( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
146 
147  /**
148  * Performs the middle mouse button click.
149  * \param eventTimeDelta The delta time of the event
150  * \param dx The delta x of the mouse.
151  * \param dy The delta y of the mouse.
152  * \return true It was performed.
153  * \return false It was not performed.
154  */
155  virtual bool performMovementMiddleMouseButton( const double eventTimeDelta, const double dx, const double dy );
156 
157  double m_zoom; //!< Zoom factor.
158  bool m_allowThrow; //!< Do we want the auto-rotation thingy?
159 
160  int m_paintMode; //!<paint mode
161 
162  double m_radius; //!< The radius of the bounding sphere
163 };
164 
166 {
167  return m_zoom;
168 }
169 
170 inline void WGEZoomTrackballManipulator::setZoom( double zoom )
171 {
172  m_zoom = zoom;
173 }
174 
175 #endif // WGEZOOMTRACKBALLMANIPULATOR_H
New OSG manipulator: TrackballManipulator with added mouse wheel zoom.
bool getThrow() const
Checks whether throwing is active.
void setThrow(bool allowThrow=true)
En-/Disables throwing.
virtual bool performMovementMiddleMouseButton(const double eventTimeDelta, const double dx, const double dy)
Performs the middle mouse button click.
void setZoom(double zoom)
Set zoom factor.
virtual void computeHomePosition(const osg::Camera *camera, bool useBoundingBox)
Computes the home position.
void fitToScreen(const osg::Camera *camera)
Zooms and centers to fit screen.
bool zoom(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
Handles events related to zooming.
bool m_allowThrow
Do we want the auto-rotation thingy?
virtual osg::Matrixd getInverseMatrix() const
Get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model...
WGEZoomTrackballManipulator()
Default constructor.
double m_radius
The radius of the bounding sphere.
virtual void setByMatrix(const osg::Matrixd &matrix)
Set the position of the manipulator using a 4x4 matrix.
virtual osg::Matrixd getMatrix() const
Get the position of the manipulator as 4x4 matrix.
double getZoom() const
Get zoom factor.
virtual void home(double currentTime)
Move the camera to the default position.
virtual osg::Matrixd getMatrixWithoutZoom() const
Get the manipulator only containing rotation and translation.
virtual bool handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
Handle events, return true if handled, false otherwise.
void setPaintMode(int mode)
setter for paint mode when set to something different from 0, a left drag should move the scene