1 // star.h
2 //
3 // Copyright (C) 2001, Chris Laurel <claurel@shatters.net>
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 #ifndef _STAR_H_
11 #define _STAR_H_
12 
13 #include <vector>
14 #include <celutil/basictypes.h>
15 #include <celutil/reshandle.h>
16 #include <celutil/color.h>
17 #include <celmath/vecmath.h>
18 #include <celengine/univcoord.h>
19 #include <celengine/celestia.h>
20 #include <celengine/stellarclass.h>
21 #include <celengine/rotation.h>
22 #include <celengine/multitexture.h>
23 
24 class Orbit;
25 class Star;
26 
27 class StarDetails
28 {
29     friend class Star;
30 
31  public:
32     StarDetails();
33     StarDetails(const StarDetails&);
34 
35     ~StarDetails();
36 
37  private:
38     // Prohibit assignment of StarDetails objects
39     StarDetails& operator=(const StarDetails&);
40 
41  public:
42     inline float getRadius() const;
43     inline float getTemperature() const;
44     inline ResourceHandle getGeometry() const;
45     inline MultiResTexture getTexture() const;
46     inline Orbit* getOrbit() const;
47     inline float getOrbitalRadius() const;
48     inline const char* getSpectralType() const;
49     inline float getBolometricCorrection() const;
50     inline Star* getOrbitBarycenter() const;
51     inline bool getVisibility() const;
52     inline const RotationModel* getRotationModel() const;
53     inline Vec3f getEllipsoidSemiAxes() const;
54     const std::string& getInfoURL() const;
55 
56     void setRadius(float);
57     void setTemperature(float);
58     void setSpectralType(const std::string&);
59     void setBolometricCorrection(float);
60     void setTexture(const MultiResTexture&);
61     void setGeometry(ResourceHandle);
62     void setOrbit(Orbit*);
63     void setOrbitBarycenter(Star*);
64     void setOrbitalRadius(float);
65     void computeOrbitalRadius();
66     void setVisibility(bool);
67     void setRotationModel(const RotationModel*);
68     void setEllipsoidSemiAxes(const Vec3f&);
69     void setInfoURL(const std::string& _infoURL);
70 
71     bool shared() const;
72 
73     enum
74     {
75         KnowRadius   = 0x1,
76         KnowRotation = 0x2,
77         KnowTexture  = 0x4,
78     };
79     inline uint32 getKnowledge() const;
80     inline bool getKnowledge(uint32) const;
81     void setKnowledge(uint32);
82     void addKnowledge(uint32);
83 
84  private:
85     void addOrbitingStar(Star*);
86 
87  private:
88     float radius;
89     float temperature;
90     float bolometricCorrection;
91 
92     uint32 knowledge;
93     bool visible;
94     char spectralType[8];
95 
96     MultiResTexture texture;
97     ResourceHandle geometry;
98 
99     Orbit* orbit;
100     float orbitalRadius;
101     Star* barycenter;
102 
103     const RotationModel* rotationModel;
104 
105     Vec3f semiAxes;
106 
107     std::string* infoURL;
108 
109     std::vector<Star*>* orbitingStars;
110     bool isShared;
111 
112  public:
113     struct StarTextureSet
114     {
115         MultiResTexture defaultTex;
116         MultiResTexture neutronStarTex;
117         MultiResTexture starTex[StellarClass::Spectral_Count];
118     };
119 
120  public:
121     static StarDetails* GetStarDetails(const StellarClass&);
122     static StarDetails* CreateStandardStarType(const std::string& _specType,
123                                                float _temperature,
124                                                float _rotationPeriod);
125 
126     static StarDetails* GetNormalStarDetails(StellarClass::SpectralClass specClass,
127                                              unsigned int subclass,
128                                              StellarClass::LuminosityClass lumClass);
129     static StarDetails* GetWhiteDwarfDetails(StellarClass::SpectralClass specClass,
130                                              unsigned int subclass);
131     static StarDetails* GetNeutronStarDetails();
132     static StarDetails* GetBlackHoleDetails();
133     static StarDetails* GetBarycenterDetails();
134 
135     static void SetStarTextures(const StarTextureSet&);
136 
137  private:
138     static StarTextureSet starTextures;
139 };
140 
141 
142 float
getRadius()143 StarDetails::getRadius() const
144 {
145     return radius;
146 }
147 
148 float
getTemperature()149 StarDetails::getTemperature() const
150 {
151     return temperature;
152 }
153 
154 ResourceHandle
getGeometry()155 StarDetails::getGeometry() const
156 {
157     return geometry;
158 }
159 
160 MultiResTexture
getTexture()161 StarDetails::getTexture() const
162 {
163     return texture;
164 }
165 
166 Orbit*
getOrbit()167 StarDetails::getOrbit() const
168 {
169     return orbit;
170 }
171 
172 float
getOrbitalRadius()173 StarDetails::getOrbitalRadius() const
174 {
175     return orbitalRadius;
176 }
177 
178 uint32
getKnowledge()179 StarDetails::getKnowledge() const
180 {
181     return knowledge;
182 }
183 
184 bool
getKnowledge(uint32 knowledgeFlags)185 StarDetails::getKnowledge(uint32 knowledgeFlags) const
186 {
187     return ((knowledge & knowledgeFlags) == knowledgeFlags);
188 }
189 
190 const char*
getSpectralType()191 StarDetails::getSpectralType() const
192 {
193     return spectralType;
194 }
195 
196 float
getBolometricCorrection()197 StarDetails::getBolometricCorrection() const
198 {
199     return bolometricCorrection;
200 }
201 
202 Star*
getOrbitBarycenter()203 StarDetails::getOrbitBarycenter() const
204 {
205     return barycenter;
206 }
207 
208 bool
getVisibility()209 StarDetails::getVisibility() const
210 {
211     return visible;
212 }
213 
214 const RotationModel*
getRotationModel()215 StarDetails::getRotationModel() const
216 {
217     return rotationModel;
218 }
219 
220 Vec3f
getEllipsoidSemiAxes()221 StarDetails::getEllipsoidSemiAxes() const
222 {
223     return semiAxes;
224 }
225 
226 
227 
228 class Star
229 {
230 public:
231     inline Star();
232     ~Star();
233 
234     // Accessor methods for members of the star class
235     inline uint32 getCatalogNumber() const;
236     inline Point3f getPosition() const;
237     inline float getAbsoluteMagnitude() const;
238     float getApparentMagnitude(float) const;
239     float getLuminosity() const;
240 
241     // Return the exact position of the star, accounting for its orbit
242     UniversalCoord getPosition(double t) const;
243     UniversalCoord getOrbitBarycenterPosition(double t) const;
244 
245 	Vec3d getVelocity(double t) const;
246 
247     void setCatalogNumber(uint32);
248     void setPosition(float, float, float);
249     void setPosition(Point3f);
250     void setAbsoluteMagnitude(float);
251     void setLuminosity(float);
252 
253     StarDetails* getDetails() const;
254     void setDetails(StarDetails*);
255     void setOrbitBarycenter(Star*);
256     void computeOrbitalRadius();
257 
258     void setRotationModel(const RotationModel*);
259 
260     void addOrbitingStar(Star*);
261     inline const std::vector<Star*>* getOrbitingStars() const;
262 
263     // Accessor methods that delegate to StarDetails
264     float getRadius() const;
265     inline float getTemperature() const;
266     inline const char* getSpectralType() const;
267     inline float getBolometricMagnitude() const;
268     MultiResTexture getTexture() const;
269     ResourceHandle getGeometry() const;
270     inline Orbit* getOrbit() const;
271     inline float getOrbitalRadius() const;
272     inline Star* getOrbitBarycenter() const;
273     inline bool getVisibility() const;
274     inline uint32 getKnowledge() const;
275     inline const RotationModel* getRotationModel() const;
276     inline Vec3f getEllipsoidSemiAxes() const;
277     const std::string& getInfoURL() const;
278 
279     enum {
280         MaxTychoCatalogNumber = 0xf0000000,
281         InvalidCatalogNumber = 0xffffffff,
282     };
283 
284 private:
285     uint32 catalogNumber;
286     Point3f position;
287     float absMag;
288     StarDetails* details;
289 };
290 
291 
Star()292 Star::Star() :
293     catalogNumber(InvalidCatalogNumber),
294     position(0, 0, 0),
295     absMag(4.83f),
296     details(NULL)
297 {
298 }
299 
300 uint32
getCatalogNumber()301 Star::getCatalogNumber() const
302 {
303     return catalogNumber;
304 }
305 
306 float
getAbsoluteMagnitude()307 Star::getAbsoluteMagnitude() const
308 {
309     return absMag;
310 }
311 
312 
313 // This getPosition() method returns the approximate star position; that is,
314 // star position without any orbital motion taken into account.  For a
315 // star in an orbit, the position should be set to the 'root' barycenter
316 // of the system.
317 Point3f
getPosition()318 Star::getPosition() const
319 {
320     return position;
321 }
322 
323 float
getTemperature()324 Star::getTemperature() const
325 {
326     return details->getTemperature();
327 }
328 
329 const char*
getSpectralType()330 Star::getSpectralType() const
331 {
332     return details->getSpectralType();
333 }
334 
335 float
getBolometricMagnitude()336 Star::getBolometricMagnitude() const
337 {
338     return absMag + details->getBolometricCorrection();
339 }
340 
341 Orbit*
getOrbit()342 Star::getOrbit() const
343 {
344     return details->getOrbit();
345 }
346 
347 float
getOrbitalRadius()348 Star::getOrbitalRadius() const
349 {
350     return details->getOrbitalRadius();
351 }
352 
353 Star*
getOrbitBarycenter()354 Star::getOrbitBarycenter() const
355 {
356     return details->getOrbitBarycenter();
357 }
358 
359 bool
getVisibility()360 Star::getVisibility() const
361 {
362     return details->getVisibility();
363 }
364 
365 const RotationModel*
getRotationModel()366 Star::getRotationModel() const
367 {
368     return details->getRotationModel();
369 }
370 
371 Vec3f
getEllipsoidSemiAxes()372 Star::getEllipsoidSemiAxes() const
373 {
374     return details->getEllipsoidSemiAxes();
375 }
376 
377 const std::vector<Star*>*
getOrbitingStars()378 Star::getOrbitingStars() const
379 {
380     return details->orbitingStars;
381 }
382 
383 #endif // _STAR_H_
384