Merge lp:~georg-zotti/stellarium/gz-planet-type-enum into lp:stellarium

Proposed by gzotti
Status: Merged
Merged at revision: 6995
Proposed branch: lp:~georg-zotti/stellarium/gz-planet-type-enum
Merge into: lp:stellarium
Diff against target: 983 lines (+58/-382)
7 files modified
src/core/modules/Comet.cpp (+3/-4)
src/core/modules/Comet.hpp (+16/-16)
src/core/modules/MinorPlanet.cpp (+3/-4)
src/core/modules/MinorPlanet.hpp (+1/-1)
src/core/modules/Planet.cpp (+31/-8)
src/core/modules/Planet.hpp (+0/-346)
src/core/modules/SolarSystem.cpp (+4/-3)
To merge this branch: bzr merge lp:~georg-zotti/stellarium/gz-planet-type-enum
Reviewer Review Type Date Requested Status
Alexander Wolf Approve
gzotti Needs Resubmitting
Review via email: mp+232802@code.launchpad.net

Description of the change

Changed Planet's pType from string to enum. Give a slight speed gain in case of many (thousands) asteroids, and makes the code somewhat cleaner.

To post a comment you must log in.
Revision history for this message
Alexander Wolf (alexwolf) wrote :

Need cleanup the code and extend the comments

review: Needs Fixing
6973. By gzotti

pre-merge cleanup

Revision history for this message
gzotti (georg-zotti) wrote :

Don't know which level of commenting should be added? QMaps are used in many classes already, usually sparsely documented.

review: Needs Resubmitting
Revision history for this message
Alexander Wolf (alexwolf) wrote :

It's OK now.

About tStar, tPlanet, etc.... Maybe better use isStar, isPlanet, etc.?

review: Approve
6974. By gzotti

renamed Planet::PlanetType enums

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/core/modules/Comet.cpp'
--- src/core/modules/Comet.cpp 2014-08-17 09:28:31 +0000
+++ src/core/modules/Comet.cpp 2014-08-31 09:14:13 +0000
@@ -52,7 +52,7 @@
52 OsculatingFunctType *osculatingFunc,52 OsculatingFunctType *osculatingFunc,
53 bool acloseOrbit,53 bool acloseOrbit,
54 bool hidden,54 bool hidden,
55 const QString& pType,55 const QString& pTypeStr,
56 float dustTailWidthFact, float dustTailLengthFact, float dustTailBrightnessFact)56 float dustTailWidthFact, float dustTailLengthFact, float dustTailBrightnessFact)
57 : Planet (englishName,57 : Planet (englishName,
58 flagLighting,58 flagLighting,
@@ -69,7 +69,7 @@
69 hidden,69 hidden,
70 false, //No atmosphere70 false, //No atmosphere
71 true, //halo71 true, //halo
72 pType),72 pTypeStr),
73 dustTailWidthFactor(dustTailWidthFact),73 dustTailWidthFactor(dustTailWidthFact),
74 dustTailLengthFactor(dustTailLengthFact),74 dustTailLengthFactor(dustTailLengthFact),
75 dustTailBrightnessFactor(dustTailBrightnessFact)75 dustTailBrightnessFactor(dustTailBrightnessFact)
@@ -142,8 +142,7 @@
142142
143 if (flags&ObjectType)143 if (flags&ObjectType)
144 {144 {
145 if (pType.length()>0)145 oss << q_("Type: <b>%1</b>").arg(q_(Planet::pTypeMap.value(pType))) << "<br />";
146 oss << q_("Type: <b>%1</b>").arg(q_(pType)) << "<br />";
147 }146 }
148147
149 if (flags&Magnitude)148 if (flags&Magnitude)
150149
=== modified file 'src/core/modules/Comet.hpp'
--- src/core/modules/Comet.hpp 2014-08-17 09:28:31 +0000
+++ src/core/modules/Comet.hpp 2014-08-31 09:14:13 +0000
@@ -38,22 +38,22 @@
38public:38public:
39 friend class SolarSystem; // Solar System initializes static constants.39 friend class SolarSystem; // Solar System initializes static constants.
40 Comet(const QString& englishName,40 Comet(const QString& englishName,
41 int flagLighting,41 int flagLighting,
42 double radius,42 double radius,
43 double oblateness,43 double oblateness,
44 Vec3f color,44 Vec3f color,
45 float albedo,45 float albedo,
46 const QString& texMapName,46 const QString& texMapName,
47 posFuncType _coordFunc,47 posFuncType _coordFunc,
48 void* userDataPtr,48 void* userDataPtr,
49 OsculatingFunctType *osculatingFunc,49 OsculatingFunctType *osculatingFunc,
50 bool closeOrbit,50 bool closeOrbit,
51 bool hidden,51 bool hidden,
52 const QString &pType,52 const QString &pTypeStr,
53 float dustTailWidthFact=1.5f,53 float dustTailWidthFact=1.5f,
54 float dustTailLengthFact=0.4f,54 float dustTailLengthFact=0.4f,
55 float dustTailBrightnessFact=1.5f55 float dustTailBrightnessFact=1.5f
56 );56 );
5757
58 virtual ~Comet();58 virtual ~Comet();
5959
6060
=== modified file 'src/core/modules/MinorPlanet.cpp'
--- src/core/modules/MinorPlanet.cpp 2014-08-16 17:40:45 +0000
+++ src/core/modules/MinorPlanet.cpp 2014-08-31 09:14:13 +0000
@@ -45,7 +45,7 @@
45 OsculatingFunctType *osculatingFunc,45 OsculatingFunctType *osculatingFunc,
46 bool acloseOrbit,46 bool acloseOrbit,
47 bool hidden,47 bool hidden,
48 const QString &pType)48 const QString &pTypeStr)
49 : Planet (englishName,49 : Planet (englishName,
50 flagLighting,50 flagLighting,
51 radius,51 radius,
@@ -61,7 +61,7 @@
61 hidden,61 hidden,
62 false, //No atmosphere62 false, //No atmosphere
63 true, //Halo63 true, //Halo
64 pType)64 pTypeStr)
65{65{
66 texMapName = atexMapName;66 texMapName = atexMapName;
67 lastOrbitJD =0;67 lastOrbitJD =0;
@@ -205,8 +205,7 @@
205205
206 if (flags&ObjectType)206 if (flags&ObjectType)
207 {207 {
208 if (pType.length()>0)208 oss << q_("Type: <b>%1</b>").arg(q_(Planet::pTypeMap.value(pType))) << "<br />";
209 oss << q_("Type: <b>%1</b>").arg(q_(pType)) << "<br />";
210 }209 }
211210
212 if (flags&Magnitude)211 if (flags&Magnitude)
213212
=== modified file 'src/core/modules/MinorPlanet.hpp'
--- src/core/modules/MinorPlanet.hpp 2014-08-16 17:40:45 +0000
+++ src/core/modules/MinorPlanet.hpp 2014-08-31 09:14:13 +0000
@@ -50,7 +50,7 @@
50 OsculatingFunctType *osculatingFunc,50 OsculatingFunctType *osculatingFunc,
51 bool closeOrbit,51 bool closeOrbit,
52 bool hidden,52 bool hidden,
53 const QString &pType);53 const QString &pTypeStr);
5454
55 ~MinorPlanet();55 ~MinorPlanet();
5656
5757
=== modified file 'src/core/modules/Planet.cpp'
--- src/core/modules/Planet.cpp 2014-08-17 19:41:04 +0000
+++ src/core/modules/Planet.cpp 2014-08-31 09:14:13 +0000
@@ -71,7 +71,7 @@
71 bool hidden,71 bool hidden,
72 bool hasAtmosphere,72 bool hasAtmosphere,
73 bool hasHalo,73 bool hasHalo,
74 const QString& pType)74 const QString& pTypeStr)
75 : englishName(englishName),75 : englishName(englishName),
76 flagLighting(flagLighting),76 flagLighting(flagLighting),
77 radius(radius),77 radius(radius),
@@ -88,8 +88,7 @@
88 parent(NULL),88 parent(NULL),
89 hidden(hidden),89 hidden(hidden),
90 atmosphere(hasAtmosphere),90 atmosphere(hasAtmosphere),
91 halo(hasHalo),91 halo(hasHalo)
92 pType(pType)
93{92{
94 texMapName = atexMapName;93 texMapName = atexMapName;
95 normalMapName = anormalMapName;94 normalMapName = anormalMapName;
@@ -100,6 +99,10 @@
100 deltaOrbitJD = 0;99 deltaOrbitJD = 0;
101 distance = 0;100 distance = 0;
102101
102 // Initialize pType with the key found in pTypeMap, or mark planet type as undefined.
103 // The latter condition should obviously never happen.
104 pType=pTypeMap.key(pTypeStr, Planet::isUNDEFINED);
105
103 eclipticPos=Vec3d(0.,0.,0.);106 eclipticPos=Vec3d(0.,0.,0.);
104 rotLocalToParent = Mat4d::identity();107 rotLocalToParent = Mat4d::identity();
105 texMap = StelApp::getInstance().getTextureManager().createTextureThread(StelFileMgr::getInstallationDir()+"/textures/"+texMapName, StelTexture::StelTextureParams(true, GL_LINEAR, GL_REPEAT));108 texMap = StelApp::getInstance().getTextureManager().createTextureThread(StelFileMgr::getInstallationDir()+"/textures/"+texMapName, StelTexture::StelTextureParams(true, GL_LINEAR, GL_REPEAT));
@@ -113,6 +116,26 @@
113 flagLabels = true;116 flagLabels = true;
114}117}
115118
119QMap<Planet::PlanetType, QString> Planet::pTypeMap;
120
121// called in SolarSystem::init() before first planet is created. Loads pTypeMap.
122void Planet::init()
123{
124 if (pTypeMap.count() > 0 )
125 {
126 // This should never happen. But it's uncritical.
127 qDebug() << "Planet::init(): Non-empty static map. This is a programming error, but we can fix that.";
128 pTypeMap.clear();
129 }
130 pTypeMap.insert(Planet::isStar, "star");
131 pTypeMap.insert(Planet::isPlanet, "planet");
132 pTypeMap.insert(Planet::isMoon, "moon");
133 pTypeMap.insert(Planet::isAsteroid, "asteroid");
134 pTypeMap.insert(Planet::isPlutoid, "plutoid");
135 pTypeMap.insert(Planet::isComet, "comet");
136 pTypeMap.insert(Planet::isUNDEFINED, "UNDEFINED"); // something must be broken before we ever see this!
137}
138
116Planet::~Planet()139Planet::~Planet()
117{140{
118 if (rings)141 if (rings)
@@ -142,8 +165,7 @@
142165
143 if (flags&ObjectType)166 if (flags&ObjectType)
144 {167 {
145 if (pType.length()>0)168 oss << q_("Type: <b>%1</b>").arg(q_(Planet::pTypeMap.value(pType))) << "<br />";
146 oss << q_("Type: <b>%1</b>").arg(q_(pType)) << "<br />";
147 }169 }
148170
149 if (flags&Magnitude)171 if (flags&Magnitude)
@@ -574,7 +596,7 @@
574 if (englishName=="Venus" || englishName=="Uranus" || englishName=="Pluto")596 if (englishName=="Venus" || englishName=="Uranus" || englishName=="Pluto")
575 sign = -1;597 sign = -1;
576598
577 if (pType.contains("moon"))599 if (pType==Planet::isMoon)
578 {600 {
579 // duration of mean solar day on moon are same as synodic month on this moon601 // duration of mean solar day on moon are same as synodic month on this moon
580 double a = parent->getSiderealPeriod()/sday;602 double a = parent->getSiderealPeriod()/sday;
@@ -646,7 +668,7 @@
646{668{
647 distance = (obsHelioPos-getHeliocentricEclipticPos()).length();669 distance = (obsHelioPos-getHeliocentricEclipticPos()).length();
648 // GZ: improve fps by juggling updates for asteroids. They must be fast if close to observer, but can be slow if further away.670 // GZ: improve fps by juggling updates for asteroids. They must be fast if close to observer, but can be slow if further away.
649 if (pType == "asteroid")671 if (pType == Planet::isAsteroid)
650 deltaJD=distance*StelCore::JD_SECOND;672 deltaJD=distance*StelCore::JD_SECOND;
651 return distance;673 return distance;
652}674}
@@ -870,7 +892,8 @@
870 // GZ: Try to improve speed for minor planets: test if visible at all.892 // GZ: Try to improve speed for minor planets: test if visible at all.
871 // For a full catalog of NEAs (11000 objects), with this and resetting deltaJD according to distance, rendering time went 4.5fps->12fps. 893 // For a full catalog of NEAs (11000 objects), with this and resetting deltaJD according to distance, rendering time went 4.5fps->12fps.
872 // AW: Apply this rule to asteroids only894 // AW: Apply this rule to asteroids only
873 if (((getVMagnitude(core)-1.0f) > core->getSkyDrawer()->getLimitMagnitude()) && pType=="asteroid")895 // Note that taking away the asteroids at this stage breaks dim-asteroid occultation of stars!
896 if (((getVMagnitude(core)-1.0f) > core->getSkyDrawer()->getLimitMagnitude()) && pType==Planet::isAsteroid)
874 {897 {
875 return;898 return;
876 }899 }
877900
=== added file 'src/core/modules/Planet.hpp'
--- src/core/modules/Planet.hpp 1970-01-01 00:00:00 +0000
+++ src/core/modules/Planet.hpp 2014-08-31 09:14:13 +0000
@@ -0,0 +1,370 @@
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.
34typedef void (*posFuncType)(double, double*, void*);
35
36typedef 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
42class StelFont;
43class StelPainter;
44class StelTranslator;
45class QOpenGLShaderProgram;
46
47// Class used to store orbital elements
48class RotationElements
49{
50public:
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
62class Ring
63{
64public:
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
73class Planet : public StelObject
74{
75public:
76 friend class SolarSystem;
77
78 Q_ENUMS(PlanetType)
79 //! numeric typecodes for the type descriptions in ssystem.ini
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
113 //! Initializes static vars. Must be called before creating first planet.
114 // Currently ensured by SolarSystem::init()
115 static void init();
116
117 ///////////////////////////////////////////////////////////////////////////
118 // Methods inherited from StelObject
119 //! Get a string with data about the Planet.
120 //! Planets support the following InfoStringGroup flags:
121 //! - Name
122 //! - Magnitude
123 //! - RaDec
124 //! - AltAzi
125 //! - Distance
126 //! - Size
127 //! - PlainText
128 //! - Extra: Heliocentric Ecliptical Coordinates & Observer-planetocentric Ecliptical Coordinates, Phase, illumination, phase angle & elongation from the Sun
129 //! @param core the StelCore object
130 //! @param flags a set of InfoStringGroup items to include in the return value.
131 //! @return a QString containing an HMTL encoded description of the Planet.
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
147 ///////////////////////////////////////////////////////////////////////////
148 // Methods of SolarSystem object
149 //! Translate planet name using the passed translator
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
156 ///////////////////////////////////////////////////////////////////////////
157 // Methods specific to Planet
158 //! Get the radius of the planet in AU.
159 //! @return the radius of the planet in astronomical units.
160 double getRadius(void) const {return radius;}
161 //! Get duration of sidereal day
162 double getSiderealDay(void) const {return re.period;}
163 //! Get duration of sidereal year
164 // GZ: made that virtual for Comets.
165 virtual double getSiderealPeriod(void) const { return re.siderealPeriod; }
166 //! Get duration of mean solar day
167 double getMeanSolarDay(void) const;
168
169 const QString& getTextMapName() const {return texMapName;}
170 //const QString getPlanetType() const {return pTypeStr;}
171 const 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
203 //! Get the Planet position in the parent Planet ecliptic coordinate in AU
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
236 ///////////////////////////////////////////////////////////////////////////
237 // DEPRECATED
238 ///// Orbit related code
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
259 //! Return the list of planets which project some shadow on this planet
260 QVector<const Planet*> getCandidatesForShadow() const;
261
262protected:
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
325 struct PlanetShaderVars {
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
345 struct RingPlanetShaderVars : public PlanetShaderVars {
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
356 struct MoonShaderVars : public PlanetShaderVars {
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
0371
=== removed file 'src/core/modules/Planet.hpp'
--- src/core/modules/Planet.hpp 2014-08-02 17:34:13 +0000
+++ src/core/modules/Planet.hpp 1970-01-01 00:00:00 +0000
@@ -1,346 +0,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
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.
34typedef void (*posFuncType)(double, double*, void*);
35
36typedef 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
42class StelFont;
43class StelPainter;
44class StelTranslator;
45class QOpenGLShaderProgram;
46
47// Class used to store orbital elements
48class RotationElements
49{
50public:
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
62class Ring
63{
64public:
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
73class Planet : public StelObject
74{
75public:
76 friend class SolarSystem;
77 Planet(const QString& englishName,
78 int flagLighting,
79 double radius,
80 double oblateness,
81 Vec3f color,
82 float albedo,
83 const QString& texMapName,
84 const QString& normalMapName,
85 posFuncType _coordFunc,
86 void* userDataPtr,
87 OsculatingFunctType *osculatingFunc,
88 bool closeOrbit,
89 bool hidden,
90 bool hasAtmosphere,
91 bool hasHalo,
92 const QString &pType);
93
94 virtual ~Planet();
95
96 ///////////////////////////////////////////////////////////////////////////
97 // Methods inherited from StelObject
98 //! Get a string with data about the Planet.
99 //! Planets support the following InfoStringGroup flags:
100 //! - Name
101 //! - Magnitude
102 //! - RaDec
103 //! - AltAzi
104 //! - Distance
105 //! - Size
106 //! - PlainText
107 //! - Extra: Heliocentric Ecliptical Coordinates & Observer-planetocentric Ecliptical Coordinates, Phase, illumination, phase angle & elongation from the Sun
108 //! @param core the StelCore object
109 //! @param flags a set of InfoStringGroup items to include in the return value.
110 //! @return a QString containing an HMTL encoded description of the Planet.
111 virtual QString getInfoString(const StelCore *core, const InfoStringGroup& flags) const;
112 virtual double getCloseViewFov(const StelCore* core) const;
113 virtual double getSatellitesFov(const StelCore* core) const;
114 virtual double getParentSatellitesFov(const StelCore* core) const;
115 virtual float getVMagnitude(const StelCore* core) const;
116 virtual float getSelectPriority(const StelCore* core) const;
117 virtual Vec3f getInfoColor(void) const;
118 virtual QString getType(void) const {return "Planet";}
119 virtual Vec3d getJ2000EquatorialPos(const StelCore *core) const;
120 virtual QString getEnglishName(void) const {return englishName;}
121 virtual QString getNameI18n(void) const {return nameI18;}
122 virtual double getAngularSize(const StelCore* core) const;
123 virtual bool hasAtmosphere(void) {return atmosphere;}
124 virtual bool hasHalo(void) {return halo;}
125
126 ///////////////////////////////////////////////////////////////////////////
127 // Methods of SolarSystem object
128 //! Translate planet name using the passed translator
129 virtual void translateName(const StelTranslator &trans);
130
131 // Draw the Planet
132 // GZ Made that virtual to allow comets having their own draw().
133 virtual void draw(StelCore* core, float maxMagLabels, const QFont& planetNameFont);
134
135 ///////////////////////////////////////////////////////////////////////////
136 // Methods specific to Planet
137 //! Get the radius of the planet in AU.
138 //! @return the radius of the planet in astronomical units.
139 double getRadius(void) const {return radius;}
140 //! Get duration of sidereal day
141 double getSiderealDay(void) const {return re.period;}
142 //! Get duration of sidereal year
143 // GZ: made that virtual for Comets.
144 virtual double getSiderealPeriod(void) const { return re.siderealPeriod; }
145 //! Get duration of mean solar day
146 double getMeanSolarDay(void) const;
147
148 const QString& getTextMapName() const {return texMapName;}
149 const QString getPlanetType() const {return pType;}
150
151 // Compute the z rotation to use from equatorial to geographic coordinates
152 double getSiderealTime(double jd) const;
153 Mat4d getRotEquatorialToVsop87(void) const;
154 void setRotEquatorialToVsop87(const Mat4d &m);
155
156 const RotationElements &getRotationElements(void) const {return re;}
157
158 // Compute the position in the parent Planet coordinate system
159 void computePositionWithoutOrbits(const double dateJD);
160 virtual void computePosition(const double dateJD);// GZ: gets overridden in Comet!
161
162 // Compute the transformation matrix from the local Planet coordinate to the parent Planet coordinate
163 void computeTransMatrix(double date);
164
165 // Get the phase angle (rad) for an observer at pos obsPos in heliocentric coordinates (in AU)
166 double getPhaseAngle(const Vec3d& obsPos) const;
167 // Get the elongation angle (rad) for an observer at pos obsPos in heliocentric coordinates (in AU)
168 double getElongation(const Vec3d& obsPos) const;
169 // Get the angular size of the spheroid of the planet (i.e. without the rings)
170 double getSpheroidAngularSize(const StelCore* core) const;
171 // Get the planet phase for an observer at pos obsPos in heliocentric coordinates (in AU)
172 float getPhase(const Vec3d& obsPos) const;
173
174 // Set the orbital elements
175 void setRotationElements(float _period, float _offset, double _epoch,
176 float _obliquity, float _ascendingNode,
177 float _precessionRate, double _siderealPeriod);
178 double getRotAscendingnode(void) const {return re.ascendingNode;}
179 double getRotObliquity(double JDay) const;
180
181 //! Get the Planet position in the parent Planet ecliptic coordinate in AU
182 Vec3d getEclipticPos() const;
183
184 // Return the heliocentric ecliptical position
185 Vec3d getHeliocentricEclipticPos() const;
186
187 // Return the heliocentric transformation for local coordinate
188 Vec3d getHeliocentricPos(Vec3d) const;
189 void setHeliocentricEclipticPos(const Vec3d &pos);
190
191 // Compute the distance to the given position in heliocentric coordinate (in AU)
192 double computeDistance(const Vec3d& obsHelioPos);
193 double getDistance(void) const {return distance;}
194
195 void setRings(Ring* r) {rings = r;}
196
197 void setSphereScale(float s) {sphereScale = s;}
198 float getSphereScale(void) const {return sphereScale;}
199
200 const QSharedPointer<Planet> getParent(void) const {return parent;}
201
202 static void setLabelColor(const Vec3f& lc) {labelColor = lc;}
203 static const Vec3f& getLabelColor(void) {return labelColor;}
204
205 // update displayed elements. @param deltaTime: ms (?)
206 void update(int deltaTime);
207
208 void setFlagHints(bool b){hintFader = b;}
209 bool getFlagHints(void) const {return hintFader;}
210
211 void setFlagLabels(bool b){flagLabels = b;}
212 bool getFlagLabels(void) const {return flagLabels;}
213
214 ///////////////////////////////////////////////////////////////////////////
215 // DEPRECATED
216 ///// Orbit related code
217 // Should move to an OrbitPath class which works on a SolarSystemObject, not a Planet
218 void setFlagOrbits(bool b){orbitFader = b;}
219 bool getFlagOrbits(void) const {return orbitFader;}
220 LinearFader orbitFader;
221 // draw orbital path of Planet
222 void drawOrbit(const StelCore*);
223 Vec3d orbit[ORBIT_SEGMENTS+1]; // store heliocentric coordinates for drawing the orbit
224 Vec3d orbitP[ORBIT_SEGMENTS+1]; // store local coordinate for orbit
225 double lastOrbitJD;
226 double deltaJD; // time difference between positional updates.
227 double deltaOrbitJD;
228 bool orbitCached; // whether orbit calculations are cached for drawing orbit yet
229 bool closeOrbit; // whether to connect the beginning of the orbit line to
230 // the end: good for elliptical orbits, bad for parabolic
231 // and hyperbolic orbits
232
233 static Vec3f orbitColor;
234 static void setOrbitColor(const Vec3f& oc) {orbitColor = oc;}
235 static const Vec3f& getOrbitColor() {return orbitColor;}
236
237 //! Return the list of planets which project some shadow on this planet
238 QVector<const Planet*> getCandidatesForShadow() const;
239
240protected:
241 static StelTextureSP texEarthShadow; // for lunar eclipses
242
243 void computeModelMatrix(Mat4d &result) const;
244
245 // Return the information string "ready to print" :)
246 QString getSkyLabel(const StelCore* core) const;
247
248 // Draw the 3d model. Call the proper functions if there are rings etc..
249 void draw3dModel(StelCore* core, StelProjector::ModelViewTranformP transfo, float screenSz, bool drawOnlyRing=false);
250
251 // Draw the 3D sphere
252 void drawSphere(StelPainter* painter, float screenSz, bool drawOnlyRing=false);
253
254 // Draw the circle and name of the Planet
255 void drawHints(const StelCore* core, const QFont& planetNameFont);
256
257 QString englishName; // english planet name
258 QString nameI18; // International translated name
259 QString texMapName; // Texture file path
260 QString normalMapName; // Texture file path
261 int flagLighting; // Set whether light computation has to be proceed
262 RotationElements re; // Rotation param
263 double radius; // Planet radius in AU
264 double oneMinusOblateness; // (polar radius)/(equatorial radius)
265 Vec3d eclipticPos; // Position in AU in the rectangular ecliptic coordinate system
266 // centered on the parent Planet
267 Vec3d screenPos; // Used to store temporarily the 2D position on screen
268 Vec3d previousScreenPos; // The position of this planet in the previous frame.
269 Vec3f color; // exclusively used for drawing the planet halo
270
271 float albedo; // Planet albedo. Used for magnitude computation (but formula dubious!)
272 Mat4d rotLocalToParent;
273 float axisRotation; // Rotation angle of the Planet on it's axis
274 StelTextureSP texMap; // Planet map texture
275 StelTextureSP normalMap; // Planet normal map texture
276
277 Ring* rings; // Planet rings
278 double distance; // Temporary variable used to store the distance to a given point
279 // it is used for sorting while drawing
280 float sphereScale; // Artificial scaling for better viewing
281 double lastJD; // caches JD of last positional computation
282 // The callback for the calculation of the equatorial rect heliocentric position at time JD.
283 posFuncType coordFunc;
284 void* userDataPtr;
285
286 OsculatingFunctType *const osculatingFunc;
287 QSharedPointer<Planet> parent; // Planet parent i.e. sun for earth
288 QList<QSharedPointer<Planet> > satellites; // satellites of the Planet
289 LinearFader hintFader;
290 LinearFader labelsFader; // Store the current state of the label for this planet
291 bool flagLabels; // Define whether labels should be displayed
292 bool hidden; // useful for fake planets used as observation positions - not drawn or labeled
293 bool atmosphere; // Does the planet have an atmosphere?
294 bool halo; // Does the planet have a halo?
295 QString pType; // Type of body
296
297 static Vec3f labelColor;
298 static StelTextureSP hintCircleTex;
299
300 // Shader-related variables
301 struct PlanetShaderVars {
302 int projectionMatrix;
303 int texCoord;
304 int unprojectedVertex;
305 int vertex;
306 int texture;
307 int lightDirection;
308 int eyeDirection;
309 int diffuseLight;
310 int ambientLight;
311 int shadowCount;
312 int shadowData;
313 int sunInfo;
314
315 void initLocations(QOpenGLShaderProgram*);
316 };
317 static PlanetShaderVars planetShaderVars;
318 static QOpenGLShaderProgram* planetShaderProgram;
319
320 // Shader-related variables
321 struct RingPlanetShaderVars : public PlanetShaderVars {
322 // Rings-specific variables
323 int isRing;
324 int ring;
325 int outerRadius;
326 int innerRadius;
327 int ringS;
328 };
329 static RingPlanetShaderVars ringPlanetShaderVars;
330 static QOpenGLShaderProgram* ringPlanetShaderProgram;
331
332 struct MoonShaderVars : public PlanetShaderVars {
333 // Moon-specific variables
334 int earthShadow;
335 int normalMap;
336 };
337 static MoonShaderVars moonShaderVars;
338 static QOpenGLShaderProgram* moonShaderProgram;
339
340 static void initShader();
341 static void deinitShader();
342
343};
344
345#endif // _PLANET_HPP_
346
3470
=== modified file 'src/core/modules/SolarSystem.cpp'
--- src/core/modules/SolarSystem.cpp 2014-08-30 16:58:25 +0000
+++ src/core/modules/SolarSystem.cpp 2014-08-31 09:14:13 +0000
@@ -119,6 +119,7 @@
119 QSettings* conf = StelApp::getInstance().getSettings();119 QSettings* conf = StelApp::getInstance().getSettings();
120 Q_ASSERT(conf);120 Q_ASSERT(conf);
121121
122 Planet::init();
122 loadPlanets(); // Load planets data123 loadPlanets(); // Load planets data
123124
124 // Compute position and matrix of sun and all the satellites (ie planets)125 // Compute position and matrix of sun and all the satellites (ie planets)
@@ -1069,7 +1070,7 @@
1069QString SolarSystem::getPlanetType(QString planetName) const1070QString SolarSystem::getPlanetType(QString planetName) const
1070{1071{
1071 PlanetP p = searchByEnglishName(planetName);1072 PlanetP p = searchByEnglishName(planetName);
1072 return p->getPlanetType();1073 return Planet::pTypeMap.value(p->getPlanetType());
1073}1074}
10741075
1075double SolarSystem::getDistanceToPlanet(QString planetName) const1076double SolarSystem::getDistanceToPlanet(QString planetName) const
@@ -1382,7 +1383,7 @@
1382 {1383 {
1383 foreach(const PlanetP& p, systemPlanets)1384 foreach(const PlanetP& p, systemPlanets)
1384 {1385 {
1385 if (p->getPlanetType()==objType)1386 if (Planet::pTypeMap.value(p->getPlanetType())==objType)
1386 result << p->getEnglishName();1387 result << p->getEnglishName();
1387 }1388 }
1388 }1389 }
@@ -1390,7 +1391,7 @@
1390 {1391 {
1391 foreach(const PlanetP& p, systemPlanets)1392 foreach(const PlanetP& p, systemPlanets)
1392 {1393 {
1393 if (p->getPlanetType()==objType)1394 if (Planet::pTypeMap.value(p->getPlanetType())==objType)
1394 result << p->getNameI18n();1395 result << p->getNameI18n();
1395 }1396 }
1396 }1397 }