Updated render and selection code so planets orbiting stars in multiple system appear in the right place. Made a similar fix for orbit paths.

ver1_5_1
Chris Laurel 2004-09-28 07:44:34 +00:00
parent bda33fa9b3
commit 2fdf2618c0
4 changed files with 58 additions and 40 deletions

View File

@ -240,6 +240,16 @@ UniversalCoord astro::universalPosition(const Point3d& heliocentric,
kilometersToMicroLightYears(heliocentric.z));
}
// universalPosition is the inverse operation of heliocentricPosition
UniversalCoord astro::universalPosition(const Point3d& heliocentric,
const UniversalCoord& starPosition)
{
return starPosition +
Vec3d(kilometersToMicroLightYears(heliocentric.x),
kilometersToMicroLightYears(heliocentric.y),
kilometersToMicroLightYears(heliocentric.z));
}
// Convert equatorial coordinates to Cartesian celestial (or ecliptical)
// coordinates.

View File

@ -104,6 +104,8 @@ namespace astro
const Point3f& starPosition);
UniversalCoord universalPosition(const Point3d& heliocentric,
const Point3f& starPosition);
UniversalCoord universalPosition(const Point3d& heliocentric,
const UniversalCoord& starPosition);
Point3f equatorialToCelestialCart(float ra, float dec, float distance);
Point3d equatorialToCelestialCart(double ra, double dec, double distance);

View File

@ -1006,10 +1006,6 @@ void Renderer::renderOrbits(PlanetarySystem* planets,
double distance = (center - observerPos).length();
// At the solar system scale, we'll handle all calculations in AU
// Not used anymore
// Vec3d opos = (center - Point3d(0.0, 0.0, 0.0)) * astro::kilometersToAU(1.0);
int nBodies = planets->getSystemSize();
for (int i = 0; i < nBodies; i++)
{
@ -1088,6 +1084,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,
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 = 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));
}
}
void Renderer::autoMag(float& faintestMag)
{
float fieldCorr = 2.0f * FOV/(fov + FOV);
@ -1352,8 +1380,12 @@ 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());
glPushMatrix();
glTranslatef((float) astro::kilometersToAU(-obsPos.x),
(float) astro::kilometersToAU(-obsPos.y),
@ -5340,7 +5372,8 @@ void Renderer::renderPlanetarySystem(const Star& sun,
bool showLabels)
{
Point3f starPos = sun.getPosition();
Point3d observerPos = astro::heliocentricPosition(observer.getPosition(), starPos);
Point3d observerPos = heliocentricPosition(observer.getPosition(),
sun, now);
int nBodies = solSystem.getSystemSize();
for (int i = 0; i < nBodies; i++)
@ -5525,33 +5558,6 @@ StarRenderer::StarRenderer() :
}
static Point3d heliocentricPosition(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 = 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));
}
}
void StarRenderer::process(const Star& star, float distance, float appMag)
{
nProcessed++;

View File

@ -39,17 +39,17 @@ UniversalCoord Selection::getPosition(double t) const
{
case Type_Body:
{
Point3f sunPos(0.0f, 0.0f, 0.0f);
PlanetarySystem* system = body()->getSystem();
const Star* sun = NULL;
if (system != NULL)
{
const Star* sun = system->getStar();
if (sun != NULL)
sunPos = sun->getPosition();
}
sun = system->getStar();
return astro::universalPosition(body()->getHeliocentricPosition(t),
sunPos);
Point3d hpos = body()->getHeliocentricPosition(t);
if (sun != NULL)
return astro::universalPosition(hpos, sun->getPosition(t));
else
return astro::universalPosition(hpos, Point3f(0.0f, 0.0f, 0.0f));
}
case Type_Star: