Stellarium 0.14.3
StelMovementMgr.hpp
1 /*
2  * Stellarium
3  * Copyright (C) 2007 Fabien Chereau
4  * Copyright (C) 2015 Georg Zotti (offset view adaptations)
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 like MountEcliptical
44  enum MountMode { MountAltAzimuthal, MountEquinoxEquatorial, MountGalactic};
45 
47  virtual ~StelMovementMgr();
48 
50  // Methods defined in the StelModule class
59  virtual void init();
60 
62  virtual void update(double) {;}
64  virtual void draw(StelCore*) {;}
66  virtual void handleKeys(QKeyEvent* event);
68  virtual bool handleMouseMoves(int x, int y, Qt::MouseButtons b);
70  virtual void handleMouseWheel(class QWheelEvent* event);
72  virtual void handleMouseClicks(class QMouseEvent* event);
73  // GZ: allow some keypress interaction by plugins.
74  virtual double getCallOrder(StelModuleActionName actionName) const;
76  virtual bool handlePinch(qreal scale, bool started);
77 
79  // Methods specific to StelMovementMgr
80 
82  void updateMotion(double deltaTime);
83 
84  // These are hopefully temporary.
85  bool getHasDragged() const {return hasDragged;}
86 
88  // TODO: what are the units?
89  double getZoomSpeed() {return keyZoomSpeed;}
90 
93  void setViewUpVectorJ2000(const Vec3d& up);
94 
95  void setMovementSpeedFactor(float s) {movementsSpeedFactor=s;}
96  float getMovementSpeedFactor() const {return movementsSpeedFactor;}
97 
98  void setDragTriggerDistance(float d) {dragTriggerDistance=d;}
99 
100 public slots:
102  void toggleMountMode() {if (getMountMode()==MountAltAzimuthal) setMountMode(MountEquinoxEquatorial); else setMountMode(MountAltAzimuthal);}
104  void setEquatorialMount(bool b) {setMountMode(b ? MountEquinoxEquatorial : MountAltAzimuthal);}
105 
107  void setFlagTracking(bool b=true);
109  bool getFlagTracking(void) const {return flagTracking;}
110 
112  void setFlagLockEquPos(bool b);
114  bool getFlagLockEquPos(void) const {return flagLockEquPos;}
115 
120  void panView(const double deltaAz, const double deltaAlt);
121 
124  void setAutoMoveDuration(float f) {autoMoveDuration = f;}
127  float getAutoMoveDuration(void) const {return autoMoveDuration;}
128 
130  void setFlagAutoZoomOutResetsDirection(bool b) {flagAutoZoomOutResetsDirection = b;}
132  bool getFlagAutoZoomOutResetsDirection(void) {return flagAutoZoomOutResetsDirection;}
133 
135  bool getFlagEnableZoomKeys() const {return flagEnableZoomKeys;}
137  void setFlagEnableZoomKeys(bool b) {flagEnableZoomKeys=b;}
138 
140  bool getFlagEnableMoveKeys() const {return flagEnableMoveKeys;}
142  void setFlagEnableMoveKeys(bool b) {flagEnableMoveKeys=b;}
143 
145  bool getFlagEnableMoveAtScreenEdge() const {return flagEnableMoveAtScreenEdge;}
147  void setFlagEnableMoveAtScreenEdge(bool b) {flagEnableMoveAtScreenEdge=b;}
148 
150  bool getFlagEnableMouseNavigation() const {return flagEnableMouseNavigation;}
152  void setFlagEnableMouseNavigation(bool b) {flagEnableMouseNavigation=b;}
153 
158  void moveToJ2000(const Vec3d& aim, float moveDuration = 1., int zooming = 0);
159  void moveToObject(const StelObjectP& target, float moveDuration = 1., int zooming = 0);
160 
164  void zoomTo(double aimFov, float moveDuration = 1.);
166  double getCurrentFov() const {return currentFov;}
167 
169  double getInitFov() const {return initFov;}
171  void setInitFov(double fov) {initFov=fov;}
172 
174  const Vec3d& getInitViewingDirection() {return initViewPos;}
178 
180  Vec3d getViewDirectionJ2000() const {return viewDirectionJ2000;}
181  void setViewDirectionJ2000(const Vec3d& v);
182 
184  void setMaxFov(double max);
186  double getMaxFov(void) const {return maxFov;}
187 
189  void autoZoomIn(float moveDuration = 1.f, bool allowManualZoom = 1);
191  void autoZoomOut(float moveDuration = 1.f, bool full = 0);
192 
194  double getAimFov(void) const;
195 
197  void turnRight(bool);
198  void turnLeft(bool);
199  void turnUp(bool);
200  void turnDown(bool);
201  void moveSlow(bool b) {flagMoveSlow=b;}
202  void zoomIn(bool);
203  void zoomOut(bool);
204 
206  void setMountMode(MountMode m);
208  MountMode getMountMode(void) const {return mountMode;}
209  bool getEquatorialMount(void) const {return mountMode == MountEquinoxEquatorial;}
210 
211  void setDragTimeMode(bool b) {dragTimeMode=b;}
212  bool getDragTimeMode() const {return dragTimeMode;}
213 
214 private slots:
216  void selectedObjectChange(StelModule::StelModuleSelectAction action);
217 
219  double getInitConstellationIntensity() const {return initConstellationIntensity;}
221  void setInitConstellationIntensity(double v) {initConstellationIntensity=v;}
222 
223 private:
224  Vec3d j2000ToMountFrame(const Vec3d& v) const;
225  Vec3d mountFrameToJ2000(const Vec3d& v) const;
226 
227  double currentFov; // The current FOV in degrees
228  double initFov; // The FOV at startup
229  double minFov; // Minimum FOV in degrees
230  double maxFov; // Maximum FOV in degrees
231  double initConstellationIntensity; // The initial constellation art intensity (level at startup)
232 
233  void setFov(double f)
234  {
235  currentFov = f;
236  if (f>maxFov)
237  currentFov = maxFov;
238  if (f<minFov)
239  currentFov = minFov;
240 
241  changeConstellationArtIntensity();
242  }
243  void changeFov(double deltaFov);
244  void changeConstellationArtIntensity();
245 
246  void updateVisionVector(double deltaTime);
247  void updateAutoZoom(double deltaTime); // Update autoZoom if activated
248 
250  void dragView(int x1, int y1, int x2, int y2);
251 
252  StelCore* core; // The core on which the movement are applied
253  class StelObjectMgr* objectMgr;
254  bool flagLockEquPos; // Define if the equatorial position is locked
255  bool flagTracking; // Define if the selected object is followed
256 
257  // Flags for mouse movements
258  bool isMouseMovingHoriz;
259  bool isMouseMovingVert;
260 
261  bool flagEnableMoveAtScreenEdge; // allow mouse at edge of screen to move view
262  bool flagEnableMouseNavigation;
263  float mouseZoomSpeed;
264 
265  bool flagEnableZoomKeys;
266  bool flagEnableMoveKeys;
267  float keyMoveSpeed; // Speed of keys movement
268  float keyZoomSpeed; // Speed of keys zoom
269  bool flagMoveSlow;
270 
271  // Speed factor for real life time movements, used for fast forward when playing scripts.
272  float movementsSpeedFactor;
273 
276  struct AutoMove
277  {
278  Vec3d start;
279  Vec3d aim;
280  float speed;
281  float coef;
282  // If not null, move to the object.
283  StelObjectP targetObject;
284  };
285 
286  AutoMove move; // Current auto movement
287  bool flagAutoMove; // Define if automove is on or off
288  int zoomingMode; // 0 : undefined, 1 zooming, -1 unzooming
289 
290  double deltaFov,deltaAlt,deltaAz; // View movement
291 
292  bool flagManualZoom; // Define whether auto zoom can go further
293  float autoMoveDuration; // Duration of movement for the auto move to a selected object in seconds
294 
295  // Mouse control options
296  bool isDragging, hasDragged;
297  int previousX, previousY;
298 
299  // Contains the last N real time / JD times pairs associated with the last N mouse move events
300  struct DragHistoryEntry
301  {
302  double runTime;
303  double jd;
304  int x;
305  int y;
306  };
307 
308  QList<DragHistoryEntry> timeDragHistory;
309  void addTimeDragPoint(int x, int y);
310  float beforeTimeDragTimeRate;
311 
312  // Time mouse control
313  bool dragTimeMode;
314 
317  // Components:
318  // startFov: field of view at start
319  // aimFov: intended field of view at end of zoom move
320  // speed: rate of change. UNITS?
321  // coef: set to 0 at begin of zoom, will increase to 1 during autozoom motion.
322  struct AutoZoom
323  {
324  double startFov;
325  double aimFov;
326  float speed;
327  float coef;
328  };
329 
330  // Automove
331  AutoZoom zoomMove; // Current auto movement
332  bool flagAutoZoom; // Define if autozoom is on or off
333  bool flagAutoZoomOutResetsDirection;
334 
335  // defines if view corrects for horizon, or uses equatorial coordinates
336  MountMode mountMode;
337 
338  Vec3d initViewPos; // Default viewing direction
339 
340  // Viewing direction in equatorial J2000 coordinates
341  Vec3d viewDirectionJ2000;
342  // Viewing direction in the mount reference frame.
343  Vec3d viewDirectionMountFrame;
344 
345  Vec3d upVectorMountFrame;
346 
347  float dragTriggerDistance;
348 };
349 
350 #endif // _STELMOVEMENTMGR_HPP_
351 
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.
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.
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 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 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 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 (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
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.
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.
void moveToJ2000(const Vec3d &aim, float moveDuration=1., int zooming=0)
Move the view to a specified J2000 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.