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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 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);
00066     virtual void selectedObjectChangeCallBack(StelModuleSelectAction action=StelModule::ReplaceSelection);
00067 
00069     // Methods specific to StelMovementMgr
00070 
00072     void updateMotion(double deltaTime);
00073 
00074     // These are hopefully temporary.
00075     bool getHasDragged() const {return hasDragged;}
00076 
00078     // TODO: what are the units?
00079     double getZoomSpeed() {return keyZoomSpeed;}
00080 
00082     Vec3d getViewUpVectorJ2000() const;
00083     void setViewUpVectorJ2000(const Vec3d& up);
00084 
00085     void setMovementSpeedFactor(float s) {movementsSpeedFactor=s;}
00086     float getMovementSpeedFactor() const {return movementsSpeedFactor;}
00087 
00088     void setDragTriggerDistance(float d) {dragTriggerDistance=d;}
00089 
00090 public slots:
00092     void toggleMountMode() {if (getMountMode()==MountAltAzimuthal) setMountMode(MountEquinoxEquatorial); else setMountMode(MountAltAzimuthal);}
00094     void setEquatorialMount(bool b) {setMountMode(b ? MountEquinoxEquatorial : MountAltAzimuthal);}
00095 
00097     void setFlagTracking(bool b=true);
00099     bool getFlagTracking(void) const {return flagTracking;}
00100 
00102     void setFlagLockEquPos(bool b);
00104     bool getFlagLockEquPos(void) const {return flagLockEquPos;}
00105 
00110     void panView(double deltaAz, double deltaAlt);
00111 
00114     void setAutoMoveDuration(float f) {autoMoveDuration = f;}
00117     float getAutoMoveDuration(void) const {return autoMoveDuration;}
00118 
00120     void setFlagAutoZoomOutResetsDirection(bool b) {flagAutoZoomOutResetsDirection = b;}
00122     bool getFlagAutoZoomOutResetsDirection(void) {return flagAutoZoomOutResetsDirection;}
00123 
00125     bool getFlagEnableZoomKeys() const {return flagEnableZoomKeys;}
00127     void setFlagEnableZoomKeys(bool b) {flagEnableZoomKeys=b;}
00128 
00130     bool getFlagEnableMoveKeys() const {return flagEnableMoveKeys;}
00132     void setFlagEnableMoveKeys(bool b) {flagEnableMoveKeys=b;}
00133 
00135     bool getFlagEnableMoveAtScreenEdge() const {return flagEnableMoveAtScreenEdge;}
00137     void setFlagEnableMoveAtScreenEdge(bool b) {flagEnableMoveAtScreenEdge=b;}
00138 
00140     bool getFlagEnableMouseNavigation() const {return flagEnableMouseNavigation;}
00142     void setFlagEnableMouseNavigation(bool b) {flagEnableMouseNavigation=b;}
00143 
00148     void moveToJ2000(const Vec3d& aim, float moveDuration = 1., int zooming = 0);
00149     void moveToObject(const StelObjectP& target, float moveDuration = 1., int zooming = 0);
00150 
00154     void zoomTo(double aimFov, float moveDuration = 1.);
00156     double getCurrentFov() const {return currentFov;}
00157 
00159     double getInitFov() const {return initFov;}
00161     void setInitFov(double fov) {initFov=fov;}
00162 
00164     const Vec3d& getInitViewingDirection() {return initViewPos;}
00167     void setInitViewDirectionToCurrent();
00168 
00170     Vec3d getViewDirectionJ2000() const {return viewDirectionJ2000;}
00171     void setViewDirectionJ2000(const Vec3d& v);
00172 
00174     void setMaxFov(double max);
00176     double getMaxFov(void) const {return maxFov;}
00177 
00179     void autoZoomIn(float moveDuration = 1.f, bool allowManualZoom = 1);
00181     void autoZoomOut(float moveDuration = 1.f, bool full = 0);
00182 
00184     double getAimFov(void) const;
00185 
00187     void turnRight(bool);
00188     void turnLeft(bool);
00189     void turnUp(bool);
00190     void turnDown(bool);
00191     void moveSlow(bool b) {flagMoveSlow=b;}
00192     void zoomIn(bool);
00193     void zoomOut(bool);
00194 
00196     void setMountMode(MountMode m);
00198     MountMode getMountMode(void) const {return mountMode;}
00199 
00200     void setDragTimeMode(bool b) {dragTimeMode=b;}
00201     bool getDragTimeMode() const {return dragTimeMode;}
00202 
00203 private:
00204     Vec3d j2000ToMountFrame(const Vec3d& v) const;
00205     Vec3d mountFrameToJ2000(const Vec3d& v) const;
00206 
00207     double currentFov; // The current FOV in degree
00208     double initFov;    // The FOV at startup
00209     double minFov;     // Minimum FOV in degree
00210     double maxFov;     // Maximum FOV in degree
00211 
00212     void setFov(double f)
00213     {
00214         currentFov = f;
00215         if (f>maxFov)
00216             currentFov = maxFov;
00217         if (f<minFov)
00218             currentFov = minFov;
00219     }
00220     void changeFov(double deltaFov);
00221 
00222     void updateVisionVector(double deltaTime);
00223     void updateAutoZoom(double deltaTime); // Update autoZoom if activated
00224 
00226     void dragView(int x1, int y1, int x2, int y2);
00227 
00228     StelCore* core;          // The core on which the movement are applied
00229     class StelObjectMgr* objectMgr;
00230     bool flagLockEquPos;     // Define if the equatorial position is locked
00231     bool flagTracking;       // Define if the selected object is followed
00232 
00233     // Flags for mouse movements
00234     bool isMouseMovingHoriz;
00235     bool isMouseMovingVert;
00236 
00237     bool flagEnableMoveAtScreenEdge; // allow mouse at edge of screen to move view
00238     bool flagEnableMouseNavigation;
00239     float mouseZoomSpeed;
00240 
00241     bool flagEnableZoomKeys;
00242     bool flagEnableMoveKeys;
00243     float keyMoveSpeed;              // Speed of keys movement
00244     float keyZoomSpeed;              // Speed of keys zoom
00245     bool flagMoveSlow;
00246 
00247     // Speed factor for real life time movements, used for fast forward when playing scripts.
00248     float movementsSpeedFactor;
00249 
00252     struct AutoMove
00253     {
00254         Vec3d start;
00255         Vec3d aim;
00256         float speed;
00257         float coef;
00258         // If not null, move to the object.
00259         StelObjectP targetObject;
00260     };
00261 
00262     AutoMove move;          // Current auto movement
00263     bool flagAutoMove;       // Define if automove is on or off
00264     int zoomingMode;        // 0 : undefined, 1 zooming, -1 unzooming
00265 
00266     double deltaFov,deltaAlt,deltaAz; // View movement
00267 
00268     bool flagManualZoom;     // Define whether auto zoom can go further
00269     float autoMoveDuration; // Duration of movement for the auto move to a selected objectin seconds
00270 
00271     // Mouse control options
00272     bool isDragging, hasDragged;
00273     int previousX, previousY;
00274 
00275     // Contains the last N real time / JD times pairs associated with the last N mouse move events
00276     QList<QPair<double, double> > timeDragHistory;
00277     void addTimeDragPoint();
00278     float beforeTimeDragTimeRate;
00279 
00280     // Time mouse control
00281     bool dragTimeMode;
00282 
00285     struct AutoZoom
00286     {
00287         double start;
00288         double aim;
00289         float speed;
00290         float coef;
00291     };
00292 
00293     // Automove
00294     AutoZoom zoomMove; // Current auto movement
00295     bool flagAutoZoom; // Define if autozoom is on or off
00296     bool flagAutoZoomOutResetsDirection;
00297 
00298     // defines if view corrects for horizon, or uses equatorial coordinates
00299     MountMode mountMode;
00300 
00301     Vec3d initViewPos;        // Default viewing direction
00302 
00303     // Viewing direction in equatorial J2000 coordinates
00304     Vec3d viewDirectionJ2000;
00305     // Viewing direction in the mount reference frame.
00306     Vec3d viewDirectionMountFrame;
00307 
00308     Vec3d upVectorMountFrame;
00309 
00310     float dragTriggerDistance;
00311 };
00312 
00313 #endif // _STELMOVEMENTMGR_HPP_
00314 

Generated on Wed Jun 2 13:11:13 2010 for Stellarium by  doxygen 1.5.5