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

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., 51 Franklin Street, Suite 500, Boston, MA  02110-1335, USA.
00018  */
00019 
00020 #ifndef _PLANET_HPP_
00021 #define _PLANET_HPP_
00022 
00023 #include <QString>
00024 
00025 #include "StelObject.hpp"
00026 #include "StelProjector.hpp"
00027 #include "VecMath.hpp"
00028 #include "StelFader.hpp"
00029 #include "renderer/GenericVertexTypes.hpp"
00030 #include "renderer/StelIndexBuffer.hpp"
00031 #include "renderer/StelVertexBuffer.hpp"
00032 #include "StelProjectorType.hpp"
00033 
00034 // The callback type for the external position computation function
00035 // The last variable is the userData pointer.
00036 typedef void (*posFuncType)(double, double*, void*);
00037 
00038 typedef void (OsculatingFunctType)(double jd0,double jd,double xyz[3]);
00039 
00040 // epoch J2000: 12 UT on 1 Jan 2000
00041 #define J2000 2451545.0
00042 #define ORBIT_SEGMENTS 360
00043 
00044 class StelFont;
00045 class StelTranslator;
00046 
00047 struct TrailPoint
00048 {
00049     Vec3d point;
00050     double date;
00051 };
00052 
00053 
00054 struct ShadowPlanetShaderInfo
00055 {
00056     int info;
00057     int current;
00058     int infoCount;
00059     float infoSize;
00060 };
00061 
00062 // Class used to store orbital elements
00063 class RotationElements
00064 {
00065 public:
00066     RotationElements(void) : period(1.), offset(0.), epoch(J2000), obliquity(0.), ascendingNode(0.), precessionRate(0.) {}
00067     float period;          // rotation period
00068     float offset;          // rotation at epoch
00069     double epoch;
00070     float obliquity;       // tilt of rotation axis w.r.t. ecliptic
00071     float ascendingNode;   // long. of ascending node of equator on the ecliptic
00072     float precessionRate;  // rate of precession of rotation axis in rads/day
00073     double siderealPeriod; // sidereal period (Planet year in earth days)
00074 };
00075 
00076 // Class to manage rings for planets like saturn
00077 class Ring
00078 {
00079     friend class Planet;
00080 public:
00081     Ring(double radiusMin,double radiusMax,const QString &texname);
00082     ~Ring(void);
00083 
00096     void draw(StelProjectorP projector, class StelRenderer* renderer, StelProjector::ModelViewTranformP transform, class StelGLSLShader *shader, double screenSz, ShadowPlanetShaderInfo *info);
00097 
00098     double getSize(void) const {return radiusMax;}
00099 private:
00100     const double radiusMin;
00101     const double radiusMax;
00102 
00103     const QString texName;
00104     class StelTextureNew* texture;
00105 
00107     class StelGeometryRing* ring;
00108 };
00109 
00110 class Planet : public StelObject
00111 {
00112 protected:
00115     struct SharedPlanetGraphics
00116     {
00118         class StelTextureNew* texEarthShadow;
00120         class StelTextureNew* texHintCircle;
00122         class StelGLSLShader* simplePlanetShader;
00124         class StelGLSLShader* shadowPlanetShader;
00125 
00127         class StelGLSLShader* planetShader;
00128 
00130         bool initialized;
00131 
00133         ShadowPlanetShaderInfo info;
00134 
00136         SharedPlanetGraphics(): initialized(false){}
00138         ~SharedPlanetGraphics();
00140         void lazyInit(class StelRenderer* renderer);
00142         bool loadPlanetShaders(StelRenderer *renderer);
00143     };
00144 
00145 public:
00146     friend class SolarSystem;
00147     Planet(const QString& englishName,
00148            int flagLighting,
00149            double radius,
00150            double oblateness,
00151            Vec3f color,
00152            float albedo,
00153            const QString& texMapName,
00154            posFuncType _coordFunc,
00155            void* userDataPtr,
00156            OsculatingFunctType *osculatingFunc,
00157            bool closeOrbit,
00158            bool hidden,
00159            bool hasAtmosphere,
00160            const QString &pType);
00161 
00162     ~Planet();
00163 
00165     // Methods inherited from StelObject
00180     virtual QString getInfoString(const StelCore *core, const InfoStringGroup& flags) const;
00181     virtual double getCloseViewFov(const StelCore* core) const;
00182     virtual double getSatellitesFov(const StelCore* core) const;
00183     virtual double getParentSatellitesFov(const StelCore* core) const;
00184     virtual float getVMagnitude(const StelCore* core, bool withExtinction=false) const;
00185     virtual float getSelectPriority(const StelCore* core) const;
00186     virtual Vec3f getInfoColor(void) const;
00187     virtual QString getType(void) const {return "Planet";}
00188     virtual Vec3d getJ2000EquatorialPos(const StelCore *core) const;
00189     virtual QString getEnglishName(void) const {return englishName;}
00190     virtual QString getNameI18n(void) const {return nameI18;}
00191     virtual double getAngularSize(const StelCore* core) const;
00192     virtual bool hasAtmosphere(void) {return atmosphere;}
00193 
00195     // Methods of SolarSystem object
00197     virtual void translateName(StelTranslator& trans);
00198 
00206     void draw(StelCore* core, class StelRenderer* renderer, float maxMagLabels,
00207               const QFont& planetNameFont, SharedPlanetGraphics& planetGraphics);
00208 
00210     // Methods specific to Planet
00213     double getRadius(void) const {return radius;}
00214     double getSiderealDay(void) const {return re.period;}
00215     double getSiderealPeriod(void) const { return re.siderealPeriod; }
00216 
00217     const QString& getTextMapName() const {return texMapName;}  
00218 
00219     // Compute the z rotation to use from equatorial to geographic coordinates
00220     double getSiderealTime(double jd) const;
00221     Mat4d getRotEquatorialToVsop87(void) const;
00222     void setRotEquatorialToVsop87(const Mat4d &m);
00223 
00224     const RotationElements &getRotationElements(void) const {return re;}
00225 
00226     // Compute the position in the parent Planet coordinate system
00227     void computePositionWithoutOrbits(const double date);
00228     void computePosition(const double date);
00229 
00230     // Compute the transformation matrix from the local Planet coordinate to the parent Planet coordinate
00231     void computeTransMatrix(double date);
00232 
00233     // Compute the transformation matrix from model to world coordinates
00234     void computeModelMatrix(Mat4d& result) const;
00235 
00236     // Get the phase angle (rad) for an observer at pos obsPos in heliocentric coordinates (in AU)
00237     double getPhaseAngle(const Vec3d& obsPos) const;
00238     // Get the elongation angle (rad) for an observer at pos obsPos in heliocentric coordinates (in AU)
00239     double getElongation(const Vec3d& obsPos) const;
00240     // Get the angular size of the spheroid of the planet (i.e. without the rings)
00241     double getSpheroidAngularSize(const StelCore* core) const;
00242     // Get the planet phase for an observer at pos obsPos in heliocentric coordinates (in AU)
00243     float getPhase(const Vec3d& obsPos) const;
00244 
00245     // Set the orbital elements
00246     void setRotationElements(float _period, float _offset, double _epoch,
00247                  float _obliquity, float _ascendingNode,
00248                  float _precessionRate, double _siderealPeriod);
00249     double getRotAscendingnode(void) const {return re.ascendingNode;}
00250     double getRotObliquity(void) const {return re.obliquity;}
00251 
00253     Vec3d getEclipticPos() const;
00254 
00255     // Return the heliocentric ecliptical position
00256     Vec3d getHeliocentricEclipticPos() const;
00257 
00258     // Return the heliocentric transformation for local coordinate
00259     Vec3d getHeliocentricPos(Vec3d) const;
00260     void setHeliocentricEclipticPos(const Vec3d &pos);
00261 
00262     // Compute the distance to the given position in heliocentric coordinate (in AU)
00263     double computeDistance(const Vec3d& obsHelioPos);
00264     double getDistance(void) const {return distance;}
00265 
00266     void setRings(Ring* r) {rings = r;}
00267 
00268     void setSphereScale(float s);
00269 
00270     float getSphereScale(void) const {return sphereScale;}
00271 
00272     const QSharedPointer<Planet> getParent(void) const {return parent;}
00273 
00274     static void setLabelColor(const Vec3f& lc) {labelColor = lc;}
00275     static const Vec3f& getLabelColor(void) {return labelColor;}
00276 
00277     void update(int deltaTime);
00278 
00279     void setFlagHints(bool b){hintFader = b;}
00280     bool getFlagHints(void) const {return hintFader;}
00281 
00282     void setFlagLabels(bool b){flagLabels = b;}
00283     bool getFlagLabels(void) const {return flagLabels;}
00284 
00286     // DEPRECATED
00288     // Should move to an OrbitPath class which works on a SolarSystemObject, not a Planet
00289     void setFlagOrbits(bool b){orbitFader = b;}
00290     bool getFlagOrbits(void) const {return orbitFader;}
00291 
00293     struct Vertex2D
00294     {
00295         Vec2f position;
00296         Vertex2D(const float x, const float y) : position(x, y){}
00297         VERTEX_ATTRIBUTES(Vec2f Position);
00298     };
00299 
00301     StelVertexBuffer<Vertex2D>* orbitVertices;
00302 
00303     LinearFader orbitFader;
00304     // draw orbital path of Planet
00305     void drawOrbit(const StelCore* core, class StelRenderer* renderer);
00306     Vec3d orbit[ORBIT_SEGMENTS+1];   // store heliocentric coordinates for drawing the orbit
00307     Vec3d orbitP[ORBIT_SEGMENTS+1];  // store local coordinate for orbit
00308     double lastOrbitJD;
00309     double deltaJD;
00310     double deltaOrbitJD;
00311     bool orbitCached;                // whether orbit calculations are cached for drawing orbit yet
00312     bool closeOrbit;                 // whether to connect the beginning of the orbit line to
00313                                      // the end: good for elliptical orbits, bad for parabolic
00314                                      // and hyperbolic orbits
00315 
00316     static Vec3f orbitColor;
00317     static void setOrbitColor(const Vec3f& oc) {orbitColor = oc;}
00318     static const Vec3f& getOrbitColor() {return orbitColor;}
00319 
00320 protected:
00321     // draw earth shadow on moon for lunar eclipses
00322     void drawEarthShadow(StelCore* core, class StelRenderer* renderer, 
00323                          SharedPlanetGraphics& planetGraphics);
00324 
00325     // Return the information string "ready to print" :)
00326     QString getSkyLabel(const StelCore* core) const;
00327 
00335     void draw3dModel(StelCore* core, class StelRenderer* renderer, 
00336                      SharedPlanetGraphics& planetGraphics,
00337                      StelProjector::ModelViewTranformP transfo, float screenSz);
00338 
00347     void drawUnlitSphere(class StelRenderer* renderer, StelProjectorP projector);
00348 
00359     void drawSphere(class StelRenderer* renderer, StelProjectorP projector,
00360                    const struct StelLight* light, SharedPlanetGraphics &planetGraphics, float screenSz);
00361 
00362     // Draw the circle and name of the Planet
00363     void drawHints(const StelCore* core, class StelRenderer* renderer, 
00364                    const QFont& planetNameFont, SharedPlanetGraphics& planetGraphics);
00365 
00366     QString englishName;             // english planet name
00367     QString nameI18;                 // International translated name
00368     QString texMapName;              // Texture file path   
00369     RotationElements re;             // Rotation param
00370 
00371     // Note: vertex/index buffer generation depends on the fact that 
00372     // flagLighting, radius and oneMinusOblateness don't change.
00373     // If they change, buffers will have to be regenerated to reflect the change.
00374     const int flagLighting;          // Set whether light computation has to be proceed
00375     const double radius;             // Planet radius in AU
00376     const double oneMinusOblateness; // (polar radius)/(equatorial radius)
00377     Vec3d eclipticPos;               // Position in AU in the rectangular ecliptic coordinate system
00378                                      // centered on the parent Planet
00379     Vec3d screenPos;                 // Used to store temporarily the 2D position on screen
00380     Vec3d previousScreenPos;         // The position of this planet in the previous frame.
00381     Vec3f color;
00382 
00383     float albedo;                    // Planet albedo
00384     Mat4d rotLocalToParent;
00385     float axisRotation;              // Rotation angle of the Planet on it's axis 
00386 
00387     class StelTextureNew* texture;   // Planet map texture
00388 
00389     Ring* rings;                     // Planet rings
00390     double distance;                 // Temporary variable used to store the distance to a given point
00391                                      // it is used for sorting while drawing
00392     float sphereScale;               // Artificial scaling for better viewing
00393     double lastJD;
00394     // The callback for the calculation of the equatorial rect heliocentric position at time JD.
00395     posFuncType coordFunc;
00396     void* userDataPtr;
00397 
00398     OsculatingFunctType *const osculatingFunc;
00399     QSharedPointer<Planet> parent;           // Planet parent i.e. sun for earth
00400     QList<QSharedPointer<Planet> > satellites;      // satellites of the Planet
00401     LinearFader hintFader;
00402     LinearFader labelsFader;         // Store the current state of the label for this planet
00403     bool flagLabels;                 // Define whether labels should be displayed
00404     bool hidden;                     // useful for fake planets used as observation positions - not drawn or labeled
00405     bool atmosphere;                 // Does the planet have an atmosphere?
00406     QString pType;           // Type of body
00407 
00409     class StelGeometrySphere* unlitSphere;
00411     class StelGeometrySphere* litSphere;
00412 
00413     static Vec3f labelColor;
00414 };
00415 
00416 #endif // _PLANET_HPP_
00417 
Generated on Thu Jan 31 14:05:39 2013 for Stellarium by  doxygen 1.6.3