Stellarium 0.12.4
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 <QString>
24 
25 #include "StelObject.hpp"
26 #include "StelProjector.hpp"
27 #include "VecMath.hpp"
28 #include "StelFader.hpp"
29 #include "renderer/GenericVertexTypes.hpp"
30 #include "renderer/StelIndexBuffer.hpp"
31 #include "renderer/StelVertexBuffer.hpp"
32 #include "StelProjectorType.hpp"
33 
34 // The callback type for the external position computation function
35 // The last variable is the userData pointer.
36 typedef void (*posFuncType)(double, double*, void*);
37 
38 typedef void (OsculatingFunctType)(double jd0,double jd,double xyz[3]);
39 
40 // epoch J2000: 12 UT on 1 Jan 2000
41 #define J2000 2451545.0
42 #define ORBIT_SEGMENTS 360
43 
44 class StelFont;
45 class StelTranslator;
46 
47 struct TrailPoint
48 {
49  Vec3d point;
50  double date;
51 };
52 
53 
55 {
56  int info;
57  int current;
58  int infoCount;
59  float infoSize;
60 };
61 
62 // Class used to store orbital elements
64 {
65 public:
66  RotationElements(void) : period(1.), offset(0.), epoch(J2000), obliquity(0.), ascendingNode(0.), precessionRate(0.) {}
67  float period; // rotation period
68  float offset; // rotation at epoch
69  double epoch;
70  float obliquity; // tilt of rotation axis w.r.t. ecliptic
71  float ascendingNode; // long. of ascending node of equator on the ecliptic
72  float precessionRate; // rate of precession of rotation axis in rads/day
73  double siderealPeriod; // sidereal period (Planet year in earth days)
74 };
75 
76 // Class to manage rings for planets like saturn
77 class Ring
78 {
79  friend class Planet;
80 public:
81  Ring(double radiusMin,double radiusMax,const QString &texname);
82  ~Ring(void);
83 
96  void draw(StelProjectorP projector, class StelRenderer* renderer, StelProjector::ModelViewTranformP transform, class StelGLSLShader *shader, double screenSz, ShadowPlanetShaderInfo *info);
97 
98  double getSize(void) const {return radiusMax;}
99 private:
100  const double radiusMin;
101  const double radiusMax;
102 
103  const QString texName;
104  class StelTextureNew* texture;
105 
107  class StelGeometryRing* ring;
108 };
109 
110 class Planet : public StelObject
111 {
112 protected:
116  {
125 
128 
131 
134 
140  void lazyInit(class StelRenderer* renderer);
142  bool loadPlanetShaders(StelRenderer *renderer);
143  };
144 
145 public:
146  friend class SolarSystem;
147  Planet(const QString& englishName,
148  int flagLighting,
149  double radius,
150  double oblateness,
151  Vec3f color,
152  float albedo,
153  const QString& texMapName,
154  posFuncType _coordFunc,
155  void* userDataPtr,
156  OsculatingFunctType *osculatingFunc,
157  bool closeOrbit,
158  bool hidden,
159  bool hasAtmosphere,
160  const QString &pType);
161 
162  ~Planet();
163 
165  // Methods inherited from StelObject
180  virtual QString getInfoString(const StelCore *core, const InfoStringGroup& flags) const;
181  virtual double getCloseViewFov(const StelCore* core) const;
182  virtual double getSatellitesFov(const StelCore* core) const;
183  virtual double getParentSatellitesFov(const StelCore* core) const;
184  virtual float getVMagnitude(const StelCore* core, bool withExtinction=false) const;
185  virtual float getSelectPriority(const StelCore* core) const;
186  virtual Vec3f getInfoColor(void) const;
187  virtual QString getType(void) const {return "Planet";}
188  virtual Vec3d getJ2000EquatorialPos(const StelCore *core) const;
189  virtual QString getEnglishName(void) const {return englishName;}
190  virtual QString getNameI18n(void) const {return nameI18;}
191  virtual double getAngularSize(const StelCore* core) const;
192  virtual bool hasAtmosphere(void) {return atmosphere;}
193 
195  // Methods of SolarSystem object
197  virtual void translateName(StelTranslator& trans);
198 
206  void draw(StelCore* core, class StelRenderer* renderer, float maxMagLabels,
207  const QFont& planetNameFont, SharedPlanetGraphics& planetGraphics);
208 
210  // Methods specific to Planet
213  double getRadius(void) const {return radius;}
215  double getSiderealDay(void) const {return re.period;}
217  double getSiderealPeriod(void) const { return re.siderealPeriod; }
219  double getMeanSolarDay(void) const;
220 
221  const QString& getTextMapName() const {return texMapName;}
222 
223  // Compute the z rotation to use from equatorial to geographic coordinates
224  double getSiderealTime(double jd) const;
225  Mat4d getRotEquatorialToVsop87(void) const;
226  void setRotEquatorialToVsop87(const Mat4d &m);
227 
228  const RotationElements &getRotationElements(void) const {return re;}
229 
230  // Compute the position in the parent Planet coordinate system
231  void computePositionWithoutOrbits(const double date);
232  void computePosition(const double date);
233 
234  // Compute the transformation matrix from the local Planet coordinate to the parent Planet coordinate
235  void computeTransMatrix(double date);
236 
237  // Compute the transformation matrix from model to world coordinates
238  void computeModelMatrix(Mat4d& result) const;
239 
240  // Get the phase angle (rad) for an observer at pos obsPos in heliocentric coordinates (in AU)
241  double getPhaseAngle(const Vec3d& obsPos) const;
242  // Get the elongation angle (rad) for an observer at pos obsPos in heliocentric coordinates (in AU)
243  double getElongation(const Vec3d& obsPos) const;
244  // Get the angular size of the spheroid of the planet (i.e. without the rings)
245  double getSpheroidAngularSize(const StelCore* core) const;
246  // Get the planet phase for an observer at pos obsPos in heliocentric coordinates (in AU)
247  float getPhase(const Vec3d& obsPos) const;
248 
249  // Set the orbital elements
250  void setRotationElements(float _period, float _offset, double _epoch,
251  float _obliquity, float _ascendingNode,
252  float _precessionRate, double _siderealPeriod);
253  double getRotAscendingnode(void) const {return re.ascendingNode;}
254  double getRotObliquity(void) const {return re.obliquity;}
255 
257  Vec3d getEclipticPos() const;
258 
259  // Return the heliocentric ecliptical position
260  Vec3d getHeliocentricEclipticPos() const;
261 
262  // Return the heliocentric transformation for local coordinate
263  Vec3d getHeliocentricPos(Vec3d) const;
264  void setHeliocentricEclipticPos(const Vec3d &pos);
265 
266  // Compute the distance to the given position in heliocentric coordinate (in AU)
267  double computeDistance(const Vec3d& obsHelioPos);
268  double getDistance(void) const {return distance;}
269 
270  void setRings(Ring* r) {rings = r;}
271 
272  void setSphereScale(float s);
273 
274  float getSphereScale(void) const {return sphereScale;}
275 
276  const QSharedPointer<Planet> getParent(void) const {return parent;}
277 
278  static void setLabelColor(const Vec3f& lc) {labelColor = lc;}
279  static const Vec3f& getLabelColor(void) {return labelColor;}
280 
281  void update(int deltaTime);
282 
283  void setFlagHints(bool b){hintFader = b;}
284  bool getFlagHints(void) const {return hintFader;}
285 
286  void setFlagLabels(bool b){flagLabels = b;}
287  bool getFlagLabels(void) const {return flagLabels;}
288 
290  // DEPRECATED
292  // Should move to an OrbitPath class which works on a SolarSystemObject, not a Planet
293  void setFlagOrbits(bool b){orbitFader = b;}
294  bool getFlagOrbits(void) const {return orbitFader;}
295 
297  struct Vertex2D
298  {
299  Vec2f position;
300  Vertex2D(const float x, const float y) : position(x, y){}
301  VERTEX_ATTRIBUTES(Vec2f Position);
302  };
303 
306 
307  LinearFader orbitFader;
308  // draw orbital path of Planet
309  void drawOrbit(const StelCore* core, class StelRenderer* renderer);
310  Vec3d orbit[ORBIT_SEGMENTS+1]; // store heliocentric coordinates for drawing the orbit
311  Vec3d orbitP[ORBIT_SEGMENTS+1]; // store local coordinate for orbit
312  double lastOrbitJD;
313  double deltaJD;
314  double deltaOrbitJD;
315  bool orbitCached; // whether orbit calculations are cached for drawing orbit yet
316  bool closeOrbit; // whether to connect the beginning of the orbit line to
317  // the end: good for elliptical orbits, bad for parabolic
318  // and hyperbolic orbits
319 
320  static Vec3f orbitColor;
321  static void setOrbitColor(const Vec3f& oc) {orbitColor = oc;}
322  static const Vec3f& getOrbitColor() {return orbitColor;}
323 
324 protected:
325  // draw earth shadow on moon for lunar eclipses
326  void drawEarthShadow(StelCore* core, class StelRenderer* renderer,
327  SharedPlanetGraphics& planetGraphics);
328 
329  // Return the information string "ready to print" :)
330  QString getSkyLabel(const StelCore* core) const;
331 
339  void draw3dModel(StelCore* core, class StelRenderer* renderer,
340  SharedPlanetGraphics& planetGraphics,
341  StelProjector::ModelViewTranformP transfo, float screenSz);
342 
351  void drawUnlitSphere(class StelRenderer* renderer, StelProjectorP projector);
352 
363  void drawSphere(class StelRenderer* renderer, StelProjectorP projector,
364  const struct StelLight* light, SharedPlanetGraphics &planetGraphics, float screenSz);
365 
366  // Draw the circle and name of the Planet
367  void drawHints(const StelCore* core, class StelRenderer* renderer,
368  const QFont& planetNameFont, SharedPlanetGraphics& planetGraphics);
369 
370  QString englishName; // english planet name
371  QString nameI18; // International translated name
372  QString texMapName; // Texture file path
373  RotationElements re; // Rotation param
374 
375  // Note: vertex/index buffer generation depends on the fact that
376  // flagLighting, radius and oneMinusOblateness don't change.
377  // If they change, buffers will have to be regenerated to reflect the change.
378  const int flagLighting; // Set whether light computation has to be proceed
379  const double radius; // Planet radius in AU
380  const double oneMinusOblateness; // (polar radius)/(equatorial radius)
381  Vec3d eclipticPos; // Position in AU in the rectangular ecliptic coordinate system
382  // centered on the parent Planet
383  Vec3d screenPos; // Used to store temporarily the 2D position on screen
384  Vec3d previousScreenPos; // The position of this planet in the previous frame.
385  Vec3f color;
386 
387  float albedo; // Planet albedo
388  Mat4d rotLocalToParent;
389  float axisRotation; // Rotation angle of the Planet on it's axis
390 
391  class StelTextureNew* texture; // Planet map texture
392 
393  Ring* rings; // Planet rings
394  double distance; // Temporary variable used to store the distance to a given point
395  // it is used for sorting while drawing
396  float sphereScale; // Artificial scaling for better viewing
397  double lastJD;
398  // The callback for the calculation of the equatorial rect heliocentric position at time JD.
399  posFuncType coordFunc;
400  void* userDataPtr;
401 
402  OsculatingFunctType *const osculatingFunc;
403  QSharedPointer<Planet> parent; // Planet parent i.e. sun for earth
404  QList<QSharedPointer<Planet> > satellites; // satellites of the Planet
405  LinearFader hintFader;
406  LinearFader labelsFader; // Store the current state of the label for this planet
407  bool flagLabels; // Define whether labels should be displayed
408  bool hidden; // useful for fake planets used as observation positions - not drawn or labeled
409  bool atmosphere; // Does the planet have an atmosphere?
410  QString pType; // Type of body
411 
416 
417  static Vec3f labelColor;
418 };
419 
420 #endif // _PLANET_HPP_
421