Stellarium 0.90.0
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
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  */
24 #include "StelModule.hpp"
25 #include "StelProjector.hpp"
26 #include "StelObjectType.hpp"
27 #include <QTimeLine>
32 {
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)
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)
47 public:
51  // TODO: add others: MountEcliptical, MountEq2000, MountEcliptical2000 and implement proper variants.
52  enum MountMode { MountAltAzimuthal, MountEquinoxEquatorial, MountGalactic, MountSupergalactic};
55  enum ZoomingMode { ZoomOut=-1, ZoomNone=0, ZoomIn=1};
58  virtual ~StelMovementMgr();
61  // Methods defined in the StelModule class
70  virtual void init();
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);
90  // Methods specific to StelMovementMgr
93  void updateMotion(double deltaTime);
95  // These are hopefully temporary.
96  bool getHasDragged() const {return hasDragged;}
99  // TODO: what are the units?
100  double getZoomSpeed() {return keyZoomSpeed;}
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);
110  void setMovementSpeedFactor(float s) {movementsSpeedFactor=s;}
111  float getMovementSpeedFactor() const {return movementsSpeedFactor;}
113  void setDragTriggerDistance(float d) {dragTriggerDistance=d;}
115 public slots:
117  void toggleMountMode() {if (getMountMode()==MountAltAzimuthal) setMountMode(MountEquinoxEquatorial); else setMountMode(MountAltAzimuthal);}
119  void setEquatorialMount(bool b) {setMountMode(b ? MountEquinoxEquatorial : MountAltAzimuthal);}
122  void setFlagTracking(bool b=true);
124  bool getFlagTracking(void) const {return flagTracking;}
127  void setFlagLockEquPos(bool b);
129  bool getFlagLockEquPos(void) const {return flagLockEquPos;}
135  void panView(const double deltaAz, const double deltaAlt);
139  void setAutoMoveDuration(float f) {autoMoveDuration = f;}
142  float getAutoMoveDuration(void) const {return autoMoveDuration;}
145  void setFlagAutoZoomOutResetsDirection(bool b) {flagAutoZoomOutResetsDirection = b;}
147  bool getFlagAutoZoomOutResetsDirection(void) {return flagAutoZoomOutResetsDirection;}
150  bool getFlagEnableZoomKeys() const {return flagEnableZoomKeys;}
152  void setFlagEnableZoomKeys(bool b) {flagEnableZoomKeys=b;}
155  bool getFlagEnableMoveKeys() const {return flagEnableMoveKeys;}
157  void setFlagEnableMoveKeys(bool b) {flagEnableMoveKeys=b;}
160  bool getFlagEnableMoveAtScreenEdge() const {return flagEnableMoveAtScreenEdge;}
162  void setFlagEnableMoveAtScreenEdge(bool b) {flagEnableMoveAtScreenEdge=b;}
165  bool getFlagEnableMouseNavigation() const {return flagEnableMouseNavigation;}
167  void setFlagEnableMouseNavigation(bool b) {flagEnableMouseNavigation=b;}
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);
194  void moveToAltAzi(const Vec3d& aim, const Vec3d &aimUp, float moveDuration = 1., ZoomingMode zooming = ZoomNone);
199  void zoomTo(double aimFov, float moveDuration = 1.);
201  double getCurrentFov() const {return currentFov;}
204  double getInitFov() const {return initFov;}
206  void setInitFov(double fov) {initFov=fov;}
209  const Vec3d& getInitViewingDirection() {return initViewPos;}
215  Vec3d getViewDirectionJ2000() const {return viewDirectionJ2000;}
216  void setViewDirectionJ2000(const Vec3d& v);
219  void setMaxFov(double max);
221  double getMaxFov(void) const {return maxFov;}
224  double getMinFov(void) const {return minFov;}
227  void autoZoomIn(float moveDuration = 1.f, bool allowManualZoom = 1);
229  void autoZoomOut(float moveDuration = 1.f, bool full = 0);
232  double getAimFov(void) const;
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);
244  void lookEast(void);
246  void lookWest(void);
248  void lookNorth(void);
250  void lookSouth(void);
252  void lookZenith(void);
254  void lookTowardsNCP(void);
256  void lookTowardsSCP(void);
263  void moveViewport(float offsetX, float offsetY, const float duration=0.f);
266  void setMountMode(MountMode m);
268  MountMode getMountMode(void) const {return mountMode;}
269  bool getEquatorialMount(void) const {return mountMode == MountEquinoxEquatorial;}
271  void setDragTimeMode(bool b) {dragTimeMode=b;}
272  bool getDragTimeMode() const {return dragTimeMode;}
276  void setInhibitAllAutomoves(bool inhibit) { flagInhibitAllAutomoves=inhibit;}
279  Vec2f getViewportOffsetTarget() const { return targetViewportOffset; }
280  float getViewportHorizontalOffsetTarget() const { return targetViewportOffset[0]; }
281  float getViewportVerticalOffsetTarget() const { return targetViewportOffset[1]; }
283  void setViewportHorizontalOffsetTarget(float f) { moveViewport(f,getViewportVerticalOffsetTarget()); }
284  void setViewportVerticalOffsetTarget(float f) { moveViewport(getViewportHorizontalOffsetTarget(),f); }
286 signals:
288  void flagTrackingChanged(bool b);
289  void equatorialMountChanged(bool b);
291  void viewportHorizontalOffsetTargetChanged(float f);
292  void viewportVerticalOffsetTargetChanged(float f);
294 private slots:
296  void selectedObjectChange(StelModule::StelModuleSelectAction action);
299  void handleViewportOffsetMovement(qreal value);
301 public:
302  Vec3d j2000ToMountFrame(const Vec3d& v) const;
303  Vec3d mountFrameToJ2000(const Vec3d& v) const;
305 private:
306  double currentFov; // The current FOV in degrees
307  double initFov; // The FOV at startup
308  double minFov; // Minimum FOV in degrees
309  double maxFov; // Maximum FOV in degrees
311  void setFov(double f)
312  {
313  currentFov = f;
314  if (f>maxFov)
315  currentFov = maxFov;
316  if (f<minFov)
317  currentFov = minFov;
318  }
319  void changeFov(double deltaFov);
321  // Move (a bit) to selected/tracked object until move.coef reaches 1, or auto-follow (track) selected object.
322  // Does nothing if flagInhibitAllAutomoves=true
323  void updateVisionVector(double deltaTime);
324  void updateAutoZoom(double deltaTime); // Update autoZoom if activated
327  void dragView(int x1, int y1, int x2, int y2);
329  StelCore* core; // The core on which the movement are applied
330  class StelObjectMgr* objectMgr;
331  bool flagLockEquPos; // Define if the equatorial position is locked
332  bool flagTracking; // Define if the selected object is followed
333  bool flagInhibitAllAutomoves; // Required for special installations: If true, there is no automatic centering etc.
335  // Flags for mouse movements
336  bool isMouseMovingHoriz;
337  bool isMouseMovingVert;
339  bool flagEnableMoveAtScreenEdge; // allow mouse at edge of screen to move view
340  bool flagEnableMouseNavigation;
341  float mouseZoomSpeed;
343  bool flagEnableZoomKeys;
344  bool flagEnableMoveKeys;
345  float keyMoveSpeed; // Speed of keys movement
346  float keyZoomSpeed; // Speed of keys zoom
347  bool flagMoveSlow;
349  // Speed factor for real life time movements, used for fast forward when playing scripts.
350  float movementsSpeedFactor;
354  struct AutoMove
355  {
356  Vec3d start;
357  Vec3d aim;
358  Vec3d startUp; // The Up vector at start time
359  Vec3d aimUp; // The Up vector at end time of move
360  float speed; // set to 1/duration[ms] during automove setup.
361  float coef; // Set to 0 at begin of an automove, runs up to 1.
362  // If not null, move to the object instead of the aim.
363  StelObjectP targetObject;
364  MountMode mountMode; // In which frame we shall move. This may be different from the frame the display is set to!
365  // The start and aim vectors are given in those coordinates, and are interpolated in the respective reference frames,
366  // then the view vector is derived from the current coef.
367  // AzAlt moves should be set to AltAz mode, else they will move towards the RA/Dec at begin of move which may have moved.
368  // It is an error to move in J2000 or Eq frame with fast timelapse!
369  // This is a March 2016 GZ hack. TODO: This class should be thought over a bit.
370  };
372  AutoMove move; // Current auto movement. 2016-03: During setup, decide upon the frame for motion!
373  bool flagAutoMove; // Define if automove is on or off
374  ZoomingMode zoomingMode;
376  double deltaFov,deltaAlt,deltaAz; // View movement
378  bool flagManualZoom; // Define whether auto zoom can go further
379  float autoMoveDuration; // Duration of movement for the auto move to a selected object in seconds
381  // Mouse control options
382  bool isDragging, hasDragged;
383  int previousX, previousY;
385  // Contains the last N real time / JD times pairs associated with the last N mouse move events
386  struct DragHistoryEntry
387  {
388  double runTime;
389  double jd;
390  int x;
391  int y;
392  };
394  QList<DragHistoryEntry> timeDragHistory;
395  void addTimeDragPoint(int x, int y);
396  float beforeTimeDragTimeRate;
398  // Time mouse control
399  bool dragTimeMode; // true during mouse time motion.
403  // Components:
404  // startFov: field of view at start
405  // aimFov: intended field of view at end of zoom move
406  // speed: rate of change. UNITS?
407  // coef: set to 0 at begin of zoom, will increase to 1 during autozoom motion.
408  struct AutoZoom
409  {
410  double startFov;
411  double aimFov;
412  float speed;
413  float coef;
414  };
416  // Automove
417  AutoZoom zoomMove; // Current auto movement
418  bool flagAutoZoom; // Define if autozoom is on or off
419  bool flagAutoZoomOutResetsDirection;
421  // defines if view corrects for horizon, or uses equatorial coordinates
422  MountMode mountMode;
424  Vec3d initViewPos; // Default viewing direction
425  Vec3d initViewUp; // original up vector. Usually 0/0/1, but maybe something else in rare setups (e.g. Planetarium dome upwards fisheye projection).
427  // Viewing direction in equatorial J2000 coordinates
428  Vec3d viewDirectionJ2000;
429  // Viewing direction in the mount reference frame.
430  Vec3d viewDirectionMountFrame;
432  // Up vector (in OpenGL terms) in the mount reference frame.
433  // 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.
434  Vec3d upVectorMountFrame;
436  // TODO: Docfix?
437  float dragTriggerDistance;
439  // Viewport shifting. This animates a property belonging to StelCore. But the shift itself is likely best placed here.
440  QTimeLine *viewportOffsetTimeline;
441  // Those two are used during viewport offset animation transitions. Both are set by moveViewport(), and irrelevant after the transition.
442  Vec2f oldViewportOffset;
443  Vec2f targetViewportOffset;
445 };
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 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.
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 lookTowardsNCP(void)
Look immediately towards North Celestial pole.
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.
Define the possible action for which an order is defined.
Definition: StelModule.hpp:117
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).
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.
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.