Stellarium 0.11.2
Home · All Namespaces · All Classes · Functions · Coding Style · Scripting · Plugins · File Structure
core/StelCore.hpp
00001 /*
00002  * Copyright (C) 2003 Fabien Chereau
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA  02110-1335, USA.
00017  */
00018 
00019 #ifndef _STELCORE_HPP_
00020 #define _STELCORE_HPP_
00021 
00022 #include "StelProjector.hpp"
00023 #include "StelProjectorType.hpp"
00024 #include "StelLocation.hpp"
00025 #include "StelSkyDrawer.hpp"
00026 #include <QString>
00027 #include <QStringList>
00028 #include <QTime>
00029 
00030 class StelToneReproducer;
00031 class StelSkyDrawer;
00032 class StelGeodesicGrid;
00033 class StelMovementMgr;
00034 class StelObserver;
00035 
00045 class StelCore : public QObject
00046 {
00047     Q_OBJECT
00048     Q_ENUMS(ProjectionType)
00049 
00050 public:
00053     enum FrameType
00054     {
00055         FrameAltAz,                   
00056         FrameHeliocentricEcliptic,    
00057         FrameObservercentricEcliptic, 
00058         FrameEquinoxEqu,              
00059 
00060         FrameJ2000,                   
00061 
00062         FrameGalactic                 
00063     };
00064 
00066     enum ProjectionType
00067     {
00068         ProjectionPerspective,    
00069         ProjectionEqualArea,      
00070         ProjectionStereographic,  
00071         ProjectionFisheye,        
00072         ProjectionHammer,         
00073         ProjectionCylinder,       
00074         ProjectionMercator,       
00075         ProjectionOrthographic    
00076     };
00077 
00079     enum RefractionMode
00080     {
00081         RefractionAuto,         
00082         RefractionOn,           
00083         RefractionOff           
00084     };
00085 
00086     StelCore();
00087     virtual ~StelCore();
00088 
00090     void init();
00091 
00094     void update(double deltaTime);
00095 
00097     void windowHasBeenResized(float x, float y, float width, float height);
00098 
00100     void preDraw();
00101 
00103     void postDraw();
00104 
00107     StelProjectorP getProjection2d() const;
00108 
00111     StelProjectorP getProjection(FrameType frameType, RefractionMode refractionMode=RefractionAuto) const;
00112 
00115     StelProjectorP getProjection(StelProjector::ModelViewTranformP modelViewTransform, ProjectionType projType=(ProjectionType)1000) const;
00116 
00118     StelToneReproducer* getToneReproducer() {return toneConverter;}
00120     const StelToneReproducer* getToneReproducer() const {return toneConverter;}
00121 
00123     StelSkyDrawer* getSkyDrawer() {return skyDrawer;}
00125     const StelSkyDrawer* getSkyDrawer() const {return skyDrawer;}
00126 
00128     const StelGeodesicGrid* getGeodesicGrid(int maxLevel) const;
00129 
00131     StelMovementMgr* getMovementMgr() {return movementMgr;}
00133     const StelMovementMgr* getMovementMgr() const {return movementMgr;}
00134 
00136     void setClippingPlanes(double znear, double zfar) {currentProjectorParams.zNear=znear;currentProjectorParams.zFar=zfar;}
00138     void getClippingPlanes(double* zn, double* zf) const {*zn = currentProjectorParams.zNear; *zf = currentProjectorParams.zFar;}
00139 
00141     QString projectionTypeKeyToNameI18n(const QString& key) const;
00142 
00144     QString projectionNameI18nToTypeKey(const QString& nameI18n) const;
00145 
00147     StelProjector::StelProjectorParams getCurrentStelProjectorParams() const {return currentProjectorParams;}
00149     void setCurrentStelProjectorParams(const StelProjector::StelProjectorParams& newParams) {currentProjectorParams=newParams;}
00150 
00152     void lookAtJ2000(const Vec3d& pos, const Vec3d& up);
00153 
00154     Vec3d altAzToEquinoxEqu(const Vec3d& v, RefractionMode refMode=RefractionAuto) const
00155     {
00156         if (refMode==RefractionOff || skyDrawer==false || (refMode==RefractionAuto && skyDrawer->getFlagHasAtmosphere()==false))
00157             return matAltAzToEquinoxEqu*v;
00158         Vec3d r(v);
00159         skyDrawer->getRefraction().backward(r);
00160         r.transfo4d(matAltAzToEquinoxEqu);
00161         return r;
00162     }
00163     Vec3d equinoxEquToAltAz(const Vec3d& v, RefractionMode refMode=RefractionAuto) const
00164     {
00165         if (refMode==RefractionOff || skyDrawer==false || (refMode==RefractionAuto && skyDrawer->getFlagHasAtmosphere()==false))
00166             return matEquinoxEquToAltAz*v;
00167         Vec3d r(v);
00168         r.transfo4d(matEquinoxEquToAltAz);
00169         skyDrawer->getRefraction().forward(r);
00170         return r;
00171     }
00172     Vec3d altAzToJ2000(const Vec3d& v, RefractionMode refMode=RefractionAuto) const
00173     {
00174         if (refMode==RefractionOff || skyDrawer==false || (refMode==RefractionAuto && skyDrawer->getFlagHasAtmosphere()==false))
00175             return matEquinoxEquToJ2000*matAltAzToEquinoxEqu*v;
00176         Vec3d r(v);
00177         skyDrawer->getRefraction().backward(r);
00178         r.transfo4d(matEquinoxEquToJ2000*matAltAzToEquinoxEqu);
00179         return r;
00180     }
00181     Vec3d j2000ToAltAz(const Vec3d& v, RefractionMode refMode=RefractionAuto) const
00182     {
00183         if (refMode==RefractionOff || skyDrawer==false || (refMode==RefractionAuto && skyDrawer->getFlagHasAtmosphere()==false))
00184             return matJ2000ToAltAz*v;
00185         Vec3d r(v);
00186         r.transfo4d(matJ2000ToAltAz);
00187         skyDrawer->getRefraction().forward(r);
00188         return r;
00189     }
00190     Vec3d galacticToJ2000(const Vec3d& v) const {return matGalacticToJ2000*v;}
00191     Vec3d equinoxEquToJ2000(const Vec3d& v) const {return matEquinoxEquToJ2000*v;}
00192     Vec3d j2000ToEquinoxEqu(const Vec3d& v) const {return matJ2000ToEquinoxEqu*v;}
00193     Vec3d j2000ToGalactic(const Vec3d& v) const {return matJ2000ToGalactic*v;}
00194 
00196     Vec3d heliocentricEclipticToAltAz(const Vec3d& v, RefractionMode refMode=RefractionAuto) const
00197     {
00198         if (refMode==RefractionOff || skyDrawer==false || (refMode==RefractionAuto && skyDrawer->getFlagHasAtmosphere()==false))
00199             return matHeliocentricEclipticToAltAz*v;
00200         Vec3d r(v);
00201         r.transfo4d(matHeliocentricEclipticToAltAz);
00202         skyDrawer->getRefraction().forward(r);
00203         return r;
00204     }
00205 
00207     Vec3d heliocentricEclipticToEquinoxEqu(const Vec3d& v) const {return matHeliocentricEclipticToEquinoxEqu*v;}
00210     Vec3d heliocentricEclipticToEarthPosEquinoxEqu(const Vec3d& v) const {return matAltAzToEquinoxEqu*matHeliocentricEclipticToAltAz*v;}
00211 
00213     StelProjector::ModelViewTranformP getHeliocentricEclipticModelViewTransform(RefractionMode refMode=RefractionAuto) const
00214     {
00215         if (refMode==RefractionOff || skyDrawer==false || (refMode==RefractionAuto && skyDrawer->getFlagHasAtmosphere()==false))
00216             return StelProjector::ModelViewTranformP(new StelProjector::Mat4dTransform(matAltAzModelView*matHeliocentricEclipticToAltAz));
00217         Refraction* refr = new Refraction(skyDrawer->getRefraction());
00218         // The pretransform matrix will convert from input coordinates to AltAz needed by the refraction function.
00219         refr->setPreTransfoMat(matHeliocentricEclipticToAltAz);
00220         refr->setPostTransfoMat(matAltAzModelView);
00221         return StelProjector::ModelViewTranformP(refr);
00222     }
00223 
00225     StelProjector::ModelViewTranformP getObservercentricEclipticModelViewTransform(RefractionMode refMode=RefractionAuto) const
00226     {
00227         if (refMode==RefractionOff || skyDrawer==false || (refMode==RefractionAuto && skyDrawer->getFlagHasAtmosphere()==false))
00228             return StelProjector::ModelViewTranformP(new StelProjector::Mat4dTransform(matAltAzModelView*matJ2000ToAltAz*matVsop87ToJ2000));
00229         Refraction* refr = new Refraction(skyDrawer->getRefraction());
00230         // The pretransform matrix will convert from input coordinates to AltAz needed by the refraction function.
00231         refr->setPreTransfoMat(matJ2000ToAltAz*matVsop87ToJ2000);
00232         refr->setPostTransfoMat(matAltAzModelView);
00233         return StelProjector::ModelViewTranformP(refr);
00234     }
00235 
00237     StelProjector::ModelViewTranformP getEquinoxEquModelViewTransform(RefractionMode refMode=RefractionAuto) const
00238     {
00239         if (refMode==RefractionOff || skyDrawer==false || (refMode==RefractionAuto && skyDrawer->getFlagHasAtmosphere()==false))
00240             return StelProjector::ModelViewTranformP(new StelProjector::Mat4dTransform(matAltAzModelView*matEquinoxEquToAltAz));
00241         Refraction* refr = new Refraction(skyDrawer->getRefraction());
00242         // The pretransform matrix will convert from input coordinates to AltAz needed by the refraction function.
00243         refr->setPreTransfoMat(matEquinoxEquToAltAz);
00244         refr->setPostTransfoMat(matAltAzModelView);
00245         return StelProjector::ModelViewTranformP(refr);
00246     }
00247 
00249     StelProjector::ModelViewTranformP getAltAzModelViewTransform(RefractionMode refMode=RefractionAuto) const
00250     {
00251         if (refMode==RefractionOff || skyDrawer==false || (refMode==RefractionAuto && skyDrawer->getFlagHasAtmosphere()==false))
00252             return StelProjector::ModelViewTranformP(new StelProjector::Mat4dTransform(matAltAzModelView));
00253         Refraction* refr = new Refraction(skyDrawer->getRefraction());
00254         // The pretransform matrix will convert from input coordinates to AltAz needed by the refraction function.
00255         refr->setPostTransfoMat(matAltAzModelView);
00256         return StelProjector::ModelViewTranformP(refr);
00257     }
00258 
00260     StelProjector::ModelViewTranformP getJ2000ModelViewTransform(RefractionMode refMode=RefractionAuto) const
00261     {
00262         if (refMode==RefractionOff || skyDrawer==false || (refMode==RefractionAuto && skyDrawer->getFlagHasAtmosphere()==false))
00263             return StelProjector::ModelViewTranformP(new StelProjector::Mat4dTransform(matAltAzModelView*matEquinoxEquToAltAz*matJ2000ToEquinoxEqu));
00264         Refraction* refr = new Refraction(skyDrawer->getRefraction());
00265         // The pretransform matrix will convert from input coordinates to AltAz needed by the refraction function.
00266         refr->setPreTransfoMat(matEquinoxEquToAltAz*matJ2000ToEquinoxEqu);
00267         refr->setPostTransfoMat(matAltAzModelView);
00268         return StelProjector::ModelViewTranformP(refr);
00269     }
00270 
00272     StelProjector::ModelViewTranformP getGalacticModelViewTransform(RefractionMode refMode=RefractionAuto) const
00273     {
00274         if (refMode==RefractionOff || skyDrawer==false || (refMode==RefractionAuto && skyDrawer->getFlagHasAtmosphere()==false))
00275             return StelProjector::ModelViewTranformP(new StelProjector::Mat4dTransform(matAltAzModelView*matEquinoxEquToAltAz*matJ2000ToEquinoxEqu*matGalacticToJ2000));
00276         Refraction* refr = new Refraction(skyDrawer->getRefraction());
00277         // The pretransform matrix will convert from input coordinates to AltAz needed by the refraction function.
00278         refr->setPreTransfoMat(matEquinoxEquToAltAz*matJ2000ToEquinoxEqu*matGalacticToJ2000);
00279         refr->setPostTransfoMat(matAltAzModelView);
00280         return StelProjector::ModelViewTranformP(refr);
00281     }
00282 
00284     static const Mat4d matJ2000ToVsop87;
00286     static const Mat4d matVsop87ToJ2000;
00288     static const Mat4d matJ2000ToGalactic;
00290     static const Mat4d matGalacticToJ2000;
00291 
00293     Vec3d getObserverHeliocentricEclipticPos() const;
00294 
00296     const StelLocation& getCurrentLocation() const;
00297 
00303     void moveObserverTo(const StelLocation& target, double duration=1., double durationIfPlanetChange=1.);
00304 
00305     // Conversion in standar Julian time format
00306     static const double JD_SECOND;
00307     static const double JD_MINUTE;
00308     static const double JD_HOUR;
00309     static const double JD_DAY;
00310 
00313     double getLocalSideralTime() const;
00314 
00316     double getLocalSideralDayLength() const;
00317 
00319     QString getStartupTimeMode() {return startupTimeMode;}
00320     void setStartupTimeMode(const QString& s);
00321 
00322 public slots:
00324     void setCurrentProjectionType(ProjectionType type);
00325     ProjectionType getCurrentProjectionType() const {return currentProjectionType;}
00326 
00328     QString getCurrentProjectionTypeKey(void) const;
00330     void setCurrentProjectionTypeKey(QString type);
00331 
00333     QStringList getAllProjectionTypeKeys() const;
00334 
00336     void setMaskType(StelProjector::StelProjectorMaskType m) {currentProjectorParams.maskType = m; }
00337 
00340     void setFlagGravityLabels(bool gravity) { currentProjectorParams.gravityLabels = gravity; }
00342     void setDefautAngleForGravityText(float a) { currentProjectorParams.defautAngleForGravityText = a; }
00345     void setFlipHorz(bool flip) {currentProjectorParams.flipHorz = flip;}
00348     void setFlipVert(bool flip) {currentProjectorParams.flipVert = flip;}
00351     bool getFlipHorz(void) const {return currentProjectorParams.flipHorz;}
00354     bool getFlipVert(void) const {return currentProjectorParams.flipVert;}
00355 
00357     QString getDefaultLocationID() const {return defaultLocationID;}
00359     void setDefaultLocationID(const QString& id);
00360 
00361 
00363     void setJDay(double JD) {JDay=JD;}
00365     double getJDay() const {return JDay;}
00366 
00368     double getPresetSkyTime() const {return presetSkyTime;}
00370     void setPresetSkyTime(double d) {presetSkyTime=d;}
00371 
00373     void setTimeRate(double ts) {timeSpeed=ts; emit timeRateChanged(timeSpeed);}
00375     double getTimeRate() const {return timeSpeed;}
00376 
00378     void increaseTimeSpeed();
00380     void decreaseTimeSpeed();
00382     void increaseTimeSpeedLess();
00384     void decreaseTimeSpeedLess();
00385 
00387     void setZeroTimeSpeed() {setTimeRate(0);}
00389     void setRealTimeSpeed() {setTimeRate(JD_SECOND);}
00391     void toggleRealTimeSpeed() {(!getRealTimeSpeed()) ? setRealTimeSpeed() : setZeroTimeSpeed();}
00393     bool getRealTimeSpeed() const {return (fabs(timeSpeed-JD_SECOND)<0.0000001);}
00394 
00396     void setTimeNow();
00398     void setTodayTime(const QTime& target);
00400     bool getIsTimeNow() const;
00401 
00403     QTime getInitTodayTime(void) {return initTodayTime;}
00405     void setInitTodayTime(const QTime& t) {initTodayTime=t;}
00407     void setPresetSkyTime(QDateTime dt);
00408 
00410     void addHour() {addSolarDays(0.04166666666666666667);}
00412     void addDay() {addSolarDays(1.0);}
00414     void addWeek() {addSolarDays(7.0);}
00415 
00418     void addSiderealDay() {addSiderealDays(1.0);}
00421     void addSiderealWeek() {addSiderealDays(7.0);}
00422 
00424     void subtractHour() {addSolarDays(-0.04166666666666666667);}
00426     void subtractDay() {addSolarDays(-1.0);}
00428     void subtractWeek() {addSolarDays(-7.0);}
00429 
00432     void subtractSiderealDay() {addSiderealDays(-1.0);}
00435     void subtractSiderealWeek() {addSiderealDays(-7.0);}
00436 
00439     void addSolarDays(double d);
00443     void addSiderealDays(double d);
00444 
00447     void moveObserverToSelected();
00448 
00449 signals:
00451     void locationChanged(StelLocation);
00453     void timeRateChanged(double rate);
00454 
00455 private:
00456     StelToneReproducer* toneConverter;      // Tones conversion between stellarium world and display device
00457     StelSkyDrawer* skyDrawer;
00458     StelMovementMgr* movementMgr;       // Manage vision movements
00459 
00460     // Manage geodesic grid
00461     mutable StelGeodesicGrid* geodesicGrid;
00462 
00463     // The currently used projection type
00464     ProjectionType currentProjectionType;
00465 
00466     // Parameters to use when creating new instances of StelProjector
00467     StelProjector::StelProjectorParams currentProjectorParams;
00468 
00469     void updateTransformMatrices();
00470     void updateTime(double deltaTime);
00471 
00472     // Matrices used for every coordinate transfo
00473     Mat4d matHeliocentricEclipticToAltAz;   // Transform from heliocentric ecliptic (Vsop87) to observer-centric altazimuthal coordinate
00474     Mat4d matAltAzToHeliocentricEcliptic;   // Transform from observer-centric altazimuthal coordinate to heliocentric ecliptic (Vsop87)
00475     Mat4d matAltAzToEquinoxEqu;             // Transform from observer-centric altazimuthal coordinate to Earth Equatorial
00476     Mat4d matEquinoxEquToAltAz;             // Transform from observer-centric altazimuthal coordinate to Earth Equatorial
00477     Mat4d matHeliocentricEclipticToEquinoxEqu;// Transform from heliocentric ecliptic (Vsop87) to earth equatorial coordinate
00478     Mat4d matEquinoxEquToJ2000;
00479     Mat4d matJ2000ToEquinoxEqu;
00480     Mat4d matJ2000ToAltAz;
00481 
00482     Mat4d matAltAzModelView;                // Modelview matrix for observer-centric altazimuthal drawing
00483     Mat4d invertMatAltAzModelView;          // Inverted modelview matrix for observer-centric altazimuthal drawing
00484 
00485     // Position variables
00486     StelObserver* position;
00487     // The ID of the default startup location
00488     QString defaultLocationID;
00489 
00490     // Time variables
00491     double timeSpeed;                       // Positive : forward, Negative : Backward, 1 = 1sec/sec
00492     double JDay;                            // Curent time in Julian day
00493     double presetSkyTime;
00494     QTime initTodayTime;
00495     QString startupTimeMode;
00496 };
00497 
00498 #endif // _STELCORE_HPP_