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

core/modules/Planet.hpp

00001 /*
00002  * Stellarium
00003  * Copyright (C) 2002 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 _PLANET_HPP_
00021 #define _PLANET_HPP_
00022 
00023 #include <QString>
00024 
00025 #include "StelObject.hpp"
00026 #include "VecMath.hpp"
00027 #include "StelFader.hpp"
00028 #include "StelTextureTypes.hpp"
00029 #include "StelProjectorType.hpp"
00030 
00031 // The callback type for the external position computation function
00032 // The last variable is the userData pointer.
00033 typedef void (*posFuncType)(double, double*, void*);
00034 
00035 typedef void (OsulatingFunctType)(double jd0,double jd,double xyz[3]);
00036 
00037 // epoch J2000: 12 UT on 1 Jan 2000
00038 #define J2000 2451545.0
00039 #define ORBIT_SEGMENTS 72
00040 
00041 class StelFont;
00042 class StelPainter;
00043 class StelTranslator;
00044 
00045 struct TrailPoint
00046 {
00047     Vec3d point;
00048     double date;
00049 };
00050 
00051 
00052 // Class used to store orbital elements
00053 class RotationElements
00054 {
00055 public:
00056     RotationElements(void) : period(1.), offset(0.), epoch(J2000), obliquity(0.), ascendingNode(0.), precessionRate(0.) {}
00057     float period;          // rotation period
00058     float offset;          // rotation at epoch
00059     double epoch;
00060     float obliquity;       // tilt of rotation axis w.r.t. ecliptic
00061     float ascendingNode;   // long. of ascending node of equator on the ecliptic
00062     float precessionRate;  // rate of precession of rotation axis in rads/day
00063     double siderealPeriod; // sidereal period (Planet year in earth days)
00064 };
00065 
00066 // Class to manage rings for planets like saturn
00067 class Ring
00068 {
00069 public:
00070     Ring(double radiusMin,double radiusMax,const QString &texname);
00071     ~Ring(void);
00072     void draw(StelPainter* painter,const Mat4d& mat,double screenSz);
00073     double getSize(void) const {return radiusMax;}
00074 private:
00075     const double radiusMin;
00076     const double radiusMax;
00077     StelTextureSP tex;
00078 };
00079 
00080 
00081 class Planet : public StelObject
00082 {
00083 public:
00084     friend class SolarSystem;
00085     Planet(const QString& englishName,
00086            int flagLighting,
00087            double radius,
00088            double oblateness,
00089            Vec3f color,
00090            float albedo,
00091            const QString& texMapName,
00092            posFuncType _coordFunc,
00093            void* userDataPtr,
00094            OsulatingFunctType *osculatingFunc,
00095            bool closeOrbit,
00096            bool hidden,
00097            bool hasAtmosphere);
00098 
00099     ~Planet();
00100 
00102     // Methods inherited from StelObject
00115     virtual QString getInfoString(const StelCore *core, const InfoStringGroup& flags) const;
00116     virtual double getCloseViewFov(const StelNavigator * nav) const;
00117     virtual double getSatellitesFov(const StelNavigator * nav) const;
00118     virtual double getParentSatellitesFov(const StelNavigator * nav) const;
00119     virtual float getVMagnitude(const StelNavigator * nav) const;
00120     virtual float getSelectPriority(const StelNavigator *nav) const;
00121     virtual Vec3f getInfoColor(void) const;
00122     virtual QString getType(void) const {return "Planet";}
00123     virtual Vec3d getJ2000EquatorialPos(const StelNavigator *nav) const;
00124     virtual QString getEnglishName(void) const {return englishName;}
00125     virtual QString getNameI18n(void) const {return nameI18;}
00126     virtual double getAngularSize(const StelCore* core) const;
00127     virtual bool hasAtmosphere(void) {return atmosphere;}
00128 
00130     // Methods of SolarSystem object
00132     virtual void translateName(StelTranslator& trans);
00133 
00134     // Draw the Planet
00135     void draw(StelCore* core, float maxMagLabels, const QFont& planetNameFont);
00136 
00138     // Methods specific to Planet
00141     double getRadius(void) const {return radius;}
00142     double getSiderealDay(void) const {return re.period;}
00143 
00144     const QString& getTextMapName() const {return texMapName;}
00145 
00146     // Compute the z rotation to use from equatorial to geographic coordinates
00147     double getSiderealTime(double jd) const;
00148     Mat4d getRotEquatorialToVsop87(void) const;
00149     void setRotEquatorialToVsop87(const Mat4d &m);
00150 
00151     const RotationElements &getRotationElements(void) const {return re;}
00152 
00153     // Compute the position in the parent Planet coordinate system
00154     void computePositionWithoutOrbits(const double date);
00155     void computePosition(const double date);
00156 
00157     // Compute the transformation matrix from the local Planet coordinate to the parent Planet coordinate
00158     void computeTransMatrix(double date);
00159 
00160     // Get the phase angle for an observer at pos obsPos in the heliocentric coordinate (in AU)
00161     double getPhase(const Vec3d& obsPos) const;
00162     // Get the angular size of the spheroid of the planet (i.e. without the rings)
00163     double getSpheroidAngularSize(const StelCore* core) const;
00164 
00165     // Set the orbital elements
00166     void setRotationElements(float _period, float _offset, double _epoch,
00167         float _obliquity, float _ascendingNode, float _precessionRate, double _siderealPeriod);
00168     double getRotAscendingnode(void) const {return re.ascendingNode;}
00169     double getRotObliquity(void) const {return re.obliquity;}
00170 
00172     Vec3d getEclipticPos() const;
00173 
00174     // Return the heliocentric ecliptical position
00175     Vec3d getHeliocentricEclipticPos() const;
00176     void setHeliocentricEclipticPos(const Vec3d &pos);
00177 
00178     // Compute the distance to the given position in heliocentric coordinate (in AU)
00179     double computeDistance(const Vec3d& obsHelioPos);
00180     double getDistance(void) const {return distance;}
00181 
00182     void setRings(Ring* r) {rings = r;}
00183 
00184     void setSphereScale(float s) {sphereScale = s;}
00185     float getSphereScale(void) const {return sphereScale;}
00186 
00187     const QSharedPointer<Planet> getParent(void) const {return parent;}
00188 
00189     static void setLabelColor(const Vec3f& lc) {labelColor = lc;}
00190     static const Vec3f& getLabelColor(void) {return labelColor;}
00191 
00192     void update(int deltaTime);
00193 
00194     void setFlagHints(bool b){hintFader = b;}
00195     bool getFlagHints(void) const {return hintFader;}
00196 
00197     void setFlagLabels(bool b){flagLabels = b;}
00198     bool getFlagLabels(void) const {return flagLabels;}
00199 
00201     // DEPRECATED
00203     // Should move to an OrbitPath class which works on a SolarSystemObject, not a Planet
00204     void setFlagOrbits(bool b){orbitFader = b;}
00205     bool getFlagOrbits(void) const {return orbitFader;}
00206     LinearFader orbitFader;
00207     // draw orbital path of Planet
00208     void drawOrbit(const StelCore*);
00209     Vec3d orbit[ORBIT_SEGMENTS+1];   // store heliocentric coordinates for drawing the orbit
00210     double lastOrbitJD;
00211     double deltaJD;
00212     double deltaOrbitJD;
00213     bool orbitCached;              // whether orbit calculations are cached for drawing orbit yet
00214     bool closeOrbit;               // whether to connect the beginning of the orbit line to
00215                                    // the end: good for elliptical orbits, bad for parabolic
00216                                    // and hyperbolic orbits
00217 
00218     static Vec3f orbitColor;
00219     static void setOrbitColor(const Vec3f& oc) {orbitColor = oc;}
00220     static const Vec3f& getOrbitColor() {return orbitColor;}
00221 
00222 protected:
00223     static StelTextureSP texEarthShadow;     // for lunar eclipses
00224 
00225     // draw earth shadow on moon for lunar eclipses
00226     void drawEarthShadow(StelCore* core, StelPainter* sPainter);
00227 
00228     // Return the information string "ready to print" :)
00229     QString getSkyLabel(const StelNavigator * nav) const;
00230 
00231     // Draw the 3d model. Call the proper functions if there are rings etc..
00232     void draw3dModel(StelCore* core, const Mat4d& mat, float screenSz);
00233 
00234     // Draw the 3D sphere
00235     void drawSphere(StelPainter* painter, float screenSz);
00236 
00237     // Draw the circle and name of the Planet
00238     void drawHints(const StelCore* core, const QFont& planetNameFont);
00239 
00240     QString englishName;            // english planet name
00241     QString nameI18;                // International translated name
00242     QString texMapName;             // Texture file path
00243     int flagLighting;               // Set whether light computation has to be proceed
00244     RotationElements re;            // Rotation param
00245     double radius;                  // Planet radius in UA
00246     double oneMinusOblateness;      // (polar radius)/(equatorial radius)
00247     Vec3d eclipticPos;             // Position in UA in the rectangular ecliptic coordinate system
00248                                     // centered on the parent Planet
00249     Vec3d screenPos;                // Used to store temporarily the 2D position on screen
00250     Vec3d previousScreenPos;        // The position of this planet in the previous frame.
00251     Vec3f color;
00252     float albedo;                   // Planet albedo
00253     Mat4d rotLocalToParent;
00254     float axisRotation;            // Rotation angle of the Planet on it's axis
00255     StelTextureSP texMap;             // Planet map texture
00256     Ring* rings;                    // Planet rings
00257     double distance;                // Temporary variable used to store the distance to a given point
00258                                     // it is used for sorting while drawing
00259     float sphereScale;             // Artificial scaling for better viewing
00260     double lastJD;
00261     // The callback for the calculation of the equatorial rect heliocentric position at time JD.
00262     posFuncType coordFunc;
00263     void* userDataPtr;
00264 
00265     OsulatingFunctType *const osculatingFunc;
00266     QSharedPointer<Planet> parent;           // Planet parent i.e. sun for earth
00267     QList<QSharedPointer<Planet> > satellites;      // satellites of the Planet
00268     LinearFader hintFader;
00269     LinearFader labelsFader;        // Store the current state of the label for this planet
00270     bool flagLabels;                // Define whether labels should be displayed
00271     bool hidden;                    // useful for fake planets used as observation positions - not drawn or labeled
00272     bool atmosphere;                // Does the planet have an atmosphere?
00273 
00274     static Vec3f labelColor;
00275     static StelTextureSP hintCircleTex;
00276 };
00277 
00278 #endif // _PLANET_HPP_
00279