Stellarium 0.13.0
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  Q_PROPERTY(bool equatorialMount
33  READ getEquatorialMount
34  WRITE setEquatorialMount)
35  Q_PROPERTY(bool tracking
36  READ getFlagTracking
37  WRITE setFlagTracking)
38 public:
39 
41  enum MountMode { MountAltAzimuthal, MountEquinoxEquatorial, MountGalactic};
42 
44  virtual ~StelMovementMgr();
45 
47  // Methods defined in the StelModule class
56  virtual void init();
57 
59  virtual void update(double) {;}
61  virtual void draw(StelCore*) {;}
63  virtual void handleKeys(QKeyEvent* event);
65  virtual bool handleMouseMoves(int x, int y, Qt::MouseButtons b);
67  virtual void handleMouseWheel(class QWheelEvent* event);
69  virtual void handleMouseClicks(class QMouseEvent* event);
70 
72  // Methods specific to StelMovementMgr
73 
75  void updateMotion(double deltaTime);
76 
77  // These are hopefully temporary.
78  bool getHasDragged() const {return hasDragged;}
79 
81  // TODO: what are the units?
82  double getZoomSpeed() {return keyZoomSpeed;}
83 
86  void setViewUpVectorJ2000(const Vec3d& up);
87 
88  void setMovementSpeedFactor(float s) {movementsSpeedFactor=s;}
89  float getMovementSpeedFactor() const {return movementsSpeedFactor;}
90 
91  void setDragTriggerDistance(float d) {dragTriggerDistance=d;}
92 
93 public slots:
95  void toggleMountMode() {if (getMountMode()==MountAltAzimuthal) setMountMode(MountEquinoxEquatorial); else setMountMode(MountAltAzimuthal);}
97  void setEquatorialMount(bool b) {setMountMode(b ? MountEquinoxEquatorial : MountAltAzimuthal);}
98 
100  void setFlagTracking(bool b=true);
102  bool getFlagTracking(void) const {return flagTracking;}
103 
105  void setFlagLockEquPos(bool b);
107  bool getFlagLockEquPos(void) const {return flagLockEquPos;}
108 
113  void panView(double deltaAz, double deltaAlt);
114 
117  void setAutoMoveDuration(float f) {autoMoveDuration = f;}
120  float getAutoMoveDuration(void) const {return autoMoveDuration;}
121 
123  void setFlagAutoZoomOutResetsDirection(bool b) {flagAutoZoomOutResetsDirection = b;}
125  bool getFlagAutoZoomOutResetsDirection(void) {return flagAutoZoomOutResetsDirection;}
126 
128  bool getFlagEnableZoomKeys() const {return flagEnableZoomKeys;}
130  void setFlagEnableZoomKeys(bool b) {flagEnableZoomKeys=b;}
131 
133  bool getFlagEnableMoveKeys() const {return flagEnableMoveKeys;}
135  void setFlagEnableMoveKeys(bool b) {flagEnableMoveKeys=b;}
136 
138  bool getFlagEnableMoveAtScreenEdge() const {return flagEnableMoveAtScreenEdge;}
140  void setFlagEnableMoveAtScreenEdge(bool b) {flagEnableMoveAtScreenEdge=b;}
141 
143  bool getFlagEnableMouseNavigation() const {return flagEnableMouseNavigation;}
145  void setFlagEnableMouseNavigation(bool b) {flagEnableMouseNavigation=b;}
146 
151  void moveToJ2000(const Vec3d& aim, float moveDuration = 1., int zooming = 0);
152  void moveToObject(const StelObjectP& target, float moveDuration = 1., int zooming = 0);
153 
157  void zoomTo(double aimFov, float moveDuration = 1.);
159  double getCurrentFov() const {return currentFov;}
160 
162  double getInitFov() const {return initFov;}
164  void setInitFov(double fov) {initFov=fov;}
165 
167  const Vec3d& getInitViewingDirection() {return initViewPos;}
171 
173  Vec3d getViewDirectionJ2000() const {return viewDirectionJ2000;}
174  void setViewDirectionJ2000(const Vec3d& v);
175 
177  void setMaxFov(double max);
179  double getMaxFov(void) const {return maxFov;}
180 
182  void autoZoomIn(float moveDuration = 1.f, bool allowManualZoom = 1);
184  void autoZoomOut(float moveDuration = 1.f, bool full = 0);
185 
187  double getAimFov(void) const;
188 
190  void turnRight(bool);
191  void turnLeft(bool);
192  void turnUp(bool);
193  void turnDown(bool);
194  void moveSlow(bool b) {flagMoveSlow=b;}
195  void zoomIn(bool);
196  void zoomOut(bool);
197 
199  void setMountMode(MountMode m);
201  MountMode getMountMode(void) const {return mountMode;}
202  bool getEquatorialMount(void) const {return mountMode == MountEquinoxEquatorial;}
203 
204  void setDragTimeMode(bool b) {dragTimeMode=b;}
205  bool getDragTimeMode() const {return dragTimeMode;}
206 
207 private slots:
209  void selectedObjectChange(StelModule::StelModuleSelectAction action);
210 
211 private:
212  Vec3d j2000ToMountFrame(const Vec3d& v) const;
213  Vec3d mountFrameToJ2000(const Vec3d& v) const;
214 
215  double currentFov; // The current FOV in degree
216  double initFov; // The FOV at startup
217  double minFov; // Minimum FOV in degree
218  double maxFov; // Maximum FOV in degree
219 
220  void setFov(double f)
221  {
222  currentFov = f;
223  if (f>maxFov)
224  currentFov = maxFov;
225  if (f<minFov)
226  currentFov = minFov;
227  }
228  void changeFov(double deltaFov);
229 
230  void updateVisionVector(double deltaTime);
231  void updateAutoZoom(double deltaTime); // Update autoZoom if activated
232 
234  void dragView(int x1, int y1, int x2, int y2);
235 
236  StelCore* core; // The core on which the movement are applied
237  class StelObjectMgr* objectMgr;
238  bool flagLockEquPos; // Define if the equatorial position is locked
239  bool flagTracking; // Define if the selected object is followed
240 
241  // Flags for mouse movements
242  bool isMouseMovingHoriz;
243  bool isMouseMovingVert;
244 
245  bool flagEnableMoveAtScreenEdge; // allow mouse at edge of screen to move view
246  bool flagEnableMouseNavigation;
247  float mouseZoomSpeed;
248 
249  bool flagEnableZoomKeys;
250  bool flagEnableMoveKeys;
251  float keyMoveSpeed; // Speed of keys movement
252  float keyZoomSpeed; // Speed of keys zoom
253  bool flagMoveSlow;
254 
255  // Speed factor for real life time movements, used for fast forward when playing scripts.
256  float movementsSpeedFactor;
257 
260  struct AutoMove
261  {
262  Vec3d start;
263  Vec3d aim;
264  float speed;
265  float coef;
266  // If not null, move to the object.
267  StelObjectP targetObject;
268  };
269 
270  AutoMove move; // Current auto movement
271  bool flagAutoMove; // Define if automove is on or off
272  int zoomingMode; // 0 : undefined, 1 zooming, -1 unzooming
273 
274  double deltaFov,deltaAlt,deltaAz; // View movement
275 
276  bool flagManualZoom; // Define whether auto zoom can go further
277  float autoMoveDuration; // Duration of movement for the auto move to a selected objectin seconds
278 
279  // Mouse control options
280  bool isDragging, hasDragged;
281  int previousX, previousY;
282 
283  // Contains the last N real time / JD times pairs associated with the last N mouse move events
284  struct DragHistoryEntry
285  {
286  double runTime;
287  double jd;
288  int x;
289  int y;
290  };
291 
292  QList<DragHistoryEntry> timeDragHistory;
293  void addTimeDragPoint(int x, int y);
294  float beforeTimeDragTimeRate;
295 
296  // Time mouse control
297  bool dragTimeMode;
298 
301  struct AutoZoom
302  {
303  double start;
304  double aim;
305  float speed;
306  float coef;
307  };
308 
309  // Automove
310  AutoZoom zoomMove; // Current auto movement
311  bool flagAutoZoom; // Define if autozoom is on or off
312  bool flagAutoZoomOutResetsDirection;
313 
314  // defines if view corrects for horizon, or uses equatorial coordinates
315  MountMode mountMode;
316 
317  Vec3d initViewPos; // Default viewing direction
318 
319  // Viewing direction in equatorial J2000 coordinates
320  Vec3d viewDirectionJ2000;
321  // Viewing direction in the mount reference frame.
322  Vec3d viewDirectionMountFrame;
323 
324  Vec3d upVectorMountFrame;
325 
326  float dragTriggerDistance;
327 };
328 
329 #endif // _STELMOVEMENTMGR_HPP_
330 
void setInitFov(double fov)
Set the initial Field Of View in degree.
Definition: StelMovementMgr.hpp:164
bool getFlagLockEquPos(void) const
Get whether sky position is locked.
Definition: StelMovementMgr.hpp:107
virtual bool handleMouseMoves(int x, int y, Qt::MouseButtons b)
Handle mouse movement events.
bool getFlagAutoZoomOutResetsDirection(void)
Get whether auto zoom out will reset the viewing direction to the inital value.
Definition: StelMovementMgr.hpp:125
void setFlagEnableZoomKeys(bool b)
Set whether keys can control zoom.
Definition: StelMovementMgr.hpp:130
bool getFlagEnableMoveKeys() const
Get whether keys can control move.
Definition: StelMovementMgr.hpp:133
void setFlagLockEquPos(bool b)
Set whether sky position is to be locked.
void panView(double deltaAz, double deltaAlt)
Move view in alt/az (or equatorial if in that mode) coordinates.
MountMode getMountMode(void) const
Get current mount type defining the reference frame in which head movements occur.
Definition: StelMovementMgr.hpp:201
Vec3d getViewUpVectorJ2000() const
Return the current up view vector.
Main class for Stellarium core processing.
Definition: StelCore.hpp:46
bool getFlagEnableMoveAtScreenEdge() const
Get whether being at the edge of the screen activates movement.
Definition: StelMovementMgr.hpp:138
void setFlagTracking(bool b=true)
Set object tracking on/off and go to selected object.
void setMountMode(MountMode m)
Set current mount type defining the reference frame in which head movements occur.
float getAutoMoveDuration(void) const
Get automove duration in seconds.
Definition: StelMovementMgr.hpp:120
void autoZoomIn(float moveDuration=1.f, bool allowManualZoom=1)
Go and zoom to the selected object. A later call to autoZoomOut will come back to the previous zoom l...
double getCurrentFov() const
Get the current Field Of View in degrees.
Definition: StelMovementMgr.hpp:159
void turnRight(bool)
Viewing direction function : true move, false stop.
void setFlagEnableMouseNavigation(bool b)
Set whether mouse can control movement.
Definition: StelMovementMgr.hpp:145
Manages the head movements and zoom operations.
Definition: StelMovementMgr.hpp:29
void setInitViewDirectionToCurrent()
Sets the initial direction of view to the current altitude and azimuth.
void toggleMountMode()
Toggle current mount mode between equatorial and altazimuthal.
Definition: StelMovementMgr.hpp:95
Define the StelObjectP type.
double getAimFov(void) const
If currently zooming, return the target FOV, otherwise return current FOV in degree.
virtual void draw(StelCore *)
Implement required draw function. Does nothing.
Definition: StelMovementMgr.hpp:61
virtual void handleKeys(QKeyEvent *event)
Handle keyboard events.
bool getFlagEnableMouseNavigation() const
Get whether mouse can control movement.
Definition: StelMovementMgr.hpp:143
double getMaxFov(void) const
Get the maximum field of View in degrees.
Definition: StelMovementMgr.hpp:179
virtual void init()
Initializes the object based on the application settings Includes:
double getZoomSpeed()
Get the zoom speed.
Definition: StelMovementMgr.hpp:82
void setFlagEnableMoveAtScreenEdge(bool b)
Set whether being at the edge of the screen activates movement.
Definition: StelMovementMgr.hpp:140
Vec3d getViewDirectionJ2000() const
Return the current viewing direction in equatorial J2000 frame.
Definition: StelMovementMgr.hpp:173
void updateMotion(double deltaTime)
Increment/decrement smoothly the vision field and position.
Manage the selection and queries on one or more StelObjects.
Definition: StelObjectMgr.hpp:36
MountMode
Possible mount modes defining the reference frame in which head movements occur.
Definition: StelMovementMgr.hpp:41
bool getFlagTracking(void) const
Get current object tracking status.
Definition: StelMovementMgr.hpp:102
void setFlagEnableMoveKeys(bool b)
Set whether keys can control movement.
Definition: StelMovementMgr.hpp:135
void zoomTo(double aimFov, float moveDuration=1.)
Change the zoom level.
void setAutoMoveDuration(float f)
Set automove duration in seconds.
Definition: StelMovementMgr.hpp:117
virtual void update(double)
Update time-dependent things (does nothing).
Definition: StelMovementMgr.hpp:59
StelModuleSelectAction
Enum used when selecting objects to define whether to add to, replace, or remove from the existing se...
Definition: StelModule.hpp:112
virtual void handleMouseWheel(class QWheelEvent *event)
Handle mouse wheel events.
void setFlagAutoZoomOutResetsDirection(bool b)
Set whether auto zoom out will reset the viewing direction to the inital value.
Definition: StelMovementMgr.hpp:123
void setEquatorialMount(bool b)
Define whether we should use equatorial mount or altazimuthal.
Definition: StelMovementMgr.hpp:97
void autoZoomOut(float moveDuration=1.f, bool full=0)
Unzoom to the previous position.
const Vec3d & getInitViewingDirection()
Return the inital viewing direction in altazimuthal coordinates.
Definition: StelMovementMgr.hpp:167
This is the common base class for all the main components of stellarium.
Definition: StelModule.hpp:52
virtual void handleMouseClicks(class QMouseEvent *event)
Handle mouse click events.
void moveToJ2000(const Vec3d &aim, float moveDuration=1., int zooming=0)
Move the view to a specified J2000 position.
bool getFlagEnableZoomKeys() const
Get whether keys can control zoom.
Definition: StelMovementMgr.hpp:128
void setMaxFov(double max)
Set the maximum field of View in degrees.
double getInitFov() const
Return the initial default FOV in degree.
Definition: StelMovementMgr.hpp:162