Stellarium 0.11.4
Home · All Namespaces · All Classes · Functions · Coding Style · Scripting · Plugins · File Structure

core/StelMovementMgr.hpp

00001 /*
00002  * Stellarium
00003  * Copyright (C) 2007 Fabien Chereau
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA  02110-1335, USA.
00018  */
00019 
00020 #ifndef _STELMOVEMENTMGR_HPP_
00021 #define _STELMOVEMENTMGR_HPP_
00022 
00023 #include "StelModule.hpp"
00024 #include "StelProjector.hpp"
00025 #include "StelObjectType.hpp"
00026 
00029 class StelMovementMgr : public StelModule
00030 {
00031     Q_OBJECT
00032 
00033 public:
00034 
00036     enum MountMode { MountAltAzimuthal, MountEquinoxEquatorial, MountGalactic};
00037 
00038     StelMovementMgr(StelCore* core);
00039     virtual ~StelMovementMgr();
00040 
00042     // Methods defined in the StelModule class
00051     virtual void init();
00052 
00054     virtual void update(double) {;}
00056     virtual void draw(StelCore*) {;}
00058     virtual void handleKeys(QKeyEvent* event);
00060     virtual bool handleMouseMoves(int x, int y, Qt::MouseButtons b);
00062     virtual void handleMouseWheel(class QWheelEvent* event);
00064     virtual void handleMouseClicks(class QMouseEvent* event);
00065 
00067     // Methods specific to StelMovementMgr
00068 
00070     void updateMotion(double deltaTime);
00071 
00072     // These are hopefully temporary.
00073     bool getHasDragged() const {return hasDragged;}
00074 
00076     // TODO: what are the units?
00077     double getZoomSpeed() {return keyZoomSpeed;}
00078 
00080     Vec3d getViewUpVectorJ2000() const;
00081     void setViewUpVectorJ2000(const Vec3d& up);
00082 
00083     void setMovementSpeedFactor(float s) {movementsSpeedFactor=s;}
00084     float getMovementSpeedFactor() const {return movementsSpeedFactor;}
00085 
00086     void setDragTriggerDistance(float d) {dragTriggerDistance=d;}
00087 
00088 public slots:
00090     void toggleMountMode() {if (getMountMode()==MountAltAzimuthal) setMountMode(MountEquinoxEquatorial); else setMountMode(MountAltAzimuthal);}
00092     void setEquatorialMount(bool b) {setMountMode(b ? MountEquinoxEquatorial : MountAltAzimuthal);}
00093 
00095     void setFlagTracking(bool b=true);
00097     bool getFlagTracking(void) const {return flagTracking;}
00098 
00100     void setFlagLockEquPos(bool b);
00102     bool getFlagLockEquPos(void) const {return flagLockEquPos;}
00103 
00108     void panView(double deltaAz, double deltaAlt);
00109 
00112     void setAutoMoveDuration(float f) {autoMoveDuration = f;}
00115     float getAutoMoveDuration(void) const {return autoMoveDuration;}
00116 
00118     void setFlagAutoZoomOutResetsDirection(bool b) {flagAutoZoomOutResetsDirection = b;}
00120     bool getFlagAutoZoomOutResetsDirection(void) {return flagAutoZoomOutResetsDirection;}
00121 
00123     bool getFlagEnableZoomKeys() const {return flagEnableZoomKeys;}
00125     void setFlagEnableZoomKeys(bool b) {flagEnableZoomKeys=b;}
00126 
00128     bool getFlagEnableMoveKeys() const {return flagEnableMoveKeys;}
00130     void setFlagEnableMoveKeys(bool b) {flagEnableMoveKeys=b;}
00131 
00133     bool getFlagEnableMoveAtScreenEdge() const {return flagEnableMoveAtScreenEdge;}
00135     void setFlagEnableMoveAtScreenEdge(bool b) {flagEnableMoveAtScreenEdge=b;}
00136 
00138     bool getFlagEnableMouseNavigation() const {return flagEnableMouseNavigation;}
00140     void setFlagEnableMouseNavigation(bool b) {flagEnableMouseNavigation=b;}
00141 
00146     void moveToJ2000(const Vec3d& aim, float moveDuration = 1., int zooming = 0);
00147     void moveToObject(const StelObjectP& target, float moveDuration = 1., int zooming = 0);
00148 
00152     void zoomTo(double aimFov, float moveDuration = 1.);
00154     double getCurrentFov() const {return currentFov;}
00155 
00157     double getInitFov() const {return initFov;}
00159     void setInitFov(double fov) {initFov=fov;}
00160 
00162     const Vec3d& getInitViewingDirection() {return initViewPos;}
00165     void setInitViewDirectionToCurrent();
00166 
00168     Vec3d getViewDirectionJ2000() const {return viewDirectionJ2000;}
00169     void setViewDirectionJ2000(const Vec3d& v);
00170 
00172     void setMaxFov(double max);
00174     double getMaxFov(void) const {return maxFov;}
00175 
00177     void autoZoomIn(float moveDuration = 1.f, bool allowManualZoom = 1);
00179     void autoZoomOut(float moveDuration = 1.f, bool full = 0);
00180 
00182     double getAimFov(void) const;
00183 
00185     void turnRight(bool);
00186     void turnLeft(bool);
00187     void turnUp(bool);
00188     void turnDown(bool);
00189     void moveSlow(bool b) {flagMoveSlow=b;}
00190     void zoomIn(bool);
00191     void zoomOut(bool);
00192 
00194     void setMountMode(MountMode m);
00196     MountMode getMountMode(void) const {return mountMode;}
00197 
00198     void setDragTimeMode(bool b) {dragTimeMode=b;}
00199     bool getDragTimeMode() const {return dragTimeMode;}
00200 
00201 private slots:
00203     void selectedObjectChange(StelModule::StelModuleSelectAction action);
00204     
00205 private:
00206     Vec3d j2000ToMountFrame(const Vec3d& v) const;
00207     Vec3d mountFrameToJ2000(const Vec3d& v) const;
00208 
00209     double currentFov; // The current FOV in degree
00210     double initFov;    // The FOV at startup
00211     double minFov;     // Minimum FOV in degree
00212     double maxFov;     // Maximum FOV in degree
00213 
00214     void setFov(double f)
00215     {
00216         currentFov = f;
00217         if (f>maxFov)
00218             currentFov = maxFov;
00219         if (f<minFov)
00220             currentFov = minFov;
00221     }
00222     void changeFov(double deltaFov);
00223 
00224     void updateVisionVector(double deltaTime);
00225     void updateAutoZoom(double deltaTime); // Update autoZoom if activated
00226 
00228     void dragView(int x1, int y1, int x2, int y2);
00229 
00230     StelCore* core;          // The core on which the movement are applied
00231     class StelObjectMgr* objectMgr;
00232     bool flagLockEquPos;     // Define if the equatorial position is locked
00233     bool flagTracking;       // Define if the selected object is followed
00234 
00235     // Flags for mouse movements
00236     bool isMouseMovingHoriz;
00237     bool isMouseMovingVert;
00238 
00239     bool flagEnableMoveAtScreenEdge; // allow mouse at edge of screen to move view
00240     bool flagEnableMouseNavigation;
00241     float mouseZoomSpeed;
00242 
00243     bool flagEnableZoomKeys;
00244     bool flagEnableMoveKeys;
00245     float keyMoveSpeed;              // Speed of keys movement
00246     float keyZoomSpeed;              // Speed of keys zoom
00247     bool flagMoveSlow;
00248 
00249     // Speed factor for real life time movements, used for fast forward when playing scripts.
00250     float movementsSpeedFactor;
00251 
00254     struct AutoMove
00255     {
00256         Vec3d start;
00257         Vec3d aim;
00258         float speed;
00259         float coef;
00260         // If not null, move to the object.
00261         StelObjectP targetObject;
00262     };
00263 
00264     AutoMove move;          // Current auto movement
00265     bool flagAutoMove;       // Define if automove is on or off
00266     int zoomingMode;        // 0 : undefined, 1 zooming, -1 unzooming
00267 
00268     double deltaFov,deltaAlt,deltaAz; // View movement
00269 
00270     bool flagManualZoom;     // Define whether auto zoom can go further
00271     float autoMoveDuration; // Duration of movement for the auto move to a selected objectin seconds
00272 
00273     // Mouse control options
00274     bool isDragging, hasDragged;
00275     int previousX, previousY;
00276 
00277     // Contains the last N real time / JD times pairs associated with the last N mouse move events
00278     struct DragHistoryEntry
00279     {
00280         double runTime;
00281         double jd;
00282         int x;
00283         int y;
00284     };
00285 
00286     QList<DragHistoryEntry> timeDragHistory;
00287     void addTimeDragPoint(int x, int y);
00288     float beforeTimeDragTimeRate;
00289 
00290     // Time mouse control
00291     bool dragTimeMode;
00292 
00295     struct AutoZoom
00296     {
00297         double start;
00298         double aim;
00299         float speed;
00300         float coef;
00301     };
00302 
00303     // Automove
00304     AutoZoom zoomMove; // Current auto movement
00305     bool flagAutoZoom; // Define if autozoom is on or off
00306     bool flagAutoZoomOutResetsDirection;
00307 
00308     // defines if view corrects for horizon, or uses equatorial coordinates
00309     MountMode mountMode;
00310 
00311     Vec3d initViewPos;        // Default viewing direction
00312 
00313     // Viewing direction in equatorial J2000 coordinates
00314     Vec3d viewDirectionJ2000;
00315     // Viewing direction in the mount reference frame.
00316     Vec3d viewDirectionMountFrame;
00317 
00318     Vec3d upVectorMountFrame;
00319 
00320     float dragTriggerDistance;
00321 };
00322 
00323 #endif // _STELMOVEMENTMGR_HPP_
00324 
Generated on Sat Aug 25 22:13:30 2012 for Stellarium by  doxygen 1.6.3