Stellarium 0.15.2
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
46  READ getViewportHorizontalOffsetTarget
47  WRITE setViewportHorizontalOffsetTarget
48  NOTIFY viewportHorizontalOffsetTargetChanged)
49  Q_PROPERTY(float viewportVerticalOffsetTarget
50  READ getViewportVerticalOffsetTarget
51  WRITE setViewportVerticalOffsetTarget
52  NOTIFY viewportVerticalOffsetTargetChanged)
54  Q_PROPERTY(bool flagAutoZoomOutResetsDirection
57  NOTIFY flagAutoZoomOutResetsDirectionChanged)
58 public:
62  // TODO: add others: MountEcliptical, MountEq2000, MountEcliptical2000 and implement proper variants.
63  enum MountMode { MountAltAzimuthal, MountEquinoxEquatorial, MountGalactic, MountSupergalactic};
66  enum ZoomingMode { ZoomOut=-1, ZoomNone=0, ZoomIn=1};
69  virtual ~StelMovementMgr();
72  // Methods defined in the StelModule class
81  virtual void init();
84  virtual void update(double)
85  {
86  if (dragTimeMode)
87  addTimeDragPoint(QCursor::pos().x(), QCursor::pos().y());
88  }
90  virtual void draw(StelCore*) {;}
92  virtual void handleKeys(QKeyEvent* event);
94  virtual bool handleMouseMoves(int x, int y, Qt::MouseButtons b);
96  virtual void handleMouseWheel(class QWheelEvent* event);
98  virtual void handleMouseClicks(class QMouseEvent* event);
99  // allow some keypress interaction by plugins.
100  virtual double getCallOrder(StelModuleActionName actionName) const;
102  virtual bool handlePinch(qreal scale, bool started);
105  // Methods specific to StelMovementMgr
108  void updateMotion(double deltaTime);
111  // TODO: what are the units?
112  double getZoomSpeed() {return keyZoomSpeed;}
115  Vec3d getViewUpVectorJ2000() const;
116  // 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.
117  void setViewUpVectorJ2000(const Vec3d& up);
118  // Set vector directly. This is set in the current mountmode, but will be translated to J2000 internally
119  // 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.
120  void setViewUpVector(const Vec3d& up);
122  void setMovementSpeedFactor(float s) {movementsSpeedFactor=s;}
123  float getMovementSpeedFactor() const {return movementsSpeedFactor;}
125  void setDragTriggerDistance(float d) {dragTriggerDistance=d;}
127 public slots:
129  void toggleMountMode() {if (getMountMode()==MountAltAzimuthal) setMountMode(MountEquinoxEquatorial); else setMountMode(MountAltAzimuthal);}
131  void setEquatorialMount(bool b) {setMountMode(b ? MountEquinoxEquatorial : MountAltAzimuthal);}
134  void setFlagTracking(bool b=true);
136  bool getFlagTracking(void) const {return flagTracking;}
139  void setFlagLockEquPos(bool b);
141  bool getFlagLockEquPos(void) const {return flagLockEquPos;}
147  void panView(const double deltaAz, const double deltaAlt);
151  void setAutoMoveDuration(float f) {autoMoveDuration = f;}
154  float getAutoMoveDuration(void) const {return autoMoveDuration;}
157  void setFlagAutoZoomOutResetsDirection(bool b) {if (flagAutoZoomOutResetsDirection != b) { flagAutoZoomOutResetsDirection = b; emit flagAutoZoomOutResetsDirectionChanged(b);}}
159  bool getFlagAutoZoomOutResetsDirection(void) {return flagAutoZoomOutResetsDirection;}
162  bool getFlagEnableZoomKeys() const {return flagEnableZoomKeys;}
164  void setFlagEnableZoomKeys(bool b) {flagEnableZoomKeys=b;}
167  bool getFlagEnableMoveKeys() const {return flagEnableMoveKeys;}
169  void setFlagEnableMoveKeys(bool b) {flagEnableMoveKeys=b;}
172  bool getFlagEnableMoveAtScreenEdge() const {return flagEnableMoveAtScreenEdge;}
174  void setFlagEnableMoveAtScreenEdge(bool b) {flagEnableMoveAtScreenEdge=b;}
177  bool getFlagEnableMouseNavigation() const {return flagEnableMouseNavigation;}
179  void setFlagEnableMouseNavigation(bool b) {flagEnableMouseNavigation=b;}
191  void moveToJ2000(const Vec3d& aim, const Vec3d &aimUp, float moveDuration = 1., ZoomingMode zooming = ZoomNone);
192  void moveToObject(const StelObjectP& target, float moveDuration = 1., ZoomingMode zooming = ZoomNone);
206  void moveToAltAzi(const Vec3d& aim, const Vec3d &aimUp, float moveDuration = 1., ZoomingMode zooming = ZoomNone);
211  void zoomTo(double aimFov, float moveDuration = 1.);
213  double getCurrentFov() const {return currentFov;}
216  double getInitFov() const {return initFov;}
218  void setInitFov(double fov) {initFov=fov;}
221  const Vec3d getInitViewingDirection() {return initViewPos;}
227  Vec3d getViewDirectionJ2000() const {return viewDirectionJ2000;}
228  void setViewDirectionJ2000(const Vec3d& v);
231  void setMaxFov(double max);
233  double getMaxFov(void) const {return maxFov;}
236  double getMinFov(void) const {return minFov;}
239  void autoZoomIn(float moveDuration = 1.f, bool allowManualZoom = 1);
241  void autoZoomOut(float moveDuration = 1.f, bool full = 0);
244  double getAimFov(void) const;
247  void turnRight(bool);
248  void turnLeft(bool);
249  void turnUp(bool);
250  void turnDown(bool);
251  void moveSlow(bool b) {flagMoveSlow=b;}
252  void zoomIn(bool);
253  void zoomOut(bool);
257  void lookEast(bool zero=false);
260  void lookWest(bool zero=false);
263  void lookNorth(bool zero=false);
266  void lookSouth(bool zero=false);
268  void lookZenith(void);
270  void lookNadir(void);
272  void lookTowardsNCP(void);
274  void lookTowardsSCP(void);
281  void moveViewport(float offsetX, float offsetY, const float duration=0.f);
284  void setMountMode(MountMode m);
286  MountMode getMountMode(void) const {return mountMode;}
287  bool getEquatorialMount(void) const {return mountMode == MountEquinoxEquatorial;}
291  void setInhibitAllAutomoves(bool inhibit) { flagInhibitAllAutomoves=inhibit;}
294  Vec2f getViewportOffsetTarget() const { return targetViewportOffset; }
295  float getViewportHorizontalOffsetTarget() const { return targetViewportOffset[0]; }
296  float getViewportVerticalOffsetTarget() const { return targetViewportOffset[1]; }
298  void setViewportHorizontalOffsetTarget(float f) { moveViewport(f,getViewportVerticalOffsetTarget()); }
299  void setViewportVerticalOffsetTarget(float f) { moveViewport(getViewportHorizontalOffsetTarget(),f); }
301 signals:
303  void flagTrackingChanged(bool b);
304  void equatorialMountChanged(bool b);
306  void flagAutoZoomOutResetsDirectionChanged(bool b);
308  void viewportHorizontalOffsetTargetChanged(float f);
309  void viewportVerticalOffsetTargetChanged(float f);
311 private slots:
313  void selectedObjectChange(StelModule::StelModuleSelectAction action);
316  void handleViewportOffsetMovement(qreal value);
318 public:
319  Vec3d j2000ToMountFrame(const Vec3d& v) const;
320  Vec3d mountFrameToJ2000(const Vec3d& v) const;
322 private:
323  double currentFov; // The current FOV in degrees
324  double initFov; // The FOV at startup
325  double minFov; // Minimum FOV in degrees
326  double maxFov; // Maximum FOV in degrees
327  double deltaFov; // requested change of FOV (degrees) used during zooming.
328  void setFov(double f)
329  {
330  currentFov=qMax(minFov, qMin(f, maxFov));
331  }
332  // immediately add deltaFov argument to FOV - does not change private var.
333  void changeFov(double deltaFov);
335  // Move (a bit) to selected/tracked object until move.coef reaches 1, or auto-follow (track) selected object.
336  // Does nothing if flagInhibitAllAutomoves=true
337  void updateVisionVector(double deltaTime);
338  void updateAutoZoom(double deltaTime); // Update autoZoom if activated
341  void dragView(int x1, int y1, int x2, int y2);
343  StelCore* core; // The core on which the movement are applied
344  class StelObjectMgr* objectMgr;
345  bool flagLockEquPos; // Define if the equatorial position is locked
346  bool flagTracking; // Define if the selected object is followed
347  bool flagInhibitAllAutomoves; // Required for special installations: If true, there is no automatic centering etc.
349  // Flags for mouse movements
350  bool isMouseMovingHoriz;
351  bool isMouseMovingVert;
353  bool flagEnableMoveAtScreenEdge; // allow mouse at edge of screen to move view
354  bool flagEnableMouseNavigation;
355  float mouseZoomSpeed;
357  bool flagEnableZoomKeys;
358  bool flagEnableMoveKeys;
359  float keyMoveSpeed; // Speed of keys movement
360  float keyZoomSpeed; // Speed of keys zoom
361  bool flagMoveSlow;
363  // Speed factor for real life time movements, used for fast forward when playing scripts.
364  float movementsSpeedFactor;
368  struct AutoMove
369  {
370  Vec3d start;
371  Vec3d aim;
372  Vec3d startUp; // The Up vector at start time
373  Vec3d aimUp; // The Up vector at end time of move
374  float speed; // set to 1/duration[ms] during automove setup.
375  float coef; // Set to 0 at begin of an automove, runs up to 1.
376  // If not null, move to the object instead of the aim.
377  StelObjectP targetObject;
378  MountMode mountMode; // In which frame we shall move. This may be different from the frame the display is set to!
379  // The start and aim vectors are given in those coordinates, and are interpolated in the respective reference frames,
380  // then the view vector is derived from the current coef.
381  // AzAlt moves should be set to AltAz mode, else they will move towards the RA/Dec at begin of move which may have moved.
382  // It is an error to move in J2000 or Eq frame with fast timelapse!
383  // This is a March 2016 GZ hack. TODO: This class should be thought over a bit.
384  };
386  AutoMove move; // Current auto movement. 2016-03: During setup, decide upon the frame for motion!
387  bool flagAutoMove; // Define if automove is on or off
388  ZoomingMode zoomingMode;
390  double deltaAlt,deltaAz; // View movement
392  bool flagManualZoom; // Define whether auto zoom can go further
393  float autoMoveDuration; // Duration of movement for the auto move to a selected object in seconds
395  // Mouse control options
396  bool isDragging, hasDragged;
397  int previousX, previousY;
399  // Contains the last N real time / JD times pairs associated with the last N mouse move events at screen coordinates x/y
400  struct DragHistoryEntry
401  {
402  double runTime;
403  double jd;
404  int x;
405  int y;
406  };
407  QList<DragHistoryEntry> timeDragHistory; // list of max 3 entries.
408  void addTimeDragPoint(int x, int y);
409  float beforeTimeDragTimeRate;
411  // Time mouse control
412  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.
416  // Components:
417  // startFov: field of view at start
418  // aimFov: intended field of view at end of zoom move
419  // speed: rate of change. UNITS?
420  // coef: set to 0 at begin of zoom, will increase to 1 during autozoom motion.
421  struct AutoZoom
422  {
423  double startFov;
424  double aimFov;
425  float speed;
426  float coef;
427  };
429  // Automove
430  AutoZoom zoomMove; // Current auto movement
431  bool flagAutoZoom; // Define if autozoom is on or off
432  bool flagAutoZoomOutResetsDirection;
434  // defines if view corrects for horizon, or uses equatorial coordinates
435  MountMode mountMode;
437  Vec3d initViewPos; // Default viewing direction
438  Vec3d initViewUp; // original up vector. Usually 0/0/1, but maybe something else in rare setups (e.g. Planetarium dome upwards fisheye projection).
440  // Viewing direction in equatorial J2000 coordinates
441  Vec3d viewDirectionJ2000;
442  // Viewing direction in the mount reference frame.
443  Vec3d viewDirectionMountFrame;
445  // Up vector (in OpenGL terms) in the mount reference frame.
446  // 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.
447  Vec3d upVectorMountFrame;
449  // TODO: Docfix?
450  float dragTriggerDistance;
452  // Viewport shifting. This animates a property belonging to StelCore. But the shift itself is likely best placed here.
453  QTimeLine *viewportOffsetTimeline;
454  // Those two are used during viewport offset animation transitions. Both are set by moveViewport(), and irrelevant after the transition.
455  Vec2f oldViewportOffset;
456  Vec2f targetViewportOffset;
458 };
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.
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.
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 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.
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, 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)
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.
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.
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.