OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
cameracontroller.hpp
Go to the documentation of this file.
1 #ifndef OPENCS_VIEW_CAMERACONTROLLER_H
2 #define OPENCS_VIEW_CAMERACONTROLLER_H
3 
4 #include <string>
5 #include <vector>
6 
7 #include <QObject>
8 
9 #include <osg/ref_ptr>
10 #include <osg/Vec3d>
11 
12 namespace osg
13 {
14  class Camera;
15  class Group;
16 }
17 
18 namespace CSMPrefs
19 {
20  class Shortcut;
21 }
22 
23 namespace CSVRender
24 {
25  class SceneWidget;
26 
27  class CameraController : public QObject
28  {
29  Q_OBJECT
30 
31  public:
32 
33  static const osg::Vec3d WorldUp;
34 
35  static const osg::Vec3d LocalUp;
36  static const osg::Vec3d LocalLeft;
37  static const osg::Vec3d LocalForward;
38 
39  CameraController(QObject* parent);
40  virtual ~CameraController();
41 
42  bool isActive() const;
43 
44  osg::Camera* getCamera() const;
45  double getCameraSensitivity() const;
46  bool getInverted() const;
47  double getSecondaryMovementMultiplier() const;
48  double getWheelMovementMultiplier() const;
49 
50  void setCamera(osg::Camera*);
51  void setCameraSensitivity(double value);
52  void setInverted(bool value);
53  void setSecondaryMovementMultiplier(double value);
54  void setWheelMovementMultiplier(double value);
55 
56  // moves the camera to an intelligent position
57  void setup(osg::Group* root, unsigned int mask, const osg::Vec3d& up);
58 
59  virtual void handleMouseMoveEvent(int x, int y) = 0;
60  virtual void handleMouseScrollEvent(int x) = 0;
61 
62  virtual void update(double dt) = 0;
63 
64  protected:
65 
66  virtual void onActivate(){}
67 
68  void addShortcut(CSMPrefs::Shortcut* shortcut);
69 
70  private:
71 
76 
77  osg::Camera* mCamera;
78 
79  std::vector<CSMPrefs::Shortcut*> mShortcuts;
80  };
81 
83  {
84  Q_OBJECT
85 
86  public:
87 
89 
90  double getLinearSpeed() const;
91  double getRotationalSpeed() const;
92  double getSpeedMultiplier() const;
93 
94  void setLinearSpeed(double value);
95  void setRotationalSpeed(double value);
96  void setSpeedMultiplier(double value);
97 
98  void fixUpAxis(const osg::Vec3d& up);
99  void unfixUpAxis();
100 
101  void handleMouseMoveEvent(int x, int y);
102  void handleMouseScrollEvent(int x);
103 
104  void update(double dt);
105 
106  private:
107 
108  void yaw(double value);
109  void pitch(double value);
110  void roll(double value);
111  void translate(const osg::Vec3d& offset);
112 
113  void stabilize();
114 
119  osg::Vec3d mUp;
120 
121  double mLinSpeed;
122  double mRotSpeed;
123  double mSpeedMult;
124 
125  private slots:
126 
127  void naviPrimary(bool active);
128  void naviSecondary(bool active);
129  void forward(bool active);
130  void left(bool active);
131  void backward(bool active);
132  void right(bool active);
133  void rollLeft(bool active);
134  void rollRight(bool active);
135  void alternateFast(bool active);
136  void swapSpeedMode();
137  };
138 
140  {
141  Q_OBJECT
142 
143  public:
144 
146 
147  osg::Vec3d getCenter() const;
148  double getOrbitSpeed() const;
149  double getOrbitSpeedMultiplier() const;
150  unsigned int getPickingMask() const;
151 
152  void setCenter(const osg::Vec3d& center);
153  void setOrbitSpeed(double value);
154  void setOrbitSpeedMultiplier(double value);
155  void setPickingMask(unsigned int value);
156 
157  void handleMouseMoveEvent(int x, int y);
158  void handleMouseScrollEvent(int x);
159 
160  void update(double dt);
161 
162  private:
163 
164  void onActivate();
165 
166  void initialize();
167 
168  void rotateHorizontal(double value);
169  void rotateVertical(double value);
170  void roll(double value);
171  void translate(const osg::Vec3d& offset);
172  void zoom(double value);
173 
178  unsigned int mPickingMask;
179  osg::Vec3d mCenter;
180  double mDistance;
181 
182  double mOrbitSpeed;
184 
185  private slots:
186 
187  void naviPrimary(bool active);
188  void naviSecondary(bool active);
189  void up(bool active);
190  void left(bool active);
191  void down(bool active);
192  void right(bool active);
193  void rollLeft(bool active);
194  void rollRight(bool active);
195  void alternateFast(bool active);
196  void swapSpeedMode();
197  };
198 }
199 
200 #endif
unsigned int mPickingMask
Definition: cameracontroller.hpp:178
double mOrbitSpeed
Definition: cameracontroller.hpp:182
void rotateVertical(double value)
Definition: cameracontroller.cpp:684
void setSpeedMultiplier(double value)
Definition: cameracontroller.cpp:262
void forward(bool active)
Definition: cameracontroller.cpp:404
void handleMouseScrollEvent(int x)
Definition: cameracontroller.cpp:596
bool mLeft
Definition: cameracontroller.hpp:177
double getLinearSpeed() const
Definition: cameracontroller.cpp:237
void translate(const osg::Vec3d &offset)
Definition: cameracontroller.cpp:381
bool mForward
Definition: cameracontroller.hpp:118
unsigned int getPickingMask() const
Definition: cameracontroller.cpp:539
bool isActive() const
Definition: cameracontroller.cpp:49
bool getInverted() const
Definition: cameracontroller.cpp:64
void setCenter(const osg::Vec3d &center)
Definition: cameracontroller.cpp:544
bool mUp
Definition: cameracontroller.hpp:177
double mCameraSensitivity
Definition: cameracontroller.hpp:73
OrbitCameraController(QWidget *parent)
Definition: cameracontroller.cpp:448
void left(bool active)
Definition: cameracontroller.cpp:741
osg::Vec3d getCenter() const
Definition: cameracontroller.cpp:524
void alternateFast(bool active)
Definition: cameracontroller.cpp:434
double getSecondaryMovementMultiplier() const
Definition: cameracontroller.cpp:69
void setWheelMovementMultiplier(double value)
Definition: cameracontroller.cpp:111
bool mInitialized
Definition: cameracontroller.hpp:174
bool mActive
Definition: cameracontroller.hpp:72
FreeCameraController(QWidget *parent)
Definition: cameracontroller.cpp:161
double getCameraSensitivity() const
Definition: cameracontroller.cpp:59
bool mFast
Definition: cameracontroller.hpp:117
void naviPrimary(bool active)
Definition: cameracontroller.cpp:394
void setup(osg::Group *root, unsigned int mask, const osg::Vec3d &up)
Definition: cameracontroller.cpp:116
bool mLockUpright
Definition: cameracontroller.hpp:115
bool mNaviPrimary
Definition: cameracontroller.hpp:116
void rotateHorizontal(double value)
Definition: cameracontroller.cpp:672
bool mFastAlternate
Definition: cameracontroller.hpp:117
bool mRight
Definition: cameracontroller.hpp:118
static const osg::Vec3d LocalForward
Definition: cameracontroller.hpp:37
void naviSecondary(bool active)
Definition: cameracontroller.cpp:731
void setCamera(osg::Camera *)
Definition: cameracontroller.cpp:79
static const osg::Vec3d WorldUp
Definition: cameracontroller.hpp:33
osg::Camera * mCamera
Definition: cameracontroller.hpp:77
void roll(double value)
Definition: cameracontroller.cpp:697
void onActivate()
Definition: cameracontroller.cpp:635
void rollRight(bool active)
Definition: cameracontroller.cpp:762
bool mNaviSecondary
Definition: cameracontroller.hpp:175
Definition: cameracontroller.hpp:27
void rollLeft(bool active)
Definition: cameracontroller.cpp:424
void backward(bool active)
Definition: cameracontroller.cpp:414
void setCameraSensitivity(double value)
Definition: cameracontroller.cpp:96
double getOrbitSpeedMultiplier() const
Definition: cameracontroller.cpp:534
void addShortcut(CSMPrefs::Shortcut *shortcut)
Definition: cameracontroller.cpp:152
virtual void update(double dt)=0
osg::Vec3d mUp
Definition: cameracontroller.hpp:119
void handleMouseScrollEvent(int x)
Definition: cameracontroller.cpp:300
void setPickingMask(unsigned int value)
Definition: cameracontroller.cpp:567
void up(bool active)
Definition: cameracontroller.cpp:736
bool mLeft
Definition: cameracontroller.hpp:118
double mDistance
Definition: cameracontroller.hpp:180
bool mRollRight
Definition: cameracontroller.hpp:118
bool mNaviSecondary
Definition: cameracontroller.hpp:116
bool mNaviPrimary
Definition: cameracontroller.hpp:175
double getRotationalSpeed() const
Definition: cameracontroller.cpp:242
void rollRight(bool active)
Definition: cameracontroller.cpp:429
void fixUpAxis(const osg::Vec3d &up)
Definition: cameracontroller.cpp:267
virtual void handleMouseScrollEvent(int x)=0
Definition: cameracontroller.hpp:82
bool mInverted
Definition: cameracontroller.hpp:72
double mLinSpeed
Definition: cameracontroller.hpp:121
void initialize()
Definition: cameracontroller.cpp:640
virtual void handleMouseMoveEvent(int x, int y)=0
static const osg::Vec3d LocalLeft
Definition: cameracontroller.hpp:36
void right(bool active)
Definition: cameracontroller.cpp:751
void setInverted(bool value)
Definition: cameracontroller.cpp:101
void naviPrimary(bool active)
Definition: cameracontroller.cpp:726
double getWheelMovementMultiplier() const
Definition: cameracontroller.cpp:74
double mSpeedMult
Definition: cameracontroller.hpp:123
void swapSpeedMode()
Definition: cameracontroller.cpp:439
Definition: cameracontroller.hpp:139
void stabilize()
Definition: cameracontroller.cpp:387
void pitch(double value)
Definition: cameracontroller.cpp:351
void right(bool active)
Definition: cameracontroller.cpp:419
bool mDown
Definition: cameracontroller.hpp:177
double getSpeedMultiplier() const
Definition: cameracontroller.cpp:247
osg::Vec3d mCenter
Definition: cameracontroller.hpp:179
osg::Camera * getCamera() const
Definition: cameracontroller.cpp:54
double mRotSpeed
Definition: cameracontroller.hpp:122
bool mFastAlternate
Definition: cameracontroller.hpp:176
void setOrbitSpeed(double value)
Definition: cameracontroller.cpp:557
bool mFast
Definition: cameracontroller.hpp:176
void update(double dt)
Definition: cameracontroller.cpp:604
bool mRollLeft
Definition: cameracontroller.hpp:177
double mWheelMoveMult
Definition: cameracontroller.hpp:75
void handleMouseMoveEvent(int x, int y)
Definition: cameracontroller.cpp:279
void handleMouseMoveEvent(int x, int y)
Definition: cameracontroller.cpp:572
void alternateFast(bool active)
Definition: cameracontroller.cpp:767
double getOrbitSpeed() const
Definition: cameracontroller.cpp:529
bool mRollLeft
Definition: cameracontroller.hpp:118
void setLinearSpeed(double value)
Definition: cameracontroller.cpp:252
bool mBackward
Definition: cameracontroller.hpp:118
void setOrbitSpeedMultiplier(double value)
Definition: cameracontroller.cpp:562
void rollLeft(bool active)
Definition: cameracontroller.cpp:756
void swapSpeedMode()
Definition: cameracontroller.cpp:772
virtual void onActivate()
Definition: cameracontroller.hpp:66
void zoom(double value)
Definition: cameracontroller.cpp:714
void setSecondaryMovementMultiplier(double value)
Definition: cameracontroller.cpp:106
void unfixUpAxis()
Definition: cameracontroller.cpp:274
bool mRight
Definition: cameracontroller.hpp:177
double mOrbitSpeedMult
Definition: cameracontroller.hpp:183
void yaw(double value)
Definition: cameracontroller.cpp:345
void naviSecondary(bool active)
Definition: cameracontroller.cpp:399
void update(double dt)
Definition: cameracontroller.cpp:308
A class similar in purpose to QShortcut, but with the ability to use mouse buttons.
Definition: shortcut.hpp:16
double mSecondaryMoveMult
Definition: cameracontroller.hpp:74
void setRotationalSpeed(double value)
Definition: cameracontroller.cpp:257
CameraController(QObject *parent)
Definition: cameracontroller.cpp:34
bool mRollRight
Definition: cameracontroller.hpp:177
static const osg::Vec3d LocalUp
Definition: cameracontroller.hpp:35
void translate(const osg::Vec3d &offset)
Definition: cameracontroller.cpp:702
void down(bool active)
Definition: cameracontroller.cpp:746
virtual ~CameraController()
Definition: cameracontroller.cpp:45
void left(bool active)
Definition: cameracontroller.cpp:409
std::vector< CSMPrefs::Shortcut * > mShortcuts
Definition: cameracontroller.hpp:79
void roll(double value)
Definition: cameracontroller.cpp:375
bool mModified
Definition: cameracontroller.hpp:115