Merge lp:~georg-zotti/stellarium/gz-planet-type-enum into lp:stellarium
- gz-planet-type-enum
- Merge into trunk
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 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Alexander Wolf | Approve | ||
gzotti | Needs Resubmitting | ||
Review via email: mp+232802@code.launchpad.net |
Commit message
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
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
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/core/modules/Comet.cpp' | |||
2 | --- src/core/modules/Comet.cpp 2014-08-17 09:28:31 +0000 | |||
3 | +++ src/core/modules/Comet.cpp 2014-08-31 09:14:13 +0000 | |||
4 | @@ -52,7 +52,7 @@ | |||
5 | 52 | OsculatingFunctType *osculatingFunc, | 52 | OsculatingFunctType *osculatingFunc, |
6 | 53 | bool acloseOrbit, | 53 | bool acloseOrbit, |
7 | 54 | bool hidden, | 54 | bool hidden, |
9 | 55 | const QString& pType, | 55 | const QString& pTypeStr, |
10 | 56 | float dustTailWidthFact, float dustTailLengthFact, float dustTailBrightnessFact) | 56 | float dustTailWidthFact, float dustTailLengthFact, float dustTailBrightnessFact) |
11 | 57 | : Planet (englishName, | 57 | : Planet (englishName, |
12 | 58 | flagLighting, | 58 | flagLighting, |
13 | @@ -69,7 +69,7 @@ | |||
14 | 69 | hidden, | 69 | hidden, |
15 | 70 | false, //No atmosphere | 70 | false, //No atmosphere |
16 | 71 | true, //halo | 71 | true, //halo |
18 | 72 | pType), | 72 | pTypeStr), |
19 | 73 | dustTailWidthFactor(dustTailWidthFact), | 73 | dustTailWidthFactor(dustTailWidthFact), |
20 | 74 | dustTailLengthFactor(dustTailLengthFact), | 74 | dustTailLengthFactor(dustTailLengthFact), |
21 | 75 | dustTailBrightnessFactor(dustTailBrightnessFact) | 75 | dustTailBrightnessFactor(dustTailBrightnessFact) |
22 | @@ -142,8 +142,7 @@ | |||
23 | 142 | 142 | ||
24 | 143 | if (flags&ObjectType) | 143 | if (flags&ObjectType) |
25 | 144 | { | 144 | { |
28 | 145 | if (pType.length()>0) | 145 | oss << q_("Type: <b>%1</b>").arg(q_(Planet::pTypeMap.value(pType))) << "<br />"; |
27 | 146 | oss << q_("Type: <b>%1</b>").arg(q_(pType)) << "<br />"; | ||
29 | 147 | } | 146 | } |
30 | 148 | 147 | ||
31 | 149 | if (flags&Magnitude) | 148 | if (flags&Magnitude) |
32 | 150 | 149 | ||
33 | === modified file 'src/core/modules/Comet.hpp' | |||
34 | --- src/core/modules/Comet.hpp 2014-08-17 09:28:31 +0000 | |||
35 | +++ src/core/modules/Comet.hpp 2014-08-31 09:14:13 +0000 | |||
36 | @@ -38,22 +38,22 @@ | |||
37 | 38 | public: | 38 | public: |
38 | 39 | friend class SolarSystem; // Solar System initializes static constants. | 39 | friend class SolarSystem; // Solar System initializes static constants. |
39 | 40 | Comet(const QString& englishName, | 40 | Comet(const QString& englishName, |
56 | 41 | int flagLighting, | 41 | int flagLighting, |
57 | 42 | double radius, | 42 | double radius, |
58 | 43 | double oblateness, | 43 | double oblateness, |
59 | 44 | Vec3f color, | 44 | Vec3f color, |
60 | 45 | float albedo, | 45 | float albedo, |
61 | 46 | const QString& texMapName, | 46 | const QString& texMapName, |
62 | 47 | posFuncType _coordFunc, | 47 | posFuncType _coordFunc, |
63 | 48 | void* userDataPtr, | 48 | void* userDataPtr, |
64 | 49 | OsculatingFunctType *osculatingFunc, | 49 | OsculatingFunctType *osculatingFunc, |
65 | 50 | bool closeOrbit, | 50 | bool closeOrbit, |
66 | 51 | bool hidden, | 51 | bool hidden, |
67 | 52 | const QString &pType, | 52 | const QString &pTypeStr, |
68 | 53 | float dustTailWidthFact=1.5f, | 53 | float dustTailWidthFact=1.5f, |
69 | 54 | float dustTailLengthFact=0.4f, | 54 | float dustTailLengthFact=0.4f, |
70 | 55 | float dustTailBrightnessFact=1.5f | 55 | float dustTailBrightnessFact=1.5f |
71 | 56 | ); | 56 | ); |
72 | 57 | 57 | ||
73 | 58 | virtual ~Comet(); | 58 | virtual ~Comet(); |
74 | 59 | 59 | ||
75 | 60 | 60 | ||
76 | === modified file 'src/core/modules/MinorPlanet.cpp' | |||
77 | --- src/core/modules/MinorPlanet.cpp 2014-08-16 17:40:45 +0000 | |||
78 | +++ src/core/modules/MinorPlanet.cpp 2014-08-31 09:14:13 +0000 | |||
79 | @@ -45,7 +45,7 @@ | |||
80 | 45 | OsculatingFunctType *osculatingFunc, | 45 | OsculatingFunctType *osculatingFunc, |
81 | 46 | bool acloseOrbit, | 46 | bool acloseOrbit, |
82 | 47 | bool hidden, | 47 | bool hidden, |
84 | 48 | const QString &pType) | 48 | const QString &pTypeStr) |
85 | 49 | : Planet (englishName, | 49 | : Planet (englishName, |
86 | 50 | flagLighting, | 50 | flagLighting, |
87 | 51 | radius, | 51 | radius, |
88 | @@ -61,7 +61,7 @@ | |||
89 | 61 | hidden, | 61 | hidden, |
90 | 62 | false, //No atmosphere | 62 | false, //No atmosphere |
91 | 63 | true, //Halo | 63 | true, //Halo |
93 | 64 | pType) | 64 | pTypeStr) |
94 | 65 | { | 65 | { |
95 | 66 | texMapName = atexMapName; | 66 | texMapName = atexMapName; |
96 | 67 | lastOrbitJD =0; | 67 | lastOrbitJD =0; |
97 | @@ -205,8 +205,7 @@ | |||
98 | 205 | 205 | ||
99 | 206 | if (flags&ObjectType) | 206 | if (flags&ObjectType) |
100 | 207 | { | 207 | { |
103 | 208 | if (pType.length()>0) | 208 | oss << q_("Type: <b>%1</b>").arg(q_(Planet::pTypeMap.value(pType))) << "<br />"; |
102 | 209 | oss << q_("Type: <b>%1</b>").arg(q_(pType)) << "<br />"; | ||
104 | 210 | } | 209 | } |
105 | 211 | 210 | ||
106 | 212 | if (flags&Magnitude) | 211 | if (flags&Magnitude) |
107 | 213 | 212 | ||
108 | === modified file 'src/core/modules/MinorPlanet.hpp' | |||
109 | --- src/core/modules/MinorPlanet.hpp 2014-08-16 17:40:45 +0000 | |||
110 | +++ src/core/modules/MinorPlanet.hpp 2014-08-31 09:14:13 +0000 | |||
111 | @@ -50,7 +50,7 @@ | |||
112 | 50 | OsculatingFunctType *osculatingFunc, | 50 | OsculatingFunctType *osculatingFunc, |
113 | 51 | bool closeOrbit, | 51 | bool closeOrbit, |
114 | 52 | bool hidden, | 52 | bool hidden, |
116 | 53 | const QString &pType); | 53 | const QString &pTypeStr); |
117 | 54 | 54 | ||
118 | 55 | ~MinorPlanet(); | 55 | ~MinorPlanet(); |
119 | 56 | 56 | ||
120 | 57 | 57 | ||
121 | === modified file 'src/core/modules/Planet.cpp' | |||
122 | --- src/core/modules/Planet.cpp 2014-08-17 19:41:04 +0000 | |||
123 | +++ src/core/modules/Planet.cpp 2014-08-31 09:14:13 +0000 | |||
124 | @@ -71,7 +71,7 @@ | |||
125 | 71 | bool hidden, | 71 | bool hidden, |
126 | 72 | bool hasAtmosphere, | 72 | bool hasAtmosphere, |
127 | 73 | bool hasHalo, | 73 | bool hasHalo, |
129 | 74 | const QString& pType) | 74 | const QString& pTypeStr) |
130 | 75 | : englishName(englishName), | 75 | : englishName(englishName), |
131 | 76 | flagLighting(flagLighting), | 76 | flagLighting(flagLighting), |
132 | 77 | radius(radius), | 77 | radius(radius), |
133 | @@ -88,8 +88,7 @@ | |||
134 | 88 | parent(NULL), | 88 | parent(NULL), |
135 | 89 | hidden(hidden), | 89 | hidden(hidden), |
136 | 90 | atmosphere(hasAtmosphere), | 90 | atmosphere(hasAtmosphere), |
139 | 91 | halo(hasHalo), | 91 | halo(hasHalo) |
138 | 92 | pType(pType) | ||
140 | 93 | { | 92 | { |
141 | 94 | texMapName = atexMapName; | 93 | texMapName = atexMapName; |
142 | 95 | normalMapName = anormalMapName; | 94 | normalMapName = anormalMapName; |
143 | @@ -100,6 +99,10 @@ | |||
144 | 100 | deltaOrbitJD = 0; | 99 | deltaOrbitJD = 0; |
145 | 101 | distance = 0; | 100 | distance = 0; |
146 | 102 | 101 | ||
147 | 102 | // Initialize pType with the key found in pTypeMap, or mark planet type as undefined. | ||
148 | 103 | // The latter condition should obviously never happen. | ||
149 | 104 | pType=pTypeMap.key(pTypeStr, Planet::isUNDEFINED); | ||
150 | 105 | |||
151 | 103 | eclipticPos=Vec3d(0.,0.,0.); | 106 | eclipticPos=Vec3d(0.,0.,0.); |
152 | 104 | rotLocalToParent = Mat4d::identity(); | 107 | rotLocalToParent = Mat4d::identity(); |
153 | 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)); |
154 | @@ -113,6 +116,26 @@ | |||
155 | 113 | flagLabels = true; | 116 | flagLabels = true; |
156 | 114 | } | 117 | } |
157 | 115 | 118 | ||
158 | 119 | QMap<Planet::PlanetType, QString> Planet::pTypeMap; | ||
159 | 120 | |||
160 | 121 | // called in SolarSystem::init() before first planet is created. Loads pTypeMap. | ||
161 | 122 | void Planet::init() | ||
162 | 123 | { | ||
163 | 124 | if (pTypeMap.count() > 0 ) | ||
164 | 125 | { | ||
165 | 126 | // This should never happen. But it's uncritical. | ||
166 | 127 | qDebug() << "Planet::init(): Non-empty static map. This is a programming error, but we can fix that."; | ||
167 | 128 | pTypeMap.clear(); | ||
168 | 129 | } | ||
169 | 130 | pTypeMap.insert(Planet::isStar, "star"); | ||
170 | 131 | pTypeMap.insert(Planet::isPlanet, "planet"); | ||
171 | 132 | pTypeMap.insert(Planet::isMoon, "moon"); | ||
172 | 133 | pTypeMap.insert(Planet::isAsteroid, "asteroid"); | ||
173 | 134 | pTypeMap.insert(Planet::isPlutoid, "plutoid"); | ||
174 | 135 | pTypeMap.insert(Planet::isComet, "comet"); | ||
175 | 136 | pTypeMap.insert(Planet::isUNDEFINED, "UNDEFINED"); // something must be broken before we ever see this! | ||
176 | 137 | } | ||
177 | 138 | |||
178 | 116 | Planet::~Planet() | 139 | Planet::~Planet() |
179 | 117 | { | 140 | { |
180 | 118 | if (rings) | 141 | if (rings) |
181 | @@ -142,8 +165,7 @@ | |||
182 | 142 | 165 | ||
183 | 143 | if (flags&ObjectType) | 166 | if (flags&ObjectType) |
184 | 144 | { | 167 | { |
187 | 145 | if (pType.length()>0) | 168 | oss << q_("Type: <b>%1</b>").arg(q_(Planet::pTypeMap.value(pType))) << "<br />"; |
186 | 146 | oss << q_("Type: <b>%1</b>").arg(q_(pType)) << "<br />"; | ||
188 | 147 | } | 169 | } |
189 | 148 | 170 | ||
190 | 149 | if (flags&Magnitude) | 171 | if (flags&Magnitude) |
191 | @@ -574,7 +596,7 @@ | |||
192 | 574 | if (englishName=="Venus" || englishName=="Uranus" || englishName=="Pluto") | 596 | if (englishName=="Venus" || englishName=="Uranus" || englishName=="Pluto") |
193 | 575 | sign = -1; | 597 | sign = -1; |
194 | 576 | 598 | ||
196 | 577 | if (pType.contains("moon")) | 599 | if (pType==Planet::isMoon) |
197 | 578 | { | 600 | { |
198 | 579 | // duration of mean solar day on moon are same as synodic month on this moon | 601 | // duration of mean solar day on moon are same as synodic month on this moon |
199 | 580 | double a = parent->getSiderealPeriod()/sday; | 602 | double a = parent->getSiderealPeriod()/sday; |
200 | @@ -646,7 +668,7 @@ | |||
201 | 646 | { | 668 | { |
202 | 647 | distance = (obsHelioPos-getHeliocentricEclipticPos()).length(); | 669 | distance = (obsHelioPos-getHeliocentricEclipticPos()).length(); |
203 | 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. |
205 | 649 | if (pType == "asteroid") | 671 | if (pType == Planet::isAsteroid) |
206 | 650 | deltaJD=distance*StelCore::JD_SECOND; | 672 | deltaJD=distance*StelCore::JD_SECOND; |
207 | 651 | return distance; | 673 | return distance; |
208 | 652 | } | 674 | } |
209 | @@ -870,7 +892,8 @@ | |||
210 | 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. |
211 | 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. |
212 | 872 | // AW: Apply this rule to asteroids only | 894 | // AW: Apply this rule to asteroids only |
214 | 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! |
215 | 896 | if (((getVMagnitude(core)-1.0f) > core->getSkyDrawer()->getLimitMagnitude()) && pType==Planet::isAsteroid) | ||
216 | 874 | { | 897 | { |
217 | 875 | return; | 898 | return; |
218 | 876 | } | 899 | } |
219 | 877 | 900 | ||
220 | === added file 'src/core/modules/Planet.hpp' | |||
221 | --- src/core/modules/Planet.hpp 1970-01-01 00:00:00 +0000 | |||
222 | +++ src/core/modules/Planet.hpp 2014-08-31 09:14:13 +0000 | |||
223 | @@ -0,0 +1,370 @@ | |||
224 | 1 | /* | ||
225 | 2 | * Stellarium | ||
226 | 3 | * Copyright (C) 2002 Fabien Chereau | ||
227 | 4 | * | ||
228 | 5 | * This program is free software; you can redistribute it and/or | ||
229 | 6 | * modify it under the terms of the GNU General Public License | ||
230 | 7 | * as published by the Free Software Foundation; either version 2 | ||
231 | 8 | * of the License, or (at your option) any later version. | ||
232 | 9 | * | ||
233 | 10 | * This program is distributed in the hope that it will be useful, | ||
234 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
235 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
236 | 13 | * GNU General Public License for more details. | ||
237 | 14 | * | ||
238 | 15 | * You should have received a copy of the GNU General Public License | ||
239 | 16 | * along with this program; if not, write to the Free Software | ||
240 | 17 | * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. | ||
241 | 18 | */ | ||
242 | 19 | |||
243 | 20 | #ifndef _PLANET_HPP_ | ||
244 | 21 | #define _PLANET_HPP_ | ||
245 | 22 | |||
246 | 23 | #include "StelObject.hpp" | ||
247 | 24 | #include "StelProjector.hpp" | ||
248 | 25 | #include "VecMath.hpp" | ||
249 | 26 | #include "StelFader.hpp" | ||
250 | 27 | #include "StelTextureTypes.hpp" | ||
251 | 28 | #include "StelProjectorType.hpp" | ||
252 | 29 | |||
253 | 30 | #include <QString> | ||
254 | 31 | |||
255 | 32 | // The callback type for the external position computation function | ||
256 | 33 | // The last variable is the userData pointer. | ||
257 | 34 | typedef void (*posFuncType)(double, double*, void*); | ||
258 | 35 | |||
259 | 36 | typedef void (OsculatingFunctType)(double jd0,double jd,double xyz[3]); | ||
260 | 37 | |||
261 | 38 | // epoch J2000: 12 UT on 1 Jan 2000 | ||
262 | 39 | #define J2000 2451545.0 | ||
263 | 40 | #define ORBIT_SEGMENTS 360 | ||
264 | 41 | |||
265 | 42 | class StelFont; | ||
266 | 43 | class StelPainter; | ||
267 | 44 | class StelTranslator; | ||
268 | 45 | class QOpenGLShaderProgram; | ||
269 | 46 | |||
270 | 47 | // Class used to store orbital elements | ||
271 | 48 | class RotationElements | ||
272 | 49 | { | ||
273 | 50 | public: | ||
274 | 51 | RotationElements(void) : period(1.), offset(0.), epoch(J2000), obliquity(0.), ascendingNode(0.), precessionRate(0.), siderealPeriod(0.) {} | ||
275 | 52 | float period; // rotation period | ||
276 | 53 | float offset; // rotation at epoch | ||
277 | 54 | double epoch; | ||
278 | 55 | float obliquity; // tilt of rotation axis w.r.t. ecliptic | ||
279 | 56 | float ascendingNode; // long. of ascending node of equator on the ecliptic | ||
280 | 57 | float precessionRate; // rate of precession of rotation axis in rads/day | ||
281 | 58 | double siderealPeriod; // sidereal period (Planet year in earth days) | ||
282 | 59 | }; | ||
283 | 60 | |||
284 | 61 | // Class to manage rings for planets like saturn | ||
285 | 62 | class Ring | ||
286 | 63 | { | ||
287 | 64 | public: | ||
288 | 65 | Ring(float radiusMin, float radiusMax,const QString &texname); | ||
289 | 66 | double getSize(void) const {return radiusMax;} | ||
290 | 67 | const float radiusMin; | ||
291 | 68 | const float radiusMax; | ||
292 | 69 | StelTextureSP tex; | ||
293 | 70 | }; | ||
294 | 71 | |||
295 | 72 | |||
296 | 73 | class Planet : public StelObject | ||
297 | 74 | { | ||
298 | 75 | public: | ||
299 | 76 | friend class SolarSystem; | ||
300 | 77 | |||
301 | 78 | Q_ENUMS(PlanetType) | ||
302 | 79 | //! numeric typecodes for the type descriptions in ssystem.ini | ||
303 | 80 | // GZ: Until 0.13 QStrings were used for types. | ||
304 | 81 | // GZ: Enums are slightly faster than string comparisons in time-critical comparisons. | ||
305 | 82 | // GZ: If other types are introduced, add here and the string in init(). | ||
306 | 83 | enum PlanetType | ||
307 | 84 | { | ||
308 | 85 | isStar, // ssystem.ini: type="star" | ||
309 | 86 | isPlanet, // ssystem.ini: type="planet" | ||
310 | 87 | isMoon, // ssystem.ini: type="moon" | ||
311 | 88 | isAsteroid, // ssystem.ini: type="asteroid" | ||
312 | 89 | isPlutoid, // ssystem.ini: type="plutoid" | ||
313 | 90 | isComet, // ssystem.ini: type="comet" | ||
314 | 91 | isUNDEFINED // ssystem.ini: type=<anything else> | ||
315 | 92 | }; | ||
316 | 93 | |||
317 | 94 | Planet(const QString& englishName, | ||
318 | 95 | int flagLighting, | ||
319 | 96 | double radius, | ||
320 | 97 | double oblateness, | ||
321 | 98 | Vec3f color, | ||
322 | 99 | float albedo, | ||
323 | 100 | const QString& texMapName, | ||
324 | 101 | const QString& normalMapName, | ||
325 | 102 | posFuncType _coordFunc, | ||
326 | 103 | void* userDataPtr, | ||
327 | 104 | OsculatingFunctType *osculatingFunc, | ||
328 | 105 | bool closeOrbit, | ||
329 | 106 | bool hidden, | ||
330 | 107 | bool hasAtmosphere, | ||
331 | 108 | bool hasHalo, | ||
332 | 109 | const QString &pTypeStr); | ||
333 | 110 | |||
334 | 111 | virtual ~Planet(); | ||
335 | 112 | |||
336 | 113 | //! Initializes static vars. Must be called before creating first planet. | ||
337 | 114 | // Currently ensured by SolarSystem::init() | ||
338 | 115 | static void init(); | ||
339 | 116 | |||
340 | 117 | /////////////////////////////////////////////////////////////////////////// | ||
341 | 118 | // Methods inherited from StelObject | ||
342 | 119 | //! Get a string with data about the Planet. | ||
343 | 120 | //! Planets support the following InfoStringGroup flags: | ||
344 | 121 | //! - Name | ||
345 | 122 | //! - Magnitude | ||
346 | 123 | //! - RaDec | ||
347 | 124 | //! - AltAzi | ||
348 | 125 | //! - Distance | ||
349 | 126 | //! - Size | ||
350 | 127 | //! - PlainText | ||
351 | 128 | //! - Extra: Heliocentric Ecliptical Coordinates & Observer-planetocentric Ecliptical Coordinates, Phase, illumination, phase angle & elongation from the Sun | ||
352 | 129 | //! @param core the StelCore object | ||
353 | 130 | //! @param flags a set of InfoStringGroup items to include in the return value. | ||
354 | 131 | //! @return a QString containing an HMTL encoded description of the Planet. | ||
355 | 132 | virtual QString getInfoString(const StelCore *core, const InfoStringGroup& flags) const; | ||
356 | 133 | virtual double getCloseViewFov(const StelCore* core) const; | ||
357 | 134 | virtual double getSatellitesFov(const StelCore* core) const; | ||
358 | 135 | virtual double getParentSatellitesFov(const StelCore* core) const; | ||
359 | 136 | virtual float getVMagnitude(const StelCore* core) const; | ||
360 | 137 | virtual float getSelectPriority(const StelCore* core) const; | ||
361 | 138 | virtual Vec3f getInfoColor(void) const; | ||
362 | 139 | virtual QString getType(void) const {return "Planet";} | ||
363 | 140 | virtual Vec3d getJ2000EquatorialPos(const StelCore *core) const; | ||
364 | 141 | virtual QString getEnglishName(void) const {return englishName;} | ||
365 | 142 | virtual QString getNameI18n(void) const {return nameI18;} | ||
366 | 143 | virtual double getAngularSize(const StelCore* core) const; | ||
367 | 144 | virtual bool hasAtmosphere(void) {return atmosphere;} | ||
368 | 145 | virtual bool hasHalo(void) {return halo;} | ||
369 | 146 | |||
370 | 147 | /////////////////////////////////////////////////////////////////////////// | ||
371 | 148 | // Methods of SolarSystem object | ||
372 | 149 | //! Translate planet name using the passed translator | ||
373 | 150 | virtual void translateName(const StelTranslator &trans); | ||
374 | 151 | |||
375 | 152 | // Draw the Planet | ||
376 | 153 | // GZ Made that virtual to allow comets having their own draw(). | ||
377 | 154 | virtual void draw(StelCore* core, float maxMagLabels, const QFont& planetNameFont); | ||
378 | 155 | |||
379 | 156 | /////////////////////////////////////////////////////////////////////////// | ||
380 | 157 | // Methods specific to Planet | ||
381 | 158 | //! Get the radius of the planet in AU. | ||
382 | 159 | //! @return the radius of the planet in astronomical units. | ||
383 | 160 | double getRadius(void) const {return radius;} | ||
384 | 161 | //! Get duration of sidereal day | ||
385 | 162 | double getSiderealDay(void) const {return re.period;} | ||
386 | 163 | //! Get duration of sidereal year | ||
387 | 164 | // GZ: made that virtual for Comets. | ||
388 | 165 | virtual double getSiderealPeriod(void) const { return re.siderealPeriod; } | ||
389 | 166 | //! Get duration of mean solar day | ||
390 | 167 | double getMeanSolarDay(void) const; | ||
391 | 168 | |||
392 | 169 | const QString& getTextMapName() const {return texMapName;} | ||
393 | 170 | //const QString getPlanetType() const {return pTypeStr;} | ||
394 | 171 | const PlanetType getPlanetType() const {return pType;} | ||
395 | 172 | |||
396 | 173 | // Compute the z rotation to use from equatorial to geographic coordinates | ||
397 | 174 | double getSiderealTime(double jd) const; | ||
398 | 175 | Mat4d getRotEquatorialToVsop87(void) const; | ||
399 | 176 | void setRotEquatorialToVsop87(const Mat4d &m); | ||
400 | 177 | |||
401 | 178 | const RotationElements &getRotationElements(void) const {return re;} | ||
402 | 179 | |||
403 | 180 | // Compute the position in the parent Planet coordinate system | ||
404 | 181 | void computePositionWithoutOrbits(const double dateJD); | ||
405 | 182 | virtual void computePosition(const double dateJD);// GZ: gets overridden in Comet! | ||
406 | 183 | |||
407 | 184 | // Compute the transformation matrix from the local Planet coordinate to the parent Planet coordinate | ||
408 | 185 | void computeTransMatrix(double date); | ||
409 | 186 | |||
410 | 187 | // Get the phase angle (rad) for an observer at pos obsPos in heliocentric coordinates (in AU) | ||
411 | 188 | double getPhaseAngle(const Vec3d& obsPos) const; | ||
412 | 189 | // Get the elongation angle (rad) for an observer at pos obsPos in heliocentric coordinates (in AU) | ||
413 | 190 | double getElongation(const Vec3d& obsPos) const; | ||
414 | 191 | // Get the angular size of the spheroid of the planet (i.e. without the rings) | ||
415 | 192 | double getSpheroidAngularSize(const StelCore* core) const; | ||
416 | 193 | // Get the planet phase for an observer at pos obsPos in heliocentric coordinates (in AU) | ||
417 | 194 | float getPhase(const Vec3d& obsPos) const; | ||
418 | 195 | |||
419 | 196 | // Set the orbital elements | ||
420 | 197 | void setRotationElements(float _period, float _offset, double _epoch, | ||
421 | 198 | float _obliquity, float _ascendingNode, | ||
422 | 199 | float _precessionRate, double _siderealPeriod); | ||
423 | 200 | double getRotAscendingnode(void) const {return re.ascendingNode;} | ||
424 | 201 | double getRotObliquity(double JDay) const; | ||
425 | 202 | |||
426 | 203 | //! Get the Planet position in the parent Planet ecliptic coordinate in AU | ||
427 | 204 | Vec3d getEclipticPos() const; | ||
428 | 205 | |||
429 | 206 | // Return the heliocentric ecliptical position | ||
430 | 207 | Vec3d getHeliocentricEclipticPos() const; | ||
431 | 208 | |||
432 | 209 | // Return the heliocentric transformation for local coordinate | ||
433 | 210 | Vec3d getHeliocentricPos(Vec3d) const; | ||
434 | 211 | void setHeliocentricEclipticPos(const Vec3d &pos); | ||
435 | 212 | |||
436 | 213 | // Compute the distance to the given position in heliocentric coordinate (in AU) | ||
437 | 214 | double computeDistance(const Vec3d& obsHelioPos); | ||
438 | 215 | double getDistance(void) const {return distance;} | ||
439 | 216 | |||
440 | 217 | void setRings(Ring* r) {rings = r;} | ||
441 | 218 | |||
442 | 219 | void setSphereScale(float s) {sphereScale = s;} | ||
443 | 220 | float getSphereScale(void) const {return sphereScale;} | ||
444 | 221 | |||
445 | 222 | const QSharedPointer<Planet> getParent(void) const {return parent;} | ||
446 | 223 | |||
447 | 224 | static void setLabelColor(const Vec3f& lc) {labelColor = lc;} | ||
448 | 225 | static const Vec3f& getLabelColor(void) {return labelColor;} | ||
449 | 226 | |||
450 | 227 | // update displayed elements. @param deltaTime: ms (?) | ||
451 | 228 | void update(int deltaTime); | ||
452 | 229 | |||
453 | 230 | void setFlagHints(bool b){hintFader = b;} | ||
454 | 231 | bool getFlagHints(void) const {return hintFader;} | ||
455 | 232 | |||
456 | 233 | void setFlagLabels(bool b){flagLabels = b;} | ||
457 | 234 | bool getFlagLabels(void) const {return flagLabels;} | ||
458 | 235 | |||
459 | 236 | /////////////////////////////////////////////////////////////////////////// | ||
460 | 237 | // DEPRECATED | ||
461 | 238 | ///// Orbit related code | ||
462 | 239 | // Should move to an OrbitPath class which works on a SolarSystemObject, not a Planet | ||
463 | 240 | void setFlagOrbits(bool b){orbitFader = b;} | ||
464 | 241 | bool getFlagOrbits(void) const {return orbitFader;} | ||
465 | 242 | LinearFader orbitFader; | ||
466 | 243 | // draw orbital path of Planet | ||
467 | 244 | void drawOrbit(const StelCore*); | ||
468 | 245 | Vec3d orbit[ORBIT_SEGMENTS+1]; // store heliocentric coordinates for drawing the orbit | ||
469 | 246 | Vec3d orbitP[ORBIT_SEGMENTS+1]; // store local coordinate for orbit | ||
470 | 247 | double lastOrbitJD; | ||
471 | 248 | double deltaJD; // time difference between positional updates. | ||
472 | 249 | double deltaOrbitJD; | ||
473 | 250 | bool orbitCached; // whether orbit calculations are cached for drawing orbit yet | ||
474 | 251 | bool closeOrbit; // whether to connect the beginning of the orbit line to | ||
475 | 252 | // the end: good for elliptical orbits, bad for parabolic | ||
476 | 253 | // and hyperbolic orbits | ||
477 | 254 | |||
478 | 255 | static Vec3f orbitColor; | ||
479 | 256 | static void setOrbitColor(const Vec3f& oc) {orbitColor = oc;} | ||
480 | 257 | static const Vec3f& getOrbitColor() {return orbitColor;} | ||
481 | 258 | |||
482 | 259 | //! Return the list of planets which project some shadow on this planet | ||
483 | 260 | QVector<const Planet*> getCandidatesForShadow() const; | ||
484 | 261 | |||
485 | 262 | protected: | ||
486 | 263 | static StelTextureSP texEarthShadow; // for lunar eclipses | ||
487 | 264 | |||
488 | 265 | void computeModelMatrix(Mat4d &result) const; | ||
489 | 266 | |||
490 | 267 | // Return the information string "ready to print" :) | ||
491 | 268 | QString getSkyLabel(const StelCore* core) const; | ||
492 | 269 | |||
493 | 270 | // Draw the 3d model. Call the proper functions if there are rings etc.. | ||
494 | 271 | void draw3dModel(StelCore* core, StelProjector::ModelViewTranformP transfo, float screenSz, bool drawOnlyRing=false); | ||
495 | 272 | |||
496 | 273 | // Draw the 3D sphere | ||
497 | 274 | void drawSphere(StelPainter* painter, float screenSz, bool drawOnlyRing=false); | ||
498 | 275 | |||
499 | 276 | // Draw the circle and name of the Planet | ||
500 | 277 | void drawHints(const StelCore* core, const QFont& planetNameFont); | ||
501 | 278 | |||
502 | 279 | QString englishName; // english planet name | ||
503 | 280 | QString nameI18; // International translated name | ||
504 | 281 | QString texMapName; // Texture file path | ||
505 | 282 | QString normalMapName; // Texture file path | ||
506 | 283 | int flagLighting; // Set whether light computation has to be proceed | ||
507 | 284 | RotationElements re; // Rotation param | ||
508 | 285 | double radius; // Planet radius in AU | ||
509 | 286 | double oneMinusOblateness; // (polar radius)/(equatorial radius) | ||
510 | 287 | Vec3d eclipticPos; // Position in AU in the rectangular ecliptic coordinate system | ||
511 | 288 | // centered on the parent Planet | ||
512 | 289 | Vec3d screenPos; // Used to store temporarily the 2D position on screen | ||
513 | 290 | Vec3d previousScreenPos; // The position of this planet in the previous frame. | ||
514 | 291 | Vec3f color; // exclusively used for drawing the planet halo | ||
515 | 292 | |||
516 | 293 | float albedo; // Planet albedo. Used for magnitude computation (but formula dubious!) | ||
517 | 294 | Mat4d rotLocalToParent; | ||
518 | 295 | float axisRotation; // Rotation angle of the Planet on it's axis | ||
519 | 296 | StelTextureSP texMap; // Planet map texture | ||
520 | 297 | StelTextureSP normalMap; // Planet normal map texture | ||
521 | 298 | |||
522 | 299 | Ring* rings; // Planet rings | ||
523 | 300 | double distance; // Temporary variable used to store the distance to a given point | ||
524 | 301 | // it is used for sorting while drawing | ||
525 | 302 | float sphereScale; // Artificial scaling for better viewing | ||
526 | 303 | double lastJD; // caches JD of last positional computation | ||
527 | 304 | // The callback for the calculation of the equatorial rect heliocentric position at time JD. | ||
528 | 305 | posFuncType coordFunc; | ||
529 | 306 | void* userDataPtr; | ||
530 | 307 | |||
531 | 308 | OsculatingFunctType *const osculatingFunc; | ||
532 | 309 | QSharedPointer<Planet> parent; // Planet parent i.e. sun for earth | ||
533 | 310 | QList<QSharedPointer<Planet> > satellites; // satellites of the Planet | ||
534 | 311 | LinearFader hintFader; | ||
535 | 312 | LinearFader labelsFader; // Store the current state of the label for this planet | ||
536 | 313 | bool flagLabels; // Define whether labels should be displayed | ||
537 | 314 | bool hidden; // useful for fake planets used as observation positions - not drawn or labeled | ||
538 | 315 | bool atmosphere; // Does the planet have an atmosphere? | ||
539 | 316 | bool halo; // Does the planet have a halo? | ||
540 | 317 | // QString pTypeStr; // Type of body, old version just had a string here. | ||
541 | 318 | PlanetType pType; // GZ this is now a proper type... | ||
542 | 319 | |||
543 | 320 | static Vec3f labelColor; | ||
544 | 321 | static StelTextureSP hintCircleTex; | ||
545 | 322 | static QMap<PlanetType, QString> pTypeMap; // GZ: maps fast type to english name. | ||
546 | 323 | |||
547 | 324 | // Shader-related variables | ||
548 | 325 | struct PlanetShaderVars { | ||
549 | 326 | int projectionMatrix; | ||
550 | 327 | int texCoord; | ||
551 | 328 | int unprojectedVertex; | ||
552 | 329 | int vertex; | ||
553 | 330 | int texture; | ||
554 | 331 | int lightDirection; | ||
555 | 332 | int eyeDirection; | ||
556 | 333 | int diffuseLight; | ||
557 | 334 | int ambientLight; | ||
558 | 335 | int shadowCount; | ||
559 | 336 | int shadowData; | ||
560 | 337 | int sunInfo; | ||
561 | 338 | |||
562 | 339 | void initLocations(QOpenGLShaderProgram*); | ||
563 | 340 | }; | ||
564 | 341 | static PlanetShaderVars planetShaderVars; | ||
565 | 342 | static QOpenGLShaderProgram* planetShaderProgram; | ||
566 | 343 | |||
567 | 344 | // Shader-related variables | ||
568 | 345 | struct RingPlanetShaderVars : public PlanetShaderVars { | ||
569 | 346 | // Rings-specific variables | ||
570 | 347 | int isRing; | ||
571 | 348 | int ring; | ||
572 | 349 | int outerRadius; | ||
573 | 350 | int innerRadius; | ||
574 | 351 | int ringS; | ||
575 | 352 | }; | ||
576 | 353 | static RingPlanetShaderVars ringPlanetShaderVars; | ||
577 | 354 | static QOpenGLShaderProgram* ringPlanetShaderProgram; | ||
578 | 355 | |||
579 | 356 | struct MoonShaderVars : public PlanetShaderVars { | ||
580 | 357 | // Moon-specific variables | ||
581 | 358 | int earthShadow; | ||
582 | 359 | int normalMap; | ||
583 | 360 | }; | ||
584 | 361 | static MoonShaderVars moonShaderVars; | ||
585 | 362 | static QOpenGLShaderProgram* moonShaderProgram; | ||
586 | 363 | |||
587 | 364 | static void initShader(); | ||
588 | 365 | static void deinitShader(); | ||
589 | 366 | |||
590 | 367 | }; | ||
591 | 368 | |||
592 | 369 | #endif // _PLANET_HPP_ | ||
593 | 370 | |||
594 | 0 | 371 | ||
595 | === removed file 'src/core/modules/Planet.hpp' | |||
596 | --- src/core/modules/Planet.hpp 2014-08-02 17:34:13 +0000 | |||
597 | +++ src/core/modules/Planet.hpp 1970-01-01 00:00:00 +0000 | |||
598 | @@ -1,346 +0,0 @@ | |||
599 | 1 | /* | ||
600 | 2 | * Stellarium | ||
601 | 3 | * Copyright (C) 2002 Fabien Chereau | ||
602 | 4 | * | ||
603 | 5 | * This program is free software; you can redistribute it and/or | ||
604 | 6 | * modify it under the terms of the GNU General Public License | ||
605 | 7 | * as published by the Free Software Foundation; either version 2 | ||
606 | 8 | * of the License, or (at your option) any later version. | ||
607 | 9 | * | ||
608 | 10 | * This program is distributed in the hope that it will be useful, | ||
609 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
610 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
611 | 13 | * GNU General Public License for more details. | ||
612 | 14 | * | ||
613 | 15 | * You should have received a copy of the GNU General Public License | ||
614 | 16 | * along with this program; if not, write to the Free Software | ||
615 | 17 | * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. | ||
616 | 18 | */ | ||
617 | 19 | |||
618 | 20 | #ifndef _PLANET_HPP_ | ||
619 | 21 | #define _PLANET_HPP_ | ||
620 | 22 | |||
621 | 23 | #include "StelObject.hpp" | ||
622 | 24 | #include "StelProjector.hpp" | ||
623 | 25 | #include "VecMath.hpp" | ||
624 | 26 | #include "StelFader.hpp" | ||
625 | 27 | #include "StelTextureTypes.hpp" | ||
626 | 28 | #include "StelProjectorType.hpp" | ||
627 | 29 | |||
628 | 30 | #include <QString> | ||
629 | 31 | |||
630 | 32 | // The callback type for the external position computation function | ||
631 | 33 | // The last variable is the userData pointer. | ||
632 | 34 | typedef void (*posFuncType)(double, double*, void*); | ||
633 | 35 | |||
634 | 36 | typedef void (OsculatingFunctType)(double jd0,double jd,double xyz[3]); | ||
635 | 37 | |||
636 | 38 | // epoch J2000: 12 UT on 1 Jan 2000 | ||
637 | 39 | #define J2000 2451545.0 | ||
638 | 40 | #define ORBIT_SEGMENTS 360 | ||
639 | 41 | |||
640 | 42 | class StelFont; | ||
641 | 43 | class StelPainter; | ||
642 | 44 | class StelTranslator; | ||
643 | 45 | class QOpenGLShaderProgram; | ||
644 | 46 | |||
645 | 47 | // Class used to store orbital elements | ||
646 | 48 | class RotationElements | ||
647 | 49 | { | ||
648 | 50 | public: | ||
649 | 51 | RotationElements(void) : period(1.), offset(0.), epoch(J2000), obliquity(0.), ascendingNode(0.), precessionRate(0.), siderealPeriod(0.) {} | ||
650 | 52 | float period; // rotation period | ||
651 | 53 | float offset; // rotation at epoch | ||
652 | 54 | double epoch; | ||
653 | 55 | float obliquity; // tilt of rotation axis w.r.t. ecliptic | ||
654 | 56 | float ascendingNode; // long. of ascending node of equator on the ecliptic | ||
655 | 57 | float precessionRate; // rate of precession of rotation axis in rads/day | ||
656 | 58 | double siderealPeriod; // sidereal period (Planet year in earth days) | ||
657 | 59 | }; | ||
658 | 60 | |||
659 | 61 | // Class to manage rings for planets like saturn | ||
660 | 62 | class Ring | ||
661 | 63 | { | ||
662 | 64 | public: | ||
663 | 65 | Ring(float radiusMin, float radiusMax,const QString &texname); | ||
664 | 66 | double getSize(void) const {return radiusMax;} | ||
665 | 67 | const float radiusMin; | ||
666 | 68 | const float radiusMax; | ||
667 | 69 | StelTextureSP tex; | ||
668 | 70 | }; | ||
669 | 71 | |||
670 | 72 | |||
671 | 73 | class Planet : public StelObject | ||
672 | 74 | { | ||
673 | 75 | public: | ||
674 | 76 | friend class SolarSystem; | ||
675 | 77 | Planet(const QString& englishName, | ||
676 | 78 | int flagLighting, | ||
677 | 79 | double radius, | ||
678 | 80 | double oblateness, | ||
679 | 81 | Vec3f color, | ||
680 | 82 | float albedo, | ||
681 | 83 | const QString& texMapName, | ||
682 | 84 | const QString& normalMapName, | ||
683 | 85 | posFuncType _coordFunc, | ||
684 | 86 | void* userDataPtr, | ||
685 | 87 | OsculatingFunctType *osculatingFunc, | ||
686 | 88 | bool closeOrbit, | ||
687 | 89 | bool hidden, | ||
688 | 90 | bool hasAtmosphere, | ||
689 | 91 | bool hasHalo, | ||
690 | 92 | const QString &pType); | ||
691 | 93 | |||
692 | 94 | virtual ~Planet(); | ||
693 | 95 | |||
694 | 96 | /////////////////////////////////////////////////////////////////////////// | ||
695 | 97 | // Methods inherited from StelObject | ||
696 | 98 | //! Get a string with data about the Planet. | ||
697 | 99 | //! Planets support the following InfoStringGroup flags: | ||
698 | 100 | //! - Name | ||
699 | 101 | //! - Magnitude | ||
700 | 102 | //! - RaDec | ||
701 | 103 | //! - AltAzi | ||
702 | 104 | //! - Distance | ||
703 | 105 | //! - Size | ||
704 | 106 | //! - PlainText | ||
705 | 107 | //! - Extra: Heliocentric Ecliptical Coordinates & Observer-planetocentric Ecliptical Coordinates, Phase, illumination, phase angle & elongation from the Sun | ||
706 | 108 | //! @param core the StelCore object | ||
707 | 109 | //! @param flags a set of InfoStringGroup items to include in the return value. | ||
708 | 110 | //! @return a QString containing an HMTL encoded description of the Planet. | ||
709 | 111 | virtual QString getInfoString(const StelCore *core, const InfoStringGroup& flags) const; | ||
710 | 112 | virtual double getCloseViewFov(const StelCore* core) const; | ||
711 | 113 | virtual double getSatellitesFov(const StelCore* core) const; | ||
712 | 114 | virtual double getParentSatellitesFov(const StelCore* core) const; | ||
713 | 115 | virtual float getVMagnitude(const StelCore* core) const; | ||
714 | 116 | virtual float getSelectPriority(const StelCore* core) const; | ||
715 | 117 | virtual Vec3f getInfoColor(void) const; | ||
716 | 118 | virtual QString getType(void) const {return "Planet";} | ||
717 | 119 | virtual Vec3d getJ2000EquatorialPos(const StelCore *core) const; | ||
718 | 120 | virtual QString getEnglishName(void) const {return englishName;} | ||
719 | 121 | virtual QString getNameI18n(void) const {return nameI18;} | ||
720 | 122 | virtual double getAngularSize(const StelCore* core) const; | ||
721 | 123 | virtual bool hasAtmosphere(void) {return atmosphere;} | ||
722 | 124 | virtual bool hasHalo(void) {return halo;} | ||
723 | 125 | |||
724 | 126 | /////////////////////////////////////////////////////////////////////////// | ||
725 | 127 | // Methods of SolarSystem object | ||
726 | 128 | //! Translate planet name using the passed translator | ||
727 | 129 | virtual void translateName(const StelTranslator &trans); | ||
728 | 130 | |||
729 | 131 | // Draw the Planet | ||
730 | 132 | // GZ Made that virtual to allow comets having their own draw(). | ||
731 | 133 | virtual void draw(StelCore* core, float maxMagLabels, const QFont& planetNameFont); | ||
732 | 134 | |||
733 | 135 | /////////////////////////////////////////////////////////////////////////// | ||
734 | 136 | // Methods specific to Planet | ||
735 | 137 | //! Get the radius of the planet in AU. | ||
736 | 138 | //! @return the radius of the planet in astronomical units. | ||
737 | 139 | double getRadius(void) const {return radius;} | ||
738 | 140 | //! Get duration of sidereal day | ||
739 | 141 | double getSiderealDay(void) const {return re.period;} | ||
740 | 142 | //! Get duration of sidereal year | ||
741 | 143 | // GZ: made that virtual for Comets. | ||
742 | 144 | virtual double getSiderealPeriod(void) const { return re.siderealPeriod; } | ||
743 | 145 | //! Get duration of mean solar day | ||
744 | 146 | double getMeanSolarDay(void) const; | ||
745 | 147 | |||
746 | 148 | const QString& getTextMapName() const {return texMapName;} | ||
747 | 149 | const QString getPlanetType() const {return pType;} | ||
748 | 150 | |||
749 | 151 | // Compute the z rotation to use from equatorial to geographic coordinates | ||
750 | 152 | double getSiderealTime(double jd) const; | ||
751 | 153 | Mat4d getRotEquatorialToVsop87(void) const; | ||
752 | 154 | void setRotEquatorialToVsop87(const Mat4d &m); | ||
753 | 155 | |||
754 | 156 | const RotationElements &getRotationElements(void) const {return re;} | ||
755 | 157 | |||
756 | 158 | // Compute the position in the parent Planet coordinate system | ||
757 | 159 | void computePositionWithoutOrbits(const double dateJD); | ||
758 | 160 | virtual void computePosition(const double dateJD);// GZ: gets overridden in Comet! | ||
759 | 161 | |||
760 | 162 | // Compute the transformation matrix from the local Planet coordinate to the parent Planet coordinate | ||
761 | 163 | void computeTransMatrix(double date); | ||
762 | 164 | |||
763 | 165 | // Get the phase angle (rad) for an observer at pos obsPos in heliocentric coordinates (in AU) | ||
764 | 166 | double getPhaseAngle(const Vec3d& obsPos) const; | ||
765 | 167 | // Get the elongation angle (rad) for an observer at pos obsPos in heliocentric coordinates (in AU) | ||
766 | 168 | double getElongation(const Vec3d& obsPos) const; | ||
767 | 169 | // Get the angular size of the spheroid of the planet (i.e. without the rings) | ||
768 | 170 | double getSpheroidAngularSize(const StelCore* core) const; | ||
769 | 171 | // Get the planet phase for an observer at pos obsPos in heliocentric coordinates (in AU) | ||
770 | 172 | float getPhase(const Vec3d& obsPos) const; | ||
771 | 173 | |||
772 | 174 | // Set the orbital elements | ||
773 | 175 | void setRotationElements(float _period, float _offset, double _epoch, | ||
774 | 176 | float _obliquity, float _ascendingNode, | ||
775 | 177 | float _precessionRate, double _siderealPeriod); | ||
776 | 178 | double getRotAscendingnode(void) const {return re.ascendingNode;} | ||
777 | 179 | double getRotObliquity(double JDay) const; | ||
778 | 180 | |||
779 | 181 | //! Get the Planet position in the parent Planet ecliptic coordinate in AU | ||
780 | 182 | Vec3d getEclipticPos() const; | ||
781 | 183 | |||
782 | 184 | // Return the heliocentric ecliptical position | ||
783 | 185 | Vec3d getHeliocentricEclipticPos() const; | ||
784 | 186 | |||
785 | 187 | // Return the heliocentric transformation for local coordinate | ||
786 | 188 | Vec3d getHeliocentricPos(Vec3d) const; | ||
787 | 189 | void setHeliocentricEclipticPos(const Vec3d &pos); | ||
788 | 190 | |||
789 | 191 | // Compute the distance to the given position in heliocentric coordinate (in AU) | ||
790 | 192 | double computeDistance(const Vec3d& obsHelioPos); | ||
791 | 193 | double getDistance(void) const {return distance;} | ||
792 | 194 | |||
793 | 195 | void setRings(Ring* r) {rings = r;} | ||
794 | 196 | |||
795 | 197 | void setSphereScale(float s) {sphereScale = s;} | ||
796 | 198 | float getSphereScale(void) const {return sphereScale;} | ||
797 | 199 | |||
798 | 200 | const QSharedPointer<Planet> getParent(void) const {return parent;} | ||
799 | 201 | |||
800 | 202 | static void setLabelColor(const Vec3f& lc) {labelColor = lc;} | ||
801 | 203 | static const Vec3f& getLabelColor(void) {return labelColor;} | ||
802 | 204 | |||
803 | 205 | // update displayed elements. @param deltaTime: ms (?) | ||
804 | 206 | void update(int deltaTime); | ||
805 | 207 | |||
806 | 208 | void setFlagHints(bool b){hintFader = b;} | ||
807 | 209 | bool getFlagHints(void) const {return hintFader;} | ||
808 | 210 | |||
809 | 211 | void setFlagLabels(bool b){flagLabels = b;} | ||
810 | 212 | bool getFlagLabels(void) const {return flagLabels;} | ||
811 | 213 | |||
812 | 214 | /////////////////////////////////////////////////////////////////////////// | ||
813 | 215 | // DEPRECATED | ||
814 | 216 | ///// Orbit related code | ||
815 | 217 | // Should move to an OrbitPath class which works on a SolarSystemObject, not a Planet | ||
816 | 218 | void setFlagOrbits(bool b){orbitFader = b;} | ||
817 | 219 | bool getFlagOrbits(void) const {return orbitFader;} | ||
818 | 220 | LinearFader orbitFader; | ||
819 | 221 | // draw orbital path of Planet | ||
820 | 222 | void drawOrbit(const StelCore*); | ||
821 | 223 | Vec3d orbit[ORBIT_SEGMENTS+1]; // store heliocentric coordinates for drawing the orbit | ||
822 | 224 | Vec3d orbitP[ORBIT_SEGMENTS+1]; // store local coordinate for orbit | ||
823 | 225 | double lastOrbitJD; | ||
824 | 226 | double deltaJD; // time difference between positional updates. | ||
825 | 227 | double deltaOrbitJD; | ||
826 | 228 | bool orbitCached; // whether orbit calculations are cached for drawing orbit yet | ||
827 | 229 | bool closeOrbit; // whether to connect the beginning of the orbit line to | ||
828 | 230 | // the end: good for elliptical orbits, bad for parabolic | ||
829 | 231 | // and hyperbolic orbits | ||
830 | 232 | |||
831 | 233 | static Vec3f orbitColor; | ||
832 | 234 | static void setOrbitColor(const Vec3f& oc) {orbitColor = oc;} | ||
833 | 235 | static const Vec3f& getOrbitColor() {return orbitColor;} | ||
834 | 236 | |||
835 | 237 | //! Return the list of planets which project some shadow on this planet | ||
836 | 238 | QVector<const Planet*> getCandidatesForShadow() const; | ||
837 | 239 | |||
838 | 240 | protected: | ||
839 | 241 | static StelTextureSP texEarthShadow; // for lunar eclipses | ||
840 | 242 | |||
841 | 243 | void computeModelMatrix(Mat4d &result) const; | ||
842 | 244 | |||
843 | 245 | // Return the information string "ready to print" :) | ||
844 | 246 | QString getSkyLabel(const StelCore* core) const; | ||
845 | 247 | |||
846 | 248 | // Draw the 3d model. Call the proper functions if there are rings etc.. | ||
847 | 249 | void draw3dModel(StelCore* core, StelProjector::ModelViewTranformP transfo, float screenSz, bool drawOnlyRing=false); | ||
848 | 250 | |||
849 | 251 | // Draw the 3D sphere | ||
850 | 252 | void drawSphere(StelPainter* painter, float screenSz, bool drawOnlyRing=false); | ||
851 | 253 | |||
852 | 254 | // Draw the circle and name of the Planet | ||
853 | 255 | void drawHints(const StelCore* core, const QFont& planetNameFont); | ||
854 | 256 | |||
855 | 257 | QString englishName; // english planet name | ||
856 | 258 | QString nameI18; // International translated name | ||
857 | 259 | QString texMapName; // Texture file path | ||
858 | 260 | QString normalMapName; // Texture file path | ||
859 | 261 | int flagLighting; // Set whether light computation has to be proceed | ||
860 | 262 | RotationElements re; // Rotation param | ||
861 | 263 | double radius; // Planet radius in AU | ||
862 | 264 | double oneMinusOblateness; // (polar radius)/(equatorial radius) | ||
863 | 265 | Vec3d eclipticPos; // Position in AU in the rectangular ecliptic coordinate system | ||
864 | 266 | // centered on the parent Planet | ||
865 | 267 | Vec3d screenPos; // Used to store temporarily the 2D position on screen | ||
866 | 268 | Vec3d previousScreenPos; // The position of this planet in the previous frame. | ||
867 | 269 | Vec3f color; // exclusively used for drawing the planet halo | ||
868 | 270 | |||
869 | 271 | float albedo; // Planet albedo. Used for magnitude computation (but formula dubious!) | ||
870 | 272 | Mat4d rotLocalToParent; | ||
871 | 273 | float axisRotation; // Rotation angle of the Planet on it's axis | ||
872 | 274 | StelTextureSP texMap; // Planet map texture | ||
873 | 275 | StelTextureSP normalMap; // Planet normal map texture | ||
874 | 276 | |||
875 | 277 | Ring* rings; // Planet rings | ||
876 | 278 | double distance; // Temporary variable used to store the distance to a given point | ||
877 | 279 | // it is used for sorting while drawing | ||
878 | 280 | float sphereScale; // Artificial scaling for better viewing | ||
879 | 281 | double lastJD; // caches JD of last positional computation | ||
880 | 282 | // The callback for the calculation of the equatorial rect heliocentric position at time JD. | ||
881 | 283 | posFuncType coordFunc; | ||
882 | 284 | void* userDataPtr; | ||
883 | 285 | |||
884 | 286 | OsculatingFunctType *const osculatingFunc; | ||
885 | 287 | QSharedPointer<Planet> parent; // Planet parent i.e. sun for earth | ||
886 | 288 | QList<QSharedPointer<Planet> > satellites; // satellites of the Planet | ||
887 | 289 | LinearFader hintFader; | ||
888 | 290 | LinearFader labelsFader; // Store the current state of the label for this planet | ||
889 | 291 | bool flagLabels; // Define whether labels should be displayed | ||
890 | 292 | bool hidden; // useful for fake planets used as observation positions - not drawn or labeled | ||
891 | 293 | bool atmosphere; // Does the planet have an atmosphere? | ||
892 | 294 | bool halo; // Does the planet have a halo? | ||
893 | 295 | QString pType; // Type of body | ||
894 | 296 | |||
895 | 297 | static Vec3f labelColor; | ||
896 | 298 | static StelTextureSP hintCircleTex; | ||
897 | 299 | |||
898 | 300 | // Shader-related variables | ||
899 | 301 | struct PlanetShaderVars { | ||
900 | 302 | int projectionMatrix; | ||
901 | 303 | int texCoord; | ||
902 | 304 | int unprojectedVertex; | ||
903 | 305 | int vertex; | ||
904 | 306 | int texture; | ||
905 | 307 | int lightDirection; | ||
906 | 308 | int eyeDirection; | ||
907 | 309 | int diffuseLight; | ||
908 | 310 | int ambientLight; | ||
909 | 311 | int shadowCount; | ||
910 | 312 | int shadowData; | ||
911 | 313 | int sunInfo; | ||
912 | 314 | |||
913 | 315 | void initLocations(QOpenGLShaderProgram*); | ||
914 | 316 | }; | ||
915 | 317 | static PlanetShaderVars planetShaderVars; | ||
916 | 318 | static QOpenGLShaderProgram* planetShaderProgram; | ||
917 | 319 | |||
918 | 320 | // Shader-related variables | ||
919 | 321 | struct RingPlanetShaderVars : public PlanetShaderVars { | ||
920 | 322 | // Rings-specific variables | ||
921 | 323 | int isRing; | ||
922 | 324 | int ring; | ||
923 | 325 | int outerRadius; | ||
924 | 326 | int innerRadius; | ||
925 | 327 | int ringS; | ||
926 | 328 | }; | ||
927 | 329 | static RingPlanetShaderVars ringPlanetShaderVars; | ||
928 | 330 | static QOpenGLShaderProgram* ringPlanetShaderProgram; | ||
929 | 331 | |||
930 | 332 | struct MoonShaderVars : public PlanetShaderVars { | ||
931 | 333 | // Moon-specific variables | ||
932 | 334 | int earthShadow; | ||
933 | 335 | int normalMap; | ||
934 | 336 | }; | ||
935 | 337 | static MoonShaderVars moonShaderVars; | ||
936 | 338 | static QOpenGLShaderProgram* moonShaderProgram; | ||
937 | 339 | |||
938 | 340 | static void initShader(); | ||
939 | 341 | static void deinitShader(); | ||
940 | 342 | |||
941 | 343 | }; | ||
942 | 344 | |||
943 | 345 | #endif // _PLANET_HPP_ | ||
944 | 346 | |||
945 | 347 | 0 | ||
946 | === modified file 'src/core/modules/SolarSystem.cpp' | |||
947 | --- src/core/modules/SolarSystem.cpp 2014-08-30 16:58:25 +0000 | |||
948 | +++ src/core/modules/SolarSystem.cpp 2014-08-31 09:14:13 +0000 | |||
949 | @@ -119,6 +119,7 @@ | |||
950 | 119 | QSettings* conf = StelApp::getInstance().getSettings(); | 119 | QSettings* conf = StelApp::getInstance().getSettings(); |
951 | 120 | Q_ASSERT(conf); | 120 | Q_ASSERT(conf); |
952 | 121 | 121 | ||
953 | 122 | Planet::init(); | ||
954 | 122 | loadPlanets(); // Load planets data | 123 | loadPlanets(); // Load planets data |
955 | 123 | 124 | ||
956 | 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) |
957 | @@ -1069,7 +1070,7 @@ | |||
958 | 1069 | QString SolarSystem::getPlanetType(QString planetName) const | 1070 | QString SolarSystem::getPlanetType(QString planetName) const |
959 | 1070 | { | 1071 | { |
960 | 1071 | PlanetP p = searchByEnglishName(planetName); | 1072 | PlanetP p = searchByEnglishName(planetName); |
962 | 1072 | return p->getPlanetType(); | 1073 | return Planet::pTypeMap.value(p->getPlanetType()); |
963 | 1073 | } | 1074 | } |
964 | 1074 | 1075 | ||
965 | 1075 | double SolarSystem::getDistanceToPlanet(QString planetName) const | 1076 | double SolarSystem::getDistanceToPlanet(QString planetName) const |
966 | @@ -1382,7 +1383,7 @@ | |||
967 | 1382 | { | 1383 | { |
968 | 1383 | foreach(const PlanetP& p, systemPlanets) | 1384 | foreach(const PlanetP& p, systemPlanets) |
969 | 1384 | { | 1385 | { |
971 | 1385 | if (p->getPlanetType()==objType) | 1386 | if (Planet::pTypeMap.value(p->getPlanetType())==objType) |
972 | 1386 | result << p->getEnglishName(); | 1387 | result << p->getEnglishName(); |
973 | 1387 | } | 1388 | } |
974 | 1388 | } | 1389 | } |
975 | @@ -1390,7 +1391,7 @@ | |||
976 | 1390 | { | 1391 | { |
977 | 1391 | foreach(const PlanetP& p, systemPlanets) | 1392 | foreach(const PlanetP& p, systemPlanets) |
978 | 1392 | { | 1393 | { |
980 | 1393 | if (p->getPlanetType()==objType) | 1394 | if (Planet::pTypeMap.value(p->getPlanetType())==objType) |
981 | 1394 | result << p->getNameI18n(); | 1395 | result << p->getNameI18n(); |
982 | 1395 | } | 1396 | } |
983 | 1396 | } | 1397 | } |
Need cleanup the code and extend the comments