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 "Projector.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
void panView(double deltaAz, double deltaAlt);
90
//! Set automove duration in seconds
91
//! @param f the number of seconds it takes for an auto-move operation to complete.
92
void setAutoMoveDuration(float f) {autoMoveDuration = f;}
93
//! Get automove duration in seconds
94
//! @return the number of seconds it takes for an auto-move operation to complete.
95
float getAutoMoveDuration(void) const {return autoMoveDuration;}
97
//! Set whether auto zoom out will reset the viewing direction to the inital value
98
void setFlagAutoZoomOutResetsDirection(bool b) {flagAutoZoomOutResetsDirection = b;}
99
//! Get whether auto zoom out will reset the viewing direction to the inital value
100
bool getFlagAutoZoomOutResetsDirection(void) {return flagAutoZoomOutResetsDirection;}
102
//! Get whether keys can control zoom
103
bool getFlagEnableZoomKeys() const {return flagEnableZoomKeys;}
104
//! Set whether keys can control zoom
105
void setFlagEnableZoomKeys(bool b) {flagEnableZoomKeys=b;}
107
//! Get whether keys can control move
108
bool getFlagEnableMoveKeys() const {return flagEnableMoveKeys;}
109
//! Set whether keys can control movement
110
void setFlagEnableMoveKeys(bool b) {flagEnableMoveKeys=b;}
112
//! Get whether being at the edge of the screen activates movement
113
bool getFlagEnableMoveAtScreenEdge() const {return flagEnableMoveAtScreenEdge;}
114
//! Set whether being at the edge of the screen activates movement
115
void setFlagEnableMoveAtScreenEdge(bool b) {flagEnableMoveAtScreenEdge=b;}
117
//! Get whether mouse can control movement
118
bool getFlagEnableMouseNavigation() const {return flagEnableMouseNavigation;}
119
//! Set whether mouse can control movement
120
void setFlagEnableMouseNavigation(bool b) {flagEnableMouseNavigation=b;}
122
//! Move the view to a specified position.
123
//! Uses equatorial or local coordinate depending on _localPos value.
124
//! @param aim The position to move to expressed as a vector.
125
//! @param moveDuration The time it takes for the move to complete.
126
//! @param localPos If false, use equatorial position, else use local.
127
//! @param zooming ???
128
void moveTo(const Vec3d& aim, float moveDuration = 1., bool localPos = false, int zooming = 0);
130
//! Change the zoom level.
131
//! @param aimFov The desired field of view in degrees.
132
//! @param moveDuration The time that the operation should take to complete.
133
void zoomTo(double aimFov, float moveDuration = 1.);
135
//! Go and zoom to the selected object. A later call to autoZoomOut will come back to the previous zoom level.
136
void autoZoomIn(float moveDuration = 1.f, bool allowManualZoom = 1);
137
//! Unzoom to the previous position.
138
void autoZoomOut(float moveDuration = 1.f, bool full = 0);
140
//! If currently zooming, return the target FOV, otherwise return current FOV in degree.
141
double getAimFov(void) const;
143
//! Viewing direction function : true move, false stop.
144
void turnRight(bool);
153
void changeFov(double deltaFov);
155
void updateVisionVector(double deltaTime);
156
void updateAutoZoom(double deltaTime); // Update autoZoom if activated
158
//! Make the first screen position correspond to the second (useful for mouse dragging)
159
void dragView(int x1, int y1, int x2, int y2);
161
StelCore* core; // The core on which the movement are applied
163
bool flagLockEquPos; // Define if the equatorial position is locked
165
bool flagTracking; // Define if the selected object is followed
167
// Flags for mouse movements
168
bool isMouseMovingHoriz;
169
bool isMouseMovingVert;
171
bool flagEnableMoveAtScreenEdge; // allow mouse at edge of screen to move view
172
bool flagEnableMouseNavigation;
173
float mouseZoomSpeed;
175
bool flagEnableZoomKeys;
176
bool flagEnableMoveKeys;
177
float keyMoveSpeed; // Speed of keys movement
178
float keyZoomSpeed; // Speed of keys zoom
181
// Struct used to store data for auto mov
188
bool localPos; // Define if the position are in equatorial or altazimutal
191
autoMove move; // Current auto movement
192
int flagAutoMove; // Define if automove is on or off
193
int zoomingMode; // 0 : undefined, 1 zooming, -1 unzooming
195
double deltaFov,deltaAlt,deltaAz; // View movement
197
bool flagManualZoom; // Define whether auto zoom can go further
198
float autoMoveDuration; // Duration of movement for the auto move to a selected objectin seconds
200
// Mouse control options
201
bool isDragging, hasDragged;
202
int previousX, previousY;
204
// Struct used to store data for auto zoom
214
autoZoom zoomMove; // Current auto movement
215
bool flagAutoZoom; // Define if autozoom is on or off
216
bool flagAutoZoomOutResetsDirection;
219
#endif // _MOVEMENTMGR_HPP_