OpenWalnut  1.3.1
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 
31 /**
32  * New OSG manipulator: TrackballManipulator with added mouse wheel zoom.
33  */
34 class WGEZoomTrackballManipulator: public osgGA::TrackballManipulator
35 {
36 public:
37  /**
38  * Default constructor
39  */
41 
42  /**
43  * Set the position of the manipulator using a 4x4 matrix.
44  * \param matrix position of the manipulator
45  */
46  virtual void setByMatrix( const osg::Matrixd& matrix );
47 
48  /**
49  * Get the position of the manipulator as 4x4 matrix.
50  *
51  * \return the matrix representing the transformation
52  */
53  virtual osg::Matrixd getMatrix() const;
54 
55  /**
56  * Get the manipulator only containing rotation and translation.
57  *
58  * \return the matrix with translation and rotation.
59  */
60  virtual osg::Matrixd getMatrixWithoutZoom() const;
61 
62  /**
63  * Get the position of the manipulator as a inverse matrix of the
64  * manipulator, typically used as a model view matrix.
65  *
66  * \return the inverse matrix
67  */
68  virtual osg::Matrixd getInverseMatrix() const;
69 
70  /**
71  * Move the camera to the default position.
72  * May be ignored by manipulators if home functionality is not appropriate.
73  * \param currentTime Variable specified in osg class but not used.
74  */
75  virtual void home( double currentTime );
76 
77  /**
78  * Handle events, return true if handled, false otherwise.
79  * \param ea Event class for storing Keyboard, mouse and window events.
80  * \param us Interface by which GUIEventHandlers may request actions of the GUI system
81  *
82  * \return true if event was handled
83  */
84  virtual bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
85 
86  /**
87  * Get zoom factor.
88  *
89  * \return the current zoom factor
90  */
91  double getZoom() const;
92 
93  /**
94  * Set zoom factor.
95  * \param zoom the zoom factor to be set.
96  */
97  void setZoom( double zoom );
98 
99  /**
100  * setter for paint mode
101  * when set to something different from 0, a left drag should move the scene
102  *
103  * \param mode the mode
104  */
105  void setPaintMode( int mode );
106 
107  /**
108  * En-/Disables throwing.
109  *
110  * \param allowThrow if true, throwing is enabled.
111  */
112  void setThrow( bool allowThrow = true );
113 
114  /**
115  * Checks whether throwing is active.
116  *
117  * \return true if active
118  */
119  bool getThrow() const;
120 
121 protected:
122 private:
123  /**
124  * Handles events related to zooming.
125  * \param ea Event class for storing Keyboard, mouse and window events.
126  * \param us Interface by which GUIEventHandlers may request actions of the GUI system
127  *
128  * \return true if event was handled
129  */
130  bool zoom( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
131 
132  double m_zoom; //!< Zoom factor.
133  bool m_allowThrow; //!< Do we want the auto-rotation thingy?
134 
135  int m_paintMode; //!<paint mode
136 };
137 
139 {
140  return m_zoom;
141 }
142 
143 inline void WGEZoomTrackballManipulator::setZoom( double zoom )
144 {
145  m_zoom = zoom;
146 }
147 
148 #endif // WGEZOOMTRACKBALLMANIPULATOR_H