OpenWalnut
1.4.0
|
00001 //--------------------------------------------------------------------------- 00002 // 00003 // Project: OpenWalnut ( http://www.openwalnut.org ) 00004 // 00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS 00006 // For more information see http://www.openwalnut.org/copying 00007 // 00008 // This file is part of OpenWalnut. 00009 // 00010 // OpenWalnut is free software: you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as published by 00012 // the Free Software Foundation, either version 3 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // OpenWalnut is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public License 00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>. 00022 // 00023 //--------------------------------------------------------------------------- 00024 00025 #ifndef WGE2DMANIPULATOR_H 00026 #define WGE2DMANIPULATOR_H 00027 00028 #include <osg/Version> 00029 00030 // OSG interface changed in 2.9.7, to make it compile also with those versions we do this: 00031 // OSG_MIN_VERSION_REQUIRED(2, 9, 8) macro is not available in e.g. OSG 2.8.1, hence we use the old way 00032 #if ( ( OPENSCENEGRAPH_MAJOR_VERSION > 2 ) || ( OPENSCENEGRAPH_MAJOR_VERSION == 2 && ( OPENSCENEGRAPH_MINOR_VERSION > 9 || \ 00033 ( OPENSCENEGRAPH_MINOR_VERSION == 9 && OPENSCENEGRAPH_PATCH_VERSION >= 8 ) ) ) ) 00034 #include <osgGA/CameraManipulator> 00035 namespace osgGA 00036 { 00037 typedef CameraManipulator MatrixManipulator; 00038 } 00039 #else 00040 #include <osgGA/MatrixManipulator> 00041 #endif 00042 00043 00044 00045 /** 00046 * A manipulator which changes the view of a 2D scene. Does things like panning 00047 * and zooming. 00048 */ 00049 class WGE2DManipulator : public osgGA::MatrixManipulator 00050 { 00051 public: 00052 /** 00053 * Constructor 00054 */ 00055 WGE2DManipulator(); 00056 00057 /** 00058 * Return the name of the object's class type. 00059 * 00060 * \return the name of the object's class type 00061 */ 00062 virtual const char* className() const; 00063 00064 /** 00065 * Set the position of the matrix manipulator using a 4x4 matrix. 00066 * 00067 * \param matrix a 4x4 matrix 00068 */ 00069 virtual void setByMatrix( const osg::Matrixd& matrix ); 00070 00071 /** 00072 * Set the position of the matrix manipulator using a 4x4 matrix. 00073 * 00074 * \param matrix a 4x4 matrix 00075 */ 00076 virtual void setByInverseMatrix( const osg::Matrixd& matrix ); 00077 00078 /** 00079 * Get the position of the manipulator as 4x4 matrix. 00080 * 00081 * \return the position of the manipulator as 4x4 matrix 00082 */ 00083 virtual osg::Matrixd getMatrix() const; 00084 00085 /** 00086 * Get the position of the manipulator as a inverse matrix of the 00087 * manipulator, typically used as a model view matrix. 00088 * 00089 * \return the position of the manipulator as a inverse matrix 00090 */ 00091 virtual osg::Matrixd getInverseMatrix() const; 00092 00093 /** 00094 * Move the camera to the default position. 00095 * 00096 * \param us the action adapter used to request actions of the GUI 00097 */ 00098 virtual void home( const osgGA::GUIEventAdapter& /*ea*/, osgGA::GUIActionAdapter& us ); // NOLINT We can not change the interface of OSG 00099 00100 /** 00101 * Start/restart the manipulator. 00102 * 00103 * \param us the action adapter used to request actions of the GUI 00104 */ 00105 virtual void init( const osgGA::GUIEventAdapter& /*ea*/, osgGA::GUIActionAdapter& us ); // NOLINT We can not change the interface of OSG 00106 00107 /** 00108 * Handle events 00109 * 00110 * \param ea event class for storing keyboard, mouse and window events 00111 * \param us the action adapter used to request actions of the GUI 00112 * \return true if handled, false otherwise 00113 */ 00114 virtual bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us ); 00115 00116 /** 00117 * Get the keyboard and mouse usage of this manipulator. 00118 * 00119 * \param usage the application usage 00120 */ 00121 virtual void getUsage( osg::ApplicationUsage& usage ) const; // NOLINT We can not change the interface of OSG 00122 00123 protected: 00124 /** 00125 * Destructor 00126 * 00127 * Note, is protected so that objects cannot be deleted other than by being 00128 * dereferenced and the reference count being zero (see osg::Referenced), 00129 * preventing the deletion of objects which are still in use. 00130 */ 00131 virtual ~WGE2DManipulator(); 00132 00133 /** 00134 * Reset the internal GUIEvent stack. 00135 */ 00136 void flushMouseEventStack(); 00137 00138 /** 00139 * Add the current mouse GUIEvent to the internal stack. 00140 * 00141 * \param ea the current event class with a mouse event 00142 */ 00143 void addMouseEvent( const osgGA::GUIEventAdapter& ea ); 00144 00145 /** 00146 * Calculate the movement of the camera for the given mouse movement. 00147 * 00148 * \return true is camera has moved and a redraw is required 00149 */ 00150 bool calcMovement(); 00151 00152 /** 00153 * The older event from the internal event stack. 00154 */ 00155 osg::ref_ptr< const osgGA::GUIEventAdapter > m_ga_t1; 00156 00157 /** 00158 * The newer event from the internal event stack. 00159 */ 00160 osg::ref_ptr< const osgGA::GUIEventAdapter > m_ga_t0; 00161 00162 private: 00163 /** 00164 * Handles events related to zooming. 00165 * 00166 * \param ea event class for storing keyboard, mouse and window events 00167 * 00168 * \return true if event was handled 00169 */ 00170 bool zoom( const osgGA::GUIEventAdapter& ea ); 00171 00172 /** 00173 * The x-position of the viewing window's lower left corner. 00174 */ 00175 double m_positionX; 00176 00177 /** 00178 * The y-position of the viewing window's lower left corner. 00179 */ 00180 double m_positionY; 00181 00182 /** 00183 * zoom factor 00184 */ 00185 double m_zoom; 00186 }; 00187 00188 #endif // WGE2DMANIPULATOR_H