~xalioth/stellarium/fix-fonts-gltex-fab

« back to all changes in this revision

Viewing changes to src/core/MovementMgr.hpp

  • Committer: matthewg42
  • Date: 2008-11-27 14:36:21 UTC
  • Revision ID: vcs-imports@canonical.com-20081127143621-fbasu1vl30kq2edv
refactor: MovementMgr -> StelMovementMgr

Show diffs side-by-side

added added

removed removed

Lines of Context:
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
 
 */
19
 
 
20
 
#ifndef _MOVEMENTMGR_HPP_
21
 
#define _MOVEMENTMGR_HPP_
22
 
 
23
 
#include "StelModule.hpp"
24
 
#include "StelProjector.hpp"
25
 
 
26
 
//! @class MovementMgr
27
 
//! Manages the movement and zoomer operations.
28
 
class MovementMgr : public StelModule
29
 
{
30
 
        Q_OBJECT
31
 
 
32
 
public:
33
 
        MovementMgr(StelCore* core);
34
 
        virtual ~MovementMgr();
35
 
        
36
 
        ///////////////////////////////////////////////////////////////////////////
37
 
        // Methods defined in the StelModule class
38
 
        //! Initializes the object based on the application settings
39
 
        //! Includes:
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.
46
 
        virtual void init();
47
 
        
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);
62
 
        
63
 
        ///////////////////////////////////////////////////////////////////////////
64
 
        // Methods specific to MovementMgr
65
 
        
66
 
        //! Increment/decrement smoothly the vision field and position.
67
 
        void updateMotion(double deltaTime);
68
 
        
69
 
        // These are hopefully temporary.
70
 
        bool getHasDragged() const {return hasDragged;}
71
 
        
72
 
        //! Get the zoom speed
73
 
        // TODO: what are the units?
74
 
        double getZoomSpeed() {return keyZoomSpeed;}
75
 
        
76
 
public slots:
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;}
81
 
 
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;}
86
 
        
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);
92
 
 
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;}
99
 
 
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;}
104
 
        
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;}
109
 
        
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;}
114
 
        
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;}
119
 
        
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;}
124
 
        
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);
132
 
 
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;}
139
 
        
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;}
144
 
        
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;}
149
 
        
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);
154
 
 
155
 
        //! If currently zooming, return the target FOV, otherwise return current FOV in degree.
156
 
        double getAimFov(void) const;
157
 
 
158
 
        //! Viewing direction function : true move, false stop.
159
 
        void turnRight(bool);
160
 
        void turnLeft(bool);
161
 
        void turnUp(bool);
162
 
        void turnDown(bool);
163
 
        void zoomIn(bool);
164
 
        void zoomOut(bool);
165
 
        
166
 
private:
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
171
 
        
172
 
        void setFov(double f)
173
 
        {
174
 
                currentFov = f;
175
 
                if (f>maxFov)
176
 
                        currentFov = maxFov;
177
 
                if (f<minFov)
178
 
                        currentFov = minFov;
179
 
        }
180
 
        void changeFov(double deltaFov);
181
 
           
182
 
        void updateVisionVector(double deltaTime); 
183
 
        void updateAutoZoom(double deltaTime); // Update autoZoom if activated
184
 
        
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);
187
 
        
188
 
        StelCore* core;          // The core on which the movement are applied
189
 
 
190
 
        bool flagLockEquPos;     // Define if the equatorial position is locked
191
 
 
192
 
        bool flagTracking;       // Define if the selected object is followed
193
 
        
194
 
        // Flags for mouse movements
195
 
        bool isMouseMovingHoriz;
196
 
        bool isMouseMovingVert;
197
 
 
198
 
        bool flagEnableMoveAtScreenEdge; // allow mouse at edge of screen to move view
199
 
        bool flagEnableMouseNavigation;
200
 
        float mouseZoomSpeed;
201
 
        
202
 
        bool flagEnableZoomKeys;
203
 
        bool flagEnableMoveKeys;
204
 
        float keyMoveSpeed;                     // Speed of keys movement
205
 
        float keyZoomSpeed;                     // Speed of keys zoom
206
 
        
207
 
        // Automove
208
 
        // Struct used to store data for auto mov
209
 
        typedef struct
210
 
        {
211
 
                Vec3d start;
212
 
                Vec3d aim;
213
 
                float speed;
214
 
                float coef;
215
 
                bool localPos;  // Define if the position are in equatorial or altazimuthal
216
 
        } autoMove;
217
 
        
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
221
 
 
222
 
        double deltaFov,deltaAlt,deltaAz; // View movement
223
 
 
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
226
 
        
227
 
        // Mouse control options
228
 
        bool isDragging, hasDragged;
229
 
        int previousX, previousY;
230
 
        
231
 
        // Struct used to store data for auto zoom
232
 
        typedef struct
233
 
        {
234
 
                double start;
235
 
                double aim;
236
 
                float speed;
237
 
                float coef;
238
 
        } autoZoom;
239
 
        
240
 
        // Automove
241
 
        autoZoom zoomMove; // Current auto movement
242
 
        bool flagAutoZoom; // Define if autozoom is on or off
243
 
        bool flagAutoZoomOutResetsDirection;
244
 
};
245
 
 
246
 
#endif // _MOVEMENTMGR_HPP_
247