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 
14 #include <osgGA/FirstPersonManipulator>
15 #include <osgViewer/Viewer>
16 #include <osg/Camera>
17 #include <osgViewer/GraphicsWindow>
18 #include <X11/Xlib.h>
19 
20 
21 
22 
23 namespace osgGA {
24 
25  const double startSpeed_ = 2.;
28  class OSGGA_EXPORT KeyboardManipulator : public FirstPersonManipulator
29  {
30  typedef FirstPersonManipulator inherited;
31 
32  public:
33  KeyboardManipulator( int flags = DEFAULT_SETTINGS );
34  KeyboardManipulator( const KeyboardManipulator& fpm, const osg::CopyOp& copyOp = osg::CopyOp::SHALLOW_COPY );
36  KeyboardManipulator(osgViewer::GraphicsWindow* window, int flags = DEFAULT_SETTINGS );
37 
38  META_Object( osgGA, KeyboardManipulator );
39 
40  protected :
41 
42  virtual bool handleKeyDown( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
43  virtual bool handleKeyUp( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
44  virtual bool handleFrame( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
45  virtual bool handleMousePush( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
46  virtual bool handleMouseRelease( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& us );
47  // virtual bool handleMouseWheel( const GUIEventAdapter& ea, GUIActionAdapter& us );
48  virtual bool performMovementLeftMouseButton( const double eventTimeDelta, const double dx, const double dy );
49 
50  virtual void rotateRoll( const double roll/*,const osg::Vec3d& localUp */);
51  virtual void getUsage(osg::ApplicationUsage &usage) const;
52  bool initKeyboard();
53  private :
54 
55  double speed_;
56  double speedX_;
57  double speedY_;
58  double speedZ_;
59  double speedRoll_;
60  /* double zNear_;
61  double zFar_;
62  double fovy_;
63  double ratio_;*/
64  osg::Quat rotateRoll_;
65  // osg::Quat rotatePitch_;
66  // osg::Quat rotateYaw_;
67  osg::Vec3d localUp_;
68  int keyLayout_;
69 
70  //osg::Camera* camera_;
71  osgViewer::GraphicsWindow* gWindow_;
72  // Display *display_;
73  int keycode_;
74  bool rightClic_;
75  bool ctrl_;
76  bool shift_;
77  bool noRoll_;
78 
79 
80  };// end class
81 
82  /*
83  * zqsd for azerty keyboard, if qwerty keyboard is detected, the keySym will be modified
84  * */
86  {
87  key_forward = GUIEventAdapter::KEY_W, //depend on qwerty / azerty
88  key_backward = GUIEventAdapter::KEY_S,
89  key_right = GUIEventAdapter::KEY_D,
90  key_left = GUIEventAdapter::KEY_A,
91  key_roll_right = GUIEventAdapter::KEY_E,
92  key_roll_left = GUIEventAdapter::KEY_Q,
93  key_up = GUIEventAdapter::KEY_Space,
94  key_down = GUIEventAdapter::KEY_V
95  };
96 
97  enum keyLayout{
99  };
100 }//namespace osgGA
101 #endif // FPSMANIPULATOR_H
Definition: keyboard-manipulator.h:88
Definition: keyboard-manipulator.h:98
Definition: keyboard-manipulator.h:98
Definition: keyboard-manipulator.h:94
Definition: keyboard-manipulator.h:93
Definition: keyboard-manipulator.h:91
Definition: keyboard-manipulator.h:89
KeyBinding
Definition: keyboard-manipulator.h:85
Definition: keyboard-manipulator.h:23
Definition: keyboard-manipulator.h:92
keyLayout
Definition: keyboard-manipulator.h:97
Definition: keyboard-manipulator.h:87
Definition: keyboard-manipulator.h:90
Definition: keyboard-manipulator.h:98
Definition: keyboard-manipulator.h:28
const double startSpeed_
Definition: keyboard-manipulator.h:25