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 
31 {
32  Q_OBJECT
33  Q_PROPERTY(bool equatorialMount
34  READ getEquatorialMount
35  WRITE setEquatorialMount)
36  Q_PROPERTY(bool tracking
37  READ getFlagTracking
38  WRITE setFlagTracking)
39 public:
40 
43  // TODO: add others: MountEcliptical, MountEq2000, MountEcliptical2000 and implement proper variants.
44  enum MountMode { MountAltAzimuthal, MountEquinoxEquatorial, MountGalactic};
45 
47  enum ZoomingMode { ZoomOut=-1, ZoomNone=0, ZoomIn=1};
48 
50  virtual ~StelMovementMgr();
51 
53  // Methods defined in the StelModule class
62  virtual void init();
63 
65  virtual void update(double) {;}
67  virtual void draw(StelCore*) {;}
69  virtual void handleKeys(QKeyEvent* event);
71  virtual bool handleMouseMoves(int x, int y, Qt::MouseButtons b);
73  virtual void handleMouseWheel(class QWheelEvent* event);
75  virtual void handleMouseClicks(class QMouseEvent* event);
76  // GZ: allow some keypress interaction by plugins.
77  virtual double getCallOrder(StelModuleActionName actionName) const;
79  virtual bool handlePinch(qreal scale, bool started);
80 
82  // Methods specific to StelMovementMgr
83 
85  void updateMotion(double deltaTime);
86 
87  // These are hopefully temporary.
88  bool getHasDragged() const {return hasDragged;}
89 
91  // TODO: what are the units?
92  double getZoomSpeed() {return keyZoomSpeed;}
93 
96  // 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.
97  void setViewUpVectorJ2000(const Vec3d& up);
98  // Set vector directly. This is set in the current mountmode, but will be translated to J2000 internally
99  // 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.
100  void setViewUpVector(const Vec3d& up);
101 
102  void setMovementSpeedFactor(float s) {movementsSpeedFactor=s;}
103  float getMovementSpeedFactor() const {return movementsSpeedFactor;}
104 
105  void setDragTriggerDistance(float d) {dragTriggerDistance=d;}
106 
107 public slots:
109  void toggleMountMode() {if (getMountMode()==MountAltAzimuthal) setMountMode(MountEquinoxEquatorial); else setMountMode(MountAltAzimuthal);}
111  void setEquatorialMount(bool b) {setMountMode(b ? MountEquinoxEquatorial : MountAltAzimuthal);}
112 
114  void setFlagTracking(bool b=true);
116  bool getFlagTracking(void) const {return flagTracking;}
117 
119  void setFlagLockEquPos(bool b);
121  bool getFlagLockEquPos(void) const {return flagLockEquPos;}
122 
127  void panView(const double deltaAz, const double deltaAlt);
128 
131  void setAutoMoveDuration(float f) {autoMoveDuration = f;}
134  float getAutoMoveDuration(void) const {return autoMoveDuration;}
135 
137  void setFlagAutoZoomOutResetsDirection(bool b) {flagAutoZoomOutResetsDirection = b;}
139  bool getFlagAutoZoomOutResetsDirection(void) {return flagAutoZoomOutResetsDirection;}
140 
142  bool getFlagEnableZoomKeys() const {return flagEnableZoomKeys;}
144  void setFlagEnableZoomKeys(bool b) {flagEnableZoomKeys=b;}
145 
147  bool getFlagEnableMoveKeys() const {return flagEnableMoveKeys;}
149  void setFlagEnableMoveKeys(bool b) {flagEnableMoveKeys=b;}
150 
152  bool getFlagEnableMoveAtScreenEdge() const {return flagEnableMoveAtScreenEdge;}
154  void setFlagEnableMoveAtScreenEdge(bool b) {flagEnableMoveAtScreenEdge=b;}
155 
157  bool getFlagEnableMouseNavigation() const {return flagEnableMouseNavigation;}
159  void setFlagEnableMouseNavigation(bool b) {flagEnableMouseNavigation=b;}
160 
171  void moveToJ2000(const Vec3d& aim, const Vec3d &aimUp, float moveDuration = 1., ZoomingMode zooming = ZoomNone);
172  void moveToObject(const StelObjectP& target, float moveDuration = 1., ZoomingMode zooming = ZoomNone);
173 
177  void zoomTo(double aimFov, float moveDuration = 1.);
179  double getCurrentFov() const {return currentFov;}
180 
182  double getInitFov() const {return initFov;}
184  void setInitFov(double fov) {initFov=fov;}
185 
187  const Vec3d& getInitViewingDirection() {return initViewPos;}
191 
193  Vec3d getViewDirectionJ2000() const {return viewDirectionJ2000;}
194  void setViewDirectionJ2000(const Vec3d& v);
195 
197  void setMaxFov(double max);
199  double getMaxFov(void) const {return maxFov;}
200 
202  void autoZoomIn(float moveDuration = 1.f, bool allowManualZoom = 1);
204  void autoZoomOut(float moveDuration = 1.f, bool full = 0);
205 
207  double getAimFov(void) const;
208 
210  void turnRight(bool);
211  void turnLeft(bool);
212  void turnUp(bool);
213  void turnDown(bool);
214  void moveSlow(bool b) {flagMoveSlow=b;}
215  void zoomIn(bool);
216  void zoomOut(bool);
217 
219  void lookEast(void);
221  void lookWest(void);
223  void lookNorth(void);
225  void lookSouth(void);
227  void lookZenith(void);
228 
230  void setMountMode(MountMode m);
232  MountMode getMountMode(void) const {return mountMode;}
233  bool getEquatorialMount(void) const {return mountMode == MountEquinoxEquatorial;}
234 
235  void setDragTimeMode(bool b) {dragTimeMode=b;}
236  bool getDragTimeMode() const {return dragTimeMode;}
237 
239  double getInitConstellationIntensity() const {return initConstellationIntensity;}
241  void setInitConstellationIntensity(double v) {initConstellationIntensity=v; changeConstellationArtIntensity();}
242 
245  void setInhibitAllAutomoves(bool inhibit) { flagInhibitAllAutomoves=inhibit;}
246 
247 private slots:
249  void selectedObjectChange(StelModule::StelModuleSelectAction action);
250 
251 public:
252  Vec3d j2000ToMountFrame(const Vec3d& v) const;
253  Vec3d mountFrameToJ2000(const Vec3d& v) const;
254 
255 private:
256  double currentFov; // The current FOV in degrees
257  double initFov; // The FOV at startup
258  double minFov; // Minimum FOV in degrees
259  double maxFov; // Maximum FOV in degrees
260  double initConstellationIntensity; // The initial constellation art intensity (level at startup)
261 
262  void setFov(double f)
263  {
264  currentFov = f;
265  if (f>maxFov)
266  currentFov = maxFov;
267  if (f<minFov)
268  currentFov = minFov;
269 
270  changeConstellationArtIntensity();
271  }
272  void changeFov(double deltaFov);
273  void changeConstellationArtIntensity();
274 
275  // Move (a bit) to selected/tracked object until move.coef reaches 1, or auto-follow (track) selected object.
276  // Does nothing if flagInhibitAllAutomoves=true
277  void updateVisionVector(double deltaTime);
278  void updateAutoZoom(double deltaTime); // Update autoZoom if activated
279 
281  void dragView(int x1, int y1, int x2, int y2);
282 
283  StelCore* core; // The core on which the movement are applied
284  class StelObjectMgr* objectMgr;
285  bool flagLockEquPos; // Define if the equatorial position is locked
286  bool flagTracking; // Define if the selected object is followed
287  bool flagInhibitAllAutomoves; // Required for special installations: If true, there is no automatic centering etc.
288 
289  // Flags for mouse movements
290  bool isMouseMovingHoriz;
291  bool isMouseMovingVert;
292 
293  bool flagEnableMoveAtScreenEdge; // allow mouse at edge of screen to move view
294  bool flagEnableMouseNavigation;
295  float mouseZoomSpeed;
296 
297  bool flagEnableZoomKeys;
298  bool flagEnableMoveKeys;
299  float keyMoveSpeed; // Speed of keys movement
300  float keyZoomSpeed; // Speed of keys zoom
301  bool flagMoveSlow;
302 
303  // Speed factor for real life time movements, used for fast forward when playing scripts.
304  float movementsSpeedFactor;
305 
308  struct AutoMove
309  {
310  Vec3d start;
311  Vec3d aim;
312  Vec3d startUp; // The Up vector at start time
313  Vec3d aimUp; // The Up vector at end time of move
314  float speed;
315  float coef;
316  // If not null, move to the object.
317  StelObjectP targetObject;
318  };
319 
320  AutoMove move; // Current auto movement
321  bool flagAutoMove; // Define if automove is on or off
322  ZoomingMode zoomingMode;
323 
324  double deltaFov,deltaAlt,deltaAz; // View movement
325 
326  bool flagManualZoom; // Define whether auto zoom can go further
327  float autoMoveDuration; // Duration of movement for the auto move to a selected object in seconds
328 
329  // Mouse control options
330  bool isDragging, hasDragged;
331  int previousX, previousY;
332 
333  // Contains the last N real time / JD times pairs associated with the last N mouse move events
334  struct DragHistoryEntry
335  {
336  double runTime;
337  double jd;
338  int x;
339  int y;
340  };
341 
342  QList<DragHistoryEntry> timeDragHistory;
343  void addTimeDragPoint(int x, int y);
344  float beforeTimeDragTimeRate;
345 
346  // Time mouse control
347  bool dragTimeMode;
348 
351  // Components:
352  // startFov: field of view at start
353  // aimFov: intended field of view at end of zoom move
354  // speed: rate of change. UNITS?
355  // coef: set to 0 at begin of zoom, will increase to 1 during autozoom motion.
356  struct AutoZoom
357  {
358  double startFov;
359  double aimFov;
360  float speed;
361  float coef;
362  };
363 
364  // Automove
365  AutoZoom zoomMove; // Current auto movement
366  bool flagAutoZoom; // Define if autozoom is on or off
367  bool flagAutoZoomOutResetsDirection;
368 
369  // defines if view corrects for horizon, or uses equatorial coordinates
370  MountMode mountMode;
371 
372  Vec3d initViewPos; // Default viewing direction
373  Vec3d initViewUp; // original up vector. Usually 0/0/1, but maybe something else in rare setups.
374 
375  // Viewing direction in equatorial J2000 coordinates
376  Vec3d viewDirectionJ2000;
377  // Viewing direction in the mount reference frame.
378  Vec3d viewDirectionMountFrame;
379 
380  // Up vector (in OpenGL terms) in the mount reference frame.
381  // 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.
382  Vec3d upVectorMountFrame;
383 
384  float dragTriggerDistance;
385 };
386 
387 #endif // _STELMOVEMENTMGR_HPP_
388 
void setInitFov(double fov)
Set the initial Field Of View in degree.
bool getFlagLockEquPos(void) const
Get whether sky position is locked.
virtual bool handleMouseMoves(int x, int y, Qt::MouseButtons b)
Handle mouse movement events.
void setInitConstellationIntensity(double v)
Set the initial value of intensity of art of constellations.
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.
A templatized 3d vector compatible with openGL.
Definition: VecMath.hpp:33
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 getInitConstellationIntensity() const
Return the initial value of intensity of art of constellations.
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.
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.
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.
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.