00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef _CELENGINE_BODY_H_
00011 #define _CELENGINE_BODY_H_
00012
00013 #include <string>
00014 #include <vector>
00015 #include <map>
00016 #include <celmath/quaternion.h>
00017 #include <celengine/surface.h>
00018 #include <celengine/atmosphere.h>
00019 #include <celengine/orbit.h>
00020 #include <celengine/star.h>
00021 #include <celengine/location.h>
00022 #include <celengine/rotation.h>
00023
00024
00025 class Body;
00026
00027 class PlanetarySystem
00028 {
00029 public:
00030 PlanetarySystem(Body* _primary);
00031 PlanetarySystem(Star* _star);
00032
00033 Star* getStar() const { return star; };
00034 Body* getPrimaryBody() const { return primary; };
00035 int getSystemSize() const { return satellites.size(); };
00036 Body* getBody(int i) const { return satellites[i]; };
00037 void addBody(Body* body);
00038 void removeBody(Body* body);
00039 void replaceBody(Body* oldBody, Body* newBody);
00040
00041 enum TraversalResult
00042 {
00043 ContinueTraversal = 0,
00044 StopTraversal = 1
00045 };
00046
00047 typedef bool (*TraversalFunc)(Body*, void*);
00048
00049 bool traverse(TraversalFunc, void*) const;
00050 Body* find(std::string, bool deepSearch = false, bool i18n = false) const;
00051 std::vector<std::string> getCompletion(const std::string& _name, bool rec = true) const;
00052
00053 private:
00054 Star* star;
00055 Body* primary;
00056 std::vector<Body*> satellites;
00057 };
00058
00059
00060 class RingSystem
00061 {
00062 public:
00063 float innerRadius;
00064 float outerRadius;
00065 Color color;
00066 MultiResTexture texture;
00067
00068 RingSystem(float inner, float outer) :
00069 innerRadius(inner), outerRadius(outer), color(1.0f, 1.0f, 1.0f), texture()
00070 { };
00071 RingSystem(float inner, float outer, Color _color, int _loTexture = -1, int _texture = -1) :
00072 innerRadius(inner), outerRadius(outer), color(_color), texture(_loTexture, _texture)
00073 { };
00074 RingSystem(float inner, float outer, Color _color, const MultiResTexture& _texture) :
00075 innerRadius(inner), outerRadius(outer), color(_color), texture(_texture)
00076 { };
00077 };
00078
00079
00080 class Body
00081 {
00082 public:
00083 Body(PlanetarySystem*);
00084 ~Body();
00085
00086 enum
00087 {
00088 Planet = 0x01,
00089 Moon = 0x02,
00090 Asteroid = 0x04,
00091 Comet = 0x08,
00092 Spacecraft = 0x10,
00093 Invisible = 0x20,
00094 Unknown = 0x10000,
00095 };
00096
00097 PlanetarySystem* getSystem() const;
00098 std::string getName(bool i18n = false) const;
00099 void setName(const std::string);
00100 Orbit* getOrbit() const;
00101 void setOrbit(Orbit*);
00102 astro::ReferencePlane getOrbitReferencePlane() const;
00103 void setOrbitReferencePlane(astro::ReferencePlane);
00104 RotationElements getRotationElements() const;
00105 void setRotationElements(const RotationElements&);
00106 float getRadius() const;
00107 void setRadius(float);
00108 float getMass() const;
00109 void setMass(float);
00110 float getOblateness() const;
00111 void setOblateness(float);
00112 float getAlbedo() const;
00113 void setAlbedo(float);
00114 Quatf getOrientation() const;
00115 void setOrientation(const Quatf&);
00116 int getClassification() const;
00117 void setClassification(int);
00118 std::string getInfoURL() const;
00119 void setInfoURL(const std::string&);
00120
00121 PlanetarySystem* getSatellites() const;
00122 void setSatellites(PlanetarySystem*);
00123
00124 float getBoundingRadius() const;
00125
00126 RingSystem* getRings() const;
00127 void setRings(const RingSystem&);
00128 const Atmosphere* getAtmosphere() const;
00129 Atmosphere* getAtmosphere();
00130 void setAtmosphere(const Atmosphere&);
00131
00132 void setModel(ResourceHandle);
00133 ResourceHandle getModel() const;
00134 void setSurface(const Surface&);
00135 const Surface& getSurface() const;
00136 Surface& getSurface();
00137
00138 float getLuminosity(const Star& sun,
00139 float distanceFromSun) const;
00140 float getLuminosity(float sunLuminosity,
00141 float distanceFromSun) const;
00142 float getApparentMagnitude(const Star& sun,
00143 float distanceFromSun,
00144 float distanceFromViewer) const;
00145 float getApparentMagnitude(const Star& sun,
00146 const Vec3d& sunPosition,
00147 const Vec3d& viewerPosition) const;
00148 float getApparentMagnitude(float sunLuminosity,
00149 const Vec3d& sunPosition,
00150 const Vec3d& viewerPosition) const;
00151
00152 Mat4d getLocalToHeliocentric(double) const;
00153 Point3d getHeliocentricPosition(double) const;
00154 Quatd getEquatorialToGeographic(double) const;
00155 Quatd getEclipticalToEquatorial(double) const;
00156 Quatd getEclipticalToGeographic(double) const;
00157 Mat4d getGeographicToHeliocentric(double) const;
00158
00159 Vec3f planetocentricToCartesian(float lon, float lat, float alt) const;
00160 Vec3f planetocentricToCartesian(const Vec3f& lonLatAlt) const;
00161 Vec3f cartesianToPlanetocentric(const Vec3f& v) const;
00162
00163 bool extant(double) const;
00164 void setLifespan(double, double);
00165 void getLifespan(double&, double&) const;
00166
00167 Surface* getAlternateSurface(const std::string&) const;
00168 void addAlternateSurface(const std::string&, Surface*);
00169 std::vector<std::string>* getAlternateSurfaceNames() const;
00170
00171 std::vector<Location*>* getLocations() const;
00172 void addLocation(Location*);
00173 Location* findLocation(const std::string&, bool i18n = false) const;
00174 void computeLocations();
00175
00176 private:
00177 std::string name;
00178 std::string i18nName;
00179
00180 PlanetarySystem* system;
00181 Orbit* orbit;
00182 astro::ReferencePlane orbitRefPlane;
00183 RotationElements rotationElements;
00184
00185 float radius;
00186 float mass;
00187 float oblateness;
00188 float albedo;
00189 Quatf orientation;
00190
00191 double protos;
00192 double eschatos;
00193
00194 ResourceHandle model;
00195 Surface surface;
00196
00197 Atmosphere* atmosphere;
00198 RingSystem* rings;
00199
00200 PlanetarySystem* satellites;
00201
00202 int classification;
00203
00204 std::string infoURL;
00205
00206 typedef std::map<std::string, Surface*> AltSurfaceTable;
00207 AltSurfaceTable *altSurfaces;
00208
00209 std::vector<Location*>* locations;
00210 mutable bool locationsComputed;
00211 };
00212
00213 #endif // _CELENGINE_BODY_H_