gepetto-viewer  6.0.0
An user-friendly Graphical Interface
keyboard-manipulator.h
Go to the documentation of this file.
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.;
23 class OSGGA_EXPORT KeyboardManipulator : public FirstPersonManipulator {
24  typedef FirstPersonManipulator inherited;
25 
26  public:
27  KeyboardManipulator(int flags = DEFAULT_SETTINGS);
29  const osg::CopyOp& copyOp = osg::CopyOp::SHALLOW_COPY);
32  KeyboardManipulator(osgViewer::GraphicsWindow* window,
33  int flags = DEFAULT_SETTINGS);
34 
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 
100 } // namespace osgGA
101 #endif // FPSMANIPULATOR_H
Definition: keyboard-manipulator.h:23
virtual bool performMovementLeftMouseButton(const double eventTimeDelta, const double dx, const double dy)
KeyboardManipulator(int flags=DEFAULT_SETTINGS)
virtual bool handleMousePush(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
virtual bool handleFrame(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
virtual bool handleMouseRelease(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
virtual bool handleKeyDown(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
META_Object(osgGA, KeyboardManipulator)
virtual bool handleKeyUp(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
virtual void getUsage(osg::ApplicationUsage &usage) const
virtual void rotateRoll(const double roll)
KeyboardManipulator(const KeyboardManipulator &fpm, const osg::CopyOp &copyOp=osg::CopyOp::SHALLOW_COPY)
KeyboardManipulator(osgViewer::GraphicsWindow *window, int flags=DEFAULT_SETTINGS)
Definition: keyboard-manipulator.h:18
const double startSpeed_
Definition: keyboard-manipulator.h:20
KeyBinding
Definition: keyboard-manipulator.h:88
@ key_forward
Definition: keyboard-manipulator.h:89
@ key_roll_right
Definition: keyboard-manipulator.h:93
@ key_up
Definition: keyboard-manipulator.h:95
@ key_backward
Definition: keyboard-manipulator.h:90
@ key_down
Definition: keyboard-manipulator.h:96
@ key_roll_left
Definition: keyboard-manipulator.h:94
@ key_left
Definition: keyboard-manipulator.h:92
@ key_right
Definition: keyboard-manipulator.h:91
keyLayout
Definition: keyboard-manipulator.h:99
@ LAYOUT_azerty
Definition: keyboard-manipulator.h:99
@ LAYOUT_unknown
Definition: keyboard-manipulator.h:99
@ LAYOUT_qwerty
Definition: keyboard-manipulator.h:99