Stellarium 0.13.1
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)
80  // GZ: Until 0.13 QStrings were used for types.
81  // GZ: Enums are slightly faster than string comparisons in time-critical comparisons.
82  // GZ: If other types are introduced, add here and the string in init().
83  enum PlanetType
84  {
85  isStar, // ssystem.ini: type="star"
86  isPlanet, // ssystem.ini: type="planet"
87  isMoon, // ssystem.ini: type="moon"
88  isAsteroid, // ssystem.ini: type="asteroid"
89  isPlutoid, // ssystem.ini: type="plutoid"
90  isComet, // ssystem.ini: type="comet"
91  isUNDEFINED // ssystem.ini: type=<anything else>
92  };
93 
94  Planet(const QString& englishName,
95  int flagLighting,
96  double radius,
97  double oblateness,
98  Vec3f color,
99  float albedo,
100  const QString& texMapName,
101  const QString& normalMapName,
102  posFuncType _coordFunc,
103  void* userDataPtr,
104  OsculatingFunctType *osculatingFunc,
105  bool closeOrbit,
106  bool hidden,
107  bool hasAtmosphere,
108  bool hasHalo,
109  const QString &pTypeStr);
110 
111  virtual ~Planet();
112 
114  // Currently ensured by SolarSystem::init()
115  static void init();
116 
118  // Methods inherited from StelObject
132  virtual QString getInfoString(const StelCore *core, const InfoStringGroup& flags) const;
133  virtual double getCloseViewFov(const StelCore* core) const;
134  virtual double getSatellitesFov(const StelCore* core) const;
135  virtual double getParentSatellitesFov(const StelCore* core) const;
136  virtual float getVMagnitude(const StelCore* core) const;
137  virtual float getSelectPriority(const StelCore* core) const;
138  virtual Vec3f getInfoColor(void) const;
139  virtual QString getType(void) const {return "Planet";}
140  virtual Vec3d getJ2000EquatorialPos(const StelCore *core) const;
141  virtual QString getEnglishName(void) const {return englishName;}
142  virtual QString getNameI18n(void) const {return nameI18;}
143  virtual double getAngularSize(const StelCore* core) const;
144  virtual bool hasAtmosphere(void) {return atmosphere;}
145  virtual bool hasHalo(void) {return halo;}
146 
148  // Methods of SolarSystem object
150  virtual void translateName(const StelTranslator &trans);
151 
152  // Draw the Planet
153  // GZ Made that virtual to allow comets having their own draw().
154  virtual void draw(StelCore* core, float maxMagLabels, const QFont& planetNameFont);
155 
157  // Methods specific to Planet
160  double getRadius(void) const {return radius;}
162  double getSiderealDay(void) const {return re.period;}
164  // GZ: made that virtual for Comets.
165  virtual double getSiderealPeriod(void) const { return re.siderealPeriod; }
167  double getMeanSolarDay(void) const;
168 
169  const QString& getTextMapName() const {return texMapName;}
170  const QString getPlanetTypeString() const {return pTypeMap.value(pType);}
171  PlanetType getPlanetType() const {return pType;}
172 
173  // Compute the z rotation to use from equatorial to geographic coordinates
174  double getSiderealTime(double jd) const;
175  Mat4d getRotEquatorialToVsop87(void) const;
176  void setRotEquatorialToVsop87(const Mat4d &m);
177 
178  const RotationElements &getRotationElements(void) const {return re;}
179 
180  // Compute the position in the parent Planet coordinate system
181  void computePositionWithoutOrbits(const double dateJD);
182  virtual void computePosition(const double dateJD);// GZ: gets overridden in Comet!
183 
184  // Compute the transformation matrix from the local Planet coordinate to the parent Planet coordinate
185  void computeTransMatrix(double date);
186 
187  // Get the phase angle (rad) for an observer at pos obsPos in heliocentric coordinates (in AU)
188  double getPhaseAngle(const Vec3d& obsPos) const;
189  // Get the elongation angle (rad) for an observer at pos obsPos in heliocentric coordinates (in AU)
190  double getElongation(const Vec3d& obsPos) const;
191  // Get the angular size of the spheroid of the planet (i.e. without the rings)
192  double getSpheroidAngularSize(const StelCore* core) const;
193  // Get the planet phase for an observer at pos obsPos in heliocentric coordinates (in AU)
194  float getPhase(const Vec3d& obsPos) const;
195 
196  // Set the orbital elements
197  void setRotationElements(float _period, float _offset, double _epoch,
198  float _obliquity, float _ascendingNode,
199  float _precessionRate, double _siderealPeriod);
200  double getRotAscendingnode(void) const {return re.ascendingNode;}
201  double getRotObliquity(double JDay) const;
202 
204  Vec3d getEclipticPos() const;
205 
206  // Return the heliocentric ecliptical position
207  Vec3d getHeliocentricEclipticPos() const;
208 
209  // Return the heliocentric transformation for local coordinate
210  Vec3d getHeliocentricPos(Vec3d) const;
211  void setHeliocentricEclipticPos(const Vec3d &pos);
212 
213  // Compute the distance to the given position in heliocentric coordinate (in AU)
214  double computeDistance(const Vec3d& obsHelioPos);
215  double getDistance(void) const {return distance;}
216 
217  void setRings(Ring* r) {rings = r;}
218 
219  void setSphereScale(float s) {sphereScale = s;}
220  float getSphereScale(void) const {return sphereScale;}
221 
222  const QSharedPointer<Planet> getParent(void) const {return parent;}
223 
224  static void setLabelColor(const Vec3f& lc) {labelColor = lc;}
225  static const Vec3f& getLabelColor(void) {return labelColor;}
226 
227  // update displayed elements. @param deltaTime: ms (?)
228  void update(int deltaTime);
229 
230  void setFlagHints(bool b){hintFader = b;}
231  bool getFlagHints(void) const {return hintFader;}
232 
233  void setFlagLabels(bool b){flagLabels = b;}
234  bool getFlagLabels(void) const {return flagLabels;}
235 
237  // DEPRECATED
239  // Should move to an OrbitPath class which works on a SolarSystemObject, not a Planet
240  void setFlagOrbits(bool b){orbitFader = b;}
241  bool getFlagOrbits(void) const {return orbitFader;}
242  LinearFader orbitFader;
243  // draw orbital path of Planet
244  void drawOrbit(const StelCore*);
245  Vec3d orbit[ORBIT_SEGMENTS+1]; // store heliocentric coordinates for drawing the orbit
246  Vec3d orbitP[ORBIT_SEGMENTS+1]; // store local coordinate for orbit
247  double lastOrbitJD;
248  double deltaJD; // time difference between positional updates.
249  double deltaOrbitJD;
250  bool orbitCached; // whether orbit calculations are cached for drawing orbit yet
251  bool closeOrbit; // whether to connect the beginning of the orbit line to
252  // the end: good for elliptical orbits, bad for parabolic
253  // and hyperbolic orbits
254 
255  static Vec3f orbitColor;
256  static void setOrbitColor(const Vec3f& oc) {orbitColor = oc;}
257  static const Vec3f& getOrbitColor() {return orbitColor;}
258 
260  QVector<const Planet*> getCandidatesForShadow() const;
261 
262 protected:
263  static StelTextureSP texEarthShadow; // for lunar eclipses
264 
265  void computeModelMatrix(Mat4d &result) const;
266 
267  // Return the information string "ready to print" :)
268  QString getSkyLabel(const StelCore* core) const;
269 
270  // Draw the 3d model. Call the proper functions if there are rings etc..
271  void draw3dModel(StelCore* core, StelProjector::ModelViewTranformP transfo, float screenSz, bool drawOnlyRing=false);
272 
273  // Draw the 3D sphere
274  void drawSphere(StelPainter* painter, float screenSz, bool drawOnlyRing=false);
275 
276  // Draw the circle and name of the Planet
277  void drawHints(const StelCore* core, const QFont& planetNameFont);
278 
279  QString englishName; // english planet name
280  QString nameI18; // International translated name
281  QString texMapName; // Texture file path
282  QString normalMapName; // Texture file path
283  int flagLighting; // Set whether light computation has to be proceed
284  RotationElements re; // Rotation param
285  double radius; // Planet radius in AU
286  double oneMinusOblateness; // (polar radius)/(equatorial radius)
287  Vec3d eclipticPos; // Position in AU in the rectangular ecliptic coordinate system
288  // centered on the parent Planet
289  Vec3d screenPos; // Used to store temporarily the 2D position on screen
290  Vec3d previousScreenPos; // The position of this planet in the previous frame.
291  Vec3f color; // exclusively used for drawing the planet halo
292 
293  float albedo; // Planet albedo. Used for magnitude computation (but formula dubious!)
294  Mat4d rotLocalToParent;
295  float axisRotation; // Rotation angle of the Planet on it's axis
296  StelTextureSP texMap; // Planet map texture
297  StelTextureSP normalMap; // Planet normal map texture
298 
299  Ring* rings; // Planet rings
300  double distance; // Temporary variable used to store the distance to a given point
301  // it is used for sorting while drawing
302  float sphereScale; // Artificial scaling for better viewing
303  double lastJD; // caches JD of last positional computation
304  // The callback for the calculation of the equatorial rect heliocentric position at time JD.
305  posFuncType coordFunc;
306  void* userDataPtr;
307 
308  OsculatingFunctType *const osculatingFunc;
309  QSharedPointer<Planet> parent; // Planet parent i.e. sun for earth
310  QList<QSharedPointer<Planet> > satellites; // satellites of the Planet
311  LinearFader hintFader;
312  LinearFader labelsFader; // Store the current state of the label for this planet
313  bool flagLabels; // Define whether labels should be displayed
314  bool hidden; // useful for fake planets used as observation positions - not drawn or labeled
315  bool atmosphere; // Does the planet have an atmosphere?
316  bool halo; // Does the planet have a halo?
317  // QString pTypeStr; // Type of body, old version just had a string here.
318  PlanetType pType; // GZ this is now a proper type...
319 
320  static Vec3f labelColor;
321  static StelTextureSP hintCircleTex;
322  static QMap<PlanetType, QString> pTypeMap; // GZ: maps fast type to english name.
323 
324  // Shader-related variables
326  int projectionMatrix;
327  int texCoord;
328  int unprojectedVertex;
329  int vertex;
330  int texture;
331  int lightDirection;
332  int eyeDirection;
333  int diffuseLight;
334  int ambientLight;
335  int shadowCount;
336  int shadowData;
337  int sunInfo;
338 
339  void initLocations(QOpenGLShaderProgram*);
340  };
341  static PlanetShaderVars planetShaderVars;
342  static QOpenGLShaderProgram* planetShaderProgram;
343 
344  // Shader-related variables
346  // Rings-specific variables
347  int isRing;
348  int ring;
349  int outerRadius;
350  int innerRadius;
351  int ringS;
352  };
353  static RingPlanetShaderVars ringPlanetShaderVars;
354  static QOpenGLShaderProgram* ringPlanetShaderProgram;
355 
357  // Moon-specific variables
358  int earthShadow;
359  int normalMap;
360  };
361  static MoonShaderVars moonShaderVars;
362  static QOpenGLShaderProgram* moonShaderProgram;
363 
364  static void initShader();
365  static void deinitShader();
366 
367 };
368 
369 #endif // _PLANET_HPP_
370 
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:165
Class used to translate strings to any language.
Implementation of StelFader which implements a linear transition.
Definition: StelFader.hpp:79
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:142
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.
Q_ENUMS(PlanetType) enum PlanetType
numeric typecodes for the type descriptions in ssystem.ini
Definition: Planet.hpp:78
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:160
virtual QString getEnglishName(void) const
Return object's name in english.
Definition: Planet.hpp:141
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:35
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:162
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:33
Define the StelProjectorP type.
virtual QString getType(void) const
Return object's type. It should be the name of the class.
Definition: Planet.hpp:139
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).