Stellarium 0.13.3
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);
70  // GZ: allow some keypress interaction by plugins.
71  virtual double getCallOrder(StelModuleActionName actionName) const;
73  virtual bool handlePinch(qreal scale, bool started);
74 
76  // Methods specific to StelMovementMgr
77 
79  void updateMotion(double deltaTime);
80 
81  // These are hopefully temporary.
82  bool getHasDragged() const {return hasDragged;}
83 
85  // TODO: what are the units?
86  double getZoomSpeed() {return keyZoomSpeed;}
87 
90  void setViewUpVectorJ2000(const Vec3d& up);
91 
92  void setMovementSpeedFactor(float s) {movementsSpeedFactor=s;}
93  float getMovementSpeedFactor() const {return movementsSpeedFactor;}
94 
95  void setDragTriggerDistance(float d) {dragTriggerDistance=d;}
96 
97 public slots:
99  void toggleMountMode() {if (getMountMode()==MountAltAzimuthal) setMountMode(MountEquinoxEquatorial); else setMountMode(MountAltAzimuthal);}
101  void setEquatorialMount(bool b) {setMountMode(b ? MountEquinoxEquatorial : MountAltAzimuthal);}
102 
104  void setFlagTracking(bool b=true);
106  bool getFlagTracking(void) const {return flagTracking;}
107 
109  void setFlagLockEquPos(bool b);
111  bool getFlagLockEquPos(void) const {return flagLockEquPos;}
112 
117  void panView(double deltaAz, double deltaAlt);
118 
121  void setAutoMoveDuration(float f) {autoMoveDuration = f;}
124  float getAutoMoveDuration(void) const {return autoMoveDuration;}
125 
127  void setFlagAutoZoomOutResetsDirection(bool b) {flagAutoZoomOutResetsDirection = b;}
129  bool getFlagAutoZoomOutResetsDirection(void) {return flagAutoZoomOutResetsDirection;}
130 
132  bool getFlagEnableZoomKeys() const {return flagEnableZoomKeys;}
134  void setFlagEnableZoomKeys(bool b) {flagEnableZoomKeys=b;}
135 
137  bool getFlagEnableMoveKeys() const {return flagEnableMoveKeys;}
139  void setFlagEnableMoveKeys(bool b) {flagEnableMoveKeys=b;}
140 
142  bool getFlagEnableMoveAtScreenEdge() const {return flagEnableMoveAtScreenEdge;}
144  void setFlagEnableMoveAtScreenEdge(bool b) {flagEnableMoveAtScreenEdge=b;}
145 
147  bool getFlagEnableMouseNavigation() const {return flagEnableMouseNavigation;}
149  void setFlagEnableMouseNavigation(bool b) {flagEnableMouseNavigation=b;}
150 
155  void moveToJ2000(const Vec3d& aim, float moveDuration = 1., int zooming = 0);
156  void moveToObject(const StelObjectP& target, float moveDuration = 1., int zooming = 0);
157 
161  void zoomTo(double aimFov, float moveDuration = 1.);
163  double getCurrentFov() const {return currentFov;}
164 
166  double getInitFov() const {return initFov;}
168  void setInitFov(double fov) {initFov=fov;}
169 
171  const Vec3d& getInitViewingDirection() {return initViewPos;}
175 
177  Vec3d getViewDirectionJ2000() const {return viewDirectionJ2000;}
178  void setViewDirectionJ2000(const Vec3d& v);
179 
181  void setMaxFov(double max);
183  double getMaxFov(void) const {return maxFov;}
184 
186  void autoZoomIn(float moveDuration = 1.f, bool allowManualZoom = 1);
188  void autoZoomOut(float moveDuration = 1.f, bool full = 0);
189 
191  double getAimFov(void) const;
192 
194  void turnRight(bool);
195  void turnLeft(bool);
196  void turnUp(bool);
197  void turnDown(bool);
198  void moveSlow(bool b) {flagMoveSlow=b;}
199  void zoomIn(bool);
200  void zoomOut(bool);
201 
203  void setMountMode(MountMode m);
205  MountMode getMountMode(void) const {return mountMode;}
206  bool getEquatorialMount(void) const {return mountMode == MountEquinoxEquatorial;}
207 
208  void setDragTimeMode(bool b) {dragTimeMode=b;}
209  bool getDragTimeMode() const {return dragTimeMode;}
210 
211 private slots:
213  void selectedObjectChange(StelModule::StelModuleSelectAction action);
214 
216  double getInitConstellationIntensity() const {return initConstellationIntensity;}
218  void setInitConstellationIntensity(double v) {initConstellationIntensity=v;}
219 
220 private:
221  Vec3d j2000ToMountFrame(const Vec3d& v) const;
222  Vec3d mountFrameToJ2000(const Vec3d& v) const;
223 
224  double currentFov; // The current FOV in degree
225  double initFov; // The FOV at startup
226  double minFov; // Minimum FOV in degree
227  double maxFov; // Maximum FOV in degree
228  double initConstellationIntensity; // The initial constellation art intensity (level at startup)
229 
230  void setFov(double f)
231  {
232  currentFov = f;
233  if (f>maxFov)
234  currentFov = maxFov;
235  if (f<minFov)
236  currentFov = minFov;
237 
238  changeConstellationArtIntensity();
239  }
240  void changeFov(double deltaFov);
241  void changeConstellationArtIntensity();
242 
243  void updateVisionVector(double deltaTime);
244  void updateAutoZoom(double deltaTime); // Update autoZoom if activated
245 
247  void dragView(int x1, int y1, int x2, int y2);
248 
249  StelCore* core; // The core on which the movement are applied
250  class StelObjectMgr* objectMgr;
251  bool flagLockEquPos; // Define if the equatorial position is locked
252  bool flagTracking; // Define if the selected object is followed
253 
254  // Flags for mouse movements
255  bool isMouseMovingHoriz;
256  bool isMouseMovingVert;
257 
258  bool flagEnableMoveAtScreenEdge; // allow mouse at edge of screen to move view
259  bool flagEnableMouseNavigation;
260  float mouseZoomSpeed;
261 
262  bool flagEnableZoomKeys;
263  bool flagEnableMoveKeys;
264  float keyMoveSpeed; // Speed of keys movement
265  float keyZoomSpeed; // Speed of keys zoom
266  bool flagMoveSlow;
267 
268  // Speed factor for real life time movements, used for fast forward when playing scripts.
269  float movementsSpeedFactor;
270 
273  struct AutoMove
274  {
275  Vec3d start;
276  Vec3d aim;
277  float speed;
278  float coef;
279  // If not null, move to the object.
280  StelObjectP targetObject;
281  };
282 
283  AutoMove move; // Current auto movement
284  bool flagAutoMove; // Define if automove is on or off
285  int zoomingMode; // 0 : undefined, 1 zooming, -1 unzooming
286 
287  double deltaFov,deltaAlt,deltaAz; // View movement
288 
289  bool flagManualZoom; // Define whether auto zoom can go further
290  float autoMoveDuration; // Duration of movement for the auto move to a selected objectin seconds
291 
292  // Mouse control options
293  bool isDragging, hasDragged;
294  int previousX, previousY;
295 
296  // Contains the last N real time / JD times pairs associated with the last N mouse move events
297  struct DragHistoryEntry
298  {
299  double runTime;
300  double jd;
301  int x;
302  int y;
303  };
304 
305  QList<DragHistoryEntry> timeDragHistory;
306  void addTimeDragPoint(int x, int y);
307  float beforeTimeDragTimeRate;
308 
309  // Time mouse control
310  bool dragTimeMode;
311 
314  struct AutoZoom
315  {
316  double start;
317  double aim;
318  float speed;
319  float coef;
320  };
321 
322  // Automove
323  AutoZoom zoomMove; // Current auto movement
324  bool flagAutoZoom; // Define if autozoom is on or off
325  bool flagAutoZoomOutResetsDirection;
326 
327  // defines if view corrects for horizon, or uses equatorial coordinates
328  MountMode mountMode;
329 
330  Vec3d initViewPos; // Default viewing direction
331 
332  // Viewing direction in equatorial J2000 coordinates
333  Vec3d viewDirectionJ2000;
334  // Viewing direction in the mount reference frame.
335  Vec3d viewDirectionMountFrame;
336 
337  Vec3d upVectorMountFrame;
338 
339  float dragTriggerDistance;
340 };
341 
342 #endif // _STELMOVEMENTMGR_HPP_
343 
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.
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
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
A templatized 3d vector compatible with openGL.
Definition: VecMath.hpp:33
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.