Stellarium  0.16.1
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 #include <QTimer>
29 #include <QCursor>
30 
34 {
35  Q_OBJECT
36  Q_PROPERTY(bool equatorialMount
37  READ getEquatorialMount
38  WRITE setEquatorialMount
39  NOTIFY equatorialMountChanged)
40  Q_PROPERTY(bool tracking
41  READ getFlagTracking
42  WRITE setFlagTracking
43  NOTIFY flagTrackingChanged)
44 
45  //The targets of viewport offset animation
46  Q_PROPERTY(float viewportHorizontalOffsetTarget
47  READ getViewportHorizontalOffsetTarget
48  WRITE setViewportHorizontalOffsetTarget
49  NOTIFY viewportHorizontalOffsetTargetChanged)
50  Q_PROPERTY(float viewportVerticalOffsetTarget
51  READ getViewportVerticalOffsetTarget
52  WRITE setViewportVerticalOffsetTarget
53  NOTIFY viewportVerticalOffsetTargetChanged)
54 
55  Q_PROPERTY(bool flagAutoZoomOutResetsDirection
58  NOTIFY flagAutoZoomOutResetsDirectionChanged)
59 public:
60 
63  // TODO: add others: MountEcliptical, MountEq2000, MountEcliptical2000 and implement proper variants.
64  enum MountMode { MountAltAzimuthal, MountEquinoxEquatorial, MountGalactic, MountSupergalactic};
65 
67  enum ZoomingMode { ZoomOut=-1, ZoomNone=0, ZoomIn=1};
68 
70  virtual ~StelMovementMgr();
71 
73  // Methods defined in the StelModule class
82  virtual void init();
83 
85  virtual void update(double)
86  {
87  if (dragTimeMode)
88  addTimeDragPoint(QCursor::pos().x(), QCursor::pos().y());
89  }
91  virtual void draw(StelCore*) {;}
93  virtual void handleKeys(QKeyEvent* event);
95  virtual bool handleMouseMoves(int x, int y, Qt::MouseButtons b);
97  virtual void handleMouseWheel(class QWheelEvent* event);
99  virtual void handleMouseClicks(class QMouseEvent* event);
100  // allow some keypress interaction by plugins.
101  virtual double getCallOrder(StelModuleActionName actionName) const;
103  virtual bool handlePinch(qreal scale, bool started);
104 
106  // Methods specific to StelMovementMgr
107 
109  void updateMotion(double deltaTime);
110 
112  // TODO: what are the units?
113  double getZoomSpeed() {return keyZoomSpeed;}
114 
116  Vec3d getViewUpVectorJ2000() const;
117  // 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.
118  void setViewUpVectorJ2000(const Vec3d& up);
119  // Set vector directly. This is set in the current mountmode, but will be translated to J2000 internally
120  // 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.
121  void setViewUpVector(const Vec3d& up);
122 
123  void setMovementSpeedFactor(float s) {movementsSpeedFactor=s;}
124  float getMovementSpeedFactor() const {return movementsSpeedFactor;}
125 
126  void setDragTriggerDistance(float d) {dragTriggerDistance=d;}
127 
128 public slots:
130  void toggleMountMode() {if (getMountMode()==MountAltAzimuthal) setMountMode(MountEquinoxEquatorial); else setMountMode(MountAltAzimuthal);}
132  void setEquatorialMount(bool b);
133 
135  void setFlagTracking(bool b=true);
137  bool getFlagTracking(void) const {return flagTracking;}
138 
140  void setFlagLockEquPos(bool b);
142  bool getFlagLockEquPos(void) const {return flagLockEquPos;}
143 
148  void panView(const double deltaAz, const double deltaAlt);
149 
152  void setAutoMoveDuration(float f) {autoMoveDuration = f;}
155  float getAutoMoveDuration(void) const {return autoMoveDuration;}
156 
158  void setFlagAutoZoomOutResetsDirection(bool b) {if (flagAutoZoomOutResetsDirection != b) { flagAutoZoomOutResetsDirection = b; emit flagAutoZoomOutResetsDirectionChanged(b);}}
160  bool getFlagAutoZoomOutResetsDirection(void) {return flagAutoZoomOutResetsDirection;}
161 
163  bool getFlagEnableZoomKeys() const {return flagEnableZoomKeys;}
165  void setFlagEnableZoomKeys(bool b) {flagEnableZoomKeys=b;}
166 
168  bool getFlagEnableMoveKeys() const {return flagEnableMoveKeys;}
170  void setFlagEnableMoveKeys(bool b) {flagEnableMoveKeys=b;}
171 
173  bool getFlagEnableMoveAtScreenEdge() const {return flagEnableMoveAtScreenEdge;}
175  void setFlagEnableMoveAtScreenEdge(bool b) {flagEnableMoveAtScreenEdge=b;}
176 
178  bool getFlagEnableMouseNavigation() const {return flagEnableMouseNavigation;}
180  void setFlagEnableMouseNavigation(bool b) {flagEnableMouseNavigation=b;}
181 
183  bool getFlagIndicationMountMode() const {return flagIndicationMountMode;}
185  void setFlagIndicationMountMode(bool b) { flagIndicationMountMode=b; }
186 
197  void moveToJ2000(const Vec3d& aim, const Vec3d &aimUp, float moveDuration = 1., ZoomingMode zooming = ZoomNone);
198  void moveToObject(const StelObjectP& target, float moveDuration = 1., ZoomingMode zooming = ZoomNone);
199 
212  void moveToAltAzi(const Vec3d& aim, const Vec3d &aimUp, float moveDuration = 1., ZoomingMode zooming = ZoomNone);
213 
217  void zoomTo(double aimFov, float moveDuration = 1.);
219  double getCurrentFov() const {return currentFov;}
220 
222  double getInitFov() const {return initFov;}
224  void setInitFov(double fov) {initFov=fov;}
225 
227  const Vec3d getInitViewingDirection() {return initViewPos;}
231 
233  Vec3d getViewDirectionJ2000() const {return viewDirectionJ2000;}
235  void setViewDirectionJ2000(const Vec3d& v);
236 
238  void setMaxFov(double max);
240  double getMaxFov(void) const {return maxFov;}
241 
243  double getMinFov(void) const {return minFov;}
244 
246  void autoZoomIn(float moveDuration = 1.f, bool allowManualZoom = 1);
248  void autoZoomOut(float moveDuration = 1.f, bool full = 0);
249 
251  double getAimFov(void) const;
252 
254  void turnRight(bool);
255  void turnLeft(bool);
256  void turnUp(bool);
257  void turnDown(bool);
258  void moveSlow(bool b) {flagMoveSlow=b;}
259  void zoomIn(bool);
260  void zoomOut(bool);
261 
264  void lookEast(bool zero=false);
267  void lookWest(bool zero=false);
270  void lookNorth(bool zero=false);
273  void lookSouth(bool zero=false);
275  void lookZenith(void);
277  void lookNadir(void);
279  void lookTowardsNCP(void);
281  void lookTowardsSCP(void);
282 
288  void moveViewport(float offsetX, float offsetY, const float duration=0.f);
289 
291  void setMountMode(MountMode m);
293  MountMode getMountMode(void) const {return mountMode;}
294  bool getEquatorialMount(void) const {return mountMode == MountEquinoxEquatorial;}
295 
298  void setInhibitAllAutomoves(bool inhibit) { flagInhibitAllAutomoves=inhibit;}
299 
301  Vec2f getViewportOffsetTarget() const { return targetViewportOffset; }
302  float getViewportHorizontalOffsetTarget() const { return targetViewportOffset[0]; }
303  float getViewportVerticalOffsetTarget() const { return targetViewportOffset[1]; }
304 
305  void setViewportHorizontalOffsetTarget(float f) { moveViewport(f,getViewportVerticalOffsetTarget()); }
306  void setViewportVerticalOffsetTarget(float f) { moveViewport(getViewportHorizontalOffsetTarget(),f); }
307 
308 signals:
310  void flagTrackingChanged(bool b);
311  void equatorialMountChanged(bool b);
312 
313  void flagAutoZoomOutResetsDirectionChanged(bool b);
314 
315  void viewportHorizontalOffsetTargetChanged(float f);
316  void viewportVerticalOffsetTargetChanged(float f);
317 
318 private slots:
320  void selectedObjectChange(StelModule::StelModuleSelectAction action);
321 
323  void handleViewportOffsetMovement(qreal value);
324 
326  void displayMessage(const QString& message, const QString hexColor="#99FF99");
328  void hideMessages();
329 
330 public:
331  Vec3d j2000ToMountFrame(const Vec3d& v) const;
332  Vec3d mountFrameToJ2000(const Vec3d& v) const;
333 
334 private:
335  double currentFov; // The current FOV in degrees
336  double initFov; // The FOV at startup
337  double minFov; // Minimum FOV in degrees
338  double maxFov; // Maximum FOV in degrees
339  double deltaFov; // requested change of FOV (degrees) used during zooming.
340  void setFov(double f)
341  {
342  currentFov=qBound(minFov, f, maxFov);
343  }
344  // immediately add deltaFov argument to FOV - does not change private var.
345  void changeFov(double deltaFov);
346 
347  // Move (a bit) to selected/tracked object until move.coef reaches 1, or auto-follow (track) selected object.
348  // Does nothing if flagInhibitAllAutomoves=true
349  void updateVisionVector(double deltaTime);
350  void updateAutoZoom(double deltaTime); // Update autoZoom if activated
351 
353  void dragView(int x1, int y1, int x2, int y2);
354 
355  StelCore* core; // The core on which the movement are applied
356  class StelObjectMgr* objectMgr;
357  bool flagLockEquPos; // Define if the equatorial position is locked
358  bool flagTracking; // Define if the selected object is followed
359  bool flagInhibitAllAutomoves; // Required for special installations: If true, there is no automatic centering etc.
360 
361  // Flags for mouse movements
362  bool isMouseMovingHoriz;
363  bool isMouseMovingVert;
364 
365  bool flagEnableMoveAtScreenEdge; // allow mouse at edge of screen to move view
366  bool flagEnableMouseNavigation;
367  float mouseZoomSpeed;
368 
369  bool flagEnableZoomKeys;
370  bool flagEnableMoveKeys;
371  float keyMoveSpeed; // Speed of keys movement
372  float keyZoomSpeed; // Speed of keys zoom
373  bool flagMoveSlow;
374 
375  // Speed factor for real life time movements, used for fast forward when playing scripts.
376  float movementsSpeedFactor;
377 
380  struct AutoMove
381  {
382  Vec3d start;
383  Vec3d aim;
384  Vec3d startUp; // The Up vector at start time
385  Vec3d aimUp; // The Up vector at end time of move
386  float speed; // set to 1/duration[ms] during automove setup.
387  float coef; // Set to 0 at begin of an automove, runs up to 1.
388  // If not null, move to the object instead of the aim.
389  StelObjectP targetObject;
390  MountMode mountMode; // In which frame we shall move. This may be different from the frame the display is set to!
391  // The start and aim vectors are given in those coordinates, and are interpolated in the respective reference frames,
392  // then the view vector is derived from the current coef.
393  // AzAlt moves should be set to AltAz mode, else they will move towards the RA/Dec at begin of move which may have moved.
394  // It is an error to move in J2000 or Eq frame with fast timelapse!
395  // This is a March 2016 GZ hack. TODO: This class should be thought over a bit.
396  };
397 
398  AutoMove move; // Current auto movement. 2016-03: During setup, decide upon the frame for motion!
399  bool flagAutoMove; // Define if automove is on or off
400  ZoomingMode zoomingMode;
401 
402  double deltaAlt,deltaAz; // View movement
403 
404  bool flagManualZoom; // Define whether auto zoom can go further
405  float autoMoveDuration; // Duration of movement for the auto move to a selected object in seconds
406 
407  // Mouse control options
408  bool isDragging, hasDragged;
409  int previousX, previousY;
410 
411  // Contains the last N real time / JD times pairs associated with the last N mouse move events at screen coordinates x/y
412  struct DragHistoryEntry
413  {
414  double runTime;
415  double jd;
416  int x;
417  int y;
418  };
419  QList<DragHistoryEntry> timeDragHistory; // list of max 3 entries.
420  void addTimeDragPoint(int x, int y);
421  float beforeTimeDragTimeRate;
422 
423  // Time mouse control
424  bool dragTimeMode; // Internal flag, true during mouse time motion. This is set true when mouse is moving with ctrl pressed. Set false when releasing ctrl.
425 
428  // Components:
429  // startFov: field of view at start
430  // aimFov: intended field of view at end of zoom move
431  // speed: rate of change. UNITS?
432  // coef: set to 0 at begin of zoom, will increase to 1 during autozoom motion.
433  struct AutoZoom
434  {
435  double startFov;
436  double aimFov;
437  float speed;
438  float coef;
439  };
440 
441  // Automove
442  AutoZoom zoomMove; // Current auto movement
443  bool flagAutoZoom; // Define if autozoom is on or off
444  bool flagAutoZoomOutResetsDirection;
445 
446  // defines if view corrects for horizon, or uses equatorial coordinates
447  MountMode mountMode;
448 
449  Vec3d initViewPos; // Default viewing direction
450  Vec3d initViewUp; // original up vector. Usually 0/0/1, but maybe something else in rare setups (e.g. Planetarium dome upwards fisheye projection).
451 
452  // Viewing direction in equatorial J2000 coordinates
453  Vec3d viewDirectionJ2000;
454  // Viewing direction in the mount reference frame.
455  Vec3d viewDirectionMountFrame;
456 
457  // Up vector (in OpenGL terms) in the mount reference frame.
458  // 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.
459  Vec3d upVectorMountFrame;
460 
461  // TODO: Docfix?
462  float dragTriggerDistance;
463 
464  // Viewport shifting. This animates a property belonging to StelCore. But the shift itself is likely best placed here.
465  QTimeLine *viewportOffsetTimeline;
466  // Those two are used during viewport offset animation transitions. Both are set by moveViewport(), and irrelevant after the transition.
467  Vec2f oldViewportOffset;
468  Vec2f targetViewportOffset;
469 
470  bool flagIndicationMountMode; // state of mount mode
471 
473 
474  QTimer* messageTimer;
475  QList<int> messageIDs;
477 
478 };
479 
480 #endif // _STELMOVEMENTMGR_HPP_
481 
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 lookEast(bool zero=false)
Look immediately towards East.
void lookTowardsSCP(void)
Look immediately towards South Celestial pole.
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.
bool getFlagIndicationMountMode() const
Get the state of flag for indication of mount mode.
Main class for Stellarium core processing.
Definition: StelCore.hpp:48
void lookNorth(bool zero=false)
Look immediately towards North.
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 lookNadir(void)
Look immediately towards Nadir, turning southern horizon to screen top.
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.
const Vec3d getInitViewingDirection()
Return the inital viewing direction in altazimuthal coordinates.
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.
void setFlagIndicationMountMode(bool b)
Set the state of flag for indication of mount mode.
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.
void lookWest(bool zero=false)
Look immediately towards West.
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 lookTowardsNCP(void)
Look immediately towards North Celestial pole.
void setFlagEnableMoveAtScreenEdge(bool b)
Set whether being at the edge of the screen activates movement.
void lookSouth(bool zero=false)
Look immediately towards South.
Vec3d getViewDirectionJ2000() const
Return the current viewing direction in the equatorial J2000 frame.
void updateMotion(double deltaTime)
Increment/decrement smoothly the vision field and position. Called in StelCore.update().
Manage the selection and queries on one or more StelObjects.
StelModuleActionName
Define the possible action for which an order is defined.
Definition: StelModule.hpp:121
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, turning southern horizon to screen bottom.
void zoomTo(double aimFov, float moveDuration=1.)
Change the zoom level.
void setAutoMoveDuration(float f)
Set automove duration in seconds.
virtual void update(double)
Update time-dependent things (triggers a time dragging record if required)
StelModuleSelectAction
Enum used when selecting objects to define whether to add to, replace, or remove from the existing se...
Definition: StelModule.hpp:111
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.
void setViewDirectionJ2000(const Vec3d &v)
Set the current viewing direction in the equatorial J2000 frame.
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.
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.