From 001a2c89e7eca76e51bd30dea6782cd8b0fa2aa7 Mon Sep 17 00:00:00 2001 From: curt Date: Tue, 15 Sep 1998 04:26:07 +0000 Subject: [PATCH] New textured moon and rewritten/restructured Astro code contributed by Durk Talsma. --- Astro/Makefile.am | 13 +- Astro/celestialBody.cxx | 152 +++++++++++++++ Astro/celestialBody.hxx | 185 ++++++++++++++++++ Astro/jupiter.cxx | 60 ++++++ Astro/jupiter.hxx | 39 ++++ Astro/mars.cxx | 54 ++++++ Astro/mars.hxx | 39 ++++ Astro/mercury.cxx | 56 ++++++ Astro/mercury.hxx | 39 ++++ Astro/moon.cxx | 406 +++++++++++++++++----------------------- Astro/moon.hxx | 109 +++-------- Astro/neptune.cxx | 55 ++++++ Astro/neptune.hxx | 39 ++++ Astro/orbits.cxx | 266 -------------------------- Astro/orbits.hxx | 132 ------------- Astro/planets.cxx | 286 ---------------------------- Astro/planets.hxx | 81 -------- Astro/pluto.hxx | 37 ++++ Astro/saturn.cxx | 64 +++++++ Astro/saturn.hxx | 46 +++++ Astro/solarsystem.cxx | 256 +++++++++++++++++++++++++ Astro/solarsystem.cxx~ | 256 +++++++++++++++++++++++++ Astro/solarsystem.hxx | 106 +++++++++++ Astro/star.cxx | 90 +++++++++ Astro/star.hxx | 97 ++++++++++ Astro/stars.cxx | 122 ++++++------ Astro/stars.hxx | 11 +- Astro/sun.cxx | 294 ----------------------------- Astro/sun.hxx | 88 --------- Astro/uranus.cxx | 55 ++++++ Astro/uranus.hxx | 39 ++++ Astro/venus.cxx | 55 ++++++ Astro/venus.hxx | 39 ++++ 33 files changed, 2142 insertions(+), 1524 deletions(-) create mode 100644 Astro/celestialBody.cxx create mode 100644 Astro/celestialBody.hxx create mode 100644 Astro/jupiter.cxx create mode 100644 Astro/jupiter.hxx create mode 100644 Astro/mars.cxx create mode 100644 Astro/mars.hxx create mode 100644 Astro/mercury.cxx create mode 100644 Astro/mercury.hxx create mode 100644 Astro/neptune.cxx create mode 100644 Astro/neptune.hxx delete mode 100644 Astro/orbits.cxx delete mode 100644 Astro/orbits.hxx delete mode 100644 Astro/planets.cxx delete mode 100644 Astro/planets.hxx create mode 100644 Astro/pluto.hxx create mode 100644 Astro/saturn.cxx create mode 100644 Astro/saturn.hxx create mode 100644 Astro/solarsystem.cxx create mode 100644 Astro/solarsystem.cxx~ create mode 100644 Astro/solarsystem.hxx create mode 100644 Astro/star.cxx create mode 100644 Astro/star.hxx delete mode 100644 Astro/sun.cxx delete mode 100644 Astro/sun.hxx create mode 100644 Astro/uranus.cxx create mode 100644 Astro/uranus.hxx create mode 100644 Astro/venus.cxx create mode 100644 Astro/venus.hxx diff --git a/Astro/Makefile.am b/Astro/Makefile.am index 0c835cee..505e24b5 100644 --- a/Astro/Makefile.am +++ b/Astro/Makefile.am @@ -1,11 +1,18 @@ noinst_LIBRARIES = libAstro.a libAstro_a_SOURCES = \ + celestialBody.cxx celestialBody.hxx \ + jupiter.cxx jupiter.hxx \ + mars.cxx mars.hxx \ + mercury.cxx mercury.hxx \ moon.cxx moon.hxx \ - orbits.cxx orbits.hxx \ - planets.cxx planets.hxx \ + neptune.cxx neptune.hxx \ + saturn.cxx saturn.hxx \ sky.cxx sky.hxx \ + solarsystem.cxx solarsystem.hxx \ + star.cxx star.hxx \ stars.cxx stars.hxx \ - sun.cxx sun.hxx + uranus.cxx uranus.hxx \ + venus.cxx venus.hxx INCLUDES += -I$(top_builddir) -I$(top_builddir)/Lib -I$(top_builddir)/Simulator diff --git a/Astro/celestialBody.cxx b/Astro/celestialBody.cxx new file mode 100644 index 00000000..ede620fe --- /dev/null +++ b/Astro/celestialBody.cxx @@ -0,0 +1,152 @@ +/************************************************************************** + * celestialBody.cxx + * Written by Durk Talsma. Originally started October 1997, for distribution + * with the FlightGear project. Version 2 was written in August and + * September 1998. This code is based upon algorithms and data kindly + * provided by Mr. Paul Schlyter. (pausch@saaf.se). + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * $Id$ + * (Log is kept at end of this file) + **************************************************************************/ + +#include "celestialBody.hxx" +#include "star.hxx" +#include + +/************************************************************************** + * void CelestialBody::updatePosition(fgTIME *t, Star *ourSun) + * + * Basically, this member function provides a general interface for + * calculating the right ascension and declinaion. This function is + * used for calculating the planetary positions. For the planets, an + * overloaded member function is provided to additionally calculate the + * planet's magnitude. + * The sun and moon have their own overloaded updatePosition member, as their + * position is calculated an a slightly different manner. + * + * arguments: + * fgTIME t: provides the current time. + * Star *ourSun: the sun's position is needed to convert heliocentric + * coordinates into geocentric coordinates. + * + * return value: none + * + *************************************************************************/ +void CelestialBody::updatePosition(fgTIME *t, Star *ourSun) +{ + double eccAnom, v, ecl, actTime, + xv, yv, xh, yh, zh, xg, yg, zg, xe, ye, ze; + + updateOrbElements(t); + actTime = fgCalcActTime(t); + + // calcualate the angle bewteen ecliptic and equatorial coordinate system + ecl = DEG_TO_RAD * (23.4393 - 3.563E-7 *actTime); + + eccAnom = fgCalcEccAnom(M, e); //calculate the eccentric anomaly + xv = a * (cos(eccAnom) - e); + yv = a * (sqrt (1.0 - e*e) * sin(eccAnom)); + v = atan2(yv, xv); // the planet's true anomaly + r = sqrt (xv*xv + yv*yv); // the planet's distance + + // calculate the planet's position in 3D space + xh = r * (cos(N) * cos(v+w) - sin(N) * sin(v+w) * cos(i)); + yh = r * (sin(N) * cos(v+w) + cos(N) * sin(v+w) * cos(i)); + zh = r * (sin(v+w) * sin(i)); + + // calculate the ecliptic longitude and latitude + xg = xh + ourSun->getxs(); + yg = yh + ourSun->getys(); + zg = zh; + + xe = xg; + ye = yg * cos(ecl) - zg * sin(ecl); + ze = yg * sin(ecl) + zg * cos(ecl); + rightAscension = atan2(ye, xe); + declination = atan2(ze, sqrt(xe*xe + ye*ye)); + fgPrintf(FG_GENERAL, FG_INFO, "Planet found at : %f (ra), %f (dec)\n", + rightAscension, declination); + + //calculate some variables specific to calculating the magnitude + //of the planet + R = sqrt (xg*xg + yg*yg + zg*zg); + s = ourSun->getDistance(); + FV = RAD_TO_DEG * acos( (r*r + R*R - s*s) / (2*r*R)); +}; + +/**************************************************************************** + * double CelestialBody::fgCalcEccAnom(double M, double e) + * this private member calculates the eccentric anomaly of a celestial body, + * given its mean anomaly and eccentricity. + * + * -Mean anomaly: the approximate angle between the perihelion and the current + * position. this angle increases uniformly with time. + * + * True anomaly: the actual angle between perihelion and current position. + * + * Eccentric anomaly: this is an auxilary angle, used in calculating the true + * anomaly from the mean anomaly. + * + * -eccentricity. Indicates the amount in which the orbit deviates from a + * circle (0 = circle, 0-1, is ellipse, 1 = parabola, > 1 = hyperbola). + * + * This function is also known as solveKeplersEquation() + * + * arguments: + * M: the mean anomaly + * e: the eccentricity + * + * return value: + * the eccentric anomaly + * + ****************************************************************************/ +double CelestialBody::fgCalcEccAnom(double M, double e) +{ + double + eccAnom, E0, E1, diff; + + eccAnom = M + e * sin(M) * (1.0 + e * cos (M)); + // iterate to achieve a greater precision for larger eccentricities + if (e > 0.05) + { + E0 = eccAnom; + do + { + E1 = E0 - (E0 - e * sin(E0) - M) / (1 - e *cos(E0)); + diff = fabs(E0 - E1); + E0 = E1; + } + while (diff > (DEG_TO_RAD * 0.001)); + return E0; + } + return eccAnom; +} + + + + + + + + + + + + + + + diff --git a/Astro/celestialBody.hxx b/Astro/celestialBody.hxx new file mode 100644 index 00000000..9b78b7f5 --- /dev/null +++ b/Astro/celestialBody.hxx @@ -0,0 +1,185 @@ +/************************************************************************** + * celestialBody.hxx + * Written by Durk Talsma. Originally started October 1997, for distribution + * with the FlightGear project. Version 2 was written in August and + * September 1998. This code is based upon algorithms and data kindly + * provided by Mr. Paul Schlyter. (pausch@saaf.se). + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * $Id$ + * (Log is kept at end of this file) + **************************************************************************/ +#ifndef _CELESTIALBODY_H_ +#define _CELESTIALBODY_H_ + +#ifndef __cplusplus +# error This library requires C++ +#endif + + +#include +#include + +#include