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>
28 #include <QCursor>
33 {
35  Q_PROPERTY(bool equatorialMount
36  READ getEquatorialMount
37  WRITE setEquatorialMount
38  NOTIFY equatorialMountChanged)
39  Q_PROPERTY(bool tracking
40  READ getFlagTracking
41  WRITE setFlagTracking
42  NOTIFY flagTrackingChanged)
44  //The targets of viewport offset animation
45  Q_PROPERTY(float viewportHorizontalOffsetTarget READ getViewportHorizontalOffsetTarget WRITE setViewportHorizontalOffsetTarget NOTIFY viewportHorizontalOffsetTargetChanged)
46  Q_PROPERTY(float viewportVerticalOffsetTarget READ getViewportVerticalOffsetTarget WRITE setViewportVerticalOffsetTarget NOTIFY viewportVerticalOffsetTargetChanged)
48  Q_PROPERTY(bool flagAutoZoomOutResetsDirection
51  NOTIFY flagAutoZoomOutResetsDirectionChanged)
52 public:
56  // TODO: add others: MountEcliptical, MountEq2000, MountEcliptical2000 and implement proper variants.
57  enum MountMode { MountAltAzimuthal, MountEquinoxEquatorial, MountGalactic, MountSupergalactic};
60  enum ZoomingMode { ZoomOut=-1, ZoomNone=0, ZoomIn=1};
63  virtual ~StelMovementMgr();
66  // Methods defined in the StelModule class
75  virtual void init();
78  virtual void update(double) {
79  if (dragTimeMode) addTimeDragPoint(QCursor::pos().x(), QCursor::pos().y());}
81  virtual void draw(StelCore*) {;}
83  virtual void handleKeys(QKeyEvent* event);
85  virtual bool handleMouseMoves(int x, int y, Qt::MouseButtons b);
87  virtual void handleMouseWheel(class QWheelEvent* event);
89  virtual void handleMouseClicks(class QMouseEvent* event);
90  // allow some keypress interaction by plugins.
91  virtual double getCallOrder(StelModuleActionName actionName) const;
93  virtual bool handlePinch(qreal scale, bool started);
96  // Methods specific to StelMovementMgr
99  void updateMotion(double deltaTime);
101  // These are hopefully temporary.
102  //bool getHasDragged() const {return hasDragged;}
105  // TODO: what are the units?
106  double getZoomSpeed() {return keyZoomSpeed;}
109  Vec3d getViewUpVectorJ2000() const;
110  // 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.
111  void setViewUpVectorJ2000(const Vec3d& up);
112  // Set vector directly. This is set in the current mountmode, but will be translated to J2000 internally
113  // 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.
114  void setViewUpVector(const Vec3d& up);
116  void setMovementSpeedFactor(float s) {movementsSpeedFactor=s;}
117  float getMovementSpeedFactor() const {return movementsSpeedFactor;}
119  void setDragTriggerDistance(float d) {dragTriggerDistance=d;}
121 public slots:
123  void toggleMountMode() {if (getMountMode()==MountAltAzimuthal) setMountMode(MountEquinoxEquatorial); else setMountMode(MountAltAzimuthal);}
125  void setEquatorialMount(bool b) {setMountMode(b ? MountEquinoxEquatorial : MountAltAzimuthal);}
128  void setFlagTracking(bool b=true);
130  bool getFlagTracking(void) const {return flagTracking;}
133  void setFlagLockEquPos(bool b);
135  bool getFlagLockEquPos(void) const {return flagLockEquPos;}
141  void panView(const double deltaAz, const double deltaAlt);
145  void setAutoMoveDuration(float f) {autoMoveDuration = f;}
148  float getAutoMoveDuration(void) const {return autoMoveDuration;}
151  void setFlagAutoZoomOutResetsDirection(bool b) {if (flagAutoZoomOutResetsDirection != b) { flagAutoZoomOutResetsDirection = b; emit flagAutoZoomOutResetsDirectionChanged(b);}}
153  bool getFlagAutoZoomOutResetsDirection(void) {return flagAutoZoomOutResetsDirection;}
156  bool getFlagEnableZoomKeys() const {return flagEnableZoomKeys;}
158  void setFlagEnableZoomKeys(bool b) {flagEnableZoomKeys=b;}
161  bool getFlagEnableMoveKeys() const {return flagEnableMoveKeys;}
163  void setFlagEnableMoveKeys(bool b) {flagEnableMoveKeys=b;}
166  bool getFlagEnableMoveAtScreenEdge() const {return flagEnableMoveAtScreenEdge;}
168  void setFlagEnableMoveAtScreenEdge(bool b) {flagEnableMoveAtScreenEdge=b;}
171  bool getFlagEnableMouseNavigation() const {return flagEnableMouseNavigation;}
173  void setFlagEnableMouseNavigation(bool b) {flagEnableMouseNavigation=b;}
185  void moveToJ2000(const Vec3d& aim, const Vec3d &aimUp, float moveDuration = 1., ZoomingMode zooming = ZoomNone);
186  void moveToObject(const StelObjectP& target, float moveDuration = 1., ZoomingMode zooming = ZoomNone);
200  void moveToAltAzi(const Vec3d& aim, const Vec3d &aimUp, float moveDuration = 1., ZoomingMode zooming = ZoomNone);
205  void zoomTo(double aimFov, float moveDuration = 1.);
207  double getCurrentFov() const {return currentFov;}
210  double getInitFov() const {return initFov;}
212  void setInitFov(double fov) {initFov=fov;}
215  const Vec3d& getInitViewingDirection() {return initViewPos;}
221  Vec3d getViewDirectionJ2000() const {return viewDirectionJ2000;}
222  void setViewDirectionJ2000(const Vec3d& v);
225  void setMaxFov(double max);
227  double getMaxFov(void) const {return maxFov;}
230  double getMinFov(void) const {return minFov;}
233  void autoZoomIn(float moveDuration = 1.f, bool allowManualZoom = 1);
235  void autoZoomOut(float moveDuration = 1.f, bool full = 0);
238  double getAimFov(void) const;
241  void turnRight(bool);
242  void turnLeft(bool);
243  void turnUp(bool);
244  void turnDown(bool);
245  void moveSlow(bool b) {flagMoveSlow=b;}
246  void zoomIn(bool);
247  void zoomOut(bool);
250  void lookEast(void);
252  void lookWest(void);
254  void lookNorth(void);
256  void lookSouth(void);
258  void lookZenith(void);
260  void lookTowardsNCP(void);
262  void lookTowardsSCP(void);
269  void moveViewport(float offsetX, float offsetY, const float duration=0.f);
272  void setMountMode(MountMode m);
274  MountMode getMountMode(void) const {return mountMode;}
275  bool getEquatorialMount(void) const {return mountMode == MountEquinoxEquatorial;}
279  void setInhibitAllAutomoves(bool inhibit) { flagInhibitAllAutomoves=inhibit;}
282  Vec2f getViewportOffsetTarget() const { return targetViewportOffset; }
283  float getViewportHorizontalOffsetTarget() const { return targetViewportOffset[0]; }
284  float getViewportVerticalOffsetTarget() const { return targetViewportOffset[1]; }
286  void setViewportHorizontalOffsetTarget(float f) { moveViewport(f,getViewportVerticalOffsetTarget()); }
287  void setViewportVerticalOffsetTarget(float f) { moveViewport(getViewportHorizontalOffsetTarget(),f); }
289 signals:
291  void flagTrackingChanged(bool b);
292  void equatorialMountChanged(bool b);
294  void flagAutoZoomOutResetsDirectionChanged(bool b);
296  void viewportHorizontalOffsetTargetChanged(float f);
297  void viewportVerticalOffsetTargetChanged(float f);
299 private slots:
301  void selectedObjectChange(StelModule::StelModuleSelectAction action);
304  void handleViewportOffsetMovement(qreal value);
306 public:
307  Vec3d j2000ToMountFrame(const Vec3d& v) const;
308  Vec3d mountFrameToJ2000(const Vec3d& v) const;
310 private:
311  double currentFov; // The current FOV in degrees
312  double initFov; // The FOV at startup
313  double minFov; // Minimum FOV in degrees
314  double maxFov; // Maximum FOV in degrees
316  void setFov(double f)
317  {
318  currentFov = f;
319  if (f>maxFov)
320  currentFov = maxFov;
321  if (f<minFov)
322  currentFov = minFov;
323  }
324  void changeFov(double deltaFov);
326  // Move (a bit) to selected/tracked object until move.coef reaches 1, or auto-follow (track) selected object.
327  // Does nothing if flagInhibitAllAutomoves=true
328  void updateVisionVector(double deltaTime);
329  void updateAutoZoom(double deltaTime); // Update autoZoom if activated
332  void dragView(int x1, int y1, int x2, int y2);
334  StelCore* core; // The core on which the movement are applied
335  class StelObjectMgr* objectMgr;
336  bool flagLockEquPos; // Define if the equatorial position is locked
337  bool flagTracking; // Define if the selected object is followed
338  bool flagInhibitAllAutomoves; // Required for special installations: If true, there is no automatic centering etc.
340  // Flags for mouse movements
341  bool isMouseMovingHoriz;
342  bool isMouseMovingVert;
344  bool flagEnableMoveAtScreenEdge; // allow mouse at edge of screen to move view
345  bool flagEnableMouseNavigation;
346  float mouseZoomSpeed;
348  bool flagEnableZoomKeys;
349  bool flagEnableMoveKeys;
350  float keyMoveSpeed; // Speed of keys movement
351  float keyZoomSpeed; // Speed of keys zoom
352  bool flagMoveSlow;
354  // Speed factor for real life time movements, used for fast forward when playing scripts.
355  float movementsSpeedFactor;
359  struct AutoMove
360  {
361  Vec3d start;
362  Vec3d aim;
363  Vec3d startUp; // The Up vector at start time
364  Vec3d aimUp; // The Up vector at end time of move
365  float speed; // set to 1/duration[ms] during automove setup.
366  float coef; // Set to 0 at begin of an automove, runs up to 1.
367  // If not null, move to the object instead of the aim.
368  StelObjectP targetObject;
369  MountMode mountMode; // In which frame we shall move. This may be different from the frame the display is set to!
370  // The start and aim vectors are given in those coordinates, and are interpolated in the respective reference frames,
371  // then the view vector is derived from the current coef.
372  // AzAlt moves should be set to AltAz mode, else they will move towards the RA/Dec at begin of move which may have moved.
373  // It is an error to move in J2000 or Eq frame with fast timelapse!
374  // This is a March 2016 GZ hack. TODO: This class should be thought over a bit.
375  };
377  AutoMove move; // Current auto movement. 2016-03: During setup, decide upon the frame for motion!
378  bool flagAutoMove; // Define if automove is on or off
379  ZoomingMode zoomingMode;
381  double deltaFov,deltaAlt,deltaAz; // View movement
383  bool flagManualZoom; // Define whether auto zoom can go further
384  float autoMoveDuration; // Duration of movement for the auto move to a selected object in seconds
386  // Mouse control options
387  bool isDragging, hasDragged;
388  int previousX, previousY;
390  // Contains the last N real time / JD times pairs associated with the last N mouse move events at screen coordinates x/y
391  struct DragHistoryEntry
392  {
393  double runTime;
394  double jd;
395  int x;
396  int y;
397  };
398  QList<DragHistoryEntry> timeDragHistory; // list of max 3 entries.
399  void addTimeDragPoint(int x, int y);
400  float beforeTimeDragTimeRate;
402  // Time mouse control
403  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.
407  // Components:
408  // startFov: field of view at start
409  // aimFov: intended field of view at end of zoom move
410  // speed: rate of change. UNITS?
411  // coef: set to 0 at begin of zoom, will increase to 1 during autozoom motion.
412  struct AutoZoom
413  {
414  double startFov;
415  double aimFov;
416  float speed;
417  float coef;
418  };
420  // Automove
421  AutoZoom zoomMove; // Current auto movement
422  bool flagAutoZoom; // Define if autozoom is on or off
423  bool flagAutoZoomOutResetsDirection;
425  // defines if view corrects for horizon, or uses equatorial coordinates
426  MountMode mountMode;
428  Vec3d initViewPos; // Default viewing direction
429  Vec3d initViewUp; // original up vector. Usually 0/0/1, but maybe something else in rare setups (e.g. Planetarium dome upwards fisheye projection).
431  // Viewing direction in equatorial J2000 coordinates
432  Vec3d viewDirectionJ2000;
433  // Viewing direction in the mount reference frame.
434  Vec3d viewDirectionMountFrame;
436  // Up vector (in OpenGL terms) in the mount reference frame.
437  // 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.
438  Vec3d upVectorMountFrame;
440  // TODO: Docfix?
441  float dragTriggerDistance;
443  // Viewport shifting. This animates a property belonging to StelCore. But the shift itself is likely best placed here.
444  QTimeLine *viewportOffsetTimeline;
445  // Those two are used during viewport offset animation transitions. Both are set by moveViewport(), and irrelevant after the transition.
446  Vec2f oldViewportOffset;
447  Vec2f targetViewportOffset;
449 };
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:121
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 (triggers a time dragging record if required)
Enum used when selecting objects to define whether to add to, replace, or remove from the existing se...
Definition: StelModule.hpp:111
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.