| Line |
Branch |
Exec |
Source |
| 1 |
|
|
#ifndef GEPETTO_VIEWER_FPSMANIPULATOR_H |
| 2 |
|
|
#define GEPETTO_VIEWER_FPSMANIPULATOR_H |
| 3 |
|
|
// |
| 4 |
|
|
// KeyboardManipulator |
| 5 |
|
|
// gepetto-viewer |
| 6 |
|
|
// |
| 7 |
|
|
// Alternative CameraManipulator for OSG, use keyboard and mouse |
| 8 |
|
|
// KeyBinding are inspired by the classic system in games |
| 9 |
|
|
// |
| 10 |
|
|
// Created by Pierre Fernbach in january 2016 |
| 11 |
|
|
// |
| 12 |
|
|
|
| 13 |
|
|
#include <osg/Camera> |
| 14 |
|
|
#include <osgGA/FirstPersonManipulator> |
| 15 |
|
|
#include <osgViewer/GraphicsWindow> |
| 16 |
|
|
#include <osgViewer/Viewer> |
| 17 |
|
|
|
| 18 |
|
|
namespace osgGA { |
| 19 |
|
|
|
| 20 |
|
|
const double startSpeed_ = 2.; |
| 21 |
|
|
/** FirstPersonManipulator is base class for camera control based on position |
| 22 |
|
|
and orientation of camera, like walk, drive, and flight manipulators. */ |
| 23 |
|
|
class OSGGA_EXPORT KeyboardManipulator : public FirstPersonManipulator { |
| 24 |
|
|
typedef FirstPersonManipulator inherited; |
| 25 |
|
|
|
| 26 |
|
|
public: |
| 27 |
|
|
KeyboardManipulator(int flags = DEFAULT_SETTINGS); |
| 28 |
|
|
KeyboardManipulator(const KeyboardManipulator& fpm, |
| 29 |
|
|
const osg::CopyOp& copyOp = osg::CopyOp::SHALLOW_COPY); |
| 30 |
|
|
/// Constructor with reference to the graphic window, needed for hidding mouse |
| 31 |
|
|
/// cursor |
| 32 |
|
|
KeyboardManipulator(osgViewer::GraphicsWindow* window, |
| 33 |
|
|
int flags = DEFAULT_SETTINGS); |
| 34 |
|
|
|
| 35 |
|
✗ |
META_Object(osgGA, KeyboardManipulator); |
| 36 |
|
|
|
| 37 |
|
|
protected: |
| 38 |
|
|
virtual bool handleKeyDown(const osgGA::GUIEventAdapter& ea, |
| 39 |
|
|
osgGA::GUIActionAdapter& us); |
| 40 |
|
|
virtual bool handleKeyUp(const osgGA::GUIEventAdapter& ea, |
| 41 |
|
|
osgGA::GUIActionAdapter& us); |
| 42 |
|
|
virtual bool handleFrame(const osgGA::GUIEventAdapter& ea, |
| 43 |
|
|
osgGA::GUIActionAdapter& us); |
| 44 |
|
|
virtual bool handleMousePush(const osgGA::GUIEventAdapter& ea, |
| 45 |
|
|
osgGA::GUIActionAdapter& us); |
| 46 |
|
|
virtual bool handleMouseRelease(const osgGA::GUIEventAdapter& ea, |
| 47 |
|
|
osgGA::GUIActionAdapter& us); |
| 48 |
|
|
// virtual bool handleMouseWheel( const GUIEventAdapter& ea, |
| 49 |
|
|
// GUIActionAdapter& us ); |
| 50 |
|
|
virtual bool performMovementLeftMouseButton(const double eventTimeDelta, |
| 51 |
|
|
const double dx, const double dy); |
| 52 |
|
|
|
| 53 |
|
|
virtual void rotateRoll(const double roll /*,const osg::Vec3d& localUp */); |
| 54 |
|
|
virtual void getUsage(osg::ApplicationUsage& usage) const; |
| 55 |
|
|
bool initKeyboard(); |
| 56 |
|
|
|
| 57 |
|
|
private: |
| 58 |
|
|
double speed_; |
| 59 |
|
|
double speedX_; |
| 60 |
|
|
double speedY_; |
| 61 |
|
|
double speedZ_; |
| 62 |
|
|
double speedRoll_; |
| 63 |
|
|
/* double zNear_; |
| 64 |
|
|
double zFar_; |
| 65 |
|
|
double fovy_; |
| 66 |
|
|
double ratio_;*/ |
| 67 |
|
|
osg::Quat rotateRoll_; |
| 68 |
|
|
// osg::Quat rotatePitch_; |
| 69 |
|
|
// osg::Quat rotateYaw_; |
| 70 |
|
|
osg::Vec3d localUp_; |
| 71 |
|
|
int keyLayout_; |
| 72 |
|
|
|
| 73 |
|
|
// osg::Camera* camera_; |
| 74 |
|
|
osgViewer::GraphicsWindow* gWindow_; |
| 75 |
|
|
// Display *display_; |
| 76 |
|
|
int keycode_; |
| 77 |
|
|
bool rightClic_; |
| 78 |
|
|
bool ctrl_; |
| 79 |
|
|
bool shift_; |
| 80 |
|
|
bool noRoll_; |
| 81 |
|
|
|
| 82 |
|
|
}; // end class |
| 83 |
|
|
|
| 84 |
|
|
/* |
| 85 |
|
|
* zqsd for azerty keyboard, if qwerty keyboard is detected, the keySym will be |
| 86 |
|
|
* modified |
| 87 |
|
|
* */ |
| 88 |
|
|
enum KeyBinding { |
| 89 |
|
|
key_forward = GUIEventAdapter::KEY_W, // depend on qwerty / azerty |
| 90 |
|
|
key_backward = GUIEventAdapter::KEY_S, |
| 91 |
|
|
key_right = GUIEventAdapter::KEY_D, |
| 92 |
|
|
key_left = GUIEventAdapter::KEY_A, |
| 93 |
|
|
key_roll_right = GUIEventAdapter::KEY_E, |
| 94 |
|
|
key_roll_left = GUIEventAdapter::KEY_Q, |
| 95 |
|
|
key_up = GUIEventAdapter::KEY_Space, |
| 96 |
|
|
key_down = GUIEventAdapter::KEY_V |
| 97 |
|
|
}; |
| 98 |
|
|
|
| 99 |
|
|
enum keyLayout { LAYOUT_unknown, LAYOUT_azerty, LAYOUT_qwerty }; |
| 100 |
|
|
} // namespace osgGA |
| 101 |
|
|
#endif // FPSMANIPULATOR_H |
| 102 |
|
|
|