3
* Copyright (C) 2002 Fabien Chereau
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
#include "stellarium.h"
26
#include "stel_utility.h"
28
#include "tone_reproductor.h"
30
#include "stel_object.h"
31
#include "callbacks.hpp"
33
#include "translator.h"
35
// The callback type for the external position computation function
36
typedef boost::callback<void, double, double*> pos_func_type;
38
typedef void (OsulatingFunctType)(double jd0,double jd,double xyz[3]);
40
// epoch J2000: 12 UT on 1 Jan 2000
41
#define J2000 2451545.0
42
#define ORBIT_SEGMENTS 72
53
// Class used to store orbital elements
54
class RotationElements
58
float period; // rotation period
59
float offset; // rotation at 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 sidereal_period; // sidereal period (Planet year in earth days)
67
// Class to manage rings for planets like saturn
71
Ring(double radius_min,double radius_max,const string &texname);
73
void draw(const Projector* prj,const Mat4d& mat,double screen_sz);
74
double get_size(void) const {return radius_max;}
76
const double radius_min;
77
const double radius_max;
82
class Planet : public StelObject
85
Planet(Planet *parent,
86
const string& englishName,
93
const string& tex_map_name,
94
const string& tex_halo_name,
95
pos_func_type _coord_func,
96
OsulatingFunctType *osculating_func,
101
double getRadius(void) const {return radius;}
103
// Return the information string "ready to print" :)
104
wstring getSkyLabel(const Navigator * nav) const;
105
wstring getInfoString(const Navigator * nav) const;
106
wstring getShortInfoString(const Navigator * nav) const;
107
virtual double get_close_fov(const Navigator * nav) const;
108
virtual double get_satellites_fov(const Navigator * nav) const;
109
virtual float get_mag(const Navigator * nav) const {return compute_magnitude(nav);}
110
const s_texture *getMapTexture(void) const {return tex_map;}
112
/** Translate planet name using the passed translator */
113
void translateName(Translator& trans) {nameI18 = trans.translate(englishName);}
115
// Compute the z rotation to use from equatorial to geographic coordinates
116
double getSiderealTime(double jd) const;
117
Mat4d getRotEquatorialToVsop87(void) const;
119
// Compute the position in the parent Planet coordinate system
120
void computePositionWithoutOrbits(double date);
121
void compute_position(double date);
123
// Compute the transformation matrix from the local Planet coordinate to the parent Planet coordinate
124
void compute_trans_matrix(double date);
126
// Get the phase angle for an observer at pos obs_pos in the heliocentric coordinate (in AU)
127
double get_phase(Vec3d obs_pos) const;
129
// Get the magnitude for an observer at pos obs_pos in the heliocentric coordinate (in AU)
130
float compute_magnitude(const Vec3d obs_pos) const;
131
float compute_magnitude(const Navigator * nav) const;
133
// Draw the Planet, if hint_ON is != 0 draw a circle and the name as well
134
// Return the squared distance in pixels between the current and the
135
// previous position this planet was drawn at.
136
double draw(Projector* prj, const Navigator* nav, const ToneReproductor* eye,
137
int flag_point, bool stencil);
139
// Set the orbital elements
140
void set_rotation_elements(float _period, float _offset, double _epoch,
141
float _obliquity, float _ascendingNode, float _precessionRate, double _sidereal_period);
142
double getRotAscendingnode(void) const {return re.ascendingNode;}
143
double getRotObliquity(void) const {return re.obliquity;}
146
// Get the Planet position in the parent Planet ecliptic coordinate
147
Vec3d get_ecliptic_pos() const;
149
// Return the heliocentric ecliptical position
150
Vec3d get_heliocentric_ecliptic_pos() const;
152
// Compute the distance to the given position in heliocentric coordinate (in AU)
153
double compute_distance(const Vec3d& obs_helio_pos);
154
double get_distance(void) const {return distance;}
156
// Get a matrix which converts from heliocentric ecliptic coordinate to local geographic coordinate
157
// Mat4d get_helio_to_geo_matrix();
159
STEL_OBJECT_TYPE get_type(void) const {return STEL_OBJECT_PLANET;}
161
// Return the Planet position in rectangular earth equatorial coordinate
162
Vec3d get_earth_equ_pos(const Navigator *nav) const;
163
// observer centered J2000 coordinates
164
Vec3d getObsJ2000Pos(const Navigator *nav) const;
166
string getEnglishName(void) const {return englishName;}
167
wstring getNameI18(void) const {return nameI18;}
169
void set_rings(Ring* r) {rings = r;}
171
void set_sphere_scale(float s) {sphere_scale = s;}
172
float get_sphere_scale(void) const {return sphere_scale;}
174
const Planet *get_parent(void) const {return parent;}
176
void set_big_halo(const string& halotexfile);
177
void set_halo_size(float s) {big_halo_size = s;}
179
static void set_font(s_font* f) {planet_name_font = f;}
181
static void setScale(float s) {object_scale = s;}
182
static float getScale(void) {return object_scale;}
184
static void set_label_color(const Vec3f& lc) {label_color = lc;}
185
static const Vec3f& getLabelColor(void) {return label_color;}
187
static void set_orbit_color(const Vec3f& oc) {orbit_color = oc;}
188
static const Vec3f& getOrbitColor() {return orbit_color;}
190
// draw orbital path of Planet
191
void draw_orbit(const Navigator * nav, const Projector* prj);
193
void update_trail(const Navigator* nav);
194
void draw_trail(const Navigator * nav, const Projector* prj);
195
static void set_trail_color(const Vec3f& c) { trail_color = c; }
196
static const Vec3f& getTrailColor() { return trail_color; }
198
//! Start/stop accumulating new trail data (clear old data)
199
void startTrail(bool b);
201
void update(int delta_time);
203
void setFlagHints(bool b){hint_fader = b;}
204
bool getFlagHints(void) const {return hint_fader;}
206
void setFlagOrbits(bool b){orbit_fader = b;}
207
bool getFlagOrbits(void) const {return orbit_fader;}
209
void setFlagTrail(bool b){trail_fader = b;}
210
bool getFlagTrail(void) const {return trail_fader;}
212
static void setflagShow(bool b) {Planet::flagShow = b;}
213
static bool getflagShow(void) {return Planet::flagShow;}
216
// Return the radius of a circle containing the object on screen
217
float get_on_screen_size(const Projector* prj, const Navigator * nav);
219
// Draw the 3D sphere
220
void draw_sphere(const Projector* prj, const Mat4d& mat, float screen_sz);
222
// Draw the small star-like 2D halo
223
void draw_halo(const Navigator* nav, const Projector* prj, const ToneReproductor* eye);
225
// Draw the small star-like point
226
void draw_point_halo(const Navigator* nav, const Projector* prj, const ToneReproductor* eye);
228
// Draw the circle and name of the Planet
229
void draw_hints(const Navigator* nav, const Projector* prj);
231
// Draw the big halo (for sun or moon)
232
void draw_big_halo(const Navigator* nav, const Projector* prj, const ToneReproductor* eye);
235
string englishName; // english planet name
236
wstring nameI18; // International translated name
237
int flagHalo; // Set wether a little "star like" halo will be drawn
238
int flag_lighting; // Set wether light computation has to be proceed
239
RotationElements re; // Rotation param
240
double radius; // Planet radius in UA
241
double one_minus_oblateness; // (polar radius)/(equatorial radius)
242
Vec3d orbit[ORBIT_SEGMENTS]; // store heliocentric coordinates for drawing the orbit
243
Vec3d ecliptic_pos; // Position in UA in the rectangular ecliptic coordinate system
244
// centered on the parent Planet
245
Vec3d screenPos; // Used to store temporarily the 2D position on screen
246
Vec3d previousScreenPos; // The position of this planet in the previous frame.
248
float albedo; // Planet albedo
249
Mat4d rot_local_to_parent;
250
Mat4d mat_local_to_parent; // Transfo matrix from local ecliptique to parent ecliptic
251
float axis_rotation; // Rotation angle of the Planet on it's axis
252
s_texture * tex_map; // Planet map texture
253
s_texture * tex_halo; // Little halo texture
254
s_texture * tex_big_halo; // Big halo texture
256
float big_halo_size; // Halo size on screen
258
Ring* rings; // Planet rings
260
double distance; // Temporary variable used to store the distance to a given point
261
// it is used for sorting while drawing
263
float sphere_scale; // Artificial scaling for better viewing
268
double delta_orbitJD;
269
bool orbit_cached; // whether orbit calculations are cached for drawing orbit yet
271
// The callback for the calculation of the equatorial rect heliocentric position at time JD.
272
pos_func_type coord_func;
273
OsulatingFunctType *const osculating_func;
275
const Planet *const parent; // Planet parent i.e. sun for earth
276
list<Planet *> satellites; // satellites of the Planet
278
static s_font* planet_name_font;// Font for names
279
static float object_scale;
280
static Vec3f label_color;
281
static Vec3f orbit_color;
282
static Vec3f trail_color;
284
list<TrailPoint>trail;
285
bool trail_on; // accumulate trail data if true
289
bool first_point; // if need to take first point of trail still
291
static LinearFader flagShow;
293
LinearFader hint_fader;
294
LinearFader orbit_fader;
295
LinearFader trail_fader;
297
bool hidden; // useful for fake planets used as observation positions - not drawn or labeled