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 deltaTime) {;}
00056     virtual void draw(StelCore* acore) {;}
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(Vec3f& up);
00084 
00085     void setMovementSpeedFactor(float s) {movementsSpeedFactor=s;}
00086     float getMovementSpeedFactor() const {return movementsSpeedFactor;}
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:
00202     Vec3d j2000ToMountFrame(const Vec3d& v) const;
00203     Vec3d mountFrameToJ2000(const Vec3d& v) const;
00204 
00205     double currentFov; // The current FOV in degree
00206     double initFov;    // The FOV at startup
00207     double minFov;     // Minimum FOV in degree
00208     double maxFov;     // Maximum FOV in degree
00209 
00210     void setFov(double f)
00211     {
00212         currentFov = f;
00213         if (f>maxFov)
00214             currentFov = maxFov;
00215         if (f<minFov)
00216             currentFov = minFov;
00217     }
00218     void changeFov(double deltaFov);
00219 
00220     void updateVisionVector(double deltaTime);
00221     void updateAutoZoom(double deltaTime); // Update autoZoom if activated
00222 
00224     void dragView(int x1, int y1, int x2, int y2);
00225 
00226     StelCore* core;          // The core on which the movement are applied
00227     class StelObjectMgr* objectMgr;
00228     bool flagLockEquPos;     // Define if the equatorial position is locked
00229     bool flagTracking;       // Define if the selected object is followed
00230 
00231     // Flags for mouse movements
00232     bool isMouseMovingHoriz;
00233     bool isMouseMovingVert;
00234 
00235     bool flagEnableMoveAtScreenEdge; // allow mouse at edge of screen to move view
00236     bool flagEnableMouseNavigation;
00237     float mouseZoomSpeed;
00238 
00239     bool flagEnableZoomKeys;
00240     bool flagEnableMoveKeys;
00241     float keyMoveSpeed;              // Speed of keys movement
00242     float keyZoomSpeed;              // Speed of keys zoom
00243     bool flagMoveSlow;
00244 
00245     // Speed factor for real life time movements, used for fast forward when playing scripts.
00246     float movementsSpeedFactor;
00247 
00250     struct AutoMove
00251     {
00252         Vec3d start;
00253         Vec3d aim;
00254         float speed;
00255         float coef;
00256         // If not null, move to the object.
00257         StelObjectP targetObject;
00258     };
00259 
00260     AutoMove move;          // Current auto movement
00261     bool flagAutoMove;       // Define if automove is on or off
00262     int zoomingMode;        // 0 : undefined, 1 zooming, -1 unzooming
00263 
00264     double deltaFov,deltaAlt,deltaAz; // View movement
00265 
00266     bool flagManualZoom;     // Define whether auto zoom can go further
00267     float autoMoveDuration; // Duration of movement for the auto move to a selected objectin seconds
00268 
00269     // Mouse control options
00270     bool isDragging, hasDragged;
00271     int previousX, previousY;
00272     // Contains the last N JD times associated with the last N mouse move events
00273     QList<double> mouseDragTimeHistory;
00274 
00275     // Time mouse control
00276     bool dragTimeMode;
00277     double startDragT;
00278     double startDragJDay;
00279 
00282     struct AutoZoom
00283     {
00284         double start;
00285         double aim;
00286         float speed;
00287         float coef;
00288     };
00289 
00290     // Automove
00291     AutoZoom zoomMove; // Current auto movement
00292     bool flagAutoZoom; // Define if autozoom is on or off
00293     bool flagAutoZoomOutResetsDirection;
00294 
00295     // defines if view corrects for horizon, or uses equatorial coordinates
00296     MountMode mountMode;
00297 
00298     Vec3d initViewPos;        // Default viewing direction
00299 
00300     // Viewing direction in equatorial J2000 coordinates
00301     Vec3d viewDirectionJ2000;
00302     // Viewing direction in the mount reference frame.
00303     Vec3d viewDirectionMountFrame;
00304 
00305     Vec3d upVectorMountFrame;
00306 };
00307 
00308 #endif // _STELMOVEMENTMGR_HPP_
00309 

Generated on Mon Mar 22 09:55:38 2010 for Stellarium by  doxygen 1.5.5