~ubuntu-branches/debian/squeeze/stellarium/squeeze

« back to all changes in this revision

Viewing changes to src/planet.h

  • Committer: Bazaar Package Importer
  • Author(s): Cédric Delfosse
  • Date: 2008-05-19 21:28:23 UTC
  • mfrom: (3.1.5 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080519212823-m5nfiuntxstxzxj7
Tags: 0.9.1-4
Add libxcursor-dev, libxfixes-dev, libxinerama-dev, libqt4-opengl-dev to
build-deps (Closes: #479906)

Show diffs side-by-side

added added

removed removed

Lines of Context:
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
 
 */
19
 
 
20
 
#ifndef _PLANET_H_
21
 
#define _PLANET_H_
22
 
 
23
 
#include <list>
24
 
#include <string>
25
 
#include "stellarium.h"
26
 
#include "stel_utility.h"
27
 
#include "s_font.h"
28
 
#include "tone_reproductor.h"
29
 
#include "vecmath.h"
30
 
#include "stel_object.h"
31
 
#include "callbacks.hpp"
32
 
#include "fader.h"
33
 
#include "translator.h"
34
 
 
35
 
// The callback type for the external position computation function
36
 
typedef boost::callback<void, double, double*> pos_func_type;
37
 
 
38
 
typedef void (OsulatingFunctType)(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 72
43
 
 
44
 
using namespace std;
45
 
 
46
 
struct TrailPoint {
47
 
  Vec3d point;
48
 
  double date;
49
 
};
50
 
 
51
 
 
52
 
 
53
 
// Class used to store orbital elements
54
 
class RotationElements
55
 
{
56
 
 public:
57
 
    RotationElements();
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 sidereal_period; // sidereal period (Planet year in earth days)
65
 
};
66
 
 
67
 
// Class to manage rings for planets like saturn
68
 
class Ring
69
 
{
70
 
public:
71
 
        Ring(double radius_min,double radius_max,const string &texname);
72
 
        ~Ring(void);
73
 
        void draw(const Projector* prj,const Mat4d& mat,double screen_sz);
74
 
        double get_size(void) const {return radius_max;}
75
 
private:
76
 
        const double radius_min;
77
 
        const double radius_max;
78
 
        const s_texture *tex;
79
 
};
80
 
 
81
 
 
82
 
class Planet : public StelObject
83
 
{
84
 
public:
85
 
        Planet(Planet *parent,
86
 
           const string& englishName,
87
 
           int flagHalo,
88
 
           int flag_lighting,
89
 
           double radius,
90
 
           double oblateness,
91
 
           Vec3f color,
92
 
           float albedo,
93
 
           const string& tex_map_name,
94
 
           const string& tex_halo_name,
95
 
           pos_func_type _coord_func,
96
 
           OsulatingFunctType *osculating_func,
97
 
                   bool hidden);
98
 
 
99
 
    virtual ~Planet();
100
 
 
101
 
    double getRadius(void) const {return radius;}
102
 
 
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;}
111
 
 
112
 
        /** Translate planet name using the passed translator */
113
 
        void translateName(Translator& trans) {nameI18 = trans.translate(englishName);}
114
 
        
115
 
    // Compute the z rotation to use from equatorial to geographic coordinates
116
 
    double getSiderealTime(double jd) const;
117
 
    Mat4d getRotEquatorialToVsop87(void) const;
118
 
 
119
 
        // Compute the position in the parent Planet coordinate system
120
 
        void computePositionWithoutOrbits(double date);
121
 
        void compute_position(double date);
122
 
 
123
 
        // Compute the transformation matrix from the local Planet coordinate to the parent Planet coordinate
124
 
        void compute_trans_matrix(double date);
125
 
 
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;
128
 
 
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;
132
 
 
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);
138
 
 
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;}
144
 
 
145
 
 
146
 
        // Get the Planet position in the parent Planet ecliptic coordinate
147
 
        Vec3d get_ecliptic_pos() const;
148
 
 
149
 
        // Return the heliocentric ecliptical position
150
 
        Vec3d get_heliocentric_ecliptic_pos() const;
151
 
 
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;}
155
 
 
156
 
        // Get a matrix which converts from heliocentric ecliptic coordinate to local geographic coordinate
157
 
//      Mat4d get_helio_to_geo_matrix();
158
 
 
159
 
        STEL_OBJECT_TYPE get_type(void) const {return STEL_OBJECT_PLANET;}
160
 
 
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;
165
 
 
166
 
        string getEnglishName(void) const {return englishName;}
167
 
        wstring getNameI18(void) const {return nameI18;}
168
 
 
169
 
        void set_rings(Ring* r) {rings = r;}
170
 
 
171
 
        void set_sphere_scale(float s) {sphere_scale = s;}
172
 
        float get_sphere_scale(void) const {return sphere_scale;}
173
 
 
174
 
        const Planet *get_parent(void) const {return parent;}
175
 
 
176
 
        void set_big_halo(const string& halotexfile);
177
 
        void set_halo_size(float s) {big_halo_size = s;}
178
 
 
179
 
        static void set_font(s_font* f) {planet_name_font = f;}
180
 
        
181
 
        static void setScale(float s) {object_scale = s;}
182
 
        static float getScale(void) {return object_scale;}
183
 
        
184
 
        static void set_label_color(const Vec3f& lc) {label_color = lc;}
185
 
        static const Vec3f& getLabelColor(void) {return label_color;}
186
 
        
187
 
        static void set_orbit_color(const Vec3f& oc) {orbit_color = oc;}
188
 
        static const Vec3f& getOrbitColor() {return orbit_color;}
189
 
 
190
 
        // draw orbital path of Planet
191
 
        void draw_orbit(const Navigator * nav, const Projector* prj);
192
 
 
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; }
197
 
        
198
 
        //! Start/stop accumulating new trail data (clear old data)
199
 
        void startTrail(bool b);
200
 
 
201
 
        void update(int delta_time);
202
 
        
203
 
        void setFlagHints(bool b){hint_fader = b;}
204
 
        bool getFlagHints(void) const {return hint_fader;}
205
 
        
206
 
        void setFlagOrbits(bool b){orbit_fader = b;}
207
 
        bool getFlagOrbits(void) const {return orbit_fader;}    
208
 
        
209
 
        void setFlagTrail(bool b){trail_fader = b;}
210
 
        bool getFlagTrail(void) const {return trail_fader;}
211
 
        
212
 
        static void setflagShow(bool b) {Planet::flagShow = b;}
213
 
        static bool getflagShow(void) {return Planet::flagShow;}
214
 
        
215
 
protected:
216
 
        // Return the radius of a circle containing the object on screen
217
 
        float get_on_screen_size(const Projector* prj, const Navigator * nav);
218
 
 
219
 
        // Draw the 3D sphere
220
 
        void draw_sphere(const Projector* prj, const Mat4d& mat, float screen_sz);
221
 
 
222
 
        // Draw the small star-like 2D halo
223
 
        void draw_halo(const Navigator* nav, const Projector* prj, const ToneReproductor* eye);
224
 
 
225
 
        // Draw the small star-like point
226
 
        void draw_point_halo(const Navigator* nav, const Projector* prj, const ToneReproductor* eye);
227
 
 
228
 
        // Draw the circle and name of the Planet
229
 
        void draw_hints(const Navigator* nav, const Projector* prj);
230
 
 
231
 
        // Draw the big halo (for sun or moon)
232
 
        void draw_big_halo(const Navigator* nav, const Projector* prj, const ToneReproductor* eye);
233
 
 
234
 
 
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.
247
 
        Vec3f color;
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
255
 
 
256
 
        float big_halo_size;                            // Halo size on screen
257
 
 
258
 
        Ring* rings;                                    // Planet rings
259
 
 
260
 
        double distance;                                // Temporary variable used to store the distance to a given point
261
 
                                                                        // it is used for sorting while drawing
262
 
 
263
 
        float sphere_scale;                             // Artificial scaling for better viewing
264
 
 
265
 
        double lastJD;
266
 
        double last_orbitJD;
267
 
        double deltaJD;
268
 
        double delta_orbitJD;
269
 
        bool orbit_cached;       // whether orbit calculations are cached for drawing orbit yet
270
 
 
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;
274
 
 
275
 
        const Planet *const parent;                             // Planet parent i.e. sun for earth
276
 
        list<Planet *> satellites;              // satellites of the Planet
277
 
 
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;
283
 
 
284
 
        list<TrailPoint>trail;
285
 
        bool trail_on;  // accumulate trail data if true
286
 
        double DeltaTrail;
287
 
        int MaxTrail;
288
 
        double last_trailJD;
289
 
        bool first_point;  // if need to take first point of trail still
290
 
 
291
 
        static LinearFader flagShow;
292
 
        
293
 
        LinearFader hint_fader;
294
 
        LinearFader orbit_fader;
295
 
        LinearFader trail_fader;
296
 
        
297
 
        bool hidden;  // useful for fake planets used as observation positions - not drawn or labeled
298
 
 
299
 
};
300
 
 
301
 
#endif // _PLANET_H_