OpenWalnut  1.4.0
WGEZoomTrackballManipulator.h
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 WGEZOOMTRACKBALLMANIPULATOR_H
00026 #define WGEZOOMTRACKBALLMANIPULATOR_H
00027 
00028 #include <osgGA/TrackballManipulator>
00029 
00030 
00031 /**
00032  * New OSG manipulator: TrackballManipulator with added mouse wheel zoom.
00033  */
00034 class WGEZoomTrackballManipulator: public osgGA::TrackballManipulator
00035 {
00036 public:
00037     /**
00038      * Default constructor
00039      */
00040     WGEZoomTrackballManipulator();
00041 
00042     /**
00043      * Set the position of the manipulator using a 4x4 matrix.
00044      * \param matrix position of the manipulator
00045      */
00046     virtual void setByMatrix( const osg::Matrixd& matrix );
00047 
00048     /**
00049      * Get the position of the manipulator as 4x4 matrix.
00050      *
00051      * \return the matrix representing the transformation
00052      */
00053     virtual osg::Matrixd getMatrix() const;
00054 
00055     /**
00056      * Get the manipulator only containing rotation and translation.
00057      *
00058      * \return the matrix with translation and rotation.
00059      */
00060     virtual osg::Matrixd getMatrixWithoutZoom() const;
00061 
00062     /**
00063      * Get the position of the manipulator as a inverse matrix of the
00064      * manipulator, typically used as a model view matrix.
00065      *
00066      * \return the inverse matrix
00067      */
00068     virtual osg::Matrixd getInverseMatrix() const;
00069 
00070     /**
00071      * Move the camera to the default position.
00072      * May be ignored by manipulators if home functionality is not appropriate.
00073      * \param currentTime Variable specified in osg class but not used.
00074      */
00075     virtual void home( double currentTime );
00076 
00077     /**
00078      * Handle events, return true if handled, false otherwise.
00079      * \param ea Event class for storing Keyboard, mouse and window events.
00080      * \param us Interface by which GUIEventHandlers may request actions of the GUI system
00081      *
00082      * \return true if event was handled
00083      */
00084     virtual bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
00085 
00086     /**
00087      * Get zoom factor.
00088      *
00089      * \return the current zoom factor
00090      */
00091     double getZoom() const;
00092 
00093     /**
00094      * Set zoom factor.
00095      * \param zoom the zoom factor to be set.
00096      */
00097     void setZoom( double zoom );
00098 
00099     /**
00100      * setter for paint mode
00101      * when set to something different from 0, a left drag should move the scene
00102      *
00103      * \param mode the mode
00104      */
00105     void setPaintMode( int mode );
00106 
00107     /**
00108      * En-/Disables throwing.
00109      *
00110      * \param allowThrow if true, throwing is enabled.
00111      */
00112     void setThrow( bool allowThrow = true );
00113 
00114     /**
00115      * Checks whether throwing is active.
00116      *
00117      * \return true if active
00118      */
00119     bool getThrow() const;
00120 
00121 protected:
00122 private:
00123     /**
00124      * Handles events related to zooming.
00125      * \param ea Event class for storing Keyboard, mouse and window events.
00126      * \param us Interface by which GUIEventHandlers may request actions of the GUI system
00127      *
00128      * \return true if event was handled
00129      */
00130     bool zoom( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
00131 
00132     double m_zoom; //!< Zoom factor.
00133     bool m_allowThrow; //!< Do we want the auto-rotation thingy?
00134 
00135     int m_paintMode; //!<paint mode
00136 };
00137 
00138 inline double WGEZoomTrackballManipulator::getZoom() const
00139 {
00140     return m_zoom;
00141 }
00142 
00143 inline void WGEZoomTrackballManipulator::setZoom( double zoom )
00144 {
00145     m_zoom = zoom;
00146 }
00147 
00148 #endif  // WGEZOOMTRACKBALLMANIPULATOR_H