Stellarium 0.15.0
StelMovementMgr.hpp
1 /*
2  * Stellarium
3  * Copyright (C) 2007 Fabien Chereau
4  * Copyright (C) 2015 Georg Zotti (offset view adaptations, Up vector fix for zenithal views)
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
19  */
20 
21 #ifndef _STELMOVEMENTMGR_HPP_
22 #define _STELMOVEMENTMGR_HPP_
23 
24 #include "StelModule.hpp"
25 #include "StelProjector.hpp"
26 #include "StelObjectType.hpp"
27 #include <QTimeLine>
28 
32 {
33  Q_OBJECT
34  Q_PROPERTY(bool equatorialMount
35  READ getEquatorialMount
36  WRITE setEquatorialMount
37  NOTIFY equatorialMountChanged)
38  Q_PROPERTY(bool tracking
39  READ getFlagTracking
40  WRITE setFlagTracking
41  NOTIFY flagTrackingChanged)
42 
43  //The targets of viewport offset animation
44  Q_PROPERTY(float viewportHorizontalOffsetTarget READ getViewportHorizontalOffsetTarget WRITE setViewportHorizontalOffsetTarget NOTIFY viewportHorizontalOffsetTargetChanged)
45  Q_PROPERTY(float viewportVerticalOffsetTarget READ getViewportVerticalOffsetTarget WRITE setViewportVerticalOffsetTarget NOTIFY viewportVerticalOffsetTargetChanged)
46 
47 public:
48 
51  // TODO: add others: MountEcliptical, MountEq2000, MountEcliptical2000 and implement proper variants.
52  enum MountMode { MountAltAzimuthal, MountEquinoxEquatorial, MountGalactic};
53 
55  enum ZoomingMode { ZoomOut=-1, ZoomNone=0, ZoomIn=1};
56 
58  virtual ~StelMovementMgr();
59 
61  // Methods defined in the StelModule class
70  virtual void init();
71 
73  virtual void update(double) {;}
75  virtual void draw(StelCore*) {;}
77  virtual void handleKeys(QKeyEvent* event);
79  virtual bool handleMouseMoves(int x, int y, Qt::MouseButtons b);
81  virtual void handleMouseWheel(class QWheelEvent* event);
83  virtual void handleMouseClicks(class QMouseEvent* event);
84  // GZ: allow some keypress interaction by plugins.
85  virtual double getCallOrder(StelModuleActionName actionName) const;
87  virtual bool handlePinch(qreal scale, bool started);
88 
90  // Methods specific to StelMovementMgr
91 
93  void updateMotion(double deltaTime);
94 
95  // These are hopefully temporary.
96  bool getHasDragged() const {return hasDragged;}
97 
99  // TODO: what are the units?
100  double getZoomSpeed() {return keyZoomSpeed;}
101 
103  Vec3d getViewUpVectorJ2000() const;
104  // You can set an upVector in J2000 coordinates which is translated to current mount mode. Important when viewing into the pole of the current mount mode coordinates.
105  void setViewUpVectorJ2000(const Vec3d& up);
106  // Set vector directly. This is set in the current mountmode, but will be translated to J2000 internally
107  // We need this only when viewing to the poles of current coordinate system where the view vector would else be parallel to the up vector.
108  void setViewUpVector(const Vec3d& up);
109 
110  void setMovementSpeedFactor(float s) {movementsSpeedFactor=s;}
111  float getMovementSpeedFactor() const {return movementsSpeedFactor;}
112 
113  void setDragTriggerDistance(float d) {dragTriggerDistance=d;}
114 
115 public slots:
117  void toggleMountMode() {if (getMountMode()==MountAltAzimuthal) setMountMode(MountEquinoxEquatorial); else setMountMode(MountAltAzimuthal);}
119  void setEquatorialMount(bool b) {setMountMode(b ? MountEquinoxEquatorial : MountAltAzimuthal);}
120 
122  void setFlagTracking(bool b=true);
124  bool getFlagTracking(void) const {return flagTracking;}
125 
127  void setFlagLockEquPos(bool b);
129  bool getFlagLockEquPos(void) const {return flagLockEquPos;}
130 
135  void panView(const double deltaAz, const double deltaAlt);
136 
139  void setAutoMoveDuration(float f) {autoMoveDuration = f;}
142  float getAutoMoveDuration(void) const {return autoMoveDuration;}
143 
145  void setFlagAutoZoomOutResetsDirection(bool b) {flagAutoZoomOutResetsDirection = b;}
147  bool getFlagAutoZoomOutResetsDirection(void) {return flagAutoZoomOutResetsDirection;}
148 
150  bool getFlagEnableZoomKeys() const {return flagEnableZoomKeys;}
152  void setFlagEnableZoomKeys(bool b) {flagEnableZoomKeys=b;}
153 
155  bool getFlagEnableMoveKeys() const {return flagEnableMoveKeys;}
157  void setFlagEnableMoveKeys(bool b) {flagEnableMoveKeys=b;}
158 
160  bool getFlagEnableMoveAtScreenEdge() const {return flagEnableMoveAtScreenEdge;}
162  void setFlagEnableMoveAtScreenEdge(bool b) {flagEnableMoveAtScreenEdge=b;}
163 
165  bool getFlagEnableMouseNavigation() const {return flagEnableMouseNavigation;}
167  void setFlagEnableMouseNavigation(bool b) {flagEnableMouseNavigation=b;}
168 
179  void moveToJ2000(const Vec3d& aim, const Vec3d &aimUp, float moveDuration = 1., ZoomingMode zooming = ZoomNone);
180  void moveToObject(const StelObjectP& target, float moveDuration = 1., ZoomingMode zooming = ZoomNone);
181 
194  void moveToAltAzi(const Vec3d& aim, const Vec3d &aimUp, float moveDuration = 1., ZoomingMode zooming = ZoomNone);
195 
199  void zoomTo(double aimFov, float moveDuration = 1.);
201  double getCurrentFov() const {return currentFov;}
202 
204  double getInitFov() const {return initFov;}
206  void setInitFov(double fov) {initFov=fov;}
207 
209  const Vec3d& getInitViewingDirection() {return initViewPos;}
213 
215  Vec3d getViewDirectionJ2000() const {return viewDirectionJ2000;}
216  void setViewDirectionJ2000(const Vec3d& v);
217 
219  void setMaxFov(double max);
221  double getMaxFov(void) const {return maxFov;}
222 
224  double getMinFov(void) const {return minFov;}
225 
227  void autoZoomIn(float moveDuration = 1.f, bool allowManualZoom = 1);
229  void autoZoomOut(float moveDuration = 1.f, bool full = 0);
230 
232  double getAimFov(void) const;
233 
235  void turnRight(bool);
236  void turnLeft(bool);
237  void turnUp(bool);
238  void turnDown(bool);
239  void moveSlow(bool b) {flagMoveSlow=b;}
240  void zoomIn(bool);
241  void zoomOut(bool);
242 
244  void lookEast(void);
246  void lookWest(void);
248  void lookNorth(void);
250  void lookSouth(void);
252  void lookZenith(void);
253 
259  void moveViewport(float offsetX, float offsetY, const float duration=0.f);
260 
262  void setMountMode(MountMode m);
264  MountMode getMountMode(void) const {return mountMode;}
265  bool getEquatorialMount(void) const {return mountMode == MountEquinoxEquatorial;}
266 
267  void setDragTimeMode(bool b) {dragTimeMode=b;}
268  bool getDragTimeMode() const {return dragTimeMode;}
269 
272  void setInhibitAllAutomoves(bool inhibit) { flagInhibitAllAutomoves=inhibit;}
273 
275  Vec2f getViewportOffsetTarget() const { return targetViewportOffset; }
276  float getViewportHorizontalOffsetTarget() const { return targetViewportOffset[0]; }
277  float getViewportVerticalOffsetTarget() const { return targetViewportOffset[1]; }
278 
279  void setViewportHorizontalOffsetTarget(float f) { moveViewport(f,getViewportVerticalOffsetTarget()); }
280  void setViewportVerticalOffsetTarget(float f) { moveViewport(getViewportHorizontalOffsetTarget(),f); }
281 
282 signals:
284  void flagTrackingChanged(bool b);
285  void equatorialMountChanged(bool b);
286 
287  void viewportHorizontalOffsetTargetChanged(float f);
288  void viewportVerticalOffsetTargetChanged(float f);
289 
290 private slots:
292  void selectedObjectChange(StelModule::StelModuleSelectAction action);
293 
295  void handleViewportOffsetMovement(qreal value);
296 
297 public:
298  Vec3d j2000ToMountFrame(const Vec3d& v) const;
299  Vec3d mountFrameToJ2000(const Vec3d& v) const;
300 
301 private:
302  double currentFov; // The current FOV in degrees
303  double initFov; // The FOV at startup
304  double minFov; // Minimum FOV in degrees
305  double maxFov; // Maximum FOV in degrees
306 
307  void setFov(double f)
308  {
309  currentFov = f;
310  if (f>maxFov)
311  currentFov = maxFov;
312  if (f<minFov)
313  currentFov = minFov;
314  }
315  void changeFov(double deltaFov);
316 
317  // Move (a bit) to selected/tracked object until move.coef reaches 1, or auto-follow (track) selected object.
318  // Does nothing if flagInhibitAllAutomoves=true
319  void updateVisionVector(double deltaTime);
320  void updateAutoZoom(double deltaTime); // Update autoZoom if activated
321 
323  void dragView(int x1, int y1, int x2, int y2);
324 
325  StelCore* core; // The core on which the movement are applied
326  class StelObjectMgr* objectMgr;
327  bool flagLockEquPos; // Define if the equatorial position is locked
328  bool flagTracking; // Define if the selected object is followed
329  bool flagInhibitAllAutomoves; // Required for special installations: If true, there is no automatic centering etc.
330 
331  // Flags for mouse movements
332  bool isMouseMovingHoriz;
333  bool isMouseMovingVert;
334 
335  bool flagEnableMoveAtScreenEdge; // allow mouse at edge of screen to move view
336  bool flagEnableMouseNavigation;
337  float mouseZoomSpeed;
338 
339  bool flagEnableZoomKeys;
340  bool flagEnableMoveKeys;
341  float keyMoveSpeed; // Speed of keys movement
342  float keyZoomSpeed; // Speed of keys zoom
343  bool flagMoveSlow;
344 
345  // Speed factor for real life time movements, used for fast forward when playing scripts.
346  float movementsSpeedFactor;
347 
350  struct AutoMove
351  {
352  Vec3d start;
353  Vec3d aim;
354  Vec3d startUp; // The Up vector at start time
355  Vec3d aimUp; // The Up vector at end time of move
356  float speed; // set to 1/duration[ms] during automove setup.
357  float coef; // Set to 0 at begin of an automove, runs up to 1.
358  // If not null, move to the object instead of the aim.
359  StelObjectP targetObject;
360  MountMode mountMode; // In which frame we shall move. This may be different from the frame the display is set to!
361  // The start and aim vectors are given in those coordinates, and are interpolated in the respective reference frames,
362  // then the view vector is derived from the current coef.
363  // AzAlt moves should be set to AltAz mode, else they will move towards the RA/Dec at begin of move which may have moved.
364  // It is an error to move in J2000 or Eq frame with fast timelapse!
365  // This is a March 2016 GZ hack. TODO: This class should be thought over a bit.
366  };
367 
368  AutoMove move; // Current auto movement. 2016-03: During setup, decide upon the frame for motion!
369  bool flagAutoMove; // Define if automove is on or off
370  ZoomingMode zoomingMode;
371 
372  double deltaFov,deltaAlt,deltaAz; // View movement
373 
374  bool flagManualZoom; // Define whether auto zoom can go further
375  float autoMoveDuration; // Duration of movement for the auto move to a selected object in seconds
376 
377  // Mouse control options
378  bool isDragging, hasDragged;
379  int previousX, previousY;
380 
381  // Contains the last N real time / JD times pairs associated with the last N mouse move events
382  struct DragHistoryEntry
383  {
384  double runTime;
385  double jd;
386  int x;
387  int y;
388  };
389 
390  QList<DragHistoryEntry> timeDragHistory;
391  void addTimeDragPoint(int x, int y);
392  float beforeTimeDragTimeRate;
393 
394  // Time mouse control
395  bool dragTimeMode; // true during mouse time motion.
396 
399  // Components:
400  // startFov: field of view at start
401  // aimFov: intended field of view at end of zoom move
402  // speed: rate of change. UNITS?
403  // coef: set to 0 at begin of zoom, will increase to 1 during autozoom motion.
404  struct AutoZoom
405  {
406  double startFov;
407  double aimFov;
408  float speed;
409  float coef;
410  };
411 
412  // Automove
413  AutoZoom zoomMove; // Current auto movement
414  bool flagAutoZoom; // Define if autozoom is on or off
415  bool flagAutoZoomOutResetsDirection;
416 
417  // defines if view corrects for horizon, or uses equatorial coordinates
418  MountMode mountMode;
419 
420  Vec3d initViewPos; // Default viewing direction
421  Vec3d initViewUp; // original up vector. Usually 0/0/1, but maybe something else in rare setups (e.g. Planetarium dome upwards fisheye projection).
422 
423  // Viewing direction in equatorial J2000 coordinates
424  Vec3d viewDirectionJ2000;
425  // Viewing direction in the mount reference frame.
426  Vec3d viewDirectionMountFrame;
427 
428  // Up vector (in OpenGL terms) in the mount reference frame.
429  // This can usually be just 0/0/1, but must be set to something useful when viewDirectionMountFrame is parallel, i.e. looks into a pole.
430  Vec3d upVectorMountFrame;
431 
432  // TODO: Docfix?
433  float dragTriggerDistance;
434 
435  // Viewport shifting. This animates a property belonging to StelCore. But the shift itself is likely best placed here.
436  QTimeLine *viewportOffsetTimeline;
437  // Those two are used during viewport offset animation transitions. Both are set by moveViewport(), and irrelevant after the transition.
438  Vec2f oldViewportOffset;
439  Vec2f targetViewportOffset;
440 
441 };
442 
443 #endif // _STELMOVEMENTMGR_HPP_
444 
void setInitFov(double fov)
Set the initial Field Of View in degree.
bool getFlagLockEquPos(void) const
Get whether sky position is locked.
void flagTrackingChanged(bool b)
Emitted when the tracking property changes.
virtual bool handleMouseMoves(int x, int y, Qt::MouseButtons b)
Handle mouse movement events.
void setInhibitAllAutomoves(bool inhibit)
Function designed only for scripting context.
bool getFlagAutoZoomOutResetsDirection(void)
Get whether auto zoom out will reset the viewing direction to the inital value.
void setFlagEnableZoomKeys(bool b)
Set whether keys can control zoom.
bool getFlagEnableMoveKeys() const
Get whether keys can control movement.
double getMinFov(void) const
Get the minimum field of View in degrees.
void panView(const double deltaAz, const double deltaAlt)
Move view in alt/az (or equatorial if in that mode) coordinates.
void setFlagLockEquPos(bool b)
Set whether sky position is to be locked.
MountMode getMountMode(void) const
Get current mount type defining the reference frame in which head movements occur.
Vec3d getViewUpVectorJ2000() const
Return the current up view vector in J2000 coordinates.
void lookWest(void)
Look immediately towards West.
Main class for Stellarium core processing.
Definition: StelCore.hpp:48
virtual double getCallOrder(StelModuleActionName actionName) const
Return the value defining the order of call for the given action For example if stars.callOrder[ActionDraw] == 10 and constellation.callOrder[ActionDraw] == 11, the stars module will be drawn before the constellations.
bool getFlagEnableMoveAtScreenEdge() const
Get whether being at the edge of the screen activates movement.
void moveToJ2000(const Vec3d &aim, const Vec3d &aimUp, float moveDuration=1., ZoomingMode zooming=ZoomNone)
Move the view to a specified J2000 position.
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.
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.
void turnRight(bool)
Viewing direction function : true move, false stop.
void setFlagEnableMouseNavigation(bool b)
Set whether mouse can control movement.
Manages the head movements and zoom operations.
void setInitViewDirectionToCurrent()
Sets the initial direction of view to the current altitude and azimuth.
void toggleMountMode()
Toggle current mount mode between equatorial and altazimuthal.
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.
virtual void handleKeys(QKeyEvent *event)
Handle keyboard events.
bool getFlagEnableMouseNavigation() const
Get whether mouse can control movement.
double getMaxFov(void) const
Get the maximum field of View in degrees.
virtual void init()
Initializes the object based on the application settings Includes:
double getZoomSpeed()
Get the zoom speed.
void lookNorth(void)
Look immediately towards North.
void setFlagEnableMoveAtScreenEdge(bool b)
Set whether being at the edge of the screen activates movement.
Vec3d getViewDirectionJ2000() const
Return the current viewing direction in equatorial J2000 frame.
void updateMotion(double deltaTime)
Increment/decrement smoothly the vision field and position.
Manage the selection and queries on one or more StelObjects.
StelModuleActionName
Define the possible action for which an order is defined.
Definition: StelModule.hpp:117
MountMode
Possible mount modes defining the reference frame in which head movements occur.
bool getFlagTracking(void) const
Get current object tracking status.
void setFlagEnableMoveKeys(bool b)
Set whether keys can control movement.
void lookZenith(void)
Look immediately towards Zenith.
void zoomTo(double aimFov, float moveDuration=1.)
Change the zoom level.
void lookEast(void)
Look immediately towards East.
void setAutoMoveDuration(float f)
Set automove duration in seconds.
virtual void update(double)
Update time-dependent things (does nothing).
StelModuleSelectAction
Enum used when selecting objects to define whether to add to, replace, or remove from the existing se...
Definition: StelModule.hpp:109
void lookSouth(void)
Look immediately towards South.
void moveViewport(float offsetX, float offsetY, const float duration=0.f)
start animated move of the viewport offset.
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.
ZoomingMode
Named constants for zoom operations.
virtual bool handlePinch(qreal scale, bool started)
Handle pinch gesture.
void setEquatorialMount(bool b)
Define whether we should use equatorial mount or altazimuthal.
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.
Vec2f getViewportOffsetTarget() const
Returns the targetted value of the viewport offset.
This is the common base class for all the main components of stellarium.
Definition: StelModule.hpp:49
virtual void handleMouseClicks(class QMouseEvent *event)
Handle mouse click events.
void moveToAltAzi(const Vec3d &aim, const Vec3d &aimUp, float moveDuration=1., ZoomingMode zooming=ZoomNone)
Move the view to a specified AltAzimuthal position.
bool getFlagEnableZoomKeys() const
Get whether keys can control zoom.
void setMaxFov(double max)
Set the maximum field of View in degrees.
double getInitFov() const
Return the initial default FOV in degree.