| 1 | /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield |
|---|
| 2 | * |
|---|
| 3 | * This library is open source and may be redistributed and/or modified under |
|---|
| 4 | * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or |
|---|
| 5 | * (at your option) any later version. The full license is in LICENSE file |
|---|
| 6 | * included with this distribution, and on the openscenegraph.org website. |
|---|
| 7 | * |
|---|
| 8 | * This library is distributed in the hope that it will be useful, |
|---|
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 11 | * OpenSceneGraph Public License for more details. |
|---|
| 12 | */ |
|---|
| 13 | |
|---|
| 14 | #ifndef OSGUTIL_KEYSWITCMATRIXMANIPULATOR |
|---|
| 15 | #define OSGUTIL_KEYSWITCMATRIXMANIPULATOR 1 |
|---|
| 16 | |
|---|
| 17 | #include <osgGA/Export> |
|---|
| 18 | #include <osgGA/MatrixManipulator> |
|---|
| 19 | #include <osgGA/GUIEventHandler> |
|---|
| 20 | |
|---|
| 21 | namespace osgGA{ |
|---|
| 22 | |
|---|
| 23 | class GUIActionAdapter; |
|---|
| 24 | |
|---|
| 25 | /** |
|---|
| 26 | KeySwitchMatrixManipulator is a decorator which allows the type of camera manipulator |
|---|
| 27 | being used to be switched by pressing a key. E.g. '1' for a TrackballManipultor, |
|---|
| 28 | '2' for a DriveManipulator, '3' for a FlightManipulator. The manipulators available, |
|---|
| 29 | and the associated switch keys, can be configured. |
|---|
| 30 | */ |
|---|
| 31 | class OSGGA_EXPORT KeySwitchMatrixManipulator : public MatrixManipulator |
|---|
| 32 | { |
|---|
| 33 | public: |
|---|
| 34 | |
|---|
| 35 | typedef std::pair<std::string, osg::ref_ptr<MatrixManipulator> > NamedManipulator; |
|---|
| 36 | typedef std::map<int, NamedManipulator> KeyManipMap; |
|---|
| 37 | |
|---|
| 38 | virtual const char* className() const { return "KeySwitchMatrixManipulator"; } |
|---|
| 39 | |
|---|
| 40 | /** |
|---|
| 41 | Add a camera manipulator with an associated name, and a key to |
|---|
| 42 | trigger the switch, |
|---|
| 43 | */ |
|---|
| 44 | void addMatrixManipulator(int key, std::string name, MatrixManipulator *cm); |
|---|
| 45 | |
|---|
| 46 | /** |
|---|
| 47 | Add a camera manipulator with an autogenerated keybinding which is '1' + previous number of camera's registerd. |
|---|
| 48 | */ |
|---|
| 49 | void addNumberedMatrixManipulator(MatrixManipulator *cm); |
|---|
| 50 | |
|---|
| 51 | unsigned int getNumMatrixManipulators() const { return _manips.size(); } |
|---|
| 52 | |
|---|
| 53 | void selectMatrixManipulator(unsigned int num); |
|---|
| 54 | |
|---|
| 55 | /** Get the complete list of manipulators attached to this keyswitch manipulator.*/ |
|---|
| 56 | KeyManipMap& getKeyManipMap() { return _manips; } |
|---|
| 57 | |
|---|
| 58 | /** Get the const complete list of manipulators attached to this keyswitch manipulator.*/ |
|---|
| 59 | const KeyManipMap& getKeyManipMap() const { return _manips; } |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | /** Get the current active manipulators.*/ |
|---|
| 63 | MatrixManipulator* getCurrentMatrixManipulator() { return _current.get(); } |
|---|
| 64 | |
|---|
| 65 | /** Get the const current active manipulators.*/ |
|---|
| 66 | const MatrixManipulator* getCurrentMatrixManipulator() const { return _current.get(); } |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | /** Get manipulator assigned to a specified index.*/ |
|---|
| 70 | MatrixManipulator* getMatrixManipulatorWithIndex(unsigned int key); |
|---|
| 71 | |
|---|
| 72 | /** Get const manipulator assigned to a specified index.*/ |
|---|
| 73 | const MatrixManipulator* getMatrixManipulatorWithIndex(unsigned int key) const; |
|---|
| 74 | |
|---|
| 75 | /** Get manipulator assigned to a specified key.*/ |
|---|
| 76 | MatrixManipulator* getMatrixManipulatorWithKey(unsigned int key); |
|---|
| 77 | |
|---|
| 78 | /** Get const manipulator assigned to a specified key.*/ |
|---|
| 79 | const MatrixManipulator* getMatrixManipulatorWithKey(unsigned int key) const; |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | // Overrides from MatrixManipulator... |
|---|
| 83 | |
|---|
| 84 | /** set the minimum distance (as ratio) the eye point can be zoomed in towards the |
|---|
| 85 | center before the center is pushed forward.*/ |
|---|
| 86 | virtual void setMinimumDistance(float minimumDistance); |
|---|
| 87 | |
|---|
| 88 | /** set the coordinate frame which callback tells the manipulator which way is up, east and north.*/ |
|---|
| 89 | virtual void setCoordinateFrameCallback(CoordinateFrameCallback* cb); |
|---|
| 90 | |
|---|
| 91 | /** Set the position of the matrix manipulator using a 4x4 Matrix.*/ |
|---|
| 92 | virtual void setByMatrix(const osg::Matrixd& matrix) { _current->setByMatrix(matrix); } |
|---|
| 93 | |
|---|
| 94 | /** set the position of the matrix manipulator using a 4x4 Matrix.*/ |
|---|
| 95 | virtual void setByInverseMatrix(const osg::Matrixd& matrix) { _current->setByInverseMatrix(matrix); } |
|---|
| 96 | |
|---|
| 97 | /** get the position of the manipulator as 4x4 Matrix.*/ |
|---|
| 98 | virtual osg::Matrixd getMatrix() const { return _current->getMatrix(); } |
|---|
| 99 | |
|---|
| 100 | /** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/ |
|---|
| 101 | virtual osg::Matrixd getInverseMatrix() const { return _current->getInverseMatrix(); } |
|---|
| 102 | |
|---|
| 103 | /** Get the FusionDistanceMode. Used by SceneView for setting up stereo convergence.*/ |
|---|
| 104 | virtual osgUtil::SceneView::FusionDistanceMode getFusionDistanceMode() const { return _current->getFusionDistanceMode(); } |
|---|
| 105 | |
|---|
| 106 | /** Get the FusionDistanceValue. Used by SceneView for setting up stereo convergence.*/ |
|---|
| 107 | virtual float getFusionDistanceValue() const { return _current->getFusionDistanceValue(); } |
|---|
| 108 | |
|---|
| 109 | /** Set the distance property. */ |
|---|
| 110 | void setDistance(double distance); |
|---|
| 111 | |
|---|
| 112 | /** Get the distance property. */ |
|---|
| 113 | double getDistance() const; |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | virtual void setNode(osg::Node* n); |
|---|
| 117 | |
|---|
| 118 | virtual const osg::Node* getNode() const { return _current->getNode(); } |
|---|
| 119 | |
|---|
| 120 | virtual osg::Node* getNode() { return _current->getNode(); } |
|---|
| 121 | |
|---|
| 122 | virtual void setHomePosition(const osg::Vec3d& eye, const osg::Vec3d& center, const osg::Vec3d& up, bool autoComputeHomePosition=false); |
|---|
| 123 | |
|---|
| 124 | virtual void setAutoComputeHomePosition(bool flag); |
|---|
| 125 | |
|---|
| 126 | virtual void computeHomePosition(); |
|---|
| 127 | |
|---|
| 128 | virtual void home(const GUIEventAdapter& ee,GUIActionAdapter& aa) { if (_current.valid()) _current->home(ee,aa); } |
|---|
| 129 | |
|---|
| 130 | virtual void init(const GUIEventAdapter& ee,GUIActionAdapter& aa) { if (_current.valid()) _current->init(ee,aa); } |
|---|
| 131 | |
|---|
| 132 | virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us); |
|---|
| 133 | |
|---|
| 134 | /** Get the keyboard and mouse usage of this manipulator.*/ |
|---|
| 135 | virtual void getUsage(osg::ApplicationUsage& usage) const; |
|---|
| 136 | |
|---|
| 137 | private: |
|---|
| 138 | |
|---|
| 139 | KeyManipMap _manips; |
|---|
| 140 | |
|---|
| 141 | osg::ref_ptr<MatrixManipulator> _current; |
|---|
| 142 | }; |
|---|
| 143 | |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | #endif |
|---|