openscenegraph
KeySwitchMatrixManipulator
Go to the documentation of this file.
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/CameraManipulator>
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 TrackballManipulator,
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 CameraManipulator
32{
33 public:
34
35 typedef std::pair<std::string, osg::ref_ptr<CameraManipulator> > 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, CameraManipulator *cm);
45
46 /**
47 Add a camera manipulator with an autogenerated keybinding which is '1' + previous number of camera's registered.
48 */
49 void addNumberedMatrixManipulator(CameraManipulator *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 CameraManipulator* getCurrentMatrixManipulator() { return _current.get(); }
64
65 /** Get the const current active manipulators.*/
66 const CameraManipulator* getCurrentMatrixManipulator() const { return _current.get(); }
67
68
69 /** Get manipulator assigned to a specified index.*/
70 CameraManipulator* getMatrixManipulatorWithIndex(unsigned int key);
71
72 /** Get const manipulator assigned to a specified index.*/
73 const CameraManipulator* getMatrixManipulatorWithIndex(unsigned int key) const;
74
75 /** Get manipulator assigned to a specified key.*/
76 CameraManipulator* getMatrixManipulatorWithKey(unsigned int key);
77
78 /** Get const manipulator assigned to a specified key.*/
79 const CameraManipulator* getMatrixManipulatorWithKey(unsigned int key) const;
80
81
82 // Overrides from CameraManipulator...
83
84 /** set the coordinate frame which callback tells the manipulator which way is up, east and north.*/
85 virtual void setCoordinateFrameCallback(CoordinateFrameCallback* cb);
86
87 /** Set the position of the matrix manipulator using a 4x4 Matrix.*/
88 virtual void setByMatrix(const osg::Matrixd& matrix) { _current->setByMatrix(matrix); }
89
90 /** set the position of the matrix manipulator using a 4x4 Matrix.*/
91 virtual void setByInverseMatrix(const osg::Matrixd& matrix) { _current->setByInverseMatrix(matrix); }
92
93 /** get the position of the manipulator as 4x4 Matrix.*/
94 virtual osg::Matrixd getMatrix() const { return _current->getMatrix(); }
95
96 /** get the position of the manipulator as a inverse matrix of the manipulator, typically used as a model view matrix.*/
97 virtual osg::Matrixd getInverseMatrix() const { return _current->getInverseMatrix(); }
98
99 /** Get the FusionDistanceMode. Used by SceneView for setting up stereo convergence.*/
100 virtual osgUtil::SceneView::FusionDistanceMode getFusionDistanceMode() const { return _current->getFusionDistanceMode(); }
101
102 /** Get the FusionDistanceValue. Used by SceneView for setting up stereo convergence.*/
103 virtual float getFusionDistanceValue() const { return _current->getFusionDistanceValue(); }
104
105
106 virtual void setNode(osg::Node* n);
107
108 virtual const osg::Node* getNode() const { return _current->getNode(); }
109
110 virtual osg::Node* getNode() { return _current->getNode(); }
111
112 virtual void setHomePosition(const osg::Vec3d& eye, const osg::Vec3d& center, const osg::Vec3d& up, bool autoComputeHomePosition=false);
113
114 virtual void setAutoComputeHomePosition(bool flag);
115
116 virtual void computeHomePosition();
117
118 virtual void finishAnimation();
119
120 virtual void home(const GUIEventAdapter& ee,GUIActionAdapter& aa);
121
122 virtual void init(const GUIEventAdapter& ee,GUIActionAdapter& aa) { if (_current.valid()) _current->init(ee,aa); }
123
124 virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us);
125
126 /** Get the keyboard and mouse usage of this manipulator.*/
127 virtual void getUsage(osg::ApplicationUsage& usage) const;
128
129 private:
130
131 KeyManipMap _manips;
132
133 osg::ref_ptr<CameraManipulator> _current;
134};
135
136}
137
138#endif