Stellarium 0.13.0
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
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  */
20 #ifndef _PLANET_HPP_
21 #define _PLANET_HPP_
23 #include "StelObject.hpp"
24 #include "StelProjector.hpp"
25 #include "VecMath.hpp"
26 #include "StelFader.hpp"
27 #include "StelTextureTypes.hpp"
28 #include "StelProjectorType.hpp"
30 #include <QString>
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*);
36 typedef void (OsculatingFunctType)(double jd0,double jd,double xyz[3]);
38 // epoch J2000: 12 UT on 1 Jan 2000
39 #define J2000 2451545.0
40 #define ORBIT_SEGMENTS 360
42 class StelFont;
43 class StelPainter;
44 class StelTranslator;
46 struct TrailPoint
47 {
48  Vec3d point;
49  double date;
50 };
53 // Class used to store orbital elements
55 {
56 public:
57  RotationElements(void) : period(1.), offset(0.), epoch(J2000), obliquity(0.), ascendingNode(0.), precessionRate(0.) {}
58  float period; // rotation period
59  float offset; // rotation at epoch
60  double epoch;
61  float obliquity; // tilt of rotation axis w.r.t. ecliptic
62  float ascendingNode; // long. of ascending node of equator on the ecliptic
63  float precessionRate; // rate of precession of rotation axis in rads/day
64  double siderealPeriod; // sidereal period (Planet year in earth days)
65 };
67 // Class to manage rings for planets like saturn
68 class Ring
69 {
70 public:
71  Ring(double radiusMin,double radiusMax,const QString &texname);
72  ~Ring(void);
73  void draw(StelPainter* painter, StelProjector::ModelViewTranformP transfo, double screenSz);
74  double getSize(void) const {return radiusMax;}
76  void setupShadow(bool setup);
78 private:
79  const double radiusMin;
80  const double radiusMax;
81  StelTextureSP tex;
82 };
85 class Planet : public StelObject
86 {
87 public:
88  friend class SolarSystem;
89  Planet(const QString& englishName,
90  int flagLighting,
91  double radius,
92  double oblateness,
93  Vec3f color,
94  float albedo,
95  const QString& texMapName,
96  posFuncType _coordFunc,
97  void* userDataPtr,
98  OsculatingFunctType *osculatingFunc,
99  bool closeOrbit,
100  bool hidden,
101  bool hasAtmosphere,
102  bool hasHalo,
103  const QString &pType);
105  virtual ~Planet();
108  // Methods inherited from StelObject
122  virtual QString getInfoString(const StelCore *core, const InfoStringGroup& flags) const;
123  virtual double getCloseViewFov(const StelCore* core) const;
124  virtual double getSatellitesFov(const StelCore* core) const;
125  virtual double getParentSatellitesFov(const StelCore* core) const;
126  virtual float getVMagnitude(const StelCore* core) const;
127  virtual float getSelectPriority(const StelCore* core) const;
128  virtual Vec3f getInfoColor(void) const;
129  virtual QString getType(void) const {return "Planet";}
130  virtual Vec3d getJ2000EquatorialPos(const StelCore *core) const;
131  virtual QString getEnglishName(void) const {return englishName;}
132  virtual QString getNameI18n(void) const {return nameI18;}
133  virtual double getAngularSize(const StelCore* core) const;
134  virtual bool hasAtmosphere(void) {return atmosphere;}
135  virtual bool hasHalo(void) {return halo;}
138  // Methods of SolarSystem object
140  virtual void translateName(const StelTranslator &trans);
142  // Draw the Planet
143  // GZ Made that virtual to allow comets having their own draw().
144  virtual void draw(StelCore* core, float maxMagLabels, const QFont& planetNameFont);
147  // Methods specific to Planet
150  double getRadius(void) const {return radius;}
152  double getSiderealDay(void) const {return re.period;}
154  // GZ: made that virtual for Comets.
155  virtual double getSiderealPeriod(void) const { return re.siderealPeriod; }
157  double getMeanSolarDay(void) const;
159  const QString& getTextMapName() const {return texMapName;}
161  // Compute the z rotation to use from equatorial to geographic coordinates
162  double getSiderealTime(double jd) const;
163  Mat4d getRotEquatorialToVsop87(void) const;
164  void setRotEquatorialToVsop87(const Mat4d &m);
166  const RotationElements &getRotationElements(void) const {return re;}
168  // Compute the position in the parent Planet coordinate system
169  void computePositionWithoutOrbits(const double date);
170  void computePosition(const double date);
172  // Compute the transformation matrix from the local Planet coordinate to the parent Planet coordinate
173  void computeTransMatrix(double date);
175  // Compute the transformation matrix from model to world coordinates
176  void computeModelMatrix(Mat4d& result) const;
178  // Get the phase angle (rad) for an observer at pos obsPos in heliocentric coordinates (in AU)
179  double getPhaseAngle(const Vec3d& obsPos) const;
180  // Get the elongation angle (rad) for an observer at pos obsPos in heliocentric coordinates (in AU)
181  double getElongation(const Vec3d& obsPos) const;
182  // Get the angular size of the spheroid of the planet (i.e. without the rings)
183  double getSpheroidAngularSize(const StelCore* core) const;
184  // Get the planet phase for an observer at pos obsPos in heliocentric coordinates (in AU)
185  float getPhase(const Vec3d& obsPos) const;
187  // Set the orbital elements
188  void setRotationElements(float _period, float _offset, double _epoch,
189  float _obliquity, float _ascendingNode,
190  float _precessionRate, double _siderealPeriod);
191  double getRotAscendingnode(void) const {return re.ascendingNode;}
192  double getRotObliquity(double JDay) const;
195  Vec3d getEclipticPos() const;
197  // Return the heliocentric ecliptical position
198  Vec3d getHeliocentricEclipticPos() const;
200  // Return the heliocentric transformation for local coordinate
201  Vec3d getHeliocentricPos(Vec3d) const;
202  void setHeliocentricEclipticPos(const Vec3d &pos);
204  // Compute the distance to the given position in heliocentric coordinate (in AU)
205  double computeDistance(const Vec3d& obsHelioPos);
206  double getDistance(void) const {return distance;}
208  void setRings(Ring* r) {rings = r;}
210  void setSphereScale(float s) {sphereScale = s;}
211  float getSphereScale(void) const {return sphereScale;}
213  const QSharedPointer<Planet> getParent(void) const {return parent;}
215  static void setLabelColor(const Vec3f& lc) {labelColor = lc;}
216  static const Vec3f& getLabelColor(void) {return labelColor;}
218  // update displayed elements. @param deltaTime: ms (?)
219  void update(int deltaTime);
221  void setFlagHints(bool b){hintFader = b;}
222  bool getFlagHints(void) const {return hintFader;}
224  void setFlagLabels(bool b){flagLabels = b;}
225  bool getFlagLabels(void) const {return flagLabels;}
230  // Should move to an OrbitPath class which works on a SolarSystemObject, not a Planet
231  void setFlagOrbits(bool b){orbitFader = b;}
232  bool getFlagOrbits(void) const {return orbitFader;}
233  LinearFader orbitFader;
234  // draw orbital path of Planet
235  void drawOrbit(const StelCore*);
236  Vec3d orbit[ORBIT_SEGMENTS+1]; // store heliocentric coordinates for drawing the orbit
237  Vec3d orbitP[ORBIT_SEGMENTS+1]; // store local coordinate for orbit
238  double lastOrbitJD;
239  double deltaJD; // time difference between positional updates.
240  double deltaOrbitJD;
241  bool orbitCached; // whether orbit calculations are cached for drawing orbit yet
242  bool closeOrbit; // whether to connect the beginning of the orbit line to
243  // the end: good for elliptical orbits, bad for parabolic
244  // and hyperbolic orbits
246  static Vec3f orbitColor;
247  static void setOrbitColor(const Vec3f& oc) {orbitColor = oc;}
248  static const Vec3f& getOrbitColor() {return orbitColor;}
250 protected:
251  static StelTextureSP texEarthShadow; // for lunar eclipses
253  // draw earth shadow on moon for lunar eclipses
254  void drawEarthShadow(StelCore* core, StelPainter* sPainter);
256  // Return the information string "ready to print" :)
257  QString getSkyLabel(const StelCore* core) const;
259  // Draw the 3d model. Call the proper functions if there are rings etc..
260  void draw3dModel(StelCore* core, StelProjector::ModelViewTranformP transfo, float screenSz);
262  // Draw the 3D sphere
263  void drawSphere(StelPainter* painter, float screenSz);
265  // Draw the circle and name of the Planet
266  void drawHints(const StelCore* core, const QFont& planetNameFont);
268  QString englishName; // english planet name
269  QString nameI18; // International translated name
270  QString texMapName; // Texture file path
271  int flagLighting; // Set whether light computation has to be proceed
272  RotationElements re; // Rotation param
273  double radius; // Planet radius in AU
274  double oneMinusOblateness; // (polar radius)/(equatorial radius)
275  Vec3d eclipticPos; // Position in AU in the rectangular ecliptic coordinate system
276  // centered on the parent Planet
277  Vec3d screenPos; // Used to store temporarily the 2D position on screen
278  Vec3d previousScreenPos; // The position of this planet in the previous frame.
279  Vec3f color; // exclusively used for drawing the planet halo
281  float albedo; // Planet albedo. Used for magnitude computation (but formula dubious!)
282  Mat4d rotLocalToParent;
283  float axisRotation; // Rotation angle of the Planet on it's axis
284  StelTextureSP texMap; // Planet map texture
286  Ring* rings; // Planet rings
287  double distance; // Temporary variable used to store the distance to a given point
288  // it is used for sorting while drawing
289  float sphereScale; // Artificial scaling for better viewing
290  double lastJD; // caches JD of last positional computation
291  // The callback for the calculation of the equatorial rect heliocentric position at time JD.
292  posFuncType coordFunc;
293  void* userDataPtr;
295  OsculatingFunctType *const osculatingFunc;
296  QSharedPointer<Planet> parent; // Planet parent i.e. sun for earth
297  QList<QSharedPointer<Planet> > satellites; // satellites of the Planet
298  LinearFader hintFader;
299  LinearFader labelsFader; // Store the current state of the label for this planet
300  bool flagLabels; // Define whether labels should be displayed
301  bool hidden; // useful for fake planets used as observation positions - not drawn or labeled
302  bool atmosphere; // Does the planet have an atmosphere?
303  bool halo; // Does the planet have a halo?
304  QString pType; // Type of body
306  static Vec3f labelColor;
307  static StelTextureSP hintCircleTex;
308 };
310 #endif // _PLANET_HPP_
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:155
Class used to translate strings to any language.
Definition: StelTranslator.hpp:51
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:132
Define the StelTextureSP type.
Definition: Planet.hpp:85
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:150
virtual QString getEnglishName(void) const
Return object's name in english.
Definition: Planet.hpp:131
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:68
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:152
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:71
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.
Definition: Planet.hpp:54
QSharedPointer< ModelViewTranform > ModelViewTranformP
Shared pointer on a ModelViewTranform instance (implement reference counting)
Definition: StelProjector.hpp:46
Definition: Planet.hpp:46
bool getFlagOrbits() const
Get the current value of the flag which determines if planet orbits are drawn or hidden.
Definition: SolarSystem.hpp:161
Define the StelProjectorP type.
virtual QString getType(void) const
Return object's type. It should be the name of the class.
Definition: Planet.hpp:129
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.
Definition: StelTextureTypes.hpp:34
bool getFlagHints() const
Get the current value of the flag which determines if planet hints are drawn or hidden along labels...
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).