Stellarium 0.90.0
Planet.hpp
1 /*
2  * Stellarium
3  * Copyright (C) 2002 Fabien Chereau
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18  */
19 
20 #ifndef _PLANET_HPP_
21 #define _PLANET_HPP_
22 
23 #include "StelObject.hpp"
24 #include "StelProjector.hpp"
25 #include "VecMath.hpp"
26 #include "StelFader.hpp"
27 #include "StelTextureTypes.hpp"
28 #include "StelProjectorType.hpp"
29 
30 #include <QString>
31 
32 // The callback type for the external position computation function
33 // The last variable is the userData pointer.
34 typedef void (*posFuncType)(double, double*, void*);
35 
36 typedef void (OsculatingFunctType)(double jde0,double jde,double xyz[3]);
37 
38 // epoch J2000: 12 UT on 1 Jan 2000
39 #define J2000 2451545.0
40 #define ORBIT_SEGMENTS 360
41 
42 class StelFont;
43 class StelPainter;
44 class StelTranslator;
45 class QOpenGLShaderProgram;
46 
47 // Class used to store rotational elements, i.e. axis orientation for the planetary body.
49 {
50 public:
51  RotationElements(void) : period(1.), offset(0.), epoch(J2000), obliquity(0.), ascendingNode(0.), precessionRate(0.), siderealPeriod(0.) {}
52  float period; // (sidereal) rotation period [earth days]
53  float offset; // rotation at epoch [degrees]
54  double epoch; // JDE (JD TT) of epoch for these elements
55  float obliquity; // tilt of rotation axis w.r.t. ecliptic [radians]
56  float ascendingNode; // long. of ascending node of equator on the ecliptic [radians]
57  float precessionRate; // rate of precession of rotation axis in [rads/JulianCentury(36525d)]
58  double siderealPeriod; // sidereal period (Planet year in earth days) [earth days]
59 };
60 
61 // Class to manage rings for planets like saturn
62 class Ring
63 {
64 public:
65  Ring(float radiusMin, float radiusMax,const QString &texname);
66  double getSize(void) const {return radiusMax;}
67  const float radiusMin;
68  const float radiusMax;
69  StelTextureSP tex;
70 };
71 
72 
73 class Planet : public StelObject
74 {
75 public:
76  friend class SolarSystem;
77 
78  Q_ENUMS(PlanetType)
79  Q_ENUMS(ApparentMagnitudeAlgorithm)
81  // GZ: Until 0.13 QStrings were used for types.
82  // GZ: Enums are slightly faster than string comparisons in time-critical comparisons.
83  // GZ: If other types are introduced, add here and the string in init().
85  {
86  isStar, // ssystem.ini: type="star"
87  isPlanet, // ssystem.ini: type="planet"
88  isMoon, // ssystem.ini: type="moon"
89  isAsteroid, // ssystem.ini: type="asteroid"
90  isPlutino, // ssystem.ini: type="plutino"
91  isComet, // ssystem.ini: type="comet"
92  isDwarfPlanet, // ssystem.ini: type="dwarf planet"
93  isCubewano, // ssystem.ini: type="cubewano"
94  isSDO, // ssystem.ini: type="sdo"
95  isOCO, // ssystem.ini: type="oco"
96  isUNDEFINED // ssystem.ini: type=<anything else>
97  };
98 
99  enum ApparentMagnitudeAlgorithm
100  {
101  Planesas, // Algorithm provided by Pere Planesas (Observatorio Astronomico Nacional)
102  Mueller, // G. Mueller, based on visual observations 1877-91. [Expl.Suppl.1961]
103  Harris, // Astronomical Almanac 1984 and later. These give V (instrumental) magnitudes (D.L. Harris)
104  UndefinedAlgorithm,
105  Generic // Visual magnitude based on phase angle and albedo
106  };
107 
108  Planet(const QString& englishName,
109  int flagLighting,
110  double radius,
111  double oblateness,
112  Vec3f halocolor,
113  float albedo,
114  const QString& texMapName,
115  const QString& normalMapName,
116  posFuncType _coordFunc,
117  void* userDataPtr,
118  OsculatingFunctType *osculatingFunc,
119  bool closeOrbit,
120  bool hidden,
121  bool hasAtmosphere,
122  bool hasHalo,
123  const QString &pTypeStr);
124 
125  virtual ~Planet();
126 
128  // Currently ensured by SolarSystem::init()
129  static void init();
130 
132  // Methods inherited from StelObject
146  virtual QString getInfoString(const StelCore *core, const InfoStringGroup& flags) const;
147  virtual double getCloseViewFov(const StelCore* core) const;
148  virtual double getSatellitesFov(const StelCore* core) const;
149  virtual double getParentSatellitesFov(const StelCore* core) const;
150  virtual float getVMagnitude(const StelCore* core) const;
151  virtual float getSelectPriority(const StelCore* core) const;
152  virtual Vec3f getInfoColor(void) const;
153  virtual QString getType(void) const {return "Planet";}
154  virtual Vec3d getJ2000EquatorialPos(const StelCore *core) const;
155  virtual QString getEnglishName(void) const;
156  virtual QString getNameI18n(void) const;
158  virtual double getAngularSize(const StelCore* core) const;
159  virtual bool hasAtmosphere(void) {return atmosphere;}
160  virtual bool hasHalo(void) {return halo;}
161 
163  // Methods of SolarSystem object
165  virtual void translateName(const StelTranslator &trans);
166 
167  // Draw the Planet
168  // GZ Made that virtual to allow comets having their own draw().
169  virtual void draw(StelCore* core, float maxMagLabels, const QFont& planetNameFont);
170 
172  // Methods specific to Planet
175  double getRadius(void) const {return radius;}
177  double getOneMinusOblateness(void) const {return oneMinusOblateness;}
179  double getSiderealDay(void) const {return re.period;}
181  // must be virtual for Comets.
182  virtual double getSiderealPeriod(void) const { return re.siderealPeriod; }
184  double getMeanSolarDay(void) const;
185 
186  const QString& getTextMapName() const {return texMapName;}
187  const QString getPlanetTypeString() const {return pTypeMap.value(pType);}
188  PlanetType getPlanetType() const {return pType;}
189 
190  void setNativeName(QString planet) { nativeName = planet; }
191 
192  ApparentMagnitudeAlgorithm getApparentMagnitudeAlgorithm() const { return vMagAlgorithm; }
193  const QString getApparentMagnitudeAlgorithmString() const { return vMagAlgorithmMap.value(vMagAlgorithm); }
194  void setApparentMagnitudeAlgorithm(QString algorithm);
195 
199  double getSiderealTime(double JD, double JDE) const;
200  Mat4d getRotEquatorialToVsop87(void) const;
201  void setRotEquatorialToVsop87(const Mat4d &m);
202 
203  const RotationElements &getRotationElements(void) const {return re;}
204 
205  // Compute the position in the parent Planet coordinate system
206  void computePositionWithoutOrbits(const double dateJDE);
207  void computePosition(const double dateJDE);
208 
209  // Compute the transformation matrix from the local Planet coordinate to the parent Planet coordinate.
210  // This requires both flavours of JD in cases involving Earth.
211  void computeTransMatrix(double JD, double JDE);
212 
213  // Get the phase angle (rad) for an observer at pos obsPos in heliocentric coordinates (in AU)
214  double getPhaseAngle(const Vec3d& obsPos) const;
215  // Get the elongation angle (rad) for an observer at pos obsPos in heliocentric coordinates (in AU)
216  double getElongation(const Vec3d& obsPos) const;
217  // Get the angular size of the spheroid of the planet (i.e. without the rings)
218  double getSpheroidAngularSize(const StelCore* core) const;
219  // Get the planet phase for an observer at pos obsPos in heliocentric coordinates (in AU)
220  float getPhase(const Vec3d& obsPos) const;
221 
222  // Set the orbital elements
223  void setRotationElements(float _period, float _offset, double _epoch,
224  float _obliquity, float _ascendingNode,
225  float _precessionRate, double _siderealPeriod);
226  double getRotAscendingnode(void) const {return re.ascendingNode;}
227  // return angle between axis and normal of ecliptic plane (or, for a moon, equatorial/reference plane defined by parent).
228  // TODO: decide if this is always angle between axis and J2000 ecliptic, or should be axis//current ecliptic!
229  double getRotObliquity(double JDE) const;
230 
232  Vec3d getEclipticPos() const;
233 
234  // Return the heliocentric ecliptical position
235  Vec3d getHeliocentricEclipticPos() const {return getHeliocentricPos(eclipticPos);}
236 
237  // Return the heliocentric transformation for local coordinate
238  Vec3d getHeliocentricPos(Vec3d) const;
239  void setHeliocentricEclipticPos(const Vec3d &pos);
240 
241  // Compute the distance to the given position in heliocentric coordinate (in AU)
242  double computeDistance(const Vec3d& obsHelioPos);
243  double getDistance(void) const {return distance;}
244 
245  void setRings(Ring* r) {rings = r;}
246 
247  void setSphereScale(float s) {sphereScale = s;}
248  float getSphereScale(void) const {return sphereScale;}
249 
250  const QSharedPointer<Planet> getParent(void) const {return parent;}
251 
252  static void setLabelColor(const Vec3f& lc) {labelColor = lc;}
253  static const Vec3f& getLabelColor(void) {return labelColor;}
254 
255  // update displayed elements. @param deltaTime: ms (since last call)
256  virtual void update(int deltaTime);
257 
258  void setFlagHints(bool b){hintFader = b;}
259  bool getFlagHints(void) const {return hintFader;}
260 
261  void setFlagLabels(bool b){flagLabels = b;}
262  bool getFlagLabels(void) const {return flagLabels;}
263 
264  bool flagNativeName;
265  void setFlagNativeName(bool b) { flagNativeName = b; }
266  bool getFlagNativeName(void) { return flagNativeName; }
267 
268  bool flagTranslatedName;
269  void setFlagTranslatedName(bool b) { flagTranslatedName = b; }
270  bool getFlagTranslatedName(void) { return flagTranslatedName; }
271 
273  // DEPRECATED
275  // Should move to an OrbitPath class which works on a SolarSystemObject, not a Planet
276  void setFlagOrbits(bool b){orbitFader = b;}
277  bool getFlagOrbits(void) const {return orbitFader;}
278  LinearFader orbitFader;
279  // draw orbital path of Planet
280  void drawOrbit(const StelCore*);
281  Vec3d orbit[ORBIT_SEGMENTS+1]; // store heliocentric coordinates for drawing the orbit
282  Vec3d orbitP[ORBIT_SEGMENTS+1]; // store local coordinate for orbit
283  double lastOrbitJDE;
284  double deltaJDE; // time difference between positional updates.
285  double deltaOrbitJDE;
286  bool orbitCached; // whether orbit calculations are cached for drawing orbit yet
287  bool closeOrbit; // whether to connect the beginning of the orbit line to
288  // the end: good for elliptical orbits, bad for parabolic
289  // and hyperbolic orbits
290 
291  static Vec3f orbitColor;
292  static void setOrbitColor(const Vec3f& oc) {orbitColor = oc;}
293  static const Vec3f& getOrbitColor() {return orbitColor;}
294 
295  static Vec3f orbitPlanetsColor;
296  static void setPlanetOrbitColor(const Vec3f& oc) { orbitPlanetsColor = oc;}
297  static const Vec3f& getPlanetOrbitColor() {return orbitPlanetsColor;}
298 
299  static Vec3f orbitAsteroidsColor;
300  static void setAsteroidOrbitColor(const Vec3f& oc) { orbitAsteroidsColor = oc;}
301  static const Vec3f& getAsteroidOrbitColor() {return orbitAsteroidsColor;}
302 
303  static Vec3f orbitCometsColor;
304  static void setCometOrbitColor(const Vec3f& oc) { orbitCometsColor = oc;}
305  static const Vec3f& getCometOrbitColor() {return orbitCometsColor;}
306 
307  static bool permanentDrawingOrbits;
308 
310  QVector<const Planet*> getCandidatesForShadow() const;
311 
312 protected:
313  static StelTextureSP texEarthShadow; // for lunar eclipses
314 
315  void computeModelMatrix(Mat4d &result) const;
316 
317  // Return the information string "ready to print" :)
318  QString getSkyLabel(const StelCore* core) const;
319 
320  // Draw the 3d model. Call the proper functions if there are rings etc..
321  void draw3dModel(StelCore* core, StelProjector::ModelViewTranformP transfo, float screenSz, bool drawOnlyRing=false);
322 
323  // Draw the 3D sphere
324  void drawSphere(StelPainter* painter, float screenSz, bool drawOnlyRing=false);
325 
326  // Draw the circle and name of the Planet
327  void drawHints(const StelCore* core, const QFont& planetNameFont);
328 
329  QString englishName; // english planet name
330  QString nameI18; // International translated name
331  QString nativeName; // Can be used in a skyculture
332  QString texMapName; // Texture file path
333  QString normalMapName; // Texture file path
334  int flagLighting; // Set whether light computation has to be proceed
335  RotationElements re; // Rotation param
336  double radius; // Planet radius in AU
337  double oneMinusOblateness; // (polar radius)/(equatorial radius)
338  Vec3d eclipticPos; // Position in AU in the rectangular ecliptic coordinate system
339  // centered on the parent Planet
340  Vec3d screenPos; // Used to store temporarily the 2D position on screen
341  Vec3d previousScreenPos; // The position of this planet in the previous frame.
342  Vec3f haloColor; // exclusively used for drawing the planet halo
343 
344  float albedo; // Planet albedo. Used for magnitude computation (but formula dubious!)
345  Mat4d rotLocalToParent; // GZ2015: was undocumented.
346  // Apparently this is the axis orientation with respect to the parent body. For planets, this is axis orientation w.r.t. VSOP87A/J2000 ecliptical system.
347  float axisRotation; // Rotation angle of the Planet on its axis.
348  // For Earth, this should be Greenwich Mean Sidereal Time GMST.
349  StelTextureSP texMap; // Planet map texture
350  StelTextureSP normalMap; // Planet normal map texture
351 
352  Ring* rings; // Planet rings
353  double distance; // Temporary variable used to store the distance to a given point
354  // it is used for sorting while drawing
355  float sphereScale; // Artificial scaling for better viewing
356  double lastJDE; // caches JDE of last positional computation
357  // The callback for the calculation of the equatorial rect heliocentric position at time JDE.
358  posFuncType coordFunc;
359  void* userDataPtr; // this is always used with an Orbit object.
360 
361  OsculatingFunctType *const osculatingFunc;
362  QSharedPointer<Planet> parent; // Planet parent i.e. sun for earth
363  QList<QSharedPointer<Planet> > satellites; // satellites of the Planet
364  LinearFader hintFader;
365  LinearFader labelsFader; // Store the current state of the label for this planet
366  bool flagLabels; // Define whether labels should be displayed
367  bool hidden; // useful for fake planets used as observation positions - not drawn or labeled
368  bool atmosphere; // Does the planet have an atmosphere?
369  bool halo; // Does the planet have a halo?
370  PlanetType pType; // Type of body
371 
372  ApparentMagnitudeAlgorithm vMagAlgorithm;
373 
374  static Vec3f labelColor;
375  static StelTextureSP hintCircleTex;
376  static QMap<PlanetType, QString> pTypeMap; // Maps fast type to english name.
377  static QMap<ApparentMagnitudeAlgorithm, QString> vMagAlgorithmMap;
378 
379  static bool flagCustomGrsSettings; // Is enabled usage of custom settings for calculation of position of Great Red Spot?
380  static double customGrsJD; // Initial JD for calculation of position of Great Red Spot
381  static int customGrsLongitude; // Longitude of Great Red Spot (System II, degrees)
382  static double customGrsDrift; // Annual drift of Great Red Spot position (degrees)
383 
384  // Shader-related variables
386  int projectionMatrix;
387  int texCoord;
388  int unprojectedVertex;
389  int vertex;
390  int texture;
391  int lightDirection;
392  int eyeDirection;
393  int diffuseLight;
394  int ambientLight;
395  int shadowCount;
396  int shadowData;
397  int sunInfo;
398  int skyBrightness;
399 
400  void initLocations(QOpenGLShaderProgram*);
401  };
402  static PlanetShaderVars planetShaderVars;
403  static QOpenGLShaderProgram* planetShaderProgram;
404 
405  // Shader-related variables
407  // Rings-specific variables
408  int isRing;
409  int ring;
410  int outerRadius;
411  int innerRadius;
412  int ringS;
413  };
414  static RingPlanetShaderVars ringPlanetShaderVars;
415  static QOpenGLShaderProgram* ringPlanetShaderProgram;
416 
418  // Moon-specific variables
419  int earthShadow;
420  int normalMap;
421  };
422  static MoonShaderVars moonShaderVars;
423  static QOpenGLShaderProgram* moonShaderProgram;
424 
425  static void initShader();
426  static void deinitShader();
427 };
428 
429 #endif // _PLANET_HPP_
430 
virtual void update(double deltaTime)
Update time-varying components.
void setFlagOrbits(bool b)
Set flag which determines if planet orbits are drawn or hidden.
virtual double getSiderealPeriod(void) const
Get duration of sidereal year.
Definition: Planet.hpp:182
Class used to translate strings to any language.
Implementation of StelFader which implements a linear transition.
Definition: StelFader.hpp:77
The base abstract class for sky objects used in Stellarium like Stars, Planets, Constellations etc...
Definition: StelObject.hpp:36
Define the StelTextureSP type.
PlanetType
numeric typecodes for the type descriptions in ssystem.ini
Definition: Planet.hpp:84
Main class for Stellarium core processing.
Definition: StelCore.hpp:48
void setFlagHints(bool b)
Set flag which determines if planet hints are drawn or hidden along labels.
void setFlagLabels(bool b)
Set flag which determines if planet labels are drawn or hidden.
bool getFlagLabels() const
Get the current value of the flag which determines if planet labels are drawn or hidden.
double getRadius(void) const
Get the radius of the planet in AU.
Definition: Planet.hpp:175
This StelObjectModule derivative is used to model SolarSystem bodies.
Definition: SolarSystem.hpp:47
Definition: Planet.hpp:62
double getSiderealDay(void) const
Get duration of sidereal day.
Definition: Planet.hpp:179
Provides functions for performing openGL drawing operations.
Definition: StelPainter.hpp:40
virtual void init()
Initialize the SolarSystem.
QSharedPointer< ModelViewTranform > ModelViewTranformP
Shared pointer on a ModelViewTranform instance (implement reference counting)
double getOneMinusOblateness(void) const
Get the value (1-f) for oblateness f.
Definition: Planet.hpp:177
bool getFlagOrbits() const
Get the current value of the flag which determines if planet orbits are drawn or hidden.
A templatized 3d vector compatible with openGL.
Definition: VecMath.hpp:33
Define the StelProjectorP type.
virtual QString getType(void) const
Return object&#39;s type. It should be the name of the class.
Definition: Planet.hpp:153
QSharedPointer< StelTexture > StelTextureSP
Use shared pointer to simplify memory managment.
bool getFlagHints() const
Get the current value of the flag which determines if planet hints are drawn or hidden along labels...
QString getPlanetType(QString planetName) const
Get type for Solar system bodies from scripts.
virtual void draw(StelCore *core)
Draw SolarSystem objects (planets).