3
* Copyright (C) 2007 Fabien Chereau
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
#ifndef _MOVEMENTMGR_HPP_
21
#define _MOVEMENTMGR_HPP_
23
#include "StelModule.hpp"
24
#include "StelProjector.hpp"
26
//! @class MovementMgr
27
//! Manages the movement and zoomer operations.
28
class MovementMgr : public StelModule
33
MovementMgr(StelCore* core);
34
virtual ~MovementMgr();
36
///////////////////////////////////////////////////////////////////////////
37
// Methods defined in the StelModule class
38
//! Initializes the object based on the application settings
40
//! - Enabling/disabling the movement keys
41
//! - Enabling/disabling the zoom keys
42
//! - Enabling/disabling the mouse zoom
43
//! - Enabling/disabling the mouse movement
44
//! - Sets the zoom and movement speeds
45
//! - Sets the auto-zoom duration and mode.
48
//! Update time-dependent things (does nothing).
49
virtual void update(double deltaTime) {;}
50
//! Implement required draw function. Does nothing.
51
virtual void draw(StelCore* core) {;}
52
//! Handle keyboard events.
53
virtual void handleKeys(QKeyEvent* event);
54
//! Handle mouse movement events.
55
virtual bool handleMouseMoves(int x, int y, Qt::MouseButtons b);
56
//! Handle mouse wheel events.
57
virtual void handleMouseWheel(class QWheelEvent* event);
58
//! Handle mouse click events.
59
virtual void handleMouseClicks(class QMouseEvent* event);
60
//! Called then the selected object changes.
61
virtual void selectedObjectChangeCallBack(StelModuleSelectAction action=StelModule::ReplaceSelection);
63
///////////////////////////////////////////////////////////////////////////
64
// Methods specific to MovementMgr
66
//! Increment/decrement smoothly the vision field and position.
67
void updateMotion(double deltaTime);
69
// These are hopefully temporary.
70
bool getHasDragged() const {return hasDragged;}
72
//! Get the zoom speed
73
// TODO: what are the units?
74
double getZoomSpeed() {return keyZoomSpeed;}
77
//! Set object tracking on/off and go to selected object
78
void setFlagTracking(bool b=true);
79
//! Get current object tracking status.
80
bool getFlagTracking(void) const {return flagTracking;}
82
//! Set whether sky position is to be locked.
83
void setFlagLockEquPos(bool b) {flagLockEquPos=b;}
84
//! Get whether sky position is locked.
85
bool getFlagLockEquPos(void) const {return flagLockEquPos;}
87
//! Move view in alt/az (or equatorial if in that mode) coordinates.
88
//! Changes to viewing direction are instantaneous.
89
//! @param deltaAz change in azimuth angle in radians
90
//! @param deltaAlt change in altitude angle in radians
91
void panView(double deltaAz, double deltaAlt);
93
//! Set automove duration in seconds
94
//! @param f the number of seconds it takes for an auto-move operation to complete.
95
void setAutoMoveDuration(float f) {autoMoveDuration = f;}
96
//! Get automove duration in seconds
97
//! @return the number of seconds it takes for an auto-move operation to complete.
98
float getAutoMoveDuration(void) const {return autoMoveDuration;}
100
//! Set whether auto zoom out will reset the viewing direction to the inital value
101
void setFlagAutoZoomOutResetsDirection(bool b) {flagAutoZoomOutResetsDirection = b;}
102
//! Get whether auto zoom out will reset the viewing direction to the inital value
103
bool getFlagAutoZoomOutResetsDirection(void) {return flagAutoZoomOutResetsDirection;}
105
//! Get whether keys can control zoom
106
bool getFlagEnableZoomKeys() const {return flagEnableZoomKeys;}
107
//! Set whether keys can control zoom
108
void setFlagEnableZoomKeys(bool b) {flagEnableZoomKeys=b;}
110
//! Get whether keys can control move
111
bool getFlagEnableMoveKeys() const {return flagEnableMoveKeys;}
112
//! Set whether keys can control movement
113
void setFlagEnableMoveKeys(bool b) {flagEnableMoveKeys=b;}
115
//! Get whether being at the edge of the screen activates movement
116
bool getFlagEnableMoveAtScreenEdge() const {return flagEnableMoveAtScreenEdge;}
117
//! Set whether being at the edge of the screen activates movement
118
void setFlagEnableMoveAtScreenEdge(bool b) {flagEnableMoveAtScreenEdge=b;}
120
//! Get whether mouse can control movement
121
bool getFlagEnableMouseNavigation() const {return flagEnableMouseNavigation;}
122
//! Set whether mouse can control movement
123
void setFlagEnableMouseNavigation(bool b) {flagEnableMouseNavigation=b;}
125
//! Move the view to a specified position.
126
//! Uses equatorial or local coordinate depending on _localPos value.
127
//! @param aim The position to move to expressed as a vector.
128
//! @param moveDuration The time it takes for the move to complete.
129
//! @param localPos If false, use equatorial position, else use local.
130
//! @param zooming ???
131
void moveTo(const Vec3d& aim, float moveDuration = 1., bool localPos = false, int zooming = 0);
133
//! Change the zoom level.
134
//! @param aimFov The desired field of view in degrees.
135
//! @param moveDuration The time that the operation should take to complete.
136
void zoomTo(double aimFov, float moveDuration = 1.);
137
//! Get the current Field Of View in degrees
138
double getCurrentFov() const {return currentFov;}
140
//! Return the initial default FOV in degree.
141
double getInitFov() const {return initFov;}
142
//! Set the initial Field Of View in degree.
143
void setInitFov(double fov) {initFov=fov;}
145
//! Set the maximum field of View in degrees.
146
void setMaxFov(double max);
147
//! Get the maximum field of View in degrees.
148
double getMaxFov(void) const {return maxFov;}
150
//! Go and zoom to the selected object. A later call to autoZoomOut will come back to the previous zoom level.
151
void autoZoomIn(float moveDuration = 1.f, bool allowManualZoom = 1);
152
//! Unzoom to the previous position.
153
void autoZoomOut(float moveDuration = 1.f, bool full = 0);
155
//! If currently zooming, return the target FOV, otherwise return current FOV in degree.
156
double getAimFov(void) const;
158
//! Viewing direction function : true move, false stop.
159
void turnRight(bool);
167
double currentFov; // The current FOV in degree
168
double initFov; // The FOV at startup
169
double minFov; // Minimum FOV in degree
170
double maxFov; // Maximum FOV in degree
172
void setFov(double f)
180
void changeFov(double deltaFov);
182
void updateVisionVector(double deltaTime);
183
void updateAutoZoom(double deltaTime); // Update autoZoom if activated
185
//! Make the first screen position correspond to the second (useful for mouse dragging)
186
void dragView(int x1, int y1, int x2, int y2);
188
StelCore* core; // The core on which the movement are applied
190
bool flagLockEquPos; // Define if the equatorial position is locked
192
bool flagTracking; // Define if the selected object is followed
194
// Flags for mouse movements
195
bool isMouseMovingHoriz;
196
bool isMouseMovingVert;
198
bool flagEnableMoveAtScreenEdge; // allow mouse at edge of screen to move view
199
bool flagEnableMouseNavigation;
200
float mouseZoomSpeed;
202
bool flagEnableZoomKeys;
203
bool flagEnableMoveKeys;
204
float keyMoveSpeed; // Speed of keys movement
205
float keyZoomSpeed; // Speed of keys zoom
208
// Struct used to store data for auto mov
215
bool localPos; // Define if the position are in equatorial or altazimuthal
218
autoMove move; // Current auto movement
219
int flagAutoMove; // Define if automove is on or off
220
int zoomingMode; // 0 : undefined, 1 zooming, -1 unzooming
222
double deltaFov,deltaAlt,deltaAz; // View movement
224
bool flagManualZoom; // Define whether auto zoom can go further
225
float autoMoveDuration; // Duration of movement for the auto move to a selected objectin seconds
227
// Mouse control options
228
bool isDragging, hasDragged;
229
int previousX, previousY;
231
// Struct used to store data for auto zoom
241
autoZoom zoomMove; // Current auto movement
242
bool flagAutoZoom; // Define if autozoom is on or off
243
bool flagAutoZoomOutResetsDirection;
246
#endif // _MOVEMENTMGR_HPP_