Stellarium 0.12.3
StelMovementMgr.hpp
1 /*
2  * Stellarium
3  * Copyright (C) 2007 Fabien Chereau
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18  */
19 
20 #ifndef _STELMOVEMENTMGR_HPP_
21 #define _STELMOVEMENTMGR_HPP_
22 
23 #include "StelModule.hpp"
24 #include "StelProjector.hpp"
25 #include "StelObjectType.hpp"
26 
30 {
31  Q_OBJECT
32 
33 public:
34 
36  enum MountMode { MountAltAzimuthal, MountEquinoxEquatorial, MountGalactic};
37 
39  virtual ~StelMovementMgr();
40 
42  // Methods defined in the StelModule class
51  virtual void init();
52 
54  virtual void update(double) {;}
56  virtual void draw(StelCore*, class StelRenderer*) {;}
58  virtual void handleKeys(QKeyEvent* event);
60  virtual bool handleMouseMoves(int x, int y, Qt::MouseButtons b);
62  virtual void handleMouseWheel(class QWheelEvent* event);
64  virtual void handleMouseClicks(class QMouseEvent* event);
65 
67  // Methods specific to StelMovementMgr
68 
70  void updateMotion(double deltaTime);
71 
72  // These are hopefully temporary.
73  bool getHasDragged() const {return hasDragged;}
74 
76  // TODO: what are the units?
77  double getZoomSpeed() {return keyZoomSpeed;}
78 
81  void setViewUpVectorJ2000(const Vec3d& up);
82 
83  void setMovementSpeedFactor(float s) {movementsSpeedFactor=s;}
84  float getMovementSpeedFactor() const {return movementsSpeedFactor;}
85 
86  void setDragTriggerDistance(float d) {dragTriggerDistance=d;}
87 
88 public slots:
90  void toggleMountMode() {if (getMountMode()==MountAltAzimuthal) setMountMode(MountEquinoxEquatorial); else setMountMode(MountAltAzimuthal);}
92  void setEquatorialMount(bool b) {setMountMode(b ? MountEquinoxEquatorial : MountAltAzimuthal);}
93 
95  void setFlagTracking(bool b=true);
97  bool getFlagTracking(void) const {return flagTracking;}
98 
100  void setFlagLockEquPos(bool b);
102  bool getFlagLockEquPos(void) const {return flagLockEquPos;}
103 
108  void panView(double deltaAz, double deltaAlt);
109 
112  void setAutoMoveDuration(float f) {autoMoveDuration = f;}
115  float getAutoMoveDuration(void) const {return autoMoveDuration;}
116 
118  void setFlagAutoZoomOutResetsDirection(bool b) {flagAutoZoomOutResetsDirection = b;}
120  bool getFlagAutoZoomOutResetsDirection(void) {return flagAutoZoomOutResetsDirection;}
121 
123  bool getFlagEnableZoomKeys() const {return flagEnableZoomKeys;}
125  void setFlagEnableZoomKeys(bool b) {flagEnableZoomKeys=b;}
126 
128  bool getFlagEnableMoveKeys() const {return flagEnableMoveKeys;}
130  void setFlagEnableMoveKeys(bool b) {flagEnableMoveKeys=b;}
131 
133  bool getFlagEnableMoveAtScreenEdge() const {return flagEnableMoveAtScreenEdge;}
135  void setFlagEnableMoveAtScreenEdge(bool b) {flagEnableMoveAtScreenEdge=b;}
136 
138  bool getFlagEnableMouseNavigation() const {return flagEnableMouseNavigation;}
140  void setFlagEnableMouseNavigation(bool b) {flagEnableMouseNavigation=b;}
141 
146  void moveToJ2000(const Vec3d& aim, float moveDuration = 1., int zooming = 0);
147  void moveToObject(const StelObjectP& target, float moveDuration = 1., int zooming = 0);
148 
152  void zoomTo(double aimFov, float moveDuration = 1.);
154  double getCurrentFov() const {return currentFov;}
155 
157  double getInitFov() const {return initFov;}
159  void setInitFov(double fov) {initFov=fov;}
160 
162  const Vec3d& getInitViewingDirection() {return initViewPos;}
166 
168  Vec3d getViewDirectionJ2000() const {return viewDirectionJ2000;}
169  void setViewDirectionJ2000(const Vec3d& v);
170 
172  void setMaxFov(double max);
174  double getMaxFov(void) const {return maxFov;}
175 
177  void autoZoomIn(float moveDuration = 1.f, bool allowManualZoom = 1);
179  void autoZoomOut(float moveDuration = 1.f, bool full = 0);
180 
182  double getAimFov(void) const;
183 
185  void turnRight(bool);
186  void turnLeft(bool);
187  void turnUp(bool);
188  void turnDown(bool);
189  void moveSlow(bool b) {flagMoveSlow=b;}
190  void zoomIn(bool);
191  void zoomOut(bool);
192 
194  void setMountMode(MountMode m);
196  MountMode getMountMode(void) const {return mountMode;}
197 
198  void setDragTimeMode(bool b) {dragTimeMode=b;}
199  bool getDragTimeMode() const {return dragTimeMode;}
200 
201 private slots:
203  void selectedObjectChange(StelModule::StelModuleSelectAction action);
204 
205 private:
206  Vec3d j2000ToMountFrame(const Vec3d& v) const;
207  Vec3d mountFrameToJ2000(const Vec3d& v) const;
208 
209  double currentFov; // The current FOV in degree
210  double initFov; // The FOV at startup
211  double minFov; // Minimum FOV in degree
212  double maxFov; // Maximum FOV in degree
213 
214  void setFov(double f)
215  {
216  currentFov = f;
217  if (f>maxFov)
218  currentFov = maxFov;
219  if (f<minFov)
220  currentFov = minFov;
221  }
222  void changeFov(double deltaFov);
223 
224  void updateVisionVector(double deltaTime);
225  void updateAutoZoom(double deltaTime); // Update autoZoom if activated
226 
228  void dragView(int x1, int y1, int x2, int y2);
229 
230  StelCore* core; // The core on which the movement are applied
231  class StelObjectMgr* objectMgr;
232  bool flagLockEquPos; // Define if the equatorial position is locked
233  bool flagTracking; // Define if the selected object is followed
234 
235  // Flags for mouse movements
236  bool isMouseMovingHoriz;
237  bool isMouseMovingVert;
238 
239  bool flagEnableMoveAtScreenEdge; // allow mouse at edge of screen to move view
240  bool flagEnableMouseNavigation;
241  float mouseZoomSpeed;
242 
243  bool flagEnableZoomKeys;
244  bool flagEnableMoveKeys;
245  float keyMoveSpeed; // Speed of keys movement
246  float keyZoomSpeed; // Speed of keys zoom
247  bool flagMoveSlow;
248 
249  // Speed factor for real life time movements, used for fast forward when playing scripts.
250  float movementsSpeedFactor;
251 
254  struct AutoMove
255  {
256  Vec3d start;
257  Vec3d aim;
258  float speed;
259  float coef;
260  // If not null, move to the object.
261  StelObjectP targetObject;
262  };
263 
264  AutoMove move; // Current auto movement
265  bool flagAutoMove; // Define if automove is on or off
266  int zoomingMode; // 0 : undefined, 1 zooming, -1 unzooming
267 
268  double deltaFov,deltaAlt,deltaAz; // View movement
269 
270  bool flagManualZoom; // Define whether auto zoom can go further
271  float autoMoveDuration; // Duration of movement for the auto move to a selected objectin seconds
272 
273  // Mouse control options
274  bool isDragging, hasDragged;
275  int previousX, previousY;
276 
277  // Contains the last N real time / JD times pairs associated with the last N mouse move events
278  struct DragHistoryEntry
279  {
280  double runTime;
281  double jd;
282  int x;
283  int y;
284  };
285 
286  QList<DragHistoryEntry> timeDragHistory;
287  void addTimeDragPoint(int x, int y);
288  float beforeTimeDragTimeRate;
289 
290  // Time mouse control
291  bool dragTimeMode;
292 
295  struct AutoZoom
296  {
297  double start;
298  double aim;
299  float speed;
300  float coef;
301  };
302 
303  // Automove
304  AutoZoom zoomMove; // Current auto movement
305  bool flagAutoZoom; // Define if autozoom is on or off
306  bool flagAutoZoomOutResetsDirection;
307 
308  // defines if view corrects for horizon, or uses equatorial coordinates
309  MountMode mountMode;
310 
311  Vec3d initViewPos; // Default viewing direction
312 
313  // Viewing direction in equatorial J2000 coordinates
314  Vec3d viewDirectionJ2000;
315  // Viewing direction in the mount reference frame.
316  Vec3d viewDirectionMountFrame;
317 
318  Vec3d upVectorMountFrame;
319 
320  float dragTriggerDistance;
321 };
322 
323 #endif // _STELMOVEMENTMGR_HPP_
324