| 1 | // Copyright (C) 2009 - 2012 Mathias Froehlich |
| 2 | // |
| 3 | // This program is free software; you can redistribute it and/or |
| 4 | // modify it under the terms of the GNU General Public License as |
| 5 | // published by the Free Software Foundation; either version 2 of the |
| 6 | // License, or (at your option) any later version. |
| 7 | // |
| 8 | // This program is distributed in the hope that it will be useful, but |
| 9 | // WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 | // General Public License for more details. |
| 12 | // |
| 13 | // You should have received a copy of the GNU General Public License |
| 14 | // along with this program; if not, write to the Free Software |
| 15 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 16 | |
| 17 | #ifndef _HLACameraManipulator_hxx |
| 18 | #define _HLACameraManipulator_hxx |
| 19 | |
| 20 | #include <osgGA/CameraManipulator> |
| 21 | #include <simgear/scene/util/OsgMath.hxx> |
| 22 | #include "HLAPerspectiveViewer.hxx" |
| 23 | |
| 24 | namespace fgviewer { |
| 25 | |
| 26 | class Viewer; |
| 27 | |
| 28 | class HLACameraManipulator : public osgGA::CameraManipulator { |
| 29 | public: |
| 30 | HLACameraManipulator(HLAPerspectiveViewer* perspectiveViewer = 0); |
| 31 | HLACameraManipulator(const HLACameraManipulator& cameraManipulator, const osg::CopyOp& copyOp = osg::CopyOp::SHALLOW_COPY); |
| 32 | virtual ~HLACameraManipulator(); |
| 33 | |
| 34 | META_Object(fgviewer, HLACameraManipulator); |
| 35 | |
| 36 | virtual void setByMatrix(const osg::Matrixd& matrix); |
| 37 | virtual void setByInverseMatrix(const osg::Matrixd& matrix); |
| 38 | |
| 39 | virtual osg::Matrixd getMatrix() const; |
| 40 | virtual osg::Matrixd getInverseMatrix() const; |
| 41 | |
| 42 | /** Handle events, return true if handled, false otherwise. */ |
| 43 | virtual bool handle(const osgGA::GUIEventAdapter& eventAdapter, osgGA::GUIActionAdapter& actionAdapter); |
| 44 | |
| 45 | protected: |
| 46 | bool _handle(const osgGA::GUIEventAdapter& eventAdapter, Viewer& viewer); |
| 47 | void _handleFrameEvent(osgGA::GUIActionAdapter& actionAdapter); |
| 48 | bool _handleKeyDownEvent(const osgGA::GUIEventAdapter& eventAdapter, Viewer& viewer); |
| 49 | bool _handleKeyUpEvent(const osgGA::GUIEventAdapter& eventAdapter, Viewer& viewer); |
| 50 | void _incrementEyePosition(const SGVec3d& offset); |
| 51 | void _resetView(); |
| 52 | void _rotateView(const osg::Vec2& inc); |
| 53 | void _rotateSun(const osg::Vec2& inc, Viewer& viewer); |
| 54 | |
| 55 | private: |
| 56 | osg::Matrixd _viewMatrix; |
| 57 | osg::Matrixd _inverseViewMatrix; |
| 58 | osg::Vec2 _lastMousePos; |
| 59 | SGSharedPtr<HLAPerspectiveViewer> _perspectiveViewer; |
| 60 | }; |
| 61 | |
| 62 | } // namespace fgviewer |
| 63 | |
| 64 | #endif |