2003-01-22 00:45:36 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
|
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2002-07-17 04:07:32 +08:00
|
|
|
|
2002-05-09 18:31:03 +08:00
|
|
|
#ifndef OSGUTIL_KEYSWITCCAMERAMANIPULATORHER
|
|
|
|
#define OSGUTIL_KEYSWITCHCAMERAMANIPULATORER 1
|
|
|
|
|
|
|
|
#include <osgGA/Export>
|
|
|
|
#include <osgGA/CameraManipulator>
|
|
|
|
#include <osgGA/GUIEventHandler>
|
|
|
|
#include <osgGA/GUIEventHandlerVisitor>
|
|
|
|
|
|
|
|
namespace osgGA{
|
|
|
|
|
|
|
|
class GUIEventAdapter;
|
|
|
|
class GUIActionAdapter;
|
|
|
|
|
2002-08-28 22:27:18 +08:00
|
|
|
/**
|
|
|
|
KeySwitchCameraManipulator is a decorator which allows the type of camera manipulator
|
|
|
|
being used to be switched by pressing a key. E.g. '1' for a TrackballManipultor,
|
|
|
|
'2' for a DriveManipulator, '3' for a FlightManipulator. The manipulators available,
|
|
|
|
and the associated switch keys, can be configured.
|
|
|
|
*/
|
2002-05-09 18:31:03 +08:00
|
|
|
class OSGGA_EXPORT KeySwitchCameraManipulator : public CameraManipulator
|
|
|
|
{
|
2002-08-28 22:27:18 +08:00
|
|
|
public:
|
2002-05-09 18:31:03 +08:00
|
|
|
|
2003-02-19 18:43:02 +08:00
|
|
|
virtual const char* className() { return "KeySwitchCamera"; }
|
|
|
|
|
2002-08-28 22:27:18 +08:00
|
|
|
/**
|
|
|
|
Add a camera manipulator with an associated name, and a key to
|
|
|
|
trigger the switch,
|
|
|
|
*/
|
2002-05-09 18:31:03 +08:00
|
|
|
void addCameraManipulator(int key, std::string name, CameraManipulator *cm);
|
|
|
|
|
2002-08-28 22:27:18 +08:00
|
|
|
/**
|
|
|
|
Add a camera manipulator with an autogenerated keybinding which is '1' + previous number of camera's registerd.
|
|
|
|
*/
|
2002-07-17 18:00:50 +08:00
|
|
|
void addNumberedCameraManipulator(CameraManipulator *cm);
|
|
|
|
|
2003-01-22 23:30:17 +08:00
|
|
|
unsigned int getNumCameraManipualtors() const { return _manips.size(); }
|
|
|
|
|
|
|
|
void selectCameraManipulator(unsigned int num);
|
|
|
|
|
|
|
|
|
2003-01-17 22:12:25 +08:00
|
|
|
CameraManipulator* getCurrentCameraManipulator() { return _current.get(); }
|
|
|
|
|
|
|
|
const CameraManipulator* getCurrentCameraManipulator() const { return _current.get(); }
|
|
|
|
|
2003-03-20 05:14:50 +08:00
|
|
|
|
|
|
|
CameraManipulator* getCameraManipulator(unsigned int num);
|
|
|
|
|
|
|
|
const CameraManipulator* getCameraManipulator(unsigned int num) const;
|
|
|
|
|
|
|
|
|
2002-05-09 18:31:03 +08:00
|
|
|
// Overrides from CameraManipulator...
|
|
|
|
|
2003-01-17 22:12:25 +08:00
|
|
|
|
2002-08-28 22:27:18 +08:00
|
|
|
virtual void setCamera(osg::Camera* c) { _current->setCamera(c); }
|
2002-05-09 18:31:03 +08:00
|
|
|
|
2002-08-28 22:27:18 +08:00
|
|
|
virtual const osg::Camera * getCamera() const { return _current->getCamera(); }
|
2002-05-09 18:31:03 +08:00
|
|
|
|
2002-08-28 22:27:18 +08:00
|
|
|
virtual osg::Camera * getCamera() { return _current->getCamera(); }
|
2002-05-09 18:31:03 +08:00
|
|
|
|
2003-04-08 21:10:47 +08:00
|
|
|
virtual void setNode(osg::Node* n);
|
2002-05-09 18:31:03 +08:00
|
|
|
|
|
|
|
virtual const osg::Node* getNode() const { return _current->getNode(); }
|
|
|
|
|
|
|
|
virtual osg::Node* getNode() { return _current->getNode(); }
|
|
|
|
|
|
|
|
virtual void home(const GUIEventAdapter& ee,GUIActionAdapter& aa) { _current->home(ee,aa); }
|
|
|
|
|
|
|
|
virtual void init(const GUIEventAdapter& ee,GUIActionAdapter& aa) { _current->init(ee,aa); }
|
|
|
|
|
|
|
|
virtual bool handle(const GUIEventAdapter& ea,GUIActionAdapter& us);
|
|
|
|
|
2003-02-19 18:43:02 +08:00
|
|
|
/** Get the keyboard and mouse usage of this manipulator.*/
|
|
|
|
virtual void getUsage(osg::ApplicationUsage& usage) const;
|
|
|
|
|
2002-08-28 22:27:18 +08:00
|
|
|
private:
|
2002-05-09 18:31:03 +08:00
|
|
|
|
|
|
|
typedef std::pair<std::string, osg::ref_ptr<CameraManipulator> > NamedManipulator;
|
|
|
|
typedef std::map<int, NamedManipulator> KeyManipMap;
|
|
|
|
KeyManipMap _manips;
|
|
|
|
|
|
|
|
osg::ref_ptr<CameraManipulator> _current;
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|