root/OpenSceneGraph/trunk/include/osgGA/KeySwitchMatrixManipulator @ 7648

Revision 7648, 5.8 kB (checked in by robert, 6 years ago)

From Roland Smeenk, "Attached you will find a large set of small typo fixes (mainly in the comments)."

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
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
21namespace osgGA{
22
23class GUIActionAdapter;
24
25/**
26KeySwitchMatrixManipulator is a decorator which allows the type of camera manipulator
27being 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,
29and the associated switch keys, can be configured.
30*/
31class OSGGA_EXPORT KeySwitchMatrixManipulator : public MatrixManipulator
32{
33public:
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
110        virtual void setNode(osg::Node* n);
111
112        virtual const osg::Node* getNode() const        { return _current->getNode(); }
113
114        virtual osg::Node* getNode()                    { return _current->getNode(); }
115
116        virtual void setHomePosition(const osg::Vec3d& eye, const osg::Vec3d& center, const osg::Vec3d& up, bool autoComputeHomePosition=false);
117
118        virtual void setAutoComputeHomePosition(bool flag);
119
120        virtual void computeHomePosition();
121
122        virtual void home(const GUIEventAdapter& ee,GUIActionAdapter& aa) { if (_current.valid()) _current->home(ee,aa); }
123
124        virtual void init(const GUIEventAdapter& ee,GUIActionAdapter& aa) { if (_current.valid()) _current->init(ee,aa); }
125
126        virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us);
127
128        /** Get the keyboard and mouse usage of this manipulator.*/
129        virtual void getUsage(osg::ApplicationUsage& usage) const;
130
131private:
132
133        KeyManipMap _manips;
134
135        osg::ref_ptr<MatrixManipulator> _current;
136};
137
138}
139
140#endif
Note: See TracBrowser for help on using the browser.