Stellarium 0.13.0
StelMovementMgr.hpp
1 /*
2  * Stellarium
3  * Copyright (C) 2007 Fabien Chereau
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18  */
19 
20 #ifndef _STELMOVEMENTMGR_HPP_
21 #define _STELMOVEMENTMGR_HPP_
22 
23 #include "StelModule.hpp"
24 #include "StelProjector.hpp"
25 #include "StelObjectType.hpp"
26 
30 {
31  Q_OBJECT
32  Q_PROPERTY(bool equatorialMount
33  READ getEquatorialMount
34  WRITE setEquatorialMount)
35  Q_PROPERTY(bool tracking
36  READ getFlagTracking
37  WRITE setFlagTracking)
38 public:
39 
41  enum MountMode { MountAltAzimuthal, MountEquinoxEquatorial, MountGalactic};
42 
44  virtual ~StelMovementMgr();
45 
47  // Methods defined in the StelModule class
56  virtual void init();
57 
59  virtual void update(double) {;}
61  virtual void draw(StelCore*) {;}
63  virtual void handleKeys(QKeyEvent* event);
65  virtual bool handleMouseMoves(int x, int y, Qt::MouseButtons b);
67  virtual void handleMouseWheel(class QWheelEvent* event);
69  virtual void handleMouseClicks(class QMouseEvent* event);
71  virtual bool handlePinch(qreal scale, bool started);
72 
74  // Methods specific to StelMovementMgr
75 
77  void updateMotion(double deltaTime);
78 
79  // These are hopefully temporary.
80  bool getHasDragged() const {return hasDragged;}
81 
83  // TODO: what are the units?
84  double getZoomSpeed() {return keyZoomSpeed;}
85 
88  void setViewUpVectorJ2000(const Vec3d& up);
89 
90  void setMovementSpeedFactor(float s) {movementsSpeedFactor=s;}
91  float getMovementSpeedFactor() const {return movementsSpeedFactor;}
92 
93  void setDragTriggerDistance(float d) {dragTriggerDistance=d;}
94 
95 public slots:
97  void toggleMountMode() {if (getMountMode()==MountAltAzimuthal) setMountMode(MountEquinoxEquatorial); else setMountMode(MountAltAzimuthal);}
99  void setEquatorialMount(bool b) {setMountMode(b ? MountEquinoxEquatorial : MountAltAzimuthal);}
100 
102  void setFlagTracking(bool b=true);
104  bool getFlagTracking(void) const {return flagTracking;}
105 
107  void setFlagLockEquPos(bool b);
109  bool getFlagLockEquPos(void) const {return flagLockEquPos;}
110 
115  void panView(double deltaAz, double deltaAlt);
116 
119  void setAutoMoveDuration(float f) {autoMoveDuration = f;}
122  float getAutoMoveDuration(void) const {return autoMoveDuration;}
123 
125  void setFlagAutoZoomOutResetsDirection(bool b) {flagAutoZoomOutResetsDirection = b;}
127  bool getFlagAutoZoomOutResetsDirection(void) {return flagAutoZoomOutResetsDirection;}
128 
130  bool getFlagEnableZoomKeys() const {return flagEnableZoomKeys;}
132  void setFlagEnableZoomKeys(bool b) {flagEnableZoomKeys=b;}
133 
135  bool getFlagEnableMoveKeys() const {return flagEnableMoveKeys;}
137  void setFlagEnableMoveKeys(bool b) {flagEnableMoveKeys=b;}
138 
140  bool getFlagEnableMoveAtScreenEdge() const {return flagEnableMoveAtScreenEdge;}
142  void setFlagEnableMoveAtScreenEdge(bool b) {flagEnableMoveAtScreenEdge=b;}
143 
145  bool getFlagEnableMouseNavigation() const {return flagEnableMouseNavigation;}
147  void setFlagEnableMouseNavigation(bool b) {flagEnableMouseNavigation=b;}
148 
153  void moveToJ2000(const Vec3d& aim, float moveDuration = 1., int zooming = 0);
154  void moveToObject(const StelObjectP& target, float moveDuration = 1., int zooming = 0);
155 
159  void zoomTo(double aimFov, float moveDuration = 1.);
161  double getCurrentFov() const {return currentFov;}
162 
164  double getInitFov() const {return initFov;}
166  void setInitFov(double fov) {initFov=fov;}
167 
169  const Vec3d& getInitViewingDirection() {return initViewPos;}
173 
175  Vec3d getViewDirectionJ2000() const {return viewDirectionJ2000;}
176  void setViewDirectionJ2000(const Vec3d& v);
177 
179  void setMaxFov(double max);
181  double getMaxFov(void) const {return maxFov;}
182 
184  void autoZoomIn(float moveDuration = 1.f, bool allowManualZoom = 1);
186  void autoZoomOut(float moveDuration = 1.f, bool full = 0);
187 
189  double getAimFov(void) const;
190 
192  void turnRight(bool);
193  void turnLeft(bool);
194  void turnUp(bool);
195  void turnDown(bool);
196  void moveSlow(bool b) {flagMoveSlow=b;}
197  void zoomIn(bool);
198  void zoomOut(bool);
199 
201  void setMountMode(MountMode m);
203  MountMode getMountMode(void) const {return mountMode;}
204  bool getEquatorialMount(void) const {return mountMode == MountEquinoxEquatorial;}
205 
206  void setDragTimeMode(bool b) {dragTimeMode=b;}
207  bool getDragTimeMode() const {return dragTimeMode;}
208 
209 private slots:
211  void selectedObjectChange(StelModule::StelModuleSelectAction action);
212 
214  double getInitConstellationIntensity() const {return initConstellationIntensity;}
216  void setInitConstellationIntensity(double v) {initConstellationIntensity=v;}
217 
218 private:
219  Vec3d j2000ToMountFrame(const Vec3d& v) const;
220  Vec3d mountFrameToJ2000(const Vec3d& v) const;
221 
222  double currentFov; // The current FOV in degree
223  double initFov; // The FOV at startup
224  double minFov; // Minimum FOV in degree
225  double maxFov; // Maximum FOV in degree
226  double initConstellationIntensity; // The initial constellation art intensity (level at startup)
227 
228  void setFov(double f)
229  {
230  currentFov = f;
231  if (f>maxFov)
232  currentFov = maxFov;
233  if (f<minFov)
234  currentFov = minFov;
235 
236  changeConstellationArtIntensity();
237  }
238  void changeFov(double deltaFov);
239  void changeConstellationArtIntensity();
240 
241  void updateVisionVector(double deltaTime);
242  void updateAutoZoom(double deltaTime); // Update autoZoom if activated
243 
245  void dragView(int x1, int y1, int x2, int y2);
246 
247  StelCore* core; // The core on which the movement are applied
248  class StelObjectMgr* objectMgr;
249  bool flagLockEquPos; // Define if the equatorial position is locked
250  bool flagTracking; // Define if the selected object is followed
251 
252  // Flags for mouse movements
253  bool isMouseMovingHoriz;
254  bool isMouseMovingVert;
255 
256  bool flagEnableMoveAtScreenEdge; // allow mouse at edge of screen to move view
257  bool flagEnableMouseNavigation;
258  float mouseZoomSpeed;
259 
260  bool flagEnableZoomKeys;
261  bool flagEnableMoveKeys;
262  float keyMoveSpeed; // Speed of keys movement
263  float keyZoomSpeed; // Speed of keys zoom
264  bool flagMoveSlow;
265 
266  // Speed factor for real life time movements, used for fast forward when playing scripts.
267  float movementsSpeedFactor;
268 
271  struct AutoMove
272  {
273  Vec3d start;
274  Vec3d aim;
275  float speed;
276  float coef;
277  // If not null, move to the object.
278  StelObjectP targetObject;
279  };
280 
281  AutoMove move; // Current auto movement
282  bool flagAutoMove; // Define if automove is on or off
283  int zoomingMode; // 0 : undefined, 1 zooming, -1 unzooming
284 
285  double deltaFov,deltaAlt,deltaAz; // View movement
286 
287  bool flagManualZoom; // Define whether auto zoom can go further
288  float autoMoveDuration; // Duration of movement for the auto move to a selected objectin seconds
289 
290  // Mouse control options
291  bool isDragging, hasDragged;
292  int previousX, previousY;
293 
294  // Contains the last N real time / JD times pairs associated with the last N mouse move events
295  struct DragHistoryEntry
296  {
297  double runTime;
298  double jd;
299  int x;
300  int y;
301  };
302 
303  QList<DragHistoryEntry> timeDragHistory;
304  void addTimeDragPoint(int x, int y);
305  float beforeTimeDragTimeRate;
306 
307  // Time mouse control
308  bool dragTimeMode;
309 
312  struct AutoZoom
313  {
314  double start;
315  double aim;
316  float speed;
317  float coef;
318  };
319 
320  // Automove
321  AutoZoom zoomMove; // Current auto movement
322  bool flagAutoZoom; // Define if autozoom is on or off
323  bool flagAutoZoomOutResetsDirection;
324 
325  // defines if view corrects for horizon, or uses equatorial coordinates
326  MountMode mountMode;
327 
328  Vec3d initViewPos; // Default viewing direction
329 
330  // Viewing direction in equatorial J2000 coordinates
331  Vec3d viewDirectionJ2000;
332  // Viewing direction in the mount reference frame.
333  Vec3d viewDirectionMountFrame;
334 
335  Vec3d upVectorMountFrame;
336 
337  float dragTriggerDistance;
338 };
339 
340 #endif // _STELMOVEMENTMGR_HPP_
341 
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 move.
void setFlagLockEquPos(bool b)
Set whether sky position is to be locked.
void panView(double deltaAz, double deltaAlt)
Move view in alt/az (or equatorial if in that mode) coordinates.
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:46
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.
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:111
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:51
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.