Added flag to set whether solar system center is a star or the barycenter of orbiting stars.

ver1_5_1
Chris Laurel 2004-09-29 16:20:21 +00:00
parent 2fdf2618c0
commit 64b2b94d96
5 changed files with 98 additions and 39 deletions

View File

@ -1085,37 +1085,38 @@ void Renderer::renderOrbits(PlanetarySystem* planets,
}
// Convert a position in the universal coordinate system to heliocentric
// (actually, astrocentric) coordinates, taking into account possible orbital
// motion of the star.
static Point3d heliocentricPosition(UniversalCoord& pos,
// Convert a position in the universal coordinate system to solar system
// coordinates. The solar system position is the same as the astrocentric
// position for the same star except when the star is part of a multiple
// star system in which planets orbit the barycenter.
static Point3d solarSystemPosition(UniversalCoord& pos,
const Star& star,
double t)
{
UniversalCoord starPos = star.getSystemCenter(t);
Vec3d v = pos - starPos;
return Point3d(astro::microLightYearsToKilometers(v.x),
astro::microLightYearsToKilometers(v.y),
astro::microLightYearsToKilometers(v.z));
}
// Convert a position in the universal coordinate system to astrocentric
// coordinates, taking into account possible orbital motion of the star.
static Point3d astrocentricPosition(UniversalCoord& pos,
const Star& star,
double t)
{
const Orbit* orbit = star.getOrbit();
if (!orbit)
{
return astro::heliocentricPosition(pos, star.getPosition());
}
else
{
Point3f barycenterPosLY = star.getPosition();
Point3f barycenterPos(barycenterPosLY.x * 1.0e6f,
barycenterPosLY.y * 1.0e6f,
barycenterPosLY.z * 1.0e6f);
UniversalCoord starPos = star.getPosition(t);
UniversalCoord starPos = UniversalCoord(barycenterPos) +
((orbit->positionAtTime(t) - Point3d(0.0, 0.0, 0.0f)) *
astro::kilometersToMicroLightYears(1.0));
Vec3d v = pos - starPos;
return Point3d(astro::microLightYearsToKilometers(v.x),
astro::microLightYearsToKilometers(v.y),
astro::microLightYearsToKilometers(v.z));
}
Vec3d v = pos - starPos;
return Point3d(astro::microLightYearsToKilometers(v.x),
astro::microLightYearsToKilometers(v.y),
astro::microLightYearsToKilometers(v.z));
}
void Renderer::autoMag(float& faintestMag)
{
float fieldCorr = 2.0f * FOV/(fov + FOV);
@ -1380,12 +1381,8 @@ void Renderer::render(const Observer& observer,
enableSmoothLines();
const Star* sun = solarSystem->getStar();
#if 0
Point3d obsPos = astro::heliocentricPosition(observer.getPosition(),
sun->getPosition());
#endif
Point3d obsPos = heliocentricPosition(observer.getPosition(),
*sun, observer.getTime());
Point3d obsPos = solarSystemPosition(observer.getPosition(),
*sun, observer.getTime());
glPushMatrix();
glTranslatef((float) astro::kilometersToAU(-obsPos.x),
(float) astro::kilometersToAU(-obsPos.y),
@ -5372,8 +5369,8 @@ void Renderer::renderPlanetarySystem(const Star& sun,
bool showLabels)
{
Point3f starPos = sun.getPosition();
Point3d observerPos = heliocentricPosition(observer.getPosition(),
sun, now);
Point3d observerPos = solarSystemPosition(observer.getPosition(),
sun, now);
int nBodies = solSystem.getSystemSize();
for (int i = 0; i < nBodies; i++)
@ -5597,8 +5594,7 @@ void StarRenderer::process(const Star& star, float distance, float appMag)
// This is a much more accurate (and expensive) distance
// calculation than the previous one which used the observer's
// position rounded off to floats.
//Point3d hPos = astro::heliocentricPosition(observer->getPosition(), starPos);
Point3d hPos = heliocentricPosition(observer->getPosition(),
Point3d hPos = astrocentricPosition(observer->getPosition(),
star,
observer->getTime());
relPos = Vec3f((float) hPos.x, (float) hPos.y, (float) hPos.z) *

View File

@ -46,7 +46,7 @@ UniversalCoord Selection::getPosition(double t) const
Point3d hpos = body()->getHeliocentricPosition(t);
if (sun != NULL)
return astro::universalPosition(hpos, sun->getPosition(t));
return astro::universalPosition(hpos, sun->getSystemCenter(t));
else
return astro::universalPosition(hpos, Point3f(0.0f, 0.0f, 0.0f));

View File

@ -706,6 +706,13 @@ StarDetails::setOrbit(Orbit* o)
}
void
StarDetails::setSystemOrigin(StarDetails::SystemOrigin o)
{
origin = o;
}
// Return the radius of the star in kilometers
float Star::getRadius() const
{
@ -756,6 +763,37 @@ Star::getPosition(double t) const
}
UniversalCoord
Star::getSystemCenter(double t) const
{
const Orbit* orbit = getOrbit();
if (!orbit)
{
return UniversalCoord(position.x * 1.0e6f,
position.y * 1.0e6f,
position.z * 1.0e6f);
}
else
{
Point3f barycenterPosLY = position;
Point3f barycenterPos(barycenterPosLY.x * 1.0e6f,
barycenterPosLY.y * 1.0e6f,
barycenterPosLY.z * 1.0e6f);
if (details->getSystemOrigin() == StarDetails::OriginStar)
{
return UniversalCoord(barycenterPos) +
((orbit->positionAtTime(t) - Point3d(0.0, 0.0, 0.0f)) *
astro::kilometersToMicroLightYears(1.0));
}
else
{
return UniversalCoord(barycenterPos);
}
}
}
MultiResTexture
Star::getTexture() const
{

View File

@ -34,16 +34,12 @@ class StarDetails
inline MultiResTexture getTexture() const;
inline Orbit* getOrbit() const;
inline float getOrbitalRadius() const;
inline uint32 getKnowledge() const;
inline bool getKnowledge(uint32) const;
inline const char* getSpectralType() const;
inline float getBolometricCorrection() const;
void setRadius(float);
void setTemperature(float);
void setRotationPeriod(float);
void setKnowledge(uint32);
void addKnowledge(uint32);
void setSpectralType(const std::string&);
void setBolometricCorrection(float);
void setTexture(const MultiResTexture&);
@ -55,6 +51,18 @@ class StarDetails
KnowRadius = 0x1,
KnowRotation = 0x2,
};
inline uint32 getKnowledge() const;
inline bool getKnowledge(uint32) const;
void setKnowledge(uint32);
void addKnowledge(uint32);
enum SystemOrigin
{
OriginStar = 0,
OriginBarycenter = 1,
};
inline SystemOrigin getSystemOrigin() const;
void setSystemOrigin(SystemOrigin);
private:
float radius;
@ -70,6 +78,7 @@ class StarDetails
Orbit* orbit;
float orbitalRadius;
SystemOrigin origin;
public:
static StarDetails* GetStarDetails(const StellarClass&);
@ -159,6 +168,12 @@ StarDetails::getBolometricCorrection() const
return bolometricCorrection;
}
StarDetails::SystemOrigin
StarDetails::getSystemOrigin() const
{
return origin;
}
class Star
{
@ -174,6 +189,8 @@ public:
// Return the exact position of the star, accounting for its orbit
UniversalCoord getPosition(double t) const;
// Get the center of the system, about which planets and stars orbit
UniversalCoord getSystemCenter(double t) const;
void setCatalogNumber(uint32);
void setPosition(float, float, float);

View File

@ -822,7 +822,15 @@ static Star* CreateStar(uint32 catalogNumber,
}
if (orbit != NULL)
{
details->setOrbit(orbit);
bool barycenterIsOrigin = false;
starData->getBoolean("BarycenterIsOrigin", barycenterIsOrigin);
if (barycenterIsOrigin)
details->setSystemOrigin(StarDetails::OriginBarycenter);
else
details->setSystemOrigin(StarDetails::OriginStar);
}
}
Star* star = new Star();