Stellarium 0.13.2
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 jd0,double jd,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 orbital elements
49 {
50 public:
51  RotationElements(void) : period(1.), offset(0.), epoch(J2000), obliquity(0.), ascendingNode(0.), precessionRate(0.), siderealPeriod(0.) {}
52  float period; // rotation period
53  float offset; // rotation at epoch
54  double epoch;
55  float obliquity; // tilt of rotation axis w.r.t. ecliptic
56  float ascendingNode; // long. of ascending node of equator on the ecliptic
57  float precessionRate; // rate of precession of rotation axis in rads/day
58  double siderealPeriod; // sidereal period (Planet year in 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().
84  enum PlanetType
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  isPlutoid, // ssystem.ini: type="plutoid"
91  isComet, // ssystem.ini: type="comet"
92  isUNDEFINED // ssystem.ini: type=<anything else>
93  };
94 
95  enum ApparentMagnitudeAlgorithm
96  {
97  Planesas, // Algorithm provided by Pere Planesas (Observatorio Astronomico Nacional)
98  Mueller, // G. Mueller, based on visual observations 1877-91. [Expl.Suppl.1961]
99  Harris, // Astronomical Almanac 1984 and later. These give V (instrumental) magnitudes (D.L. Harris)
100  UndefinedAlgorithm
101  };
102 
103  Planet(const QString& englishName,
104  int flagLighting,
105  double radius,
106  double oblateness,
107  Vec3f color,
108  float albedo,
109  const QString& texMapName,
110  const QString& normalMapName,
111  posFuncType _coordFunc,
112  void* userDataPtr,
113  OsculatingFunctType *osculatingFunc,
114  bool closeOrbit,
115  bool hidden,
116  bool hasAtmosphere,
117  bool hasHalo,
118  const QString &pTypeStr);
119 
120  virtual ~Planet();
121 
123  // Currently ensured by SolarSystem::init()
124  static void init();
125 
127  // Methods inherited from StelObject
141  virtual QString getInfoString(const StelCore *core, const InfoStringGroup& flags) const;
142  virtual double getCloseViewFov(const StelCore* core) const;
143  virtual double getSatellitesFov(const StelCore* core) const;
144  virtual double getParentSatellitesFov(const StelCore* core) const;
145  virtual float getVMagnitude(const StelCore* core) const;
146  virtual float getSelectPriority(const StelCore* core) const;
147  virtual Vec3f getInfoColor(void) const;
148  virtual QString getType(void) const {return "Planet";}
149  virtual Vec3d getJ2000EquatorialPos(const StelCore *core) const;
150  virtual QString getEnglishName(void) const {return englishName;}
151  virtual QString getNameI18n(void) const {return nameI18;}
152  virtual double getAngularSize(const StelCore* core) const;
153  virtual bool hasAtmosphere(void) {return atmosphere;}
154  virtual bool hasHalo(void) {return halo;}
155 
157  // Methods of SolarSystem object
159  virtual void translateName(const StelTranslator &trans);
160 
161  // Draw the Planet
162  // GZ Made that virtual to allow comets having their own draw().
163  virtual void draw(StelCore* core, float maxMagLabels, const QFont& planetNameFont);
164 
166  // Methods specific to Planet
169  double getRadius(void) const {return radius;}
171  double getSiderealDay(void) const {return re.period;}
173  // GZ: made that virtual for Comets.
174  virtual double getSiderealPeriod(void) const { return re.siderealPeriod; }
176  double getMeanSolarDay(void) const;
177 
178  const QString& getTextMapName() const {return texMapName;}
179  const QString getPlanetTypeString() const {return pTypeMap.value(pType);}
180  PlanetType getPlanetType() const {return pType;}
181 
182  ApparentMagnitudeAlgorithm getApparentMagnitudeAlgorithm() const { return vMagAlgorithm; }
183  const QString getApparentMagnitudeAlgorithmString() const { return vMagAlgorithmMap.value(vMagAlgorithm); }
184  void setApparentMagnitudeAlgorithm(QString algorithm);
185 
186  // Compute the z rotation to use from equatorial to geographic coordinates
187  double getSiderealTime(double jd) const;
188  Mat4d getRotEquatorialToVsop87(void) const;
189  void setRotEquatorialToVsop87(const Mat4d &m);
190 
191  const RotationElements &getRotationElements(void) const {return re;}
192 
193  // Compute the position in the parent Planet coordinate system
194  void computePositionWithoutOrbits(const double dateJD);
195  virtual void computePosition(const double dateJD);// GZ: gets overridden in Comet!
196 
197  // Compute the transformation matrix from the local Planet coordinate to the parent Planet coordinate
198  void computeTransMatrix(double date);
199 
200  // Get the phase angle (rad) for an observer at pos obsPos in heliocentric coordinates (in AU)
201  double getPhaseAngle(const Vec3d& obsPos) const;
202  // Get the elongation angle (rad) for an observer at pos obsPos in heliocentric coordinates (in AU)
203  double getElongation(const Vec3d& obsPos) const;
204  // Get the angular size of the spheroid of the planet (i.e. without the rings)
205  double getSpheroidAngularSize(const StelCore* core) const;
206  // Get the planet phase for an observer at pos obsPos in heliocentric coordinates (in AU)
207  float getPhase(const Vec3d& obsPos) const;
208 
209  // Set the orbital elements
210  void setRotationElements(float _period, float _offset, double _epoch,
211  float _obliquity, float _ascendingNode,
212  float _precessionRate, double _siderealPeriod);
213  double getRotAscendingnode(void) const {return re.ascendingNode;}
214  double getRotObliquity(double JDay) const;
215 
217  Vec3d getEclipticPos() const;
218 
219  // Return the heliocentric ecliptical position
220  Vec3d getHeliocentricEclipticPos() const;
221 
222  // Return the heliocentric transformation for local coordinate
223  Vec3d getHeliocentricPos(Vec3d) const;
224  void setHeliocentricEclipticPos(const Vec3d &pos);
225 
226  // Compute the distance to the given position in heliocentric coordinate (in AU)
227  double computeDistance(const Vec3d& obsHelioPos);
228  double getDistance(void) const {return distance;}
229 
230  void setRings(Ring* r) {rings = r;}
231 
232  void setSphereScale(float s) {sphereScale = s;}
233  float getSphereScale(void) const {return sphereScale;}
234 
235  const QSharedPointer<Planet> getParent(void) const {return parent;}
236 
237  static void setLabelColor(const Vec3f& lc) {labelColor = lc;}
238  static const Vec3f& getLabelColor(void) {return labelColor;}
239 
240  // update displayed elements. @param deltaTime: ms (?)
241  void update(int deltaTime);
242 
243  void setFlagHints(bool b){hintFader = b;}
244  bool getFlagHints(void) const {return hintFader;}
245 
246  void setFlagLabels(bool b){flagLabels = b;}
247  bool getFlagLabels(void) const {return flagLabels;}
248 
250  // DEPRECATED
252  // Should move to an OrbitPath class which works on a SolarSystemObject, not a Planet
253  void setFlagOrbits(bool b){orbitFader = b;}
254  bool getFlagOrbits(void) const {return orbitFader;}
255  LinearFader orbitFader;
256  // draw orbital path of Planet
257  void drawOrbit(const StelCore*);
258  Vec3d orbit[ORBIT_SEGMENTS+1]; // store heliocentric coordinates for drawing the orbit
259  Vec3d orbitP[ORBIT_SEGMENTS+1]; // store local coordinate for orbit
260  double lastOrbitJD;
261  double deltaJD; // time difference between positional updates.
262  double deltaOrbitJD;
263  bool orbitCached; // whether orbit calculations are cached for drawing orbit yet
264  bool closeOrbit; // whether to connect the beginning of the orbit line to
265  // the end: good for elliptical orbits, bad for parabolic
266  // and hyperbolic orbits
267 
268  static Vec3f orbitColor;
269  static void setOrbitColor(const Vec3f& oc) {orbitColor = oc;}
270  static const Vec3f& getOrbitColor() {return orbitColor;}
271 
273  QVector<const Planet*> getCandidatesForShadow() const;
274 
275 protected:
276  static StelTextureSP texEarthShadow; // for lunar eclipses
277 
278  void computeModelMatrix(Mat4d &result) const;
279 
280  // Return the information string "ready to print" :)
281  QString getSkyLabel(const StelCore* core) const;
282 
283  // Draw the 3d model. Call the proper functions if there are rings etc..
284  void draw3dModel(StelCore* core, StelProjector::ModelViewTranformP transfo, float screenSz, bool drawOnlyRing=false);
285 
286  // Draw the 3D sphere
287  void drawSphere(StelPainter* painter, float screenSz, bool drawOnlyRing=false);
288 
289  // Draw the circle and name of the Planet
290  void drawHints(const StelCore* core, const QFont& planetNameFont);
291 
292  QString englishName; // english planet name
293  QString nameI18; // International translated name
294  QString texMapName; // Texture file path
295  QString normalMapName; // Texture file path
296  int flagLighting; // Set whether light computation has to be proceed
297  RotationElements re; // Rotation param
298  double radius; // Planet radius in AU
299  double oneMinusOblateness; // (polar radius)/(equatorial radius)
300  Vec3d eclipticPos; // Position in AU in the rectangular ecliptic coordinate system
301  // centered on the parent Planet
302  Vec3d screenPos; // Used to store temporarily the 2D position on screen
303  Vec3d previousScreenPos; // The position of this planet in the previous frame.
304  Vec3f color; // exclusively used for drawing the planet halo
305 
306  float albedo; // Planet albedo. Used for magnitude computation (but formula dubious!)
307  Mat4d rotLocalToParent;
308  float axisRotation; // Rotation angle of the Planet on it's axis
309  StelTextureSP texMap; // Planet map texture
310  StelTextureSP normalMap; // Planet normal map texture
311 
312  Ring* rings; // Planet rings
313  double distance; // Temporary variable used to store the distance to a given point
314  // it is used for sorting while drawing
315  float sphereScale; // Artificial scaling for better viewing
316  double lastJD; // caches JD of last positional computation
317  // The callback for the calculation of the equatorial rect heliocentric position at time JD.
318  posFuncType coordFunc;
319  void* userDataPtr;
320 
321  OsculatingFunctType *const osculatingFunc;
322  QSharedPointer<Planet> parent; // Planet parent i.e. sun for earth
323  QList<QSharedPointer<Planet> > satellites; // satellites of the Planet
324  LinearFader hintFader;
325  LinearFader labelsFader; // Store the current state of the label for this planet
326  bool flagLabels; // Define whether labels should be displayed
327  bool hidden; // useful for fake planets used as observation positions - not drawn or labeled
328  bool atmosphere; // Does the planet have an atmosphere?
329  bool halo; // Does the planet have a halo?
330  PlanetType pType; // Type of body
331 
332  ApparentMagnitudeAlgorithm vMagAlgorithm;
333 
334  static Vec3f labelColor;
335  static StelTextureSP hintCircleTex;
336  static QMap<PlanetType, QString> pTypeMap; // Maps fast type to english name.
337  static QMap<ApparentMagnitudeAlgorithm, QString> vMagAlgorithmMap;
338 
339  // Shader-related variables
341  int projectionMatrix;
342  int texCoord;
343  int unprojectedVertex;
344  int vertex;
345  int texture;
346  int lightDirection;
347  int eyeDirection;
348  int diffuseLight;
349  int ambientLight;
350  int shadowCount;
351  int shadowData;
352  int sunInfo;
353 
354  void initLocations(QOpenGLShaderProgram*);
355  };
356  static PlanetShaderVars planetShaderVars;
357  static QOpenGLShaderProgram* planetShaderProgram;
358 
359  // Shader-related variables
361  // Rings-specific variables
362  int isRing;
363  int ring;
364  int outerRadius;
365  int innerRadius;
366  int ringS;
367  };
368  static RingPlanetShaderVars ringPlanetShaderVars;
369  static QOpenGLShaderProgram* ringPlanetShaderProgram;
370 
372  // Moon-specific variables
373  int earthShadow;
374  int normalMap;
375  };
376  static MoonShaderVars moonShaderVars;
377  static QOpenGLShaderProgram* moonShaderProgram;
378 
379  static void initShader();
380  static void deinitShader();
381 
382 };
383 
384 #endif // _PLANET_HPP_
385 
Q_ENUMS(PlanetType) Q_ENUMS(ApparentMagnitudeAlgorithm) enum PlanetType
numeric typecodes for the type descriptions in ssystem.ini
Definition: Planet.hpp:78
QVector< const Planet * > getCandidatesForShadow() const
Return the list of planets which project some shadow on this planet.
virtual void update(double deltaTime)
Update time-varying components.
void setFlagOrbits(bool b)
Set flag which determines if planet orbits are drawn or hidden.
double getMeanSolarDay(void) const
Get duration of mean solar day.
virtual double getSiderealPeriod(void) const
Get duration of sidereal year.
Definition: Planet.hpp:174
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
virtual QString getNameI18n(void) const
Return translated object's name.
Definition: Planet.hpp:151
Define the StelTextureSP type.
virtual double getAngularSize(const StelCore *core) const
Return the angular radius of a circle containing the object as seen from the observer with the circle...
virtual Vec3f getInfoColor(void) const
Get a color used to display info about the object.
Main class for Stellarium core processing.
Definition: StelCore.hpp:46
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:169
virtual QString getEnglishName(void) const
Return object's name in english.
Definition: Planet.hpp:150
This StelObjectModule derivative is used to model SolarSystem bodies.
Definition: SolarSystem.hpp:46
virtual QString getInfoString(const StelCore *core, const InfoStringGroup &flags) const
Get a string with data about the Planet.
Definition: Planet.hpp:62
A templatized column-major 4x4 matrix compatible with openGL.
Definition: VecMath.hpp:33
virtual double getCloseViewFov(const StelCore *core) const
Return the best FOV in degree to use for a close view of the object.
double getSiderealDay(void) const
Get duration of sidereal day.
Definition: Planet.hpp:171
virtual double getSatellitesFov(const StelCore *core) const
Return the best FOV in degree to use for a global view of the object satellite system (if there are s...
virtual Vec3d getJ2000EquatorialPos(const StelCore *core) const
Get observer-centered equatorial coordinates at equinox J2000.
Provides functions for performing openGL drawing operations.
Definition: StelPainter.hpp:40
virtual void translateName(const StelTranslator &trans)
Translate planet name using the passed translator.
virtual float getVMagnitude(const StelCore *core) const
Return object's apparent V magnitude as seen from observer, without including extinction.
QSharedPointer< ModelViewTranform > ModelViewTranformP
Shared pointer on a ModelViewTranform instance (implement reference counting)
bool getFlagOrbits() const
Get the current value of the flag which determines if planet orbits are drawn or hidden.
static void init()
Initializes static vars. Must be called before creating first planet.
A templatized 3d vector compatible with openGL.
Definition: VecMath.hpp:31
Define the StelProjectorP type.
virtual QString getType(void) const
Return object's type. It should be the name of the class.
Definition: Planet.hpp:148
Vec3d getEclipticPos() const
Get the Planet position in the parent Planet ecliptic coordinate in AU.
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 float getSelectPriority(const StelCore *core) const
Return a priority value which is used to discriminate objects by priority As for magnitudes, the lower is the higher priority.
virtual void draw(StelCore *core)
Draw SolarSystem objects (planets).