+++ /dev/null
-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 \
- neptune.cxx neptune.hxx \
- pluto.hxx \
- saturn.cxx saturn.hxx \
- sky.cxx sky.hxx \
- solarsystem.cxx solarsystem.hxx \
- star.cxx star.hxx \
- stars.cxx stars.hxx \
- uranus.cxx uranus.hxx \
- venus.cxx venus.hxx
-
-INCLUDES += -I$(top_builddir) -I$(top_builddir)/Lib -I$(top_builddir)/Simulator
+++ /dev/null
-/**************************************************************************
- * 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 <Debug/logstream.hxx>
-
-#ifdef FG_MATH_EXCEPTION_CLASH
-# define exception c_exception
-#endif
-#include <math.h>
-
-/**************************************************************************
- * 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;
-
- lonEcl = atan2(yh, xh);
- latEcl = atan2(zh, sqrt(xh*xh+yh*yh));
-
- 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));
- FG_LOG(FG_GENERAL, FG_INFO, "Planet found at : "
- << rightAscension << " (ra), " << declination << " (dec)" );
-
- //calculate some variables specific to calculating the magnitude
- //of the planet
- R = sqrt (xg*xg + yg*yg + zg*zg);
- s = ourSun->getDistance();
-
- // It is possible from these calculations for the argument to acos
- // to exceed the valid range for acos(). So we do a little extra
- // checking.
-
- double tmp = (r*r + R*R - s*s) / (2*r*R);
- if ( tmp > 1.0) {
- tmp = 1.0;
- } else if ( tmp < -1.0) {
- tmp = -1.0;
- }
-
- FV = RAD_TO_DEG * acos( tmp );
-};
-
-/****************************************************************************
- * 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;
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+++ /dev/null
-/**************************************************************************
- * 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 <Time/fg_time.hxx>
-#include <Include/fg_constants.h>
-
-class Star;
-
-class CelestialBody
-{
-protected: // make the data protected, in order to give the inherited
- // classes direct access to the data
- double NFirst; /* longitude of the ascending node first part */
- double NSec; /* longitude of the ascending node second part */
- double iFirst; /* inclination to the ecliptic first part */
- double iSec; /* inclination to the ecliptic second part */
- double wFirst; /* first part of argument of perihelion */
- double wSec; /* second part of argument of perihelion */
- double aFirst; /* semimayor axis first part*/
- double aSec; /* semimayor axis second part */
- double eFirst; /* eccentricity first part */
- double eSec; /* eccentricity second part */
- double MFirst; /* Mean anomaly first part */
- double MSec; /* Mean anomaly second part */
-
- double N, i, w, a, e, M; /* the resulting orbital elements, obtained from the former */
-
- double rightAscension, declination;
- double r, R, s, FV;
- double magnitude;
- double lonEcl, latEcl;
-
- double fgCalcEccAnom(double M, double e);
- double fgCalcActTime(fgTIME *t);
- void updateOrbElements(fgTIME *t);
-
-public:
- CelestialBody(double Nf, double Ns,
- double If, double Is,
- double wf, double ws,
- double af, double as,
- double ef, double es,
- double Mf, double Ms, fgTIME *t);
- void getPos(double *ra, double *dec);
- void getPos(double *ra, double *dec, double *magnitude);
- double getLon();
- double getLat();
- void updatePosition(fgTIME *t, Star *ourSun);
-};
-
-/*****************************************************************************
- * inline CelestialBody::CelestialBody
- * public constructor for a generic celestialBody object.
- * initializes the 6 primary orbital elements. The elements are:
- * N: longitude of the ascending node
- * i: inclination to the ecliptic
- * w: argument of perihelion
- * a: semi-major axis, or mean distance from the sun
- * e: eccenticity
- * M: mean anomaly
- * Each orbital element consists of a constant part and a variable part that
- * gradually changes over time.
- *
- * Argumetns:
- * the 13 arguments to the constructor constitute the first, constant
- * ([NiwaeM]f) and the second variable ([NiwaeM]s) part of the orbital
- * elements. The 13th argument is the current time. Note that the inclination
- * is written with a capital (If, Is), because 'if' is a reserved word in the
- * C/C++ programming language.
- ***************************************************************************/
-inline CelestialBody::CelestialBody(double Nf, double Ns,
- double If, double Is,
- double wf, double ws,
- double af, double as,
- double ef, double es,
- double Mf, double Ms, fgTIME *t)
-{
- NFirst = Nf; NSec = Ns;
- iFirst = If; iSec = Is;
- wFirst = wf; wSec = ws;
- aFirst = af; aSec = as;
- eFirst = ef; eSec = es;
- MFirst = Mf; MSec = Ms;
- updateOrbElements(t);
-};
-
-/****************************************************************************
- * inline void CelestialBody::updateOrbElements(fgTIME *t)
- * given the current time, this private member calculates the actual
- * orbital elements
- *
- * Arguments: fgTIME *t: the current time:
- *
- * return value: none
- ***************************************************************************/
-inline void CelestialBody::updateOrbElements(fgTIME *t)
-{
- double actTime = fgCalcActTime(t);
- M = DEG_TO_RAD * (MFirst + (MSec * actTime));
- w = DEG_TO_RAD * (wFirst + (wSec * actTime));
- N = DEG_TO_RAD * (NFirst + (NSec * actTime));
- i = DEG_TO_RAD * (iFirst + (iSec * actTime));
- e = eFirst + (eSec * actTime);
- a = aFirst + (aSec * actTime);
-}
-/*****************************************************************************
- * inline double CelestialBody::fgCalcActTime(fgTIME *t)
- * this private member function returns the offset in days from the epoch for
- * wich the orbital elements are calculated (Jan, 1st, 2000).
- *
- * Argument: the current time
- *
- * return value: the (fractional) number of days until Jan 1, 2000.
- ****************************************************************************/
-inline double CelestialBody::fgCalcActTime(fgTIME *t)
-{
- return (t->mjd - 36523.5);
-}
-
-/*****************************************************************************
- * inline void CelestialBody::getPos(double* ra, double* dec)
- * gives public access to Right Ascension and declination
- *
- ****************************************************************************/
-inline void CelestialBody::getPos(double* ra, double* dec)
-{
- *ra = rightAscension;
- *dec = declination;
-}
-
-/*****************************************************************************
- * inline void CelestialBody::getPos(double* ra, double* dec, double* magnitude
- * gives public acces to the current Right ascension, declination, and
- * magnitude
- ****************************************************************************/
-inline void CelestialBody::getPos(double* ra, double* dec, double* magn)
-{
- *ra = rightAscension;
- *dec = declination;
- *magn = magnitude;
-}
-
-inline double CelestialBody::getLon()
-{
- return lonEcl;
-}
-
-inline double CelestialBody::getLat()
-{
- return latEcl;
-}
-
-#endif // _CELESTIALBODY_H_
-
-
-
-
-
-
-
-
-
-
-
-
+++ /dev/null
-/**************************************************************************
- * jupiter.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)
- **************************************************************************/
-
-
-#ifdef __BORLANDC__
-# define exception c_exception
-#endif
-#include <math.h>
-
-#include "jupiter.hxx"
-
-/*************************************************************************
- * Jupiter::Jupiter(fgTIME *t)
- * Public constructor for class Jupiter
- * Argument: The current time.
- * the hard coded orbital elements for Jupiter are passed to
- * CelestialBody::CelestialBody();
- ************************************************************************/
-Jupiter::Jupiter(fgTIME *t) :
- CelestialBody(100.4542, 2.7685400E-5,
- 1.3030, -1.557E-7,
- 273.8777, 1.6450500E-5,
- 5.2025600, 0.000000,
- 0.048498, 4.469E-9,
- 19.89500, 0.08308530010, t)
-{
-}
-
-/*************************************************************************
- * void Jupiter::updatePosition(fgTIME *t, Star *ourSun)
- *
- * calculates the current position of Jupiter, by calling the base class,
- * CelestialBody::updatePosition(); The current magnitude is calculated using
- * a Jupiter specific equation
- *************************************************************************/
-void Jupiter::updatePosition(fgTIME *t, Star *ourSun)
-{
- CelestialBody::updatePosition(t, ourSun);
- magnitude = -9.25 + 5*log10( r*R ) + 0.014 * FV;
-}
-
-
-
-
+++ /dev/null
-/**************************************************************************
- * jupiter.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 _JUPITER_HXX_
-#define _JUPITER_HXX_
-
-#include <Time/fg_time.hxx>
-#include "celestialBody.hxx"
-#include "star.hxx"
-
-class Jupiter : public CelestialBody
-{
-public:
- Jupiter (fgTIME *t);
- void updatePosition(fgTIME *t, Star *ourSun);
-};
-
-#endif // _JUPITER_HXX_
+++ /dev/null
-/**************************************************************************
- * mars.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)
- **************************************************************************/
-
-#ifdef __BORLANDC__
-# define exception c_exception
-#endif
-#include <math.h>
-
-#include "mars.hxx"
-
-/*************************************************************************
- * Mars::Mars(fgTIME *t)
- * Public constructor for class Mars
- * Argument: The current time.
- * the hard coded orbital elements for Mars are passed to
- * CelestialBody::CelestialBody();
- ************************************************************************/
-Mars::Mars(fgTIME *t) :
- CelestialBody(49.55740, 2.1108100E-5,
- 1.8497, -1.78E-8,
- 286.5016, 2.9296100E-5,
- 1.5236880, 0.000000,
- 0.093405, 2.516E-9,
- 18.60210, 0.52402077660, t)
-{
-}
-/*************************************************************************
- * void Mars::updatePosition(fgTIME *t, Star *ourSun)
- *
- * calculates the current position of Mars, by calling the base class,
- * CelestialBody::updatePosition(); The current magnitude is calculated using
- * a Mars specific equation
- *************************************************************************/
-void Mars::updatePosition(fgTIME *t, Star *ourSun)
-{
- CelestialBody::updatePosition(t, ourSun);
- magnitude = -1.51 + 5*log10( r*R ) + 0.016 * FV;
-}
+++ /dev/null
-/**************************************************************************
- * mars.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 _MARS_HXX_
-#define _MARS_HXX_
-
-#include <Time/fg_time.hxx>
-#include "celestialBody.hxx"
-#include "star.hxx"
-
-class Mars : public CelestialBody
-{
-public:
- Mars ( fgTIME *t);
- void updatePosition(fgTIME *t, Star *ourSun);
-};
-
-#endif // _MARS_HXX_
+++ /dev/null
-/**************************************************************************
- * mercury.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)
- **************************************************************************/
-
-#ifdef __BORLANDC__
-# define exception c_exception
-#endif
-#include <math.h>
-
-#include "mercury.hxx"
-
-/*************************************************************************
- * Mercury::Mercury(fgTIME *t)
- * Public constructor for class Mercury
- * Argument: The current time.
- * the hard coded orbital elements for Mercury are passed to
- * CelestialBody::CelestialBody();
- ************************************************************************/
-Mercury::Mercury(fgTIME *t) :
- CelestialBody (48.33130, 3.2458700E-5,
- 7.0047, 5.00E-8,
- 29.12410, 1.0144400E-5,
- 0.3870980, 0.000000,
- 0.205635, 5.59E-10,
- 168.6562, 4.09233443680, t)
-{
-}
-/*************************************************************************
- * void Mercury::updatePosition(fgTIME *t, Star *ourSun)
- *
- * calculates the current position of Mercury, by calling the base class,
- * CelestialBody::updatePosition(); The current magnitude is calculated using
- * a Mercury specific equation
- *************************************************************************/
-void Mercury::updatePosition(fgTIME *t, Star *ourSun)
-{
- CelestialBody::updatePosition(t, ourSun);
- magnitude = -0.36 + 5*log10( r*R ) + 0.027 * FV + 2.2E-13 * pow(FV, 6);
-}
-
-
+++ /dev/null
-/**************************************************************************
- * mercury.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 _MERCURY_HXX_
-#define _MERCURY_HXX_
-
-#include <Time/fg_time.hxx>
-#include "celestialBody.hxx"
-#include "star.hxx"
-
-class Mercury : public CelestialBody
-{
-public:
- Mercury ( fgTIME *t);
- void updatePosition(fgTIME *t, Star* ourSun);
-};
-
-#endif // _MERURY_HXX_
+++ /dev/null
-/**************************************************************************
- * moon.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 <FDM/flight.hxx>
-
-#include <string.h>
-#include "moon.hxx"
-
-#include <Debug/logstream.hxx>
-#include <Objects/texload.h>
-
-#ifdef __BORLANDC__
-# define exception c_exception
-#endif
-#include <math.h>
-
-
-/*************************************************************************
- * Moon::Moon(fgTIME *t)
- * Public constructor for class Moon. Initializes the orbital elements and
- * sets up the moon texture.
- * Argument: The current time.
- * the hard coded orbital elements for Moon are passed to
- * CelestialBody::CelestialBody();
- ************************************************************************/
-Moon::Moon(fgTIME *t) :
- CelestialBody(125.1228, -0.0529538083,
- 5.1454, 0.00000,
- 318.0634, 0.1643573223,
- 60.266600, 0.000000,
- 0.054900, 0.000000,
- 115.3654, 13.0649929509, t)
-{
- string tpath, fg_tpath;
- int width, height;
-
- FG_LOG( FG_GENERAL, FG_INFO, "Initializing Moon Texture");
-#ifdef GL_VERSION_1_1
- xglGenTextures(1, &moon_texid);
- xglBindTexture(GL_TEXTURE_2D, moon_texid);
-#elif GL_EXT_texture_object
- xglGenTexturesEXT(1, &moon_texid);
- xglBindTextureEXT(GL_TEXTURE_2D, moon_texid);
-#else
-# error port me
-#endif
-
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-
- // load in the texture data
- tpath = current_options.get_fg_root() + "/Textures/" + "moon.rgb";
-
- if ( (moon_texbuf = read_rgb_texture(tpath.c_str(), &width, &height))
- == NULL )
- {
- // Try compressed
- fg_tpath = tpath + ".gz";
- if ( (moon_texbuf = read_rgb_texture(fg_tpath.c_str(), &width, &height))
- == NULL )
- {
- FG_LOG( FG_GENERAL, FG_ALERT,
- "Error in loading moon texture " << tpath );
- exit(-1);
- }
- }
-
- glTexImage2D( GL_TEXTURE_2D,
- 0,
- GL_RGB,
- 256, 256,
- 0,
- GL_RGB, GL_UNSIGNED_BYTE,
- moon_texbuf);
-
- // setup the halo texture
- FG_LOG( FG_GENERAL, FG_INFO, "Initializing Moon Texture");
-#ifdef GL_VERSION_1_1
- xglGenTextures(1, &moon_halotexid);
- xglBindTexture(GL_TEXTURE_2D, moon_halotexid);
-#elif GL_EXT_texture_object
- xglGenTexturesEXT(1, &moon_halotexid);
- xglBindTextureEXT(GL_TEXTURE_2D, moon_halotexid);
-#else
-# error port me
-#endif
-
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- setHalo();
- glTexImage2D( GL_TEXTURE_2D,
- 0,
- GL_RGBA,
- 256, 256,
- 0,
- GL_RGBA, GL_UNSIGNED_BYTE,
- moon_halotexbuf);
- moonObject = gluNewQuadric();
-}
-
-Moon::~Moon()
-{
- //delete moonObject;
- delete moon_texbuf;
- delete moon_halotexbuf;
-}
-
-
-static int texWidth = 256; /* 64x64 is plenty */
-
-void Moon::setHalo()
-{
- int texSize;
- //void *textureBuf;
- GLubyte *p;
- int i,j;
- double radius;
-
- texSize = texWidth*texWidth;
-
- moon_halotexbuf = new GLubyte[texSize*4];
- if (!moon_halotexbuf)
- return; // Ugly!
-
- p = moon_halotexbuf;
-
- radius = (double)(texWidth / 2);
-
- for (i=0; i < texWidth; i++) {
- for (j=0; j < texWidth; j++) {
- double x, y, d;
-
- x = fabs((double)(i - (texWidth / 2)));
- y = fabs((double)(j - (texWidth / 2)));
-
- d = sqrt((x * x) + (y * y));
- if (d < radius)
- {
- double t = 1.0 - (d / radius); // t is 1.0 at center, 0.0 at edge */
- // inverse square looks nice
- *p = (int)((double)0xff * (t * t));
- *(p+1) = (int)((double) 0xff * (t*t));
- *(p+2) = (int)((double) 0xff * (t*t));
- *(p+3) = 0x11;
- }
- else
- {
- *p = 0x00;
- *(p+1) = 0x00;
- *(p+2) = 0x00;
- *(p+3) = 0x11;
- }
- p += 4;
- }
- }
- //gluBuild2DMipmaps(GL_TEXTURE_2D, 1, texWidth, texWidth,
- // GL_LUMINANCE,
- // GL_UNSIGNED_BYTE, textureBuf);
- //free(textureBuf);
-}
-
-
-/*****************************************************************************
- * void Moon::updatePosition(fgTIME *t, Star *ourSun)
- * this member function calculates the actual topocentric position (i.e.)
- * the position of the moon as seen from the current position on the surface
- * of the moon.
- ****************************************************************************/
-void Moon::updatePosition(fgTIME *t, Star *ourSun)
-{
- double
- eccAnom, ecl, actTime,
- xv, yv, v, r, xh, yh, zh, xg, yg, zg, xe, ye, ze,
- Ls, Lm, D, F, mpar, gclat, rho, HA, g,
- geoRa, geoDec;
-
- fgAIRCRAFT *air;
- FGInterface *f;
-
- air = ¤t_aircraft;
- f = air->fdm_state;
-
- updateOrbElements(t);
- actTime = fgCalcActTime(t);
-
- // calculate the angle between ecliptic and equatorial coordinate system
- // in Radians
- ecl = ((DEG_TO_RAD * 23.4393) - (DEG_TO_RAD * 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 moon's true anomaly
- r = sqrt (xv*xv + yv*yv); // and its distance
-
- // estimate the geocentric rectangular coordinates here
- 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 latitude and longitude here
- lonEcl = atan2 (yh, xh);
- latEcl = atan2(zh, sqrt(xh*xh + yh*yh));
-
- /* Calculate a number of perturbatioin, i.e. disturbances caused by the
- * gravitational infuence of the sun and the other major planets.
- * The largest of these even have a name */
- Ls = ourSun->getM() + ourSun->getw();
- Lm = M + w + N;
- D = Lm - Ls;
- F = Lm - N;
-
- lonEcl += DEG_TO_RAD * (-1.274 * sin (M - 2*D)
- +0.658 * sin (2*D)
- -0.186 * sin(ourSun->getM())
- -0.059 * sin(2*M - 2*D)
- -0.057 * sin(M - 2*D + ourSun->getM())
- +0.053 * sin(M + 2*D)
- +0.046 * sin(2*D - ourSun->getM())
- +0.041 * sin(M - ourSun->getM())
- -0.035 * sin(D)
- -0.031 * sin(M + ourSun->getM())
- -0.015 * sin(2*F - 2*D)
- +0.011 * sin(M - 4*D)
- );
- latEcl += DEG_TO_RAD * (-0.173 * sin(F-2*D)
- -0.055 * sin(M - F - 2*D)
- -0.046 * sin(M + F - 2*D)
- +0.033 * sin(F + 2*D)
- +0.017 * sin(2*M + F)
- );
- r += (-0.58 * cos(M - 2*D)
- -0.46 * cos(2*D)
- );
- FG_LOG(FG_GENERAL, FG_INFO, "Running moon update");
- xg = r * cos(lonEcl) * cos(latEcl);
- yg = r * sin(lonEcl) * cos(latEcl);
- zg = r * sin(latEcl);
-
- xe = xg;
- ye = yg * cos(ecl) -zg * sin(ecl);
- ze = yg * sin(ecl) +zg * cos(ecl);
-
- geoRa = atan2(ye, xe);
- geoDec = atan2(ze, sqrt(xe*xe + ye*ye));
-
- // Given the moon's geocentric ra and dec, calculate its
- // topocentric ra and dec. i.e. the position as seen from the
- // surface of the earth, instead of the center of the earth
-
- // First calculate the moon's parrallax, that is, the apparent size of the
- // (equatorial) radius of the earth, as seen from the moon
- mpar = asin ( 1 / r);
- gclat = f->get_Latitude() - 0.003358 *
- sin (2 * DEG_TO_RAD * f->get_Latitude() );
- rho = 0.99883 + 0.00167 * cos(2 * DEG_TO_RAD * f->get_Latitude());
- if (geoRa < 0)
- geoRa += (2*FG_PI);
-
- HA = t->lst - (3.8197186 * geoRa);
- g = atan (tan(gclat) / cos ((HA / 3.8197186)));
- rightAscension = geoRa - mpar * rho * cos(gclat) * sin(HA) / cos (geoDec);
- declination = geoDec - mpar * rho * sin (gclat) * sin (g - geoDec) / sin(g);
-}
-
-
-/************************************************************************
- * void Moon::newImage()
- *
- * This function regenerates a new visual image of the moon, which is added to
- * solarSystem display list.
- *
- * Arguments: Right Ascension and declination
- *
- * return value: none
- **************************************************************************/
-void Moon::newImage()
-{
- fgLIGHT *l = &cur_light_params;
- float moon_angle = l->moon_angle;
-
- /*double x_2, x_4, x_8, x_10;
- GLfloat ambient;
- GLfloat amb[4];*/
- int moonSize = 750;
-
- GLfloat moonColor[4] = {0.85, 0.75, 0.35, 1.0};
- GLfloat black[4] = {0.0, 0.0,0.0,1.0};
- GLfloat white[4] = {1.0, 1.0,1.0,1.0};
-
- if( moon_angle*RAD_TO_DEG < 100 )
- {
- /*
- x_2 = moon_angle * moon_angle;
- x_4 = x_2 * x_2;
- x_8 = x_4 * x_4;
- x_10 = x_8 * x_2;
- ambient = (float)(0.4 * pow (1.1, - x_10 / 30.0));
- if (ambient < 0.3) ambient = 0.3;
- if (ambient > 1.0) ambient = 1.0;
-
- amb[0] = ((ambient * 6.0) - 1.0); // minimum value = 0.8
- amb[1] = ((ambient * 11.0) - 3.0); // minimum value = 0.3
- amb[2] = ((ambient * 12.0) - 3.6); // minimum value = 0.0
- amb[3] = 1.00;
-
- if (amb[0] > 1.0) amb[0] = 1.0;
- if (amb[1] > 1.0) amb[1] = 1.0;
- if (amb[2] > 1.0) amb[2] = 1.0;
- xglColor3fv(amb);
- xglColor3f(1.0, 1.0, 1.0); */
- xglPushMatrix();
- {
- //xglRotatef(-90, 0.0, 0.0, 1.0);
- xglRotatef(((RAD_TO_DEG * rightAscension)- 90.0), 0.0, 0.0, 1.0);
- xglRotatef((RAD_TO_DEG * declination), 1.0, 0.0, 0.0);
-
- FG_LOG( FG_GENERAL, FG_INFO,
- "Ra = (" << (RAD_TO_DEG *rightAscension)
- << "), Dec= (" << (RAD_TO_DEG *declination) << ")" );
- xglTranslatef(0.0, 58600.0, 0.0);
-
- glEnable(GL_TEXTURE_2D); // TEXTURE ENABLED
- glEnable(GL_BLEND); // BLEND ENABLED
- glBlendFunc(GL_SRC_ALPHA, GL_ONE);
- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- glBindTexture(GL_TEXTURE_2D, moon_halotexid);
-
- glBegin(GL_QUADS);
- glTexCoord2f(0.0f, 0.0f); glVertex3f(-5000, 0.0, -5000);
- glTexCoord2f(1.0f, 0.0f); glVertex3f( 5000, 0.0, -5000);
- glTexCoord2f(1.0f, 1.0f); glVertex3f( 5000, 0.0, 5000);
- glTexCoord2f(0.0f, 1.0f); glVertex3f(-5000, 0.0, 5000);
- glEnd();
-
- xglEnable(GL_LIGHTING); // LIGHTING ENABLED
- xglEnable( GL_LIGHT0 );
- // set lighting parameters
- xglLightfv(GL_LIGHT0, GL_AMBIENT, white );
- xglLightfv(GL_LIGHT0, GL_DIFFUSE, white );
- xglEnable( GL_CULL_FACE );
- xglMaterialfv(GL_FRONT, GL_AMBIENT, black);
- xglMaterialfv(GL_FRONT, GL_DIFFUSE, moonColor);
-
- //glEnable(GL_TEXTURE_2D);
- glBlendFunc(GL_ONE, GL_ONE);
-
- //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- glBindTexture(GL_TEXTURE_2D, moon_texid);
- //glDisable(GL_LIGHTING); // LIGHTING DISABLED
-
- gluQuadricTexture(moonObject, GL_TRUE );
- gluSphere(moonObject, moonSize, 12, 12 );
- glDisable(GL_TEXTURE_2D); // TEXTURE DISABLED
- glDisable(GL_BLEND); // BLEND DISABLED
- }
- xglPopMatrix();
- glDisable(GL_LIGHTING); // LIGHTING DISABLED
-
- }
- else
- {
- }
-}
-
-
-
-
-
-
-
+++ /dev/null
-/**************************************************************************
- * moon.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 _MOON_HXX_
-#define _MOON_HXX_
-
-#include <Aircraft/aircraft.hxx>
-#include <Include/fg_constants.h>
-#include <Main/views.hxx>
-#include <Time/fg_time.hxx>
-
-#include "celestialBody.hxx"
-#include "star.hxx"
-
-class Moon : public CelestialBody
-{
-private:
- void TexInit(); // This should move to the constructor eventually.
-
- GLUquadricObj *moonObject;
- GLuint Sphere;
- GLuint moon_texid;
- GLuint moon_halotexid;
- GLubyte *moon_texbuf;
- GLubyte *moon_halotexbuf;
-
- void setHalo();
-public:
- Moon ( fgTIME *t);
- ~Moon();
- void updatePosition(fgTIME *t, Star *ourSun);
- void newImage();
-};
-
-
-#endif // _MOON_HXX_
+++ /dev/null
-/**************************************************************************
- * neptune.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)
- **************************************************************************/
-
-#ifdef __BORLANDC__
-# define exception c_exception
-#endif
-#include <math.h>
-
-#include "neptune.hxx"
-
-/*************************************************************************
- * Neptune::Neptune(fgTIME *t)
- * Public constructor for class Neptune
- * Argument: The current time.
- * the hard coded orbital elements for Neptune are passed to
- * CelestialBody::CelestialBody();
- ************************************************************************/
-Neptune::Neptune(fgTIME *t) :
- CelestialBody(131.7806, 3.0173000E-5,
- 1.7700, -2.550E-7,
- 272.8461, -6.027000E-6,
- 30.058260, 3.313E-8,
- 0.008606, 2.150E-9,
- 260.2471, 0.00599514700, t)
-{
-}
-/*************************************************************************
- * void Neptune::updatePosition(fgTIME *t, Star *ourSun)
- *
- * calculates the current position of Neptune, by calling the base class,
- * CelestialBody::updatePosition(); The current magnitude is calculated using
- * a Neptune specific equation
- *************************************************************************/
-void Neptune::updatePosition(fgTIME *t, Star *ourSun)
-{
- CelestialBody::updatePosition(t, ourSun);
- magnitude = -6.90 + 5*log10 (r*R) + 0.001 *FV;
-}
+++ /dev/null
-/**************************************************************************
- * neptune.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 _NEPTUNE_HXX_
-#define _NEPTUNE_HXX_
-
-#include <Time/fg_time.hxx>
-#include "celestialBody.hxx"
-#include "star.hxx"
-
-class Neptune : public CelestialBody
-{
-public:
- Neptune ( fgTIME *t);
- void updatePosition(fgTIME *t, Star *ourSun);
-};
-
-#endif // _NEPTUNE_HXX_
+++ /dev/null
-/**************************************************************************
- * pluto.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 _PLUTO_HXX_
-#define _PLUTO_HXX_
-
-#include <Time/fg_time.hxx>
-#include "celestialBody.hxx"
-
-class Pluto : public CelestialBody
-{
-public:
- Pluto ( fgTIME t);
-};
-
-#endif // _PLUTO_HXX_
+++ /dev/null
-/**************************************************************************
- * saturn.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)
- **************************************************************************/
-
-#ifdef __BORLANDC__
-# define exception c_exception
-#endif
-#include <math.h>
-
-#include "saturn.hxx"
-
-/*************************************************************************
- * Saturn::Saturn(fgTIME *t)
- * Public constructor for class Saturn
- * Argument: The current time.
- * the hard coded orbital elements for Saturn are passed to
- * CelestialBody::CelestialBody();
- ************************************************************************/
-Saturn::Saturn(fgTIME *t) :
- CelestialBody(113.6634, 2.3898000E-5,
- 2.4886, -1.081E-7,
- 339.3939, 2.9766100E-5,
- 9.5547500, 0.000000,
- 0.055546, -9.499E-9,
- 316.9670, 0.03344422820, t)
-{
-}
-
-/*************************************************************************
- * void Saturn::updatePosition(fgTIME *t, Star *ourSun)
- *
- * calculates the current position of Saturn, by calling the base class,
- * CelestialBody::updatePosition(); The current magnitude is calculated using
- * a Saturn specific equation
- *************************************************************************/
-void Saturn::updatePosition(fgTIME *t, Star *ourSun)
-{
- CelestialBody::updatePosition(t, ourSun);
-
- double actTime = fgCalcActTime(t);
- double ir = 0.4897394;
- double Nr = 2.9585076 + 6.6672E-7*actTime;
- double B = asin (sin(declination) * cos(ir) -
- cos(declination) * sin(ir) *
- sin(rightAscension - Nr));
- double ring_magn = -2.6 * sin(fabs(B)) + 1.2 * pow(sin(B), 2);
- magnitude = -9.0 + 5*log10(r*R) + 0.044 * FV + ring_magn;
-}
-
+++ /dev/null
-/**************************************************************************
- * saturn.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 _SATURN_HXX_
-#define _SATURN_HXX_
-
-#include <Time/fg_time.hxx>
-#include "celestialBody.hxx"
-#include "star.hxx"
-
-class Saturn : public CelestialBody
-{
-public:
- Saturn ( fgTIME *t);
- void updatePosition(fgTIME *t, Star *ourSun);
-};
-
-#endif // _SATURN_HXX_
-
-
-
-
-
-
-
+++ /dev/null
-// sky.cxx -- model sky with an upside down "bowl"
-//
-// Written by Curtis Olson, started December 1997.
-//
-// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
-//
-// 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)
-
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#ifdef HAVE_WINDOWS_H
-# include <windows.h>
-#endif
-
-#include <math.h>
-
-#include <GL/glut.h>
-#include <XGL/xgl.h>
-
-#include <Aircraft/aircraft.hxx>
-#include <Debug/logstream.hxx>
-#include <FDM/flight.hxx>
-#include <Include/fg_constants.h>
-#include <Main/views.hxx>
-#include <Math/fg_random.h>
-#include <Time/event.hxx>
-#include <Time/fg_time.hxx>
-
-#include "sky.hxx"
-
-
-// in meters of course
-#define CENTER_ELEV 25000.0
-
-#define INNER_RADIUS 50000.0
-#define INNER_ELEV 20000.0
-
-#define MIDDLE_RADIUS 70000.0
-#define MIDDLE_ELEV 8000.0
-
-#define OUTER_RADIUS 80000.0
-#define OUTER_ELEV 0.0
-
-#define BOTTOM_RADIUS 50000.0
-#define BOTTOM_ELEV -2000.0
-
-
-static float inner_vertex[12][3];
-static float middle_vertex[12][3];
-static float outer_vertex[12][3];
-static float bottom_vertex[12][3];
-
-static float inner_color[12][4];
-static float middle_color[12][4];
-static float outer_color[12][4];
-
-
-// Calculate the sky structure vertices
-void fgSkyVerticesInit( void ) {
- float theta;
- int i;
-
- FG_LOG(FG_ASTRO, FG_INFO, " Generating the sky dome vertices.");
-
- for ( i = 0; i < 12; i++ ) {
- theta = (i * 30.0) * DEG_TO_RAD;
-
- inner_vertex[i][0] = cos(theta) * INNER_RADIUS;
- inner_vertex[i][1] = sin(theta) * INNER_RADIUS;
- inner_vertex[i][2] = INNER_ELEV;
-
- // printf(" %.2f %.2f\n", cos(theta) * INNER_RADIUS,
- // sin(theta) * INNER_RADIUS);
-
- middle_vertex[i][0] = cos((double)theta) * MIDDLE_RADIUS;
- middle_vertex[i][1] = sin((double)theta) * MIDDLE_RADIUS;
- middle_vertex[i][2] = MIDDLE_ELEV;
-
- outer_vertex[i][0] = cos((double)theta) * OUTER_RADIUS;
- outer_vertex[i][1] = sin((double)theta) * OUTER_RADIUS;
- outer_vertex[i][2] = OUTER_ELEV;
-
- bottom_vertex[i][0] = cos((double)theta) * BOTTOM_RADIUS;
- bottom_vertex[i][1] = sin((double)theta) * BOTTOM_RADIUS;
- bottom_vertex[i][2] = BOTTOM_ELEV;
- }
-}
-
-
-// (Re)calculate the sky colors at each vertex
-void fgSkyColorsInit( void ) {
- fgLIGHT *l;
- double sun_angle, diff;
- double outer_param[3], outer_amt[3], outer_diff[3];
- double middle_param[3], middle_amt[3], middle_diff[3];
- int i, j;
-
- l = &cur_light_params;
-
- FG_LOG( FG_ASTRO, FG_INFO,
- " Generating the sky colors for each vertex." );
-
- // setup for the possibility of sunset effects
- sun_angle = l->sun_angle * RAD_TO_DEG;
- // fgPrintf( FG_ASTRO, FG_INFO,
- // " Sun angle in degrees = %.2f\n", sun_angle);
-
- if ( (sun_angle > 80.0) && (sun_angle < 100.0) ) {
- // 0.0 - 0.4
- outer_param[0] = (10.0 - fabs(90.0 - sun_angle)) / 20.0;
- outer_param[1] = (10.0 - fabs(90.0 - sun_angle)) / 40.0;
- outer_param[2] = -(10.0 - fabs(90.0 - sun_angle)) / 30.0;
- // outer_param[2] = 0.0;
-
- middle_param[0] = (10.0 - fabs(90.0 - sun_angle)) / 40.0;
- middle_param[1] = (10.0 - fabs(90.0 - sun_angle)) / 80.0;
- middle_param[2] = 0.0;
-
- outer_diff[0] = outer_param[0] / 6.0;
- outer_diff[1] = outer_param[1] / 6.0;
- outer_diff[2] = outer_param[2] / 6.0;
-
- middle_diff[0] = middle_param[0] / 6.0;
- middle_diff[1] = middle_param[1] / 6.0;
- middle_diff[2] = middle_param[2] / 6.0;
- } else {
- outer_param[0] = outer_param[1] = outer_param[2] = 0.0;
- middle_param[0] = middle_param[1] = middle_param[2] = 0.0;
-
- outer_diff[0] = outer_diff[1] = outer_diff[2] = 0.0;
- middle_diff[0] = middle_diff[1] = middle_diff[2] = 0.0;
- }
- // printf(" outer_red_param = %.2f outer_red_diff = %.2f\n",
- // outer_red_param, outer_red_diff);
-
- // calculate transition colors between sky and fog
- for ( j = 0; j < 3; j++ ) {
- outer_amt[j] = outer_param[j];
- middle_amt[j] = middle_param[j];
- }
-
- for ( i = 0; i < 6; i++ ) {
- for ( j = 0; j < 3; j++ ) {
- diff = l->sky_color[j] - l->fog_color[j];
-
- // printf("sky = %.2f fog = %.2f diff = %.2f\n",
- // l->sky_color[j], l->fog_color[j], diff);
-
- inner_color[i][j] = l->sky_color[j] - diff * 0.3;
- middle_color[i][j] = l->sky_color[j] - diff * 0.9 + middle_amt[j];
- outer_color[i][j] = l->fog_color[j] + outer_amt[j];
-
- if ( inner_color[i][j] > 1.00 ) { inner_color[i][j] = 1.00; }
- if ( inner_color[i][j] < 0.10 ) { inner_color[i][j] = 0.10; }
- if ( middle_color[i][j] > 1.00 ) { middle_color[i][j] = 1.00; }
- if ( middle_color[i][j] < 0.10 ) { middle_color[i][j] = 0.10; }
- if ( outer_color[i][j] > 1.00 ) { outer_color[i][j] = 1.00; }
- if ( outer_color[i][j] < 0.10 ) { outer_color[i][j] = 0.10; }
- }
- inner_color[i][3] = middle_color[i][3] = outer_color[i][3] =
- l->sky_color[3];
-
- for ( j = 0; j < 3; j++ ) {
- outer_amt[j] -= outer_diff[j];
- middle_amt[j] -= middle_diff[j];
- }
-
- /*
- printf("inner_color[%d] = %.2f %.2f %.2f %.2f\n", i, inner_color[i][0],
- inner_color[i][1], inner_color[i][2], inner_color[i][3]);
- printf("middle_color[%d] = %.2f %.2f %.2f %.2f\n", i,
- middle_color[i][0], middle_color[i][1], middle_color[i][2],
- middle_color[i][3]);
- printf("outer_color[%d] = %.2f %.2f %.2f %.2f\n", i,
- outer_color[i][0], outer_color[i][1], outer_color[i][2],
- outer_color[i][3]);
- */
- }
-
- for ( j = 0; j < 3; j++ ) {
- outer_amt[j] = 0.0;
- middle_amt[j] = 0.0;
- }
-
- for ( i = 6; i < 12; i++ ) {
-
- for ( j = 0; j < 3; j++ ) {
- diff = l->sky_color[j] - l->fog_color[j];
-
- // printf("sky = %.2f fog = %.2f diff = %.2f\n",
- // l->sky_color[j], l->fog_color[j], diff);
-
- inner_color[i][j] = l->sky_color[j] - diff * 0.3;
- middle_color[i][j] = l->sky_color[j] - diff * 0.9 + middle_amt[j];
- outer_color[i][j] = l->fog_color[j] + outer_amt[j];
-
- if ( inner_color[i][j] > 1.00 ) { inner_color[i][j] = 1.00; }
- if ( inner_color[i][j] < 0.10 ) { inner_color[i][j] = 0.10; }
- if ( middle_color[i][j] > 1.00 ) { middle_color[i][j] = 1.00; }
- if ( middle_color[i][j] < 0.10 ) { middle_color[i][j] = 0.10; }
- if ( outer_color[i][j] > 1.00 ) { outer_color[i][j] = 1.00; }
- if ( outer_color[i][j] < 0.15 ) { outer_color[i][j] = 0.15; }
- }
- inner_color[i][3] = middle_color[i][3] = outer_color[i][3] =
- l->sky_color[3];
-
- for ( j = 0; j < 3; j++ ) {
- outer_amt[j] += outer_diff[j];
- middle_amt[j] += middle_diff[j];
- }
-
- /*
- printf("inner_color[%d] = %.2f %.2f %.2f %.2f\n", i, inner_color[i][0],
- inner_color[i][1], inner_color[i][2], inner_color[i][3]);
- printf("middle_color[%d] = %.2f %.2f %.2f %.2f\n", i,
- middle_color[i][0], middle_color[i][1], middle_color[i][2],
- middle_color[i][3]);
- printf("outer_color[%d] = %.2f %.2f %.2f %.2f\n", i,
- outer_color[i][0], outer_color[i][1], outer_color[i][2],
- outer_color[i][3]);
- */
- }
-}
-
-
-// Initialize the sky structure and colors
-void fgSkyInit( void ) {
- FG_LOG( FG_ASTRO, FG_INFO, "Initializing the sky" );
-
- fgSkyVerticesInit();
-
- // regester fgSkyColorsInit() as an event to be run periodically
- global_events.Register( "fgSkyColorsInit()", fgSkyColorsInit,
- fgEVENT::FG_EVENT_READY, 30000);
-}
-
-
-// Draw the Sky
-void fgSkyRender( void ) {
- FGInterface *f;
- fgLIGHT *l;
- float inner_color[4];
- float middle_color[4];
- float outer_color[4];
- double diff;
- int i;
-
- f = current_aircraft.fdm_state;
- l = &cur_light_params;
-
- // printf("Rendering the sky.\n");
-
- // calculate the proper colors
- for ( i = 0; i < 3; i++ ) {
- diff = l->sky_color[i] - l->adj_fog_color[i];
-
- // printf("sky = %.2f fog = %.2f diff = %.2f\n",
- // l->sky_color[j], l->adj_fog_color[j], diff);
-
- inner_color[i] = l->sky_color[i] - diff * 0.3;
- middle_color[i] = l->sky_color[i] - diff * 0.9;
- outer_color[i] = l->adj_fog_color[i];
- }
- inner_color[3] = middle_color[3] = outer_color[3] = l->adj_fog_color[3];
-
- xglPushMatrix();
-
- // Translate to view position
- Point3D zero_elev = current_view.get_cur_zero_elev();
- xglTranslatef( zero_elev.x(), zero_elev.y(), zero_elev.z() );
- // printf(" Translated to %.2f %.2f %.2f\n",
- // zero_elev.x, zero_elev.y, zero_elev.z );
-
- // Rotate to proper orientation
- // printf(" lon = %.2f lat = %.2f\n", FG_Longitude * RAD_TO_DEG,
- // FG_Latitude * RAD_TO_DEG);
- xglRotatef( f->get_Longitude() * RAD_TO_DEG, 0.0, 0.0, 1.0 );
- xglRotatef( 90.0 - f->get_Latitude() * RAD_TO_DEG, 0.0, 1.0, 0.0 );
- xglRotatef( l->sun_rotation * RAD_TO_DEG, 0.0, 0.0, 1.0 );
-
- // Draw inner/center section of sky*/
- xglBegin( GL_TRIANGLE_FAN );
- xglColor4fv(l->sky_color);
- xglVertex3f(0.0, 0.0, CENTER_ELEV);
- for ( i = 11; i >= 0; i-- ) {
- xglColor4fv( inner_color );
- xglVertex3fv( inner_vertex[i] );
- }
- xglColor4fv( inner_color );
- xglVertex3fv( inner_vertex[11] );
- xglEnd();
-
- // Draw the middle ring
- xglBegin( GL_TRIANGLE_STRIP );
- for ( i = 0; i < 12; i++ ) {
- xglColor4fv( middle_color );
- // printf("middle_color[%d] = %.2f %.2f %.2f %.2f\n", i,
- // middle_color[i][0], middle_color[i][1], middle_color[i][2],
- // middle_color[i][3]);
- // xglColor4f(1.0, 0.0, 0.0, 1.0);
- xglVertex3fv( middle_vertex[i] );
- xglColor4fv( inner_color );
- // printf("inner_color[%d] = %.2f %.2f %.2f %.2f\n", i,
- // inner_color[i][0], inner_color[i][1], inner_color[i][2],
- // inner_color[i][3]);
- // xglColor4f(0.0, 0.0, 1.0, 1.0);
- xglVertex3fv( inner_vertex[i] );
- }
- xglColor4fv( middle_color );
- // xglColor4f(1.0, 0.0, 0.0, 1.0);
- xglVertex3fv( middle_vertex[0] );
- xglColor4fv( inner_color );
- // xglColor4f(0.0, 0.0, 1.0, 1.0);
- xglVertex3fv( inner_vertex[0] );
- xglEnd();
-
- // Draw the outer ring
- xglBegin( GL_TRIANGLE_STRIP );
- for ( i = 0; i < 12; i++ ) {
- xglColor4fv( outer_color );
- xglVertex3fv( outer_vertex[i] );
- xglColor4fv( middle_color );
- xglVertex3fv( middle_vertex[i] );
- }
- xglColor4fv( outer_color );
- xglVertex3fv( outer_vertex[0] );
- xglColor4fv( middle_color );
- xglVertex3fv( middle_vertex[0] );
- xglEnd();
-
- // Draw the bottom skirt
- xglBegin( GL_TRIANGLE_STRIP );
- xglColor4fv( outer_color );
- for ( i = 0; i < 12; i++ ) {
- xglVertex3fv( bottom_vertex[i] );
- xglVertex3fv( outer_vertex[i] );
- }
- xglVertex3fv( bottom_vertex[0] );
- xglVertex3fv( outer_vertex[0] );
- xglEnd();
-
- xglPopMatrix();
-}
-
-
-// $Log$
-// Revision 1.21 1999/02/05 21:28:50 curt
-// Modifications to incorporate Jon S. Berndts flight model code.
-//
-// Revision 1.20 1999/02/02 20:13:29 curt
-// MSVC++ portability changes by Bernie Bright:
-//
-// Lib/Serial/serial.[ch]xx: Initial Windows support - incomplete.
-// Simulator/Astro/stars.cxx: typo? included <stdio> instead of <cstdio>
-// Simulator/Cockpit/hud.cxx: Added Standard headers
-// Simulator/Cockpit/panel.cxx: Redefinition of default parameter
-// Simulator/Flight/flight.cxx: Replaced cout with FG_LOG. Deleted <stdio.h>
-// Simulator/Main/fg_init.cxx:
-// Simulator/Main/GLUTmain.cxx:
-// Simulator/Main/options.hxx: Shuffled <fg_serial.hxx> dependency
-// Simulator/Objects/material.hxx:
-// Simulator/Time/timestamp.hxx: VC++ friend kludge
-// Simulator/Scenery/tile.[ch]xx: Fixed using std::X declarations
-// Simulator/Main/views.hxx: Added a constant
-//
-// Revision 1.19 1999/02/01 21:33:26 curt
-// Renamed FlightGear/Simulator/Flight to FlightGear/Simulator/FDM since
-// Jon accepted my offer to do this and thought it was a good idea.
-//
-// Revision 1.18 1999/02/01 21:09:00 curt
-// Bug fix in vertex order of inner disk (fan) of the sky dome.
-//
-// Revision 1.17 1998/12/09 18:50:12 curt
-// Converted "class fgVIEW" to "class FGView" and updated to make data
-// members private and make required accessor functions.
-//
-// Revision 1.16 1998/12/05 15:54:03 curt
-// Renamed class fgFLIGHT to class FGState as per request by JSB.
-//
-// Revision 1.15 1998/12/03 01:15:36 curt
-// Converted fgFLIGHT to a class.
-// Tweaks for Sun portability.
-//
-// Revision 1.14 1998/11/06 21:17:39 curt
-// Converted to new logstream debugging facility. This allows release
-// builds with no messages at all (and no performance impact) by using
-// the -DFG_NDEBUG flag.
-//
-// Revision 1.13 1998/10/20 18:28:30 curt
-// Tweaked sunset/sunrise colors.
-//
-// Revision 1.12 1998/10/16 23:27:18 curt
-// C++-ifying.
-//
-// Revision 1.11 1998/10/16 00:52:19 curt
-// Converted to Point3D class.
-//
-// Revision 1.10 1998/08/29 13:07:16 curt
-// Rewrite of event manager thanks to Bernie Bright.
-//
-// Revision 1.9 1998/08/22 01:18:59 curt
-// Minor tweaks to avoid using unitialized memory.
-//
-// Revision 1.8 1998/08/12 21:40:44 curt
-// Sky now tracks adjusted fog color so it blends well with terrain.
-//
-// Revision 1.7 1998/07/22 21:39:21 curt
-// Lower skirt tracks adjusted fog color, not fog color.
-//
-// Revision 1.6 1998/05/23 14:07:14 curt
-// Use new C++ events class.
-//
-// Revision 1.5 1998/04/28 01:19:02 curt
-// Type-ified fgTIME and fgVIEW
-//
-// Revision 1.4 1998/04/26 05:10:01 curt
-// "struct fgLIGHT" -> "fgLIGHT" because fgLIGHT is typedef'd.
-//
-// Revision 1.3 1998/04/25 22:06:25 curt
-// Edited cvs log messages in source files ... bad bad bad!
-//
-// Revision 1.2 1998/04/24 00:45:03 curt
-// Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
-// Fixed a bug when generating sky colors.
-//
-// Revision 1.1 1998/04/22 13:21:32 curt
-// C++ - ifing the code a bit.
-//
-// Revision 1.9 1998/04/03 21:52:50 curt
-// Converting to Gnu autoconf system.
-//
-// Revision 1.8 1998/03/09 22:47:25 curt
-// Incorporated Durk's updates.
-//
-// Revision 1.7 1998/02/19 13:05:49 curt
-// Incorporated some HUD tweaks from Michelle America.
-// Tweaked the sky's sunset/rise colors.
-// Other misc. tweaks.
-//
-// Revision 1.6 1998/02/07 15:29:32 curt
-// Incorporated HUD changes and struct/typedef changes from Charlie Hotchkiss
-// <chotchkiss@namg.us.anritsu.com>
-//
-// Revision 1.5 1998/01/27 00:47:48 curt
-// Incorporated Paul Bleisch's <pbleisch@acm.org> new debug message
-// system and commandline/config file processing code.
-//
-// Revision 1.4 1998/01/26 15:54:28 curt
-// Added a "skirt" to try to help hide gaps between scenery and sky. This will
-// have to be revisited in the future.
-//
-// Revision 1.3 1998/01/19 19:26:59 curt
-// Merged in make system changes from Bob Kuehne <rpk@sgi.com>
-// This should simplify things tremendously.
-//
-// Revision 1.2 1998/01/19 18:40:17 curt
-// Tons of little changes to clean up the code and to remove fatal errors
-// when building with the c++ compiler.
-//
-// Revision 1.1 1998/01/07 03:16:19 curt
-// Moved from .../Src/Scenery/ to .../Src/Astro/
-//
-// Revision 1.11 1997/12/30 22:22:38 curt
-// Further integration of event manager.
-//
-// Revision 1.10 1997/12/30 20:47:53 curt
-// Integrated new event manager with subsystem initializations.
-//
-// Revision 1.9 1997/12/30 13:06:57 curt
-// A couple lighting tweaks ...
-//
-// Revision 1.8 1997/12/23 04:58:38 curt
-// Tweaked the sky coloring a bit to build in structures to allow finer rgb
-// control.
-//
-// Revision 1.7 1997/12/22 23:45:48 curt
-// First stab at sunset/sunrise sky glow effects.
-//
-// Revision 1.6 1997/12/22 04:14:34 curt
-// Aligned sky with sun so dusk/dawn effects can be correct relative to the sun.
-//
-// Revision 1.5 1997/12/19 23:34:59 curt
-// Lot's of tweaking with sky rendering and lighting.
-//
-// Revision 1.4 1997/12/19 16:45:02 curt
-// Working on scene rendering order and options.
-//
-// Revision 1.3 1997/12/18 23:32:36 curt
-// First stab at sky dome actually starting to look reasonable. :-)
-//
-// Revision 1.2 1997/12/18 04:07:03 curt
-// Worked on properly translating and positioning the sky dome.
-//
-// Revision 1.1 1997/12/17 23:14:30 curt
-// Initial revision.
-// Begin work on rendering the sky. (Rather than just using a clear screen.)
-//
-
+++ /dev/null
-// sky.hxx -- model sky with an upside down "bowl"
-//
-// Written by Curtis Olson, started December 1997.
-//
-// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
-//
-// 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 _SKY_HXX
-#define _SKY_HXX
-
-
-#ifndef __cplusplus
-# error This library requires C++
-#endif
-
-
-// (Re)generate the display list
-void fgSkyInit( void );
-
-// (Re)calculate the sky colors at each vertex
-void fgSkyColorsInit( void );
-
-// Draw the Sky
-void fgSkyRender( void );
-
-
-#endif // _SKY_HXX
-
-
-// $Log$
-// Revision 1.2 1998/10/16 23:27:19 curt
-// C++-ifying.
-//
-// Revision 1.1 1998/04/22 13:21:33 curt
-// C++ - ifing the code a bit.
-//
-// Revision 1.4 1998/04/21 17:02:32 curt
-// Prepairing for C++ integration.
-//
-// Revision 1.3 1998/01/22 02:59:28 curt
-// Changed #ifdef FILE_H to #ifdef _FILE_H
-//
-// Revision 1.2 1998/01/19 18:40:17 curt
-// Tons of little changes to clean up the code and to remove fatal errors
-// when building with the c++ compiler.
-//
-// Revision 1.1 1998/01/07 03:16:19 curt
-// Moved from .../Src/Scenery/ to .../Src/Astro/
-//
-// Revision 1.2 1997/12/22 23:45:49 curt
-// First stab at sunset/sunrise sky glow effects.
-//
-// Revision 1.1 1997/12/17 23:14:31 curt
-// Initial revision.
-// Begin work on rendering the sky. (Rather than just using a clear screen.)
-//
+++ /dev/null
-/**************************************************************************
- * solarsystem.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)
- **************************************************************************/
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#ifdef HAVE_WINDOWS_H
-# include <windows.h>
-#endif
-
-#ifdef __BORLANDC__
-# define exception c_exception
-#endif
-#include <math.h>
-
-#include <GL/glut.h>
-#include <XGL/xgl.h>
-#include <Debug/logstream.hxx>
-#include <Time/sunpos.hxx>
-#include <Time/moonpos.hxx>
-#include "solarsystem.hxx"
-
-/***************************************************************************
- * default constructor for class SolarSystem:
- * or course there can only be one way to create an entire solar system -:) )
- * the fgTIME argument is needed to properly initialize the the current orbital
- * elements
- *************************************************************************/
-SolarSystem::SolarSystem(fgTIME *t)
-{
- if (theSolarSystem)
- {
- FG_LOG( FG_GENERAL, FG_ALERT, "Error: only one solarsystem allowed" );
- exit(-1);
- }
- theSolarSystem = this;
- ourSun = new Star(t);
- earthsMoon = new Moon(t);
- mercury = new Mercury(t);
- venus = new Venus(t);
- mars = new Mars(t);
- jupiter = new Jupiter(t);
- saturn = new Saturn(t);
- uranus = new Uranus(t);
- neptune = new Neptune(t);
-
- displayList = 0;
-};
-
-/**************************************************************************
- * the destructor for class SolarSystem;
- **************************************************************************/
-SolarSystem::~SolarSystem()
-{
- delete ourSun;
- delete earthsMoon;
- delete mercury;
- delete venus;
- delete mars;
- delete jupiter;
- delete saturn;
- delete uranus;
- delete neptune;
-}
-/****************************************************************************
- * void SolarSystem::rebuild()
- *
- * this member function updates the positions for the sun, moon, and planets,
- * and then rebuilds the display list.
- *
- * arguments: none
- * return value: none
- ***************************************************************************/
-void SolarSystem::rebuild()
-{
- //fgLIGHT *l = &cur_light_params;
- fgTIME *t = &cur_time_params;
- //float x, y, z;
- //double sun_angle;
- double ra, dec;
- //double x_2, x_4, x_8, x_10;*/
- double magnitude;
- //GLfloat ambient;
- //GLfloat amb[4];
-
-
- glDisable(GL_LIGHTING);
-
-
- // Step 1: update all the positions
- ourSun->updatePosition(t);
- earthsMoon->updatePosition(t, ourSun);
- mercury->updatePosition(t, ourSun);
- venus->updatePosition(t, ourSun);
- mars->updatePosition(t, ourSun);
- jupiter->updatePosition(t, ourSun);
- saturn->updatePosition(t, ourSun);
- uranus->updatePosition(t, ourSun);
- neptune->updatePosition(t, ourSun);
-
- fgUpdateSunPos(); // get the right sun angle (especially important when
- // running for the first time).
- fgUpdateMoonPos();
-
- if (displayList)
- xglDeleteLists(displayList, 1);
-
- displayList = xglGenLists(1);
-
- // Step 2: rebuild the display list
- xglNewList( displayList, GL_COMPILE);
- {
- // Step 2a: Add the moon...
- // Not that it is preferred to draw the moon first, and the sun next, in order to mime a
- // solar eclipse. This is yet untested though...
-
- earthsMoon->newImage();
- // Step 2b: Add the sun
- //xglPushMatrix();
- //{
- ourSun->newImage();
- //}
- //xglPopMatrix();
- // Step 2c: Add the planets
- xglBegin(GL_POINTS);
- mercury->getPos(&ra, &dec, &magnitude);addPlanetToList(ra, dec, magnitude);
- venus ->getPos(&ra, &dec, &magnitude);addPlanetToList(ra, dec, magnitude);
- mars ->getPos(&ra, &dec, &magnitude);addPlanetToList(ra, dec, magnitude);
- jupiter->getPos(&ra, &dec, &magnitude);addPlanetToList(ra, dec, magnitude);
- saturn ->getPos(&ra, &dec, &magnitude);addPlanetToList(ra, dec, magnitude);
- uranus ->getPos(&ra, &dec, &magnitude);addPlanetToList(ra, dec, magnitude);
- neptune->getPos(&ra, &dec, &magnitude);addPlanetToList(ra, dec, magnitude);
- xglEnd();
- xglEnable(GL_LIGHTING);
- }
- xglEndList();
-}
-
-/*****************************************************************************
- * double SolarSystem::scaleMagnitude(double magn)
- * This private member function rescales the original magnitude, as used in the
- * astronomical sense of the word, into a value used by OpenGL to draw a
- * convincing Star or planet
- *
- * Argument: the astronomical magnitude
- *
- * return value: the rescaled magnitude
- ****************************************************************************/
-double SolarSystem::scaleMagnitude(double magn)
-{
- double magnitude = (0.0 - magn) / 5.0 + 1.0;
- magnitude = magnitude * 0.7 + (3 * 0.1);
- if (magnitude > 1.0) magnitude = 1.0;
- if (magnitude < 0.0) magnitude = 0.0;
- return magnitude;
-}
-
-/***************************************************************************
- * void SolarSytem::addPlanetToList(double ra, double dec, double magn);
- *
- * This private member function first causes the magnitude to be properly
- * rescaled, and then adds the planet to the display list.
- *
- * arguments: Right Ascension, declination, and magnitude
- *
- * return value: none
- **************************************************************************/
-void SolarSystem::addPlanetToList(double ra, double dec, double magn)
-{
- double
- magnitude = scaleMagnitude ( magn );
-
- fgLIGHT *l = &cur_light_params;
-
- if ((double) (l->sun_angle - FG_PI_2) >
- ((magnitude - 1.0) * - 20 * DEG_TO_RAD))
- {
- xglColor3f (magnitude, magnitude, magnitude);
- xglVertex3f( 50000.0 * cos (ra) * cos (dec),
- 50000.0 * sin (ra) * cos (dec),
- 50000.0 * sin (dec));
- }
-}
-
-
-SolarSystem* SolarSystem::theSolarSystem = 0;
-
-/******************************************************************************
- * void solarSystemRebuild()
- * this a just a wrapper function, provided for use as an interface to the
- * event manager
- *****************************************************************************/
-void solarSystemRebuild()
-{
- SolarSystem::theSolarSystem->rebuild();
-}
+++ /dev/null
-/**************************************************************************
- * solarsystem.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 _SOLARSYSTEM_H_
-#define _SOLARSYSTEM_H_
-
-#include <Time/light.hxx>
-#include <Time/fg_time.hxx>
-#include <Main/views.hxx>
-
-#include "star.hxx"
-#include "moon.hxx"
-#include "mercury.hxx"
-#include "venus.hxx"
-#include "mars.hxx"
-#include "jupiter.hxx"
-#include "saturn.hxx"
-#include "uranus.hxx"
-#include "neptune.hxx"
-#include "pluto.hxx"
-
-
-class SolarSystem
-{
-private:
- Star* ourSun;
- Moon* earthsMoon;
- Mercury* mercury;
- Venus* venus;
- Mars* mars;
- Jupiter* jupiter;
- Saturn* saturn;
- Uranus* uranus;
- Neptune* neptune;
- //Pluto* pluto;
-
- GLint displayList;
- double scaleMagnitude(double magn);
- void addPlanetToList(double ra, double dec, double magn);
-
-
-public:
- SolarSystem(fgTIME *t);
- CelestialBody *getSun();
- CelestialBody *getMoon();
- ~SolarSystem();
-
- static SolarSystem *theSolarSystem; // thanks to Bernie Bright!
- void rebuild();
- friend void solarSystemRebuild();
- void draw();
-};
-
-inline CelestialBody* SolarSystem::getSun()
-{
- return ourSun;
-}
-
-inline CelestialBody* SolarSystem::getMoon()
-{
- return earthsMoon;
-}
-
-inline void SolarSystem::draw()
-{
- xglCallList(displayList);
-}
-
-extern void solarSystemRebuild();
-
-#endif // _SOLARSYSTEM_H_
+++ /dev/null
-/**************************************************************************
- * star.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)
- **************************************************************************/
-
-#ifdef __BORLANDC__
-# define exception c_exception
-#endif
-#include <math.h>
-#include <Time/sunpos.hxx>
-#include <Debug/logstream.hxx>
-#include <Time/light.hxx>
-#include "star.hxx"
-
-/*************************************************************************
- * Star::Star(fgTIME *t)
- * Public constructor for class Star
- * Argument: The current time.
- * the hard coded orbital elements our sun are passed to
- * CelestialBody::CelestialBody();
- * note that the word sun is avoided, in order to prevent some compilation
- * problems on sun systems
- ************************************************************************/
-Star::Star(fgTIME *t) :
- CelestialBody (0.000000, 0.0000000000,
- 0.0000, 0.00000,
- 282.9404, 4.7093500E-5,
- 1.0000000, 0.000000,
- 0.016709, -1.151E-9,
- 356.0470, 0.98560025850, t)
-{
-
- FG_LOG( FG_GENERAL, FG_INFO, "Initializing Sun Texture");
-#ifdef GL_VERSION_1_1
- xglGenTextures(1, &sun_texid);
- xglBindTexture(GL_TEXTURE_2D, sun_texid);
-#elif GL_EXT_texture_object
- xglGenTexturesEXT(1, &sun_texid);
- xglBindTextureEXT(GL_TEXTURE_2D, sun_texid);
-#else
-# error port me
-#endif
-
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- setTexture();
- glTexImage2D( GL_TEXTURE_2D,
- 0,
- GL_RGBA,
- 256, 256,
- 0,
- GL_RGBA, GL_UNSIGNED_BYTE,
- sun_texbuf);
-
- SunObject = gluNewQuadric();
- if(SunObject == NULL)
- {
- printf("gluNewQuadric(SunObject) failed !\n");
- exit(0);
- }
-
- //SunList = 0;
- distance = 0.0;
-}
-
-Star::~Star()
-{
- //delete SunObject;
- delete [] sun_texbuf;
-}
-
-
-
-static int texWidth = 256; /* 64x64 is plenty */
-
-void Star::setTexture()
-{
- int texSize;
- //void *textureBuf;
- GLubyte *p;
- int i,j;
- double radius;
-
- texSize = texWidth*texWidth;
-
- sun_texbuf = new GLubyte[texSize*4];
- if (!sun_texbuf)
- return; // Ugly!
-
- p = sun_texbuf;
-
- radius = (double)(texWidth / 2);
-
- for (i=0; i < texWidth; i++) {
- for (j=0; j < texWidth; j++) {
- double x, y, d;
-
- x = fabs((double)(i - (texWidth / 2)));
- y = fabs((double)(j - (texWidth / 2)));
-
- d = sqrt((x * x) + (y * y));
- if (d < radius)
- {
- double t = 1.0 - (d / radius); // t is 1.0 at center, 0.0 at edge */
- // inverse square looks nice
- *p = (int)((double)0xff * (t * t));
- *(p+1) = (int)((double) 0xff * (t*t));
- *(p+2) = (int)((double) 0xff * (t*t));
- *(p+3) = (int)((double) 0xff * (t*t));
- }
- else
- {
- *p = 0x00;
- *(p+1) = 0x00;
- *(p+2) = 0x00;
- *(p+3) = 0x00;
- }
- p += 4;
- }
- }
- //gluBuild2DMipmaps(GL_TEXTURE_2D, 1, texWidth, texWidth,
- // GL_LUMINANCE,
- // GL_UNSIGNED_BYTE, textureBuf);
- //free(textureBuf);
-}
-/*************************************************************************
- * void Jupiter::updatePosition(fgTIME *t, Star *ourSun)
- *
- * calculates the current position of our sun.
- *************************************************************************/
-void Star::updatePosition(fgTIME *t)
-{
- double
- actTime, eccAnom,
- xv, yv, v, r,
- xe, ye, ze, ecl;
-
- updateOrbElements(t);
-
- actTime = fgCalcActTime(t);
- ecl = DEG_TO_RAD * (23.4393 - 3.563E-7 * actTime); // Angle in Radians
- eccAnom = fgCalcEccAnom(M, e); // Calculate the eccentric Anomaly (also known as solving Kepler's equation)
-
- xv = cos(eccAnom) - e;
- yv = sqrt (1.0 - e*e) * sin(eccAnom);
- v = atan2 (yv, xv); // the sun's true anomaly
- distance = r = sqrt (xv*xv + yv*yv); // and its distance
-
- lonEcl = v + w; // the sun's true longitude
- latEcl = 0;
-
- // convert the sun's true longitude to ecliptic rectangular
- // geocentric coordinates (xs, ys)
- xs = r * cos (lonEcl);
- ys = r * sin (lonEcl);
-
- // convert ecliptic coordinates to equatorial rectangular
- // geocentric coordinates
-
- xe = xs;
- ye = ys * cos (ecl);
- ze = ys * sin (ecl);
-
- // And finally, calculate right ascension and declination
- rightAscension = atan2 (ye, xe);
- declination = atan2 (ze, sqrt (xe*xe + ye*ye));
-}
-
-void Star::newImage(void)
-{
- /*static float stars[3];
- stars[0] = 0.0;
- stars[1] = 0.0;
- stars[2] = 1.0;*/
-
- fgLIGHT *l = &cur_light_params;
- float sun_angle = l->sun_angle;
-
- if( sun_angle*RAD_TO_DEG < 100 ) { // else no need to draw sun
-
-
- double x_2, x_4, x_8, x_10;
- GLfloat ambient;
- GLfloat amb[4];
- int sun_size = 750;
-
- // daily variation sun gets larger near horizon
- /*if(sun_angle*RAD_TO_DEG > 84.0 && sun_angle*RAD_TO_DEG < 95)
- {
- double sun_grow = 9*fabs(94-sun_angle*RAD_TO_DEG);
- sun_size = (int)(sun_size + sun_size * cos(sun_grow*DEG_TO_RAD));
- }*/
- x_2 = sun_angle * sun_angle;
- x_4 = x_2 * x_2;
- x_8 = x_4 * x_4;
- x_10 = x_8 * x_2;
- ambient = (float)(0.4 * pow (1.1, - x_10 / 30.0));
- if (ambient < 0.3) ambient = 0.3;
- if (ambient > 1.0) ambient = 1.0;
-
- amb[0] = ((ambient * 6.0) - 1.0); // minimum value = 0.8
- amb[1] = ((ambient * 11.0) - 3.0); // minimum value = 0.3
- amb[2] = ((ambient * 12.0) - 3.6); // minimum value = 0.0
- amb[3] = 1.00;
-
- if (amb[0] > 1.0) amb[0] = 1.0;
- if (amb[1] > 1.0) amb[1] = 1.0;
- if (amb[2] > 1.0) amb[2] = 1.0;
- xglColor3fv(amb);
- glPushMatrix();
- {
- xglRotatef(((RAD_TO_DEG * rightAscension)- 90.0), 0.0, 0.0, 1.0);
- xglRotatef((RAD_TO_DEG * declination), 1.0, 0.0, 0.0);
- xglTranslatef(0,60000,0);
-
- glEnable(GL_TEXTURE_2D); // TEXTURE ENABLED
- glEnable(GL_BLEND); // BLEND ENABLED
-
- //glEnable(GL_TEXTURE_2D);
- //glEnable(GL_BLEND);
- //glDisable(GL_LIGHTING);
- glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- glBindTexture(GL_TEXTURE_2D, sun_texid);
-
- glBegin(GL_QUADS);
- glTexCoord2f(0.0f, 0.0f); glVertex3f(-5000, 0.0, -5000);
- glTexCoord2f(1.0f, 0.0f); glVertex3f( 5000, 0.0, -5000);
- glTexCoord2f(1.0f, 1.0f); glVertex3f( 5000, 0.0, 5000);
- glTexCoord2f(0.0f, 1.0f); glVertex3f(-5000, 0.0, 5000);
- glEnd();
- }
- glPopMatrix();
- xglDisable(GL_TEXTURE_2D);
- glDisable(GL_BLEND);
- glPushMatrix();
- {
- xglRotatef(((RAD_TO_DEG * rightAscension)- 90.0), 0.0, 0.0, 1.0);
- xglRotatef((RAD_TO_DEG * declination), 1.0, 0.0, 0.0);
- xglTranslatef(0,58600,0);
- gluSphere( SunObject, sun_size, 10, 10 );
- }
- glPopMatrix();
- glDisable(GL_TEXTURE_2D); // TEXTURE DISABLED
- glDisable(GL_BLEND); // BLEND DISABLED
- }
-}
-
-
-
-
+++ /dev/null
-/**************************************************************************
- * star.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 _STAR_HXX_
-#define _STAR_HXX_
-
-#include <Time/fg_time.hxx>
-#include "celestialBody.hxx"
-
-
-class Star : public CelestialBody
-{
-private:
- //double longitude; // the sun's true longitude - this is depreciated by
- // CelestialBody::lonEcl
- double xs, ys; // the sun's rectangular geocentric coordinates
- double distance; // the sun's distance to the earth
- GLUquadricObj *SunObject;
- GLuint sun_texid;
- GLubyte *sun_texbuf;
-
- void setTexture();
-public:
- Star (fgTIME *t);
- ~Star();
- void updatePosition(fgTIME *t);
- double getM();
- double getw();
- //double getLon();
- double getxs();
- double getys();
- double getDistance();
- void newImage();
-};
-
-
-
-inline double Star::getM()
-{
- return M;
-}
-
-inline double Star::getw()
-{
- return w;
-}
-
-inline double Star::getxs()
-{
- return xs;
-}
-
-inline double Star::getys()
-{
- return ys;
-}
-
-inline double Star::getDistance()
-{
- return distance;
-}
-
-
-#endif // _STAR_HXX_
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+++ /dev/null
-// stars.cxx -- data structures and routines for managing and rendering stars.
-//
-// Written by Curtis Olson, started August 1997.
-//
-// Copyright (C) 1997 Curtis L. Olson - curt@me.umn.edu
-//
-// 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)
-//*************************************************************************/
-
-
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-
-#ifdef HAVE_WINDOWS_H
-# include <windows.h>
-#endif
-
-#include "Include/compiler.h"
-#ifdef FG_HAVE_STD_INCLUDES
-# include <cmath>
-# include <cstdio>
-# include <cstring>
-# include <ctime>
-#else
-# include <math.h>
-# include <stdio.h>
-# include <string.h>
-# include <time.h>
-#endif
-
-#include <string>
-
-#include <GL/glut.h>
-#include <XGL/xgl.h>
-
-#include <Aircraft/aircraft.hxx>
-#include <Debug/logstream.hxx>
-#include <Include/fg_constants.h>
-#include <Misc/fgstream.hxx>
-#include <Main/options.hxx>
-#include <Main/views.hxx>
-#include <Misc/stopwatch.hxx>
-#include <Time/fg_time.hxx>
-#include "Misc/stopwatch.hxx"
-
-#include "stars.hxx"
-
-FG_USING_STD(getline);
-
-#define EpochStart (631065600)
-#define DaysSinceEpoch(secs) (((secs)-EpochStart)*(1.0/(24*3600)))
-#define FG_MAX_STARS 3500
-
-// Define four structures, each with varying amounts of stars
-static GLint stars[FG_STAR_LEVELS];
-
-
-// Initialize the Star Management Subsystem
-int fgStarsInit( void ) {
- Point3D starlist[FG_MAX_STARS];
- // struct CelestialCoord pltPos;
- double right_ascension, declination, magnitude;
- double min_magnitude[FG_STAR_LEVELS];
- // double ra_save, decl_save;
- // double ra_save1, decl_save1;
- int i, j, starcount, count;
-
- FG_LOG( FG_ASTRO, FG_INFO, "Initializing stars" );
-
- if ( FG_STAR_LEVELS < 4 ) {
- FG_LOG( FG_ASTRO, FG_ALERT, "Big whups in stars.cxx" );
- exit(-1);
- }
-
- // build the full path name to the stars data base file
- string path = current_options.get_fg_root() + "/Astro/stars" + ".gz";
-
- FG_LOG( FG_ASTRO, FG_INFO, " Loading stars from " << path );
-
- fg_gzifstream in( path );
- if ( ! in ) {
- FG_LOG( FG_ASTRO, FG_ALERT, "Cannot open star file: " << path );
- exit(-1);
- }
-
- starcount = 0;
-
- StopWatch timer;
- timer.start();
-
- // read in each line of the file
- while ( ! in.eof() && starcount < FG_MAX_STARS )
- {
- in >> skipcomment;
- string name;
- getline( in, name, ',' );
- in >> starlist[starcount];
- ++starcount;
- }
-
- timer.stop();
- FG_LOG( FG_ASTRO, FG_INFO,
- "Loaded " << starcount << " stars in "
- << timer.elapsedSeconds() << " seconds" );
-
- min_magnitude[0] = 4.2;
- min_magnitude[1] = 3.6;
- min_magnitude[2] = 3.0;
- min_magnitude[3] = 2.4;
- min_magnitude[4] = 1.8;
- min_magnitude[5] = 1.2;
- min_magnitude[6] = 0.6;
- min_magnitude[7] = 0.0;
-
- // build the various star display lists
- for ( i = 0; i < FG_STAR_LEVELS; i++ ) {
-
- stars[i] = xglGenLists(1);
- xglNewList( stars[i], GL_COMPILE );
- xglBegin( GL_POINTS );
-
- count = 0;
-
- for ( j = 0; j < starcount; j++ ) {
- magnitude = starlist[j].z();
- // printf("magnitude = %.2f\n", magnitude);
-
- if ( magnitude < min_magnitude[i] ) {
- right_ascension = starlist[j].x();
- declination = starlist[j].y();
-
- count++;
-
- // scale magnitudes to (0.0 - 1.0)
- magnitude = (0.0 - magnitude) / 5.0 + 1.0;
-
- // scale magnitudes again so they look ok
- if ( magnitude > 1.0 ) { magnitude = 1.0; }
- if ( magnitude < 0.0 ) { magnitude = 0.0; }
- // magnitude =
- // magnitude * 0.7 + (((FG_STAR_LEVELS - 1) - i) * 0.042);
-
- magnitude = magnitude * 0.9 +
- (((FG_STAR_LEVELS - 1) - i) * 0.014);
- // printf(" Found star: %d %s, %.3f %.3f %.3f\n", count,
- // name, right_ascension, declination, magnitude);
-
- xglColor3f( magnitude, magnitude, magnitude );
- //xglColor3f(0,0,0);*/
- xglVertex3f( 50000.0*cos(right_ascension)*cos(declination),
- 50000.0*sin(right_ascension)*cos(declination),
- 50000.0*sin(declination) );
- }
- } // while
-
- xglEnd();
-
- /*
- xglBegin(GL_LINE_LOOP);
- xglColor3f(1.0, 0.0, 0.0);
- xglVertex3f( 50000.0 * cos(ra_save-0.2) * cos(decl_save-0.2),
- 50000.0 * sin(ra_save-0.2) * cos(decl_save-0.2),
- 50000.0 * sin(decl_save-0.2) );
- xglVertex3f( 50000.0 * cos(ra_save+0.2) * cos(decl_save-0.2),
- 50000.0 * sin(ra_save+0.2) * cos(decl_save-0.2),
- 50000.0 * sin(decl_save-0.2) );
- xglVertex3f( 50000.0 * cos(ra_save+0.2) * cos(decl_save+0.2),
- 50000.0 * sin(ra_save+0.2) * cos(decl_save+0.2),
- 50000.0 * sin(decl_save+0.2) );
- xglVertex3f( 50000.0 * cos(ra_save-0.2) * cos(decl_save+0.2),
- 50000.0 * sin(ra_save-0.2) * cos(decl_save+0.2),
- 50000.0 * sin(decl_save+0.2) );
- xglEnd();
- */
-
- /*
- xglBegin(GL_LINE_LOOP);
- xglColor3f(0.0, 1.0, 0.0);
- xglVertex3f( 50000.0 * cos(ra_save1-0.2) * cos(decl_save1-0.2),
- 50000.0 * sin(ra_save1-0.2) * cos(decl_save1-0.2),
- 50000.0 * sin(decl_save1-0.2) );
- xglVertex3f( 50000.0 * cos(ra_save1+0.2) * cos(decl_save1-0.2),
- 50000.0 * sin(ra_save1+0.2) * cos(decl_save1-0.2),
- 50000.0 * sin(decl_save1-0.2) );
- xglVertex3f( 50000.0 * cos(ra_save1+0.2) * cos(decl_save1+0.2),
- 50000.0 * sin(ra_save1+0.2) * cos(decl_save1+0.2),
- 50000.0 * sin(decl_save1+0.2) );
- xglVertex3f( 50000.0 * cos(ra_save1-0.2) * cos(decl_save1+0.2),
- 50000.0 * sin(ra_save1-0.2) * cos(decl_save1+0.2),
- 50000.0 * sin(decl_save1+0.2) );
- xglEnd();
- */
-
- xglEndList();
-
- FG_LOG( FG_ASTRO, FG_INFO,
- " Loading " << count << " stars brighter than "
- << min_magnitude[i] );
- }
-
- return 1; // OK, we got here because initialization worked.
-}
-
-
-// Draw the Stars
-void fgStarsRender( void ) {
- FGInterface *f;
- fgLIGHT *l;
- fgTIME *t;
- int i;
-
- f = current_aircraft.fdm_state;
- l = &cur_light_params;
- t = &cur_time_params;
-
- // FG_PI_2 + 0.1 is about 6 degrees after sundown and before sunrise
-
- // t->sun_angle = 3.0; // to force stars to be drawn (for testing)
-
- // render the stars
- if ( l->sun_angle > (FG_PI_2 + 5 * DEG_TO_RAD ) ) {
- // determine which star structure to draw
- if ( l->sun_angle > (FG_PI_2 + 10.0 * DEG_TO_RAD ) ) {
- i = 0;
- } else if ( l->sun_angle > (FG_PI_2 + 8.8 * DEG_TO_RAD ) ) {
- i = 1;
- } else if ( l->sun_angle > (FG_PI_2 + 7.5 * DEG_TO_RAD ) ) {
- i = 2;
- } else if ( l->sun_angle > (FG_PI_2 + 7.0 * DEG_TO_RAD ) ) {
- i = 3;
- } else if ( l->sun_angle > (FG_PI_2 + 6.5 * DEG_TO_RAD ) ) {
- i = 4;
- } else if ( l->sun_angle > (FG_PI_2 + 6.0 * DEG_TO_RAD ) ) {
- i = 5;
- } else if ( l->sun_angle > (FG_PI_2 + 5.5 * DEG_TO_RAD ) ) {
- i = 6;
- } else {
- i = 7;
- }
-
- // printf("RENDERING STARS = %d (night)\n", i);
-
- xglCallList(stars[i]);
- } else {
- // printf("not RENDERING STARS (day)\n");
- }
-}
-
-
-// $Log$
-// Revision 1.27 1999/02/05 21:28:52 curt
-// Modifications to incorporate Jon S. Berndts flight model code.
-//
-// Revision 1.26 1999/02/02 20:13:30 curt
-// MSVC++ portability changes by Bernie Bright:
-//
-// Lib/Serial/serial.[ch]xx: Initial Windows support - incomplete.
-// Simulator/Astro/stars.cxx: typo? included <stdio> instead of <cstdio>
-// Simulator/Cockpit/hud.cxx: Added Standard headers
-// Simulator/Cockpit/panel.cxx: Redefinition of default parameter
-// Simulator/Flight/flight.cxx: Replaced cout with FG_LOG. Deleted <stdio.h>
-// Simulator/Main/fg_init.cxx:
-// Simulator/Main/GLUTmain.cxx:
-// Simulator/Main/options.hxx: Shuffled <fg_serial.hxx> dependency
-// Simulator/Objects/material.hxx:
-// Simulator/Time/timestamp.hxx: VC++ friend kludge
-// Simulator/Scenery/tile.[ch]xx: Fixed using std::X declarations
-// Simulator/Main/views.hxx: Added a constant
-//
-// Revision 1.25 1998/12/09 18:50:15 curt
-// Converted "class fgVIEW" to "class FGView" and updated to make data
-// members private and make required accessor functions.
-//
-// Revision 1.24 1998/12/05 15:54:04 curt
-// Renamed class fgFLIGHT to class FGState as per request by JSB.
-//
-// Revision 1.23 1998/11/23 21:48:28 curt
-// Borland portability tweaks.
-//
-// Revision 1.22 1998/11/07 19:07:07 curt
-// Enable release builds using the --without-logging option to the configure
-// script. Also a couple log message cleanups, plus some C to C++ comment
-// conversion.
-//
-// Revision 1.21 1998/11/06 21:17:42 curt
-// Converted to new logstream debugging facility. This allows release
-// builds with no messages at all (and no performance impact) by using
-// the -DFG_NDEBUG flag.
-//
-// Revision 1.20 1998/11/06 14:47:02 curt
-// Changes to track Bernie's updates to fgstream.
-//
-// Revision 1.19 1998/10/16 23:27:21 curt
-// C++-ifying.
-//
-// Revision 1.18 1998/10/16 00:52:20 curt
-// Converted to Point3D class.
-//
-// Revision 1.17 1998/09/24 15:36:19 curt
-// Converted to c++ style comments.
-//
-// Revision 1.16 1998/09/24 15:25:24 curt
-// Miscellaneous tweaks.
-//
-//
-// Revision 1.15 1998/09/17 18:25:12 curt
-// Fixed output message.
-//
-// Revision 1.14 1998/09/15 04:26:22 curt
-// New textured moon and rewritten/restructured Astro code contributed by Durk
-// Talsma.
-//
-// Revision 1.13 1998/09/01 19:03:04 curt
-// Changes contributed by Bernie Bright <bbright@c031.aone.net.au>
-// - The new classes in libmisc.tgz define a stream interface into zlib.
-// I've put these in a new directory, Lib/Misc. Feel free to rename it
-// to something more appropriate. However you'll have to change the
-// include directives in all the other files. Additionally you'll have
-// add the library to Lib/Makefile.am and Simulator/Main/Makefile.am.
-//
-// The StopWatch class in Lib/Misc requires a HAVE_GETRUSAGE autoconf
-// test so I've included the required changes in config.tgz.
-//
-// There are a fair few changes to Simulator/Objects as I've moved
-// things around. Loading tiles is quicker but thats not where the delay
-// is. Tile loading takes a few tenths of a second per file on a P200
-// but it seems to be the post-processing that leads to a noticeable
-// blip in framerate. I suppose its time to start profiling to see where
-// the delays are.
-//
-// I've included a brief description of each archives contents.
-//
-// Lib/Misc/
-// zfstream.cxx
-// zfstream.hxx
-// C++ stream interface into zlib.
-// Taken from zlib-1.1.3/contrib/iostream/.
-// Minor mods for STL compatibility.
-// There's no copyright associated with these so I assume they're
-// covered by zlib's.
-//
-// fgstream.cxx
-// fgstream.hxx
-// FlightGear input stream using gz_ifstream. Tries to open the
-// given filename. If that fails then filename is examined and a
-// ".gz" suffix is removed or appended and that file is opened.
-//
-// stopwatch.hxx
-// A simple timer for benchmarking. Not used in production code.
-// Taken from the Blitz++ project. Covered by GPL.
-//
-// strutils.cxx
-// strutils.hxx
-// Some simple string manipulation routines.
-//
-// Simulator/Airports/
-// Load airports database using fgstream.
-// Changed fgAIRPORTS to use set<> instead of map<>.
-// Added bool fgAIRPORTS::search() as a neater way doing the lookup.
-// Returns true if found.
-//
-// Simulator/Astro/
-// Modified fgStarsInit() to load stars database using fgstream.
-//
-// Simulator/Objects/
-// Modified fgObjLoad() to use fgstream.
-// Modified fgMATERIAL_MGR::load_lib() to use fgstream.
-// Many changes to fgMATERIAL.
-// Some changes to fgFRAGMENT but I forget what!
-//
-// Revision 1.12 1998/08/27 17:02:01 curt
-// Contributions from Bernie Bright <bbright@c031.aone.net.au>
-// - use strings for fg_root and airport_id and added methods to return
-// them as strings,
-// - inlined all access methods,
-// - made the parsing functions private methods,
-// - deleted some unused functions.
-// - propogated some of these changes out a bit further.
-//
-// Revision 1.11 1998/08/25 20:53:29 curt
-// Shuffled $FG_ROOT file layout.
-//
-// Revision 1.10 1998/08/10 20:33:09 curt
-// Rewrote star loading and rendering to:
-// 1. significantly improve load speed
-// 2. transition from no stars to stars through eight stages.
-//
-// Revision 1.9 1998/08/06 12:45:20 curt
-// Modified to bring in stars in 8 increments based on magnitude, not number
-// of stars.
-//
-// Revision 1.8 1998/07/13 21:00:10 curt
-// Wrote access functions for current fgOPTIONS.
-//
-// Revision 1.7 1998/05/29 20:35:42 curt
-// Added zlib support for reading in compressed data files.
-//
-// Revision 1.6 1998/05/13 18:25:35 curt
-// Root path info moved to fgOPTIONS.
-//
-// Revision 1.5 1998/04/28 01:19:03 curt
-// Type-ified fgTIME and fgVIEW
-//
-// Revision 1.4 1998/04/26 05:10:02 curt
-// "struct fgLIGHT" -> "fgLIGHT" because fgLIGHT is typedef'd.
-//
-// Revision 1.3 1998/04/25 22:06:26 curt
-// Edited cvs log messages in source files ... bad bad bad!
-//
-// Revision 1.2 1998/04/24 00:45:03 curt
-// Wrapped "#include <config.h>" in "#ifdef HAVE_CONFIG_H"
-// Fixed a bug when generating sky colors.
-//
-// Revision 1.1 1998/04/22 13:21:34 curt
-// C++ - ifing the code a bit.
-//
-// Revision 1.11 1998/04/18 04:13:58 curt
-// Moved fg_debug.c to it's own library.
-//
-// Revision 1.10 1998/04/03 21:52:51 curt
-// Converting to Gnu autoconf system.
-//
-// Revision 1.9 1998/03/14 00:27:12 curt
-// Updated fgGENERAL to a "type" of struct.
-//
-// Revision 1.8 1998/02/12 21:59:38 curt
-// Incorporated code changes contributed by Charlie Hotchkiss
-// <chotchkiss@namg.us.anritsu.com>
-//
-// Revision 1.7 1998/02/09 15:07:48 curt
-// Minor tweaks.
-//
-// Revision 1.6 1998/02/02 20:53:23 curt
-// To version 0.29
-//
-// Revision 1.5 1998/01/27 18:35:53 curt
-// Minor tweaks.
-//
-// Revision 1.4 1998/01/27 00:47:49 curt
-// Incorporated Paul Bleisch's <pbleisch@acm.org> new debug message
-// system and commandline/config file processing code.
-//
-// Revision 1.3 1998/01/19 19:26:59 curt
-// Merged in make system changes from Bob Kuehne <rpk@sgi.com>
-// This should simplify things tremendously.
-//
-// Revision 1.2 1998/01/19 18:40:18 curt
-// Tons of little changes to clean up the code and to remove fatal errors
-// when building with the c++ compiler.
-//
-// Revision 1.1 1998/01/07 03:16:20 curt
-// Moved from .../Src/Scenery/ to .../Src/Astro/
-//
-// Revision 1.24 1997/12/30 22:22:39 curt
-// Further integration of event manager.
-//
-// Revision 1.23 1997/12/30 20:47:53 curt
-// Integrated new event manager with subsystem initializations.
-//
-// Revision 1.22 1997/12/30 16:36:53 curt
-// Merged in Durk's changes ...
-//
-// Revision 1.21 1997/12/19 23:35:00 curt
-// Lot's of tweaking with sky rendering and lighting.
-//
-// Revision 1.20 1997/12/15 23:55:03 curt
-// Add xgl wrappers for debugging.
-// Generate terrain normals on the fly.
-//
-// Revision 1.19 1997/12/12 19:53:00 curt
-// Working on lightling and material properties.
-//
-// Revision 1.18 1997/12/10 22:37:52 curt
-// Prepended "fg" on the name of all global structures that didn't have it yet.
-// i.e. "struct WEATHER {}" became "struct fgWEATHER {}"
-//
-// Revision 1.17 1997/12/09 04:25:33 curt
-// Working on adding a global lighting params structure.
-//
-// Revision 1.16 1997/11/25 19:25:38 curt
-// Changes to integrate Durk's moon/sun code updates + clean up.
-//
-// Revision 1.15 1997/10/30 12:38:45 curt
-// Working on new scenery subsystem.
-//
-// Revision 1.14 1997/10/28 21:00:22 curt
-// Changing to new terrain format.
-//
-// Revision 1.13 1997/10/25 03:18:28 curt
-// Incorporated sun, moon, and planet position and rendering code contributed
-// by Durk Talsma.
-//
-// Revision 1.12 1997/09/23 00:29:43 curt
-// Tweaks to get things to compile with gcc-win32.
-//
-// Revision 1.11 1997/09/22 14:44:21 curt
-// Continuing to try to align stars correctly.
-//
-// Revision 1.10 1997/09/20 03:34:32 curt
-// Still trying to get those durned stars aligned properly.
-//
-// Revision 1.9 1997/09/18 16:20:09 curt
-// At dusk/dawn add/remove stars in stages.
-//
-// Revision 1.8 1997/09/16 22:14:52 curt
-// Tweaked time of day lighting equations. Don't draw stars during the day.
-//
-// Revision 1.7 1997/09/16 15:50:31 curt
-// Working on star alignment and time issues.
-//
-// Revision 1.6 1997/09/05 14:17:31 curt
-// More tweaking with stars.
-//
-// Revision 1.5 1997/09/05 01:35:59 curt
-// Working on getting stars right.
-//
-// Revision 1.4 1997/09/04 02:17:38 curt
-// Shufflin' stuff.
-//
-// Revision 1.3 1997/08/29 17:55:28 curt
-// Worked on properly aligning the stars.
-//
-// Revision 1.2 1997/08/27 21:32:30 curt
-// Restructured view calculation code. Added stars.
-//
-// Revision 1.1 1997/08/27 03:34:48 curt
-// Initial revision.
-
-
+++ /dev/null
-// stars.hxx -- data structures and routines for managing and rendering stars.
-//
-// Written by Curtis Olson, started August 1997.
-//
-// Copyright (C) 1997 Curtis L. Olson - curt@me.umn.edu
-//
-// 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 _STARS_HXX
-#define _STARS_HXX
-
-
-#ifndef __cplusplus
-# error This library requires C++
-#endif
-
-#include <Time/fg_time.hxx>
-
-#define FG_STAR_LEVELS 8 // how many star transitions
-
-// Initialize the Star Management Subsystem
-int fgStarsInit( void );
-
-// Draw the Stars
-void fgStarsRender( void );
-
-// [no longer used?] extern struct OrbElements pltOrbElements[9];
-extern fgTIME cur_time_params;
-
-
-#endif // _STARS_HXX
-
-
-// $Log$
-// Revision 1.8 1999/01/19 20:57:00 curt
-// MacOS portability changes contributed by "Robert Puyol" <puyol@abvent.fr>
-//
-// Revision 1.7 1998/09/24 15:36:20 curt
-// Converted to c++ style comments.
-//
-// Revision 1.6 1998/09/24 15:25:26 curt
-// Miscellaneous tweaks.
-//
-//
-// Revision 1.5 1998/09/17 18:25:13 curt
-// Fixed output message.
-//
-// Revision 1.4 1998/09/15 04:26:23 curt
-// New textured moon and rewritten/restructured Astro code contributed by Durk
-// Talsma.
-//
-// Revision 1.3 1998/08/06 12:45:20 curt
-// Modified to bring in stars in 8 increments based on magnitude, not number
-// of stars.
-//
-// Revision 1.2 1998/04/28 01:19:03 curt
-// Type-ified fgTIME and fgVIEW
-//
-// Revision 1.1 1998/04/22 13:21:35 curt
-// C++ - ifing the code a bit.
-//
-// Revision 1.5 1998/04/21 17:02:33 curt
-// Prepairing for C++ integration.
-//
-// Revision 1.4 1998/02/12 21:59:39 curt
-// Incorporated code changes contributed by Charlie Hotchkiss
-// <chotchkiss@namg.us.anritsu.com>
-//
-// Revision 1.3 1998/01/22 02:59:28 curt
-// Changed #ifdef FILE_H to #ifdef _FILE_H
-//
-// Revision 1.2 1998/01/19 18:40:18 curt
-// Tons of little changes to clean up the code and to remove fatal errors
-// when building with the c++ compiler.
-//
-// Revision 1.1 1998/01/07 03:16:20 curt
-// Moved from .../Src/Scenery/ to .../Src/Astro/
-//
-// Revision 1.6 1997/10/25 03:18:29 curt
-// Incorporated sun, moon, and planet position and rendering code contributed
-// by Durk Talsma.
-//
-// Revision 1.5 1997/09/18 16:20:09 curt
-// At dusk/dawn add/remove stars in stages.
-//
-// Revision 1.4 1997/09/05 01:36:00 curt
-// Working on getting stars right.
-//
-// Revision 1.3 1997/08/29 17:55:28 curt
-// Worked on properly aligning the stars.
-//
-// Revision 1.2 1997/08/27 21:32:30 curt
-// Restructured view calculation code. Added stars.
-//
-// Revision 1.1 1997/08/27 03:34:50 curt
-// Initial revision.
-//
-
+++ /dev/null
-/**************************************************************************
- * uranus.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)
- **************************************************************************/
-
-#ifdef __BORLANDC__
-# define exception c_exception
-#endif
-#include <math.h>
-
-#include "uranus.hxx"
-
-/*************************************************************************
- * Uranus::Uranus(fgTIME *t)
- * Public constructor for class Uranus
- * Argument: The current time.
- * the hard coded orbital elements for Uranus are passed to
- * CelestialBody::CelestialBody();
- ************************************************************************/
-Uranus::Uranus(fgTIME *t) :
- CelestialBody(74.00050, 1.3978000E-5,
- 0.7733, 1.900E-8,
- 96.66120, 3.0565000E-5,
- 19.181710, -1.55E-8,
- 0.047318, 7.450E-9,
- 142.5905, 0.01172580600, t)
-{
-}
-
-/*************************************************************************
- * void Uranus::updatePosition(fgTIME *t, Star *ourSun)
- *
- * calculates the current position of Uranus, by calling the base class,
- * CelestialBody::updatePosition(); The current magnitude is calculated using
- * a Uranus specific equation
- *************************************************************************/
-void Uranus::updatePosition(fgTIME *t, Star *ourSun)
-{
- CelestialBody::updatePosition(t, ourSun);
- magnitude = -7.15 + 5*log10( r*R) + 0.001 * FV;
-}
+++ /dev/null
-/**************************************************************************
- * uranus.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 _URANUS_HXX_
-#define _URANUS_HXX_
-
-#include <Time/fg_time.hxx>
-#include "celestialBody.hxx"
-#include "star.hxx"
-
-class Uranus : public CelestialBody
-{
-public:
- Uranus ( fgTIME *t);
- void updatePosition(fgTIME *t, Star *ourSun);
-};
-
-#endif // _URANUS_HXX_
+++ /dev/null
-/**************************************************************************
- * venus.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)
- **************************************************************************/
-
-#ifdef __BORLANDC__
-# define exception c_exception
-#endif
-#include <math.h>
-
-#include "venus.hxx"
-
-/*************************************************************************
- * Venus::Venus(fgTIME *t)
- * Public constructor for class Venus
- * Argument: The current time.
- * the hard coded orbital elements for Venus are passed to
- * CelestialBody::CelestialBody();
- ************************************************************************/
-Venus::Venus(fgTIME *t) :
- CelestialBody(76.67990, 2.4659000E-5,
- 3.3946, 2.75E-8,
- 54.89100, 1.3837400E-5,
- 0.7233300, 0.000000,
- 0.006773, -1.302E-9,
- 48.00520, 1.60213022440, t)
-{
-}
-
-/*************************************************************************
- * void Venus::updatePosition(fgTIME *t, Star *ourSun)
- *
- * calculates the current position of Venus, by calling the base class,
- * CelestialBody::updatePosition(); The current magnitude is calculated using
- * a Venus specific equation
- *************************************************************************/
-void Venus::updatePosition(fgTIME *t, Star *ourSun)
-{
- CelestialBody::updatePosition(t, ourSun);
- magnitude = -4.34 + 5*log10( r*R ) + 0.013 * FV + 4.2E-07 * pow(FV,3);
-}
+++ /dev/null
-/**************************************************************************
- * venus.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 _VENUS_HXX_
-#define _VENUS_HXX_
-
-#include <Time/fg_time.hxx>
-#include "celestialBody.hxx"
-#include "star.hxx"
-
-class Venus : public CelestialBody
-{
-public:
- Venus ( fgTIME *t);
- void updatePosition(fgTIME *t, Star *ourSun);
-};
-
-#endif // _VENUS_HXX_
--- /dev/null
+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 \
+ neptune.cxx neptune.hxx \
+ pluto.hxx \
+ saturn.cxx saturn.hxx \
+ sky.cxx sky.hxx \
+ solarsystem.cxx solarsystem.hxx \
+ star.cxx star.hxx \
+ stars.cxx stars.hxx \
+ uranus.cxx uranus.hxx \
+ venus.cxx venus.hxx
+
+INCLUDES += -I$(top_builddir) -I$(top_builddir)/Lib -I$(top_builddir)/Simulator
--- /dev/null
+/**************************************************************************
+ * 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$
+ **************************************************************************/
+
+#include "celestialBody.hxx"
+#include "star.hxx"
+#include <Debug/logstream.hxx>
+
+#ifdef FG_MATH_EXCEPTION_CLASH
+# define exception c_exception
+#endif
+#include <math.h>
+
+/**************************************************************************
+ * 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;
+
+ lonEcl = atan2(yh, xh);
+ latEcl = atan2(zh, sqrt(xh*xh+yh*yh));
+
+ 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));
+ FG_LOG(FG_GENERAL, FG_INFO, "Planet found at : "
+ << rightAscension << " (ra), " << declination << " (dec)" );
+
+ //calculate some variables specific to calculating the magnitude
+ //of the planet
+ R = sqrt (xg*xg + yg*yg + zg*zg);
+ s = ourSun->getDistance();
+
+ // It is possible from these calculations for the argument to acos
+ // to exceed the valid range for acos(). So we do a little extra
+ // checking.
+
+ double tmp = (r*r + R*R - s*s) / (2*r*R);
+ if ( tmp > 1.0) {
+ tmp = 1.0;
+ } else if ( tmp < -1.0) {
+ tmp = -1.0;
+ }
+
+ FV = RAD_TO_DEG * acos( tmp );
+};
+
+/****************************************************************************
+ * 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;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
--- /dev/null
+/**************************************************************************
+ * 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$
+ **************************************************************************/
+
+
+#ifndef _CELESTIALBODY_H_
+#define _CELESTIALBODY_H_
+
+#ifndef __cplusplus
+# error This library requires C++
+#endif
+
+
+#include <Time/fg_time.hxx>
+#include <Include/fg_constants.h>
+
+class Star;
+
+class CelestialBody
+{
+protected: // make the data protected, in order to give the inherited
+ // classes direct access to the data
+ double NFirst; /* longitude of the ascending node first part */
+ double NSec; /* longitude of the ascending node second part */
+ double iFirst; /* inclination to the ecliptic first part */
+ double iSec; /* inclination to the ecliptic second part */
+ double wFirst; /* first part of argument of perihelion */
+ double wSec; /* second part of argument of perihelion */
+ double aFirst; /* semimayor axis first part*/
+ double aSec; /* semimayor axis second part */
+ double eFirst; /* eccentricity first part */
+ double eSec; /* eccentricity second part */
+ double MFirst; /* Mean anomaly first part */
+ double MSec; /* Mean anomaly second part */
+
+ double N, i, w, a, e, M; /* the resulting orbital elements, obtained from the former */
+
+ double rightAscension, declination;
+ double r, R, s, FV;
+ double magnitude;
+ double lonEcl, latEcl;
+
+ double fgCalcEccAnom(double M, double e);
+ double fgCalcActTime(FGTime *t);
+ void updateOrbElements(FGTime *t);
+
+public:
+ CelestialBody(double Nf, double Ns,
+ double If, double Is,
+ double wf, double ws,
+ double af, double as,
+ double ef, double es,
+ double Mf, double Ms, FGTime *t);
+ void getPos(double *ra, double *dec);
+ void getPos(double *ra, double *dec, double *magnitude);
+ double getLon();
+ double getLat();
+ void updatePosition(FGTime *t, Star *ourSun);
+};
+
+/*****************************************************************************
+ * inline CelestialBody::CelestialBody
+ * public constructor for a generic celestialBody object.
+ * initializes the 6 primary orbital elements. The elements are:
+ * N: longitude of the ascending node
+ * i: inclination to the ecliptic
+ * w: argument of perihelion
+ * a: semi-major axis, or mean distance from the sun
+ * e: eccenticity
+ * M: mean anomaly
+ * Each orbital element consists of a constant part and a variable part that
+ * gradually changes over time.
+ *
+ * Argumetns:
+ * the 13 arguments to the constructor constitute the first, constant
+ * ([NiwaeM]f) and the second variable ([NiwaeM]s) part of the orbital
+ * elements. The 13th argument is the current time. Note that the inclination
+ * is written with a capital (If, Is), because 'if' is a reserved word in the
+ * C/C++ programming language.
+ ***************************************************************************/
+inline CelestialBody::CelestialBody(double Nf, double Ns,
+ double If, double Is,
+ double wf, double ws,
+ double af, double as,
+ double ef, double es,
+ double Mf, double Ms, FGTime *t)
+{
+ NFirst = Nf; NSec = Ns;
+ iFirst = If; iSec = Is;
+ wFirst = wf; wSec = ws;
+ aFirst = af; aSec = as;
+ eFirst = ef; eSec = es;
+ MFirst = Mf; MSec = Ms;
+ updateOrbElements(t);
+};
+
+/****************************************************************************
+ * inline void CelestialBody::updateOrbElements(FGTime *t)
+ * given the current time, this private member calculates the actual
+ * orbital elements
+ *
+ * Arguments: FGTime *t: the current time:
+ *
+ * return value: none
+ ***************************************************************************/
+inline void CelestialBody::updateOrbElements(FGTime *t)
+{
+ double actTime = fgCalcActTime(t);
+ M = DEG_TO_RAD * (MFirst + (MSec * actTime));
+ w = DEG_TO_RAD * (wFirst + (wSec * actTime));
+ N = DEG_TO_RAD * (NFirst + (NSec * actTime));
+ i = DEG_TO_RAD * (iFirst + (iSec * actTime));
+ e = eFirst + (eSec * actTime);
+ a = aFirst + (aSec * actTime);
+}
+/*****************************************************************************
+ * inline double CelestialBody::fgCalcActTime(FGTime *t)
+ * this private member function returns the offset in days from the epoch for
+ * wich the orbital elements are calculated (Jan, 1st, 2000).
+ *
+ * Argument: the current time
+ *
+ * return value: the (fractional) number of days until Jan 1, 2000.
+ ****************************************************************************/
+inline double CelestialBody::fgCalcActTime(FGTime *t)
+{
+ return (t->getMjd() - 36523.5);
+}
+
+/*****************************************************************************
+ * inline void CelestialBody::getPos(double* ra, double* dec)
+ * gives public access to Right Ascension and declination
+ *
+ ****************************************************************************/
+inline void CelestialBody::getPos(double* ra, double* dec)
+{
+ *ra = rightAscension;
+ *dec = declination;
+}
+
+/*****************************************************************************
+ * inline void CelestialBody::getPos(double* ra, double* dec, double* magnitude
+ * gives public acces to the current Right ascension, declination, and
+ * magnitude
+ ****************************************************************************/
+inline void CelestialBody::getPos(double* ra, double* dec, double* magn)
+{
+ *ra = rightAscension;
+ *dec = declination;
+ *magn = magnitude;
+}
+
+inline double CelestialBody::getLon()
+{
+ return lonEcl;
+}
+
+inline double CelestialBody::getLat()
+{
+ return latEcl;
+}
+
+#endif // _CELESTIALBODY_H_
+
+
+
+
+
+
+
+
+
+
+
+
--- /dev/null
+/**************************************************************************
+ * jupiter.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$
+ **************************************************************************/
+
+
+#ifdef __BORLANDC__
+# define exception c_exception
+#endif
+#include <math.h>
+
+#include "jupiter.hxx"
+
+/*************************************************************************
+ * Jupiter::Jupiter(FGTime *t)
+ * Public constructor for class Jupiter
+ * Argument: The current time.
+ * the hard coded orbital elements for Jupiter are passed to
+ * CelestialBody::CelestialBody();
+ ************************************************************************/
+Jupiter::Jupiter(FGTime *t) :
+ CelestialBody(100.4542, 2.7685400E-5,
+ 1.3030, -1.557E-7,
+ 273.8777, 1.6450500E-5,
+ 5.2025600, 0.000000,
+ 0.048498, 4.469E-9,
+ 19.89500, 0.08308530010, t)
+{
+}
+
+/*************************************************************************
+ * void Jupiter::updatePosition(FGTime *t, Star *ourSun)
+ *
+ * calculates the current position of Jupiter, by calling the base class,
+ * CelestialBody::updatePosition(); The current magnitude is calculated using
+ * a Jupiter specific equation
+ *************************************************************************/
+void Jupiter::updatePosition(FGTime *t, Star *ourSun)
+{
+ CelestialBody::updatePosition(t, ourSun);
+ magnitude = -9.25 + 5*log10( r*R ) + 0.014 * FV;
+}
+
+
+
+
--- /dev/null
+/**************************************************************************
+ * jupiter.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$
+ **************************************************************************/
+#ifndef _JUPITER_HXX_
+#define _JUPITER_HXX_
+
+#include <Time/fg_time.hxx>
+#include "celestialBody.hxx"
+#include "star.hxx"
+
+class Jupiter : public CelestialBody
+{
+public:
+ Jupiter (FGTime *t);
+ void updatePosition(FGTime *t, Star *ourSun);
+};
+
+#endif // _JUPITER_HXX_
--- /dev/null
+/**************************************************************************
+ * mars.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$
+ **************************************************************************/
+
+#ifdef __BORLANDC__
+# define exception c_exception
+#endif
+#include <math.h>
+
+#include "mars.hxx"
+
+/*************************************************************************
+ * Mars::Mars(FGTime *t)
+ * Public constructor for class Mars
+ * Argument: The current time.
+ * the hard coded orbital elements for Mars are passed to
+ * CelestialBody::CelestialBody();
+ ************************************************************************/
+Mars::Mars(FGTime *t) :
+ CelestialBody(49.55740, 2.1108100E-5,
+ 1.8497, -1.78E-8,
+ 286.5016, 2.9296100E-5,
+ 1.5236880, 0.000000,
+ 0.093405, 2.516E-9,
+ 18.60210, 0.52402077660, t)
+{
+}
+/*************************************************************************
+ * void Mars::updatePosition(FGTime *t, Star *ourSun)
+ *
+ * calculates the current position of Mars, by calling the base class,
+ * CelestialBody::updatePosition(); The current magnitude is calculated using
+ * a Mars specific equation
+ *************************************************************************/
+void Mars::updatePosition(FGTime *t, Star *ourSun)
+{
+ CelestialBody::updatePosition(t, ourSun);
+ magnitude = -1.51 + 5*log10( r*R ) + 0.016 * FV;
+}
--- /dev/null
+/**************************************************************************
+ * mars.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$
+ **************************************************************************/
+#ifndef _MARS_HXX_
+#define _MARS_HXX_
+
+#include <Time/fg_time.hxx>
+#include "celestialBody.hxx"
+#include "star.hxx"
+
+class Mars : public CelestialBody
+{
+public:
+ Mars ( FGTime *t);
+ void updatePosition(FGTime *t, Star *ourSun);
+};
+
+#endif // _MARS_HXX_
--- /dev/null
+/**************************************************************************
+ * mercury.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$
+ **************************************************************************/
+
+#ifdef __BORLANDC__
+# define exception c_exception
+#endif
+#include <math.h>
+
+#include "mercury.hxx"
+
+/*************************************************************************
+ * Mercury::Mercury(FGTime *t)
+ * Public constructor for class Mercury
+ * Argument: The current time.
+ * the hard coded orbital elements for Mercury are passed to
+ * CelestialBody::CelestialBody();
+ ************************************************************************/
+Mercury::Mercury(FGTime *t) :
+ CelestialBody (48.33130, 3.2458700E-5,
+ 7.0047, 5.00E-8,
+ 29.12410, 1.0144400E-5,
+ 0.3870980, 0.000000,
+ 0.205635, 5.59E-10,
+ 168.6562, 4.09233443680, t)
+{
+}
+/*************************************************************************
+ * void Mercury::updatePosition(FGTime *t, Star *ourSun)
+ *
+ * calculates the current position of Mercury, by calling the base class,
+ * CelestialBody::updatePosition(); The current magnitude is calculated using
+ * a Mercury specific equation
+ *************************************************************************/
+void Mercury::updatePosition(FGTime *t, Star *ourSun)
+{
+ CelestialBody::updatePosition(t, ourSun);
+ magnitude = -0.36 + 5*log10( r*R ) + 0.027 * FV + 2.2E-13 * pow(FV, 6);
+}
+
+
--- /dev/null
+/**************************************************************************
+ * mercury.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$
+ **************************************************************************/
+#ifndef _MERCURY_HXX_
+#define _MERCURY_HXX_
+
+#include <Time/fg_time.hxx>
+#include "celestialBody.hxx"
+#include "star.hxx"
+
+class Mercury : public CelestialBody
+{
+public:
+ Mercury ( FGTime *t);
+ void updatePosition(FGTime *t, Star* ourSun);
+};
+
+#endif // _MERURY_HXX_
--- /dev/null
+/**************************************************************************
+ * moon.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$
+ **************************************************************************/
+
+#include <FDM/flight.hxx>
+
+#include <string.h>
+#include "moon.hxx"
+
+#include <Debug/logstream.hxx>
+#include <Main/options.hxx>
+#include <Misc/fgpath.hxx>
+#include <Objects/texload.h>
+
+#ifdef __BORLANDC__
+# define exception c_exception
+#endif
+#include <math.h>
+
+
+/*************************************************************************
+ * Moon::Moon(FGTime *t)
+ * Public constructor for class Moon. Initializes the orbital elements and
+ * sets up the moon texture.
+ * Argument: The current time.
+ * the hard coded orbital elements for Moon are passed to
+ * CelestialBody::CelestialBody();
+ ************************************************************************/
+Moon::Moon(FGTime *t) :
+ CelestialBody(125.1228, -0.0529538083,
+ 5.1454, 0.00000,
+ 318.0634, 0.1643573223,
+ 60.266600, 0.000000,
+ 0.054900, 0.000000,
+ 115.3654, 13.0649929509, t)
+{
+ int width, height;
+
+ FG_LOG( FG_GENERAL, FG_INFO, "Initializing Moon Texture");
+#ifdef GL_VERSION_1_1
+ xglGenTextures(1, &moon_texid);
+ xglBindTexture(GL_TEXTURE_2D, moon_texid);
+#elif GL_EXT_texture_object
+ xglGenTexturesEXT(1, &moon_texid);
+ xglBindTextureEXT(GL_TEXTURE_2D, moon_texid);
+#else
+# error port me
+#endif
+
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+ // load in the texture data
+ FGPath tpath( current_options.get_fg_root() );
+ tpath.append( "Textures" );
+ tpath.append( "moon.rgb" );
+
+ if ( (moon_texbuf = read_rgb_texture(tpath.c_str(), &width, &height))
+ == NULL )
+ {
+ // Try compressed
+ FGPath fg_tpath = tpath;
+ fg_tpath.append( ".gz" );
+ if ( (moon_texbuf = read_rgb_texture(fg_tpath.c_str(), &width, &height))
+ == NULL )
+ {
+ FG_LOG( FG_GENERAL, FG_ALERT,
+ "Error in loading moon texture " << tpath.str() );
+ exit(-1);
+ }
+ }
+
+ glTexImage2D( GL_TEXTURE_2D,
+ 0,
+ GL_RGB,
+ 256, 256,
+ 0,
+ GL_RGB, GL_UNSIGNED_BYTE,
+ moon_texbuf);
+
+ // setup the halo texture
+ FG_LOG( FG_GENERAL, FG_INFO, "Initializing Moon Texture");
+#ifdef GL_VERSION_1_1
+ xglGenTextures(1, &moon_halotexid);
+ xglBindTexture(GL_TEXTURE_2D, moon_halotexid);
+#elif GL_EXT_texture_object
+ xglGenTexturesEXT(1, &moon_halotexid);
+ xglBindTextureEXT(GL_TEXTURE_2D, moon_halotexid);
+#else
+# error port me
+#endif
+
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ setHalo();
+ glTexImage2D( GL_TEXTURE_2D,
+ 0,
+ GL_RGBA,
+ 256, 256,
+ 0,
+ GL_RGBA, GL_UNSIGNED_BYTE,
+ moon_halotexbuf);
+ moonObject = gluNewQuadric();
+}
+
+Moon::~Moon()
+{
+ //delete moonObject;
+ delete moon_texbuf;
+ delete moon_halotexbuf;
+}
+
+
+static int texWidth = 256; /* 64x64 is plenty */
+
+void Moon::setHalo()
+{
+ int texSize;
+ //void *textureBuf;
+ GLubyte *p;
+ int i,j;
+ double radius;
+
+ texSize = texWidth*texWidth;
+
+ moon_halotexbuf = new GLubyte[texSize*4];
+ if (!moon_halotexbuf)
+ return; // Ugly!
+
+ p = moon_halotexbuf;
+
+ radius = (double)(texWidth / 2);
+
+ for (i=0; i < texWidth; i++) {
+ for (j=0; j < texWidth; j++) {
+ double x, y, d;
+
+ x = fabs((double)(i - (texWidth / 2)));
+ y = fabs((double)(j - (texWidth / 2)));
+
+ d = sqrt((x * x) + (y * y));
+ if (d < radius)
+ {
+ double t = 1.0 - (d / radius); // t is 1.0 at center, 0.0 at edge */
+ // inverse square looks nice
+ *p = (int)((double)0xff * (t * t));
+ *(p+1) = (int)((double) 0xff * (t*t));
+ *(p+2) = (int)((double) 0xff * (t*t));
+ *(p+3) = 0x11;
+ }
+ else
+ {
+ *p = 0x00;
+ *(p+1) = 0x00;
+ *(p+2) = 0x00;
+ *(p+3) = 0x11;
+ }
+ p += 4;
+ }
+ }
+ //gluBuild2DMipmaps(GL_TEXTURE_2D, 1, texWidth, texWidth,
+ // GL_LUMINANCE,
+ // GL_UNSIGNED_BYTE, textureBuf);
+ //free(textureBuf);
+}
+
+
+/*****************************************************************************
+ * void Moon::updatePosition(FGTime *t, Star *ourSun)
+ * this member function calculates the actual topocentric position (i.e.)
+ * the position of the moon as seen from the current position on the surface
+ * of the moon.
+ ****************************************************************************/
+void Moon::updatePosition(FGTime *t, Star *ourSun)
+{
+ double
+ eccAnom, ecl, actTime,
+ xv, yv, v, r, xh, yh, zh, xg, yg, zg, xe, ye, ze,
+ Ls, Lm, D, F, mpar, gclat, rho, HA, g,
+ geoRa, geoDec;
+
+ fgAIRCRAFT *air;
+ FGInterface *f;
+
+ air = ¤t_aircraft;
+ f = air->fdm_state;
+
+ updateOrbElements(t);
+ actTime = fgCalcActTime(t);
+
+ // calculate the angle between ecliptic and equatorial coordinate system
+ // in Radians
+ ecl = ((DEG_TO_RAD * 23.4393) - (DEG_TO_RAD * 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 moon's true anomaly
+ r = sqrt (xv*xv + yv*yv); // and its distance
+
+ // estimate the geocentric rectangular coordinates here
+ 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 latitude and longitude here
+ lonEcl = atan2 (yh, xh);
+ latEcl = atan2(zh, sqrt(xh*xh + yh*yh));
+
+ /* Calculate a number of perturbatioin, i.e. disturbances caused by the
+ * gravitational infuence of the sun and the other major planets.
+ * The largest of these even have a name */
+ Ls = ourSun->getM() + ourSun->getw();
+ Lm = M + w + N;
+ D = Lm - Ls;
+ F = Lm - N;
+
+ lonEcl += DEG_TO_RAD * (-1.274 * sin (M - 2*D)
+ +0.658 * sin (2*D)
+ -0.186 * sin(ourSun->getM())
+ -0.059 * sin(2*M - 2*D)
+ -0.057 * sin(M - 2*D + ourSun->getM())
+ +0.053 * sin(M + 2*D)
+ +0.046 * sin(2*D - ourSun->getM())
+ +0.041 * sin(M - ourSun->getM())
+ -0.035 * sin(D)
+ -0.031 * sin(M + ourSun->getM())
+ -0.015 * sin(2*F - 2*D)
+ +0.011 * sin(M - 4*D)
+ );
+ latEcl += DEG_TO_RAD * (-0.173 * sin(F-2*D)
+ -0.055 * sin(M - F - 2*D)
+ -0.046 * sin(M + F - 2*D)
+ +0.033 * sin(F + 2*D)
+ +0.017 * sin(2*M + F)
+ );
+ r += (-0.58 * cos(M - 2*D)
+ -0.46 * cos(2*D)
+ );
+ FG_LOG(FG_GENERAL, FG_INFO, "Running moon update");
+ xg = r * cos(lonEcl) * cos(latEcl);
+ yg = r * sin(lonEcl) * cos(latEcl);
+ zg = r * sin(latEcl);
+
+ xe = xg;
+ ye = yg * cos(ecl) -zg * sin(ecl);
+ ze = yg * sin(ecl) +zg * cos(ecl);
+
+ geoRa = atan2(ye, xe);
+ geoDec = atan2(ze, sqrt(xe*xe + ye*ye));
+
+ /* FG_LOG( FG_GENERAL, FG_INFO,
+ "(geocentric) geoRa = (" << (RAD_TO_DEG * geoRa)
+ << "), geoDec= (" << (RAD_TO_DEG * geoDec) << ")" ); */
+
+
+ // Given the moon's geocentric ra and dec, calculate its
+ // topocentric ra and dec. i.e. the position as seen from the
+ // surface of the earth, instead of the center of the earth
+
+ // First calculate the moon's parrallax, that is, the apparent size of the
+ // (equatorial) radius of the earth, as seen from the moon
+ mpar = asin ( 1 / r);
+ // FG_LOG( FG_GENERAL, FG_INFO, "r = " << r << " mpar = " << mpar );
+ // FG_LOG( FG_GENERAL, FG_INFO, "lat = " << f->get_Latitude() );
+
+ gclat = f->get_Latitude() - 0.003358 *
+ sin (2 * DEG_TO_RAD * f->get_Latitude() );
+ // FG_LOG( FG_GENERAL, FG_INFO, "gclat = " << gclat );
+
+ rho = 0.99883 + 0.00167 * cos(2 * DEG_TO_RAD * f->get_Latitude());
+ // FG_LOG( FG_GENERAL, FG_INFO, "rho = " << rho );
+
+ if (geoRa < 0)
+ geoRa += (2*FG_PI);
+
+ HA = t->getLst() - (3.8197186 * geoRa);
+ /* FG_LOG( FG_GENERAL, FG_INFO, "t->getLst() = " << t->getLst()
+ << " HA = " << HA ); */
+
+ g = atan (tan(gclat) / cos ((HA / 3.8197186)));
+ // FG_LOG( FG_GENERAL, FG_INFO, "g = " << g );
+
+ rightAscension = geoRa - mpar * rho * cos(gclat) * sin(HA) / cos (geoDec);
+ declination = geoDec - mpar * rho * sin (gclat) * sin (g - geoDec) / sin(g);
+
+ /* FG_LOG( FG_GENERAL, FG_INFO,
+ "Ra = (" << (RAD_TO_DEG *rightAscension)
+ << "), Dec= (" << (RAD_TO_DEG *declination) << ")" ); */
+}
+
+
+/************************************************************************
+ * void Moon::newImage()
+ *
+ * This function regenerates a new visual image of the moon, which is added to
+ * solarSystem display list.
+ *
+ * Arguments: Right Ascension and declination
+ *
+ * return value: none
+ **************************************************************************/
+void Moon::newImage()
+{
+ fgLIGHT *l = &cur_light_params;
+ float moon_angle = l->moon_angle;
+
+ /*double x_2, x_4, x_8, x_10;
+ GLfloat ambient;
+ GLfloat amb[4];*/
+ int moonSize = 750;
+
+ GLfloat moonColor[4] = {0.85, 0.75, 0.35, 1.0};
+ GLfloat black[4] = {0.0, 0.0, 0.0, 1.0};
+ GLfloat white[4] = {1.0, 1.0, 1.0, 0.0};
+
+ if( moon_angle*RAD_TO_DEG < 100 )
+ {
+ FG_LOG( FG_ASTRO, FG_INFO, "Generating Moon Image" );
+
+ xglPushMatrix();
+ {
+ xglRotatef(((RAD_TO_DEG * rightAscension)- 90.0), 0.0, 0.0, 1.0);
+ xglRotatef((RAD_TO_DEG * declination), 1.0, 0.0, 0.0);
+
+ FG_LOG( FG_GENERAL, FG_INFO,
+ "Ra = (" << (RAD_TO_DEG *rightAscension)
+ << "), Dec= (" << (RAD_TO_DEG *declination) << ")" );
+ xglTranslatef(0.0, 60000.0, 0.0);
+ glEnable(GL_BLEND); // BLEND ENABLED
+
+ // Draw the halo...
+ if (current_options.get_textures())
+ {
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE);
+ glEnable(GL_TEXTURE_2D); // TEXTURE ENABLED
+ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+ glBindTexture(GL_TEXTURE_2D, moon_halotexid);
+
+ glBegin(GL_QUADS);
+ glTexCoord2f(0.0f, 0.0f); glVertex3f(-5000, 0.0, -5000);
+ glTexCoord2f(1.0f, 0.0f); glVertex3f( 5000, 0.0, -5000);
+ glTexCoord2f(1.0f, 1.0f); glVertex3f( 5000, 0.0, 5000);
+ glTexCoord2f(0.0f, 1.0f); glVertex3f(-5000, 0.0, 5000);
+ glEnd();
+ }
+
+ xglEnable(GL_LIGHTING); // LIGHTING ENABLED
+ xglEnable( GL_LIGHT0 );
+ // set lighting parameters
+ xglLightfv(GL_LIGHT0, GL_AMBIENT, white );
+ xglLightfv(GL_LIGHT0, GL_DIFFUSE, white );
+ // xglEnable( GL_CULL_FACE );
+ xglMaterialfv(GL_FRONT, GL_AMBIENT, black);
+ xglMaterialfv(GL_FRONT, GL_DIFFUSE, moonColor);
+
+ //glEnable(GL_TEXTURE_2D);
+
+ glBlendFunc(GL_ONE, GL_ONE);
+
+ //glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+ // Draw the moon-proper
+
+ if (current_options.get_textures())
+ {
+ glBindTexture(GL_TEXTURE_2D, moon_texid);
+ gluQuadricTexture(moonObject, GL_TRUE );
+ }
+ gluSphere(moonObject, moonSize, 12, 12 );
+ glDisable(GL_TEXTURE_2D); // TEXTURE DISABLED
+ glDisable(GL_BLEND); // BLEND DISABLED
+ }
+ xglPopMatrix();
+ glDisable(GL_LIGHTING); // Lighting Disabled.
+
+ }
+ else
+ {
+ }
+}
--- /dev/null
+/**************************************************************************
+ * moon.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$
+ **************************************************************************/
+#ifndef _MOON_HXX_
+#define _MOON_HXX_
+
+#include <Aircraft/aircraft.hxx>
+#include <Include/fg_constants.h>
+#include <Main/views.hxx>
+#include <Time/fg_time.hxx>
+
+#include "celestialBody.hxx"
+#include "star.hxx"
+
+class Moon : public CelestialBody
+{
+private:
+ void TexInit(); // This should move to the constructor eventually.
+
+ GLUquadricObj *moonObject;
+ GLuint Sphere;
+ GLuint moon_texid;
+ GLuint moon_halotexid;
+ GLubyte *moon_texbuf;
+ GLubyte *moon_halotexbuf;
+
+ void setHalo();
+public:
+ Moon ( FGTime *t);
+ ~Moon();
+ void updatePosition(FGTime *t, Star *ourSun);
+ void newImage();
+};
+
+
+#endif // _MOON_HXX_
--- /dev/null
+/**************************************************************************
+ * neptune.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$
+ **************************************************************************/
+
+#ifdef __BORLANDC__
+# define exception c_exception
+#endif
+#include <math.h>
+
+#include "neptune.hxx"
+
+/*************************************************************************
+ * Neptune::Neptune(FGTime *t)
+ * Public constructor for class Neptune
+ * Argument: The current time.
+ * the hard coded orbital elements for Neptune are passed to
+ * CelestialBody::CelestialBody();
+ ************************************************************************/
+Neptune::Neptune(FGTime *t) :
+ CelestialBody(131.7806, 3.0173000E-5,
+ 1.7700, -2.550E-7,
+ 272.8461, -6.027000E-6,
+ 30.058260, 3.313E-8,
+ 0.008606, 2.150E-9,
+ 260.2471, 0.00599514700, t)
+{
+}
+/*************************************************************************
+ * void Neptune::updatePosition(FGTime *t, Star *ourSun)
+ *
+ * calculates the current position of Neptune, by calling the base class,
+ * CelestialBody::updatePosition(); The current magnitude is calculated using
+ * a Neptune specific equation
+ *************************************************************************/
+void Neptune::updatePosition(FGTime *t, Star *ourSun)
+{
+ CelestialBody::updatePosition(t, ourSun);
+ magnitude = -6.90 + 5*log10 (r*R) + 0.001 *FV;
+}
--- /dev/null
+/**************************************************************************
+ * neptune.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$
+ **************************************************************************/
+#ifndef _NEPTUNE_HXX_
+#define _NEPTUNE_HXX_
+
+#include <Time/fg_time.hxx>
+#include "celestialBody.hxx"
+#include "star.hxx"
+
+class Neptune : public CelestialBody
+{
+public:
+ Neptune ( FGTime *t);
+ void updatePosition(FGTime *t, Star *ourSun);
+};
+
+#endif // _NEPTUNE_HXX_
--- /dev/null
+/**************************************************************************
+ * pluto.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$
+ **************************************************************************/
+#ifndef _PLUTO_HXX_
+#define _PLUTO_HXX_
+
+#include <Time/fg_time.hxx>
+#include "celestialBody.hxx"
+
+class Pluto : public CelestialBody
+{
+public:
+ Pluto ( FGTime t);
+};
+
+#endif // _PLUTO_HXX_
--- /dev/null
+/**************************************************************************
+ * saturn.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$
+ **************************************************************************/
+
+#ifdef __BORLANDC__
+# define exception c_exception
+#endif
+#include <math.h>
+
+#include "saturn.hxx"
+
+/*************************************************************************
+ * Saturn::Saturn(FGTime *t)
+ * Public constructor for class Saturn
+ * Argument: The current time.
+ * the hard coded orbital elements for Saturn are passed to
+ * CelestialBody::CelestialBody();
+ ************************************************************************/
+Saturn::Saturn(FGTime *t) :
+ CelestialBody(113.6634, 2.3898000E-5,
+ 2.4886, -1.081E-7,
+ 339.3939, 2.9766100E-5,
+ 9.5547500, 0.000000,
+ 0.055546, -9.499E-9,
+ 316.9670, 0.03344422820, t)
+{
+}
+
+/*************************************************************************
+ * void Saturn::updatePosition(FGTime *t, Star *ourSun)
+ *
+ * calculates the current position of Saturn, by calling the base class,
+ * CelestialBody::updatePosition(); The current magnitude is calculated using
+ * a Saturn specific equation
+ *************************************************************************/
+void Saturn::updatePosition(FGTime *t, Star *ourSun)
+{
+ CelestialBody::updatePosition(t, ourSun);
+
+ double actTime = fgCalcActTime(t);
+ double ir = 0.4897394;
+ double Nr = 2.9585076 + 6.6672E-7*actTime;
+ double B = asin (sin(declination) * cos(ir) -
+ cos(declination) * sin(ir) *
+ sin(rightAscension - Nr));
+ double ring_magn = -2.6 * sin(fabs(B)) + 1.2 * pow(sin(B), 2);
+ magnitude = -9.0 + 5*log10(r*R) + 0.044 * FV + ring_magn;
+}
+
--- /dev/null
+/**************************************************************************
+ * saturn.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$
+ **************************************************************************/
+#ifndef _SATURN_HXX_
+#define _SATURN_HXX_
+
+#include <Time/fg_time.hxx>
+#include "celestialBody.hxx"
+#include "star.hxx"
+
+class Saturn : public CelestialBody
+{
+public:
+ Saturn ( FGTime *t);
+ void updatePosition(FGTime *t, Star *ourSun);
+};
+
+#endif // _SATURN_HXX_
+
+
+
+
+
+
+
--- /dev/null
+// sky.cxx -- model sky with an upside down "bowl"
+//
+// Written by Curtis Olson, started December 1997.
+//
+// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
+//
+// 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$
+
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#ifdef HAVE_WINDOWS_H
+# include <windows.h>
+#endif
+
+#include <math.h>
+
+#include <GL/glut.h>
+#include <XGL/xgl.h>
+
+#include <Aircraft/aircraft.hxx>
+#include <Debug/logstream.hxx>
+#include <FDM/flight.hxx>
+#include <Include/fg_constants.h>
+#include <Main/views.hxx>
+#include <Math/fg_random.h>
+#include <Time/event.hxx>
+#include <Time/fg_time.hxx>
+
+#include "sky.hxx"
+
+
+#ifdef __MWERKS__
+# pragma global_optimizer off
+#endif
+
+
+// in meters of course
+#define CENTER_ELEV 25000.0
+
+#define INNER_RADIUS 50000.0
+#define INNER_ELEV 20000.0
+
+#define MIDDLE_RADIUS 70000.0
+#define MIDDLE_ELEV 8000.0
+
+#define OUTER_RADIUS 80000.0
+#define OUTER_ELEV 0.0
+
+#define BOTTOM_RADIUS 50000.0
+#define BOTTOM_ELEV -2000.0
+
+
+static float inner_vertex[12][3];
+static float middle_vertex[12][3];
+static float outer_vertex[12][3];
+static float bottom_vertex[12][3];
+
+static float inner_color[12][4];
+static float middle_color[12][4];
+static float outer_color[12][4];
+
+
+// Calculate the sky structure vertices
+void fgSkyVerticesInit( void ) {
+ float theta;
+ int i;
+
+ FG_LOG(FG_ASTRO, FG_INFO, " Generating the sky dome vertices.");
+
+ for ( i = 0; i < 12; i++ ) {
+ theta = (i * 30.0) * DEG_TO_RAD;
+
+ inner_vertex[i][0] = cos(theta) * INNER_RADIUS;
+ inner_vertex[i][1] = sin(theta) * INNER_RADIUS;
+ inner_vertex[i][2] = INNER_ELEV;
+
+ // printf(" %.2f %.2f\n", cos(theta) * INNER_RADIUS,
+ // sin(theta) * INNER_RADIUS);
+
+ middle_vertex[i][0] = cos((double)theta) * MIDDLE_RADIUS;
+ middle_vertex[i][1] = sin((double)theta) * MIDDLE_RADIUS;
+ middle_vertex[i][2] = MIDDLE_ELEV;
+
+ outer_vertex[i][0] = cos((double)theta) * OUTER_RADIUS;
+ outer_vertex[i][1] = sin((double)theta) * OUTER_RADIUS;
+ outer_vertex[i][2] = OUTER_ELEV;
+
+ bottom_vertex[i][0] = cos((double)theta) * BOTTOM_RADIUS;
+ bottom_vertex[i][1] = sin((double)theta) * BOTTOM_RADIUS;
+ bottom_vertex[i][2] = BOTTOM_ELEV;
+ }
+}
+
+
+// (Re)calculate the sky colors at each vertex
+void fgSkyColorsInit( void ) {
+ fgLIGHT *l;
+ double sun_angle, diff;
+ double outer_param[3], outer_amt[3], outer_diff[3];
+ double middle_param[3], middle_amt[3], middle_diff[3];
+ int i, j;
+
+ l = &cur_light_params;
+
+ FG_LOG( FG_ASTRO, FG_INFO,
+ " Generating the sky colors for each vertex." );
+
+ // setup for the possibility of sunset effects
+ sun_angle = l->sun_angle * RAD_TO_DEG;
+ // fgPrintf( FG_ASTRO, FG_INFO,
+ // " Sun angle in degrees = %.2f\n", sun_angle);
+
+ if ( (sun_angle > 80.0) && (sun_angle < 100.0) ) {
+ // 0.0 - 0.4
+ outer_param[0] = (10.0 - fabs(90.0 - sun_angle)) / 20.0;
+ outer_param[1] = (10.0 - fabs(90.0 - sun_angle)) / 40.0;
+ outer_param[2] = -(10.0 - fabs(90.0 - sun_angle)) / 30.0;
+ // outer_param[2] = 0.0;
+
+ middle_param[0] = (10.0 - fabs(90.0 - sun_angle)) / 40.0;
+ middle_param[1] = (10.0 - fabs(90.0 - sun_angle)) / 80.0;
+ middle_param[2] = 0.0;
+
+ outer_diff[0] = outer_param[0] / 6.0;
+ outer_diff[1] = outer_param[1] / 6.0;
+ outer_diff[2] = outer_param[2] / 6.0;
+
+ middle_diff[0] = middle_param[0] / 6.0;
+ middle_diff[1] = middle_param[1] / 6.0;
+ middle_diff[2] = middle_param[2] / 6.0;
+ } else {
+ outer_param[0] = outer_param[1] = outer_param[2] = 0.0;
+ middle_param[0] = middle_param[1] = middle_param[2] = 0.0;
+
+ outer_diff[0] = outer_diff[1] = outer_diff[2] = 0.0;
+ middle_diff[0] = middle_diff[1] = middle_diff[2] = 0.0;
+ }
+ // printf(" outer_red_param = %.2f outer_red_diff = %.2f\n",
+ // outer_red_param, outer_red_diff);
+
+ // calculate transition colors between sky and fog
+ for ( j = 0; j < 3; j++ ) {
+ outer_amt[j] = outer_param[j];
+ middle_amt[j] = middle_param[j];
+ }
+
+ for ( i = 0; i < 6; i++ ) {
+ for ( j = 0; j < 3; j++ ) {
+ diff = l->sky_color[j] - l->fog_color[j];
+
+ // printf("sky = %.2f fog = %.2f diff = %.2f\n",
+ // l->sky_color[j], l->fog_color[j], diff);
+
+ inner_color[i][j] = l->sky_color[j] - diff * 0.3;
+ middle_color[i][j] = l->sky_color[j] - diff * 0.9 + middle_amt[j];
+ outer_color[i][j] = l->fog_color[j] + outer_amt[j];
+
+ if ( inner_color[i][j] > 1.00 ) { inner_color[i][j] = 1.00; }
+ if ( inner_color[i][j] < 0.10 ) { inner_color[i][j] = 0.10; }
+ if ( middle_color[i][j] > 1.00 ) { middle_color[i][j] = 1.00; }
+ if ( middle_color[i][j] < 0.10 ) { middle_color[i][j] = 0.10; }
+ if ( outer_color[i][j] > 1.00 ) { outer_color[i][j] = 1.00; }
+ if ( outer_color[i][j] < 0.10 ) { outer_color[i][j] = 0.10; }
+ }
+ inner_color[i][3] = middle_color[i][3] = outer_color[i][3] =
+ l->sky_color[3];
+
+ for ( j = 0; j < 3; j++ ) {
+ outer_amt[j] -= outer_diff[j];
+ middle_amt[j] -= middle_diff[j];
+ }
+
+ /*
+ printf("inner_color[%d] = %.2f %.2f %.2f %.2f\n", i, inner_color[i][0],
+ inner_color[i][1], inner_color[i][2], inner_color[i][3]);
+ printf("middle_color[%d] = %.2f %.2f %.2f %.2f\n", i,
+ middle_color[i][0], middle_color[i][1], middle_color[i][2],
+ middle_color[i][3]);
+ printf("outer_color[%d] = %.2f %.2f %.2f %.2f\n", i,
+ outer_color[i][0], outer_color[i][1], outer_color[i][2],
+ outer_color[i][3]);
+ */
+ }
+
+ for ( j = 0; j < 3; j++ ) {
+ outer_amt[j] = 0.0;
+ middle_amt[j] = 0.0;
+ }
+
+ for ( i = 6; i < 12; i++ ) {
+
+ for ( j = 0; j < 3; j++ ) {
+ diff = l->sky_color[j] - l->fog_color[j];
+
+ // printf("sky = %.2f fog = %.2f diff = %.2f\n",
+ // l->sky_color[j], l->fog_color[j], diff);
+
+ inner_color[i][j] = l->sky_color[j] - diff * 0.3;
+ middle_color[i][j] = l->sky_color[j] - diff * 0.9 + middle_amt[j];
+ outer_color[i][j] = l->fog_color[j] + outer_amt[j];
+
+ if ( inner_color[i][j] > 1.00 ) { inner_color[i][j] = 1.00; }
+ if ( inner_color[i][j] < 0.10 ) { inner_color[i][j] = 0.10; }
+ if ( middle_color[i][j] > 1.00 ) { middle_color[i][j] = 1.00; }
+ if ( middle_color[i][j] < 0.10 ) { middle_color[i][j] = 0.10; }
+ if ( outer_color[i][j] > 1.00 ) { outer_color[i][j] = 1.00; }
+ if ( outer_color[i][j] < 0.15 ) { outer_color[i][j] = 0.15; }
+ }
+ inner_color[i][3] = middle_color[i][3] = outer_color[i][3] =
+ l->sky_color[3];
+
+ for ( j = 0; j < 3; j++ ) {
+ outer_amt[j] += outer_diff[j];
+ middle_amt[j] += middle_diff[j];
+ }
+
+ /*
+ printf("inner_color[%d] = %.2f %.2f %.2f %.2f\n", i, inner_color[i][0],
+ inner_color[i][1], inner_color[i][2], inner_color[i][3]);
+ printf("middle_color[%d] = %.2f %.2f %.2f %.2f\n", i,
+ middle_color[i][0], middle_color[i][1], middle_color[i][2],
+ middle_color[i][3]);
+ printf("outer_color[%d] = %.2f %.2f %.2f %.2f\n", i,
+ outer_color[i][0], outer_color[i][1], outer_color[i][2],
+ outer_color[i][3]);
+ */
+ }
+}
+
+
+// Initialize the sky structure and colors
+void fgSkyInit( void ) {
+ FG_LOG( FG_ASTRO, FG_INFO, "Initializing the sky" );
+
+ fgSkyVerticesInit();
+
+ // regester fgSkyColorsInit() as an event to be run periodically
+ global_events.Register( "fgSkyColorsInit()", fgSkyColorsInit,
+ fgEVENT::FG_EVENT_READY, 30000);
+}
+
+
+// Draw the Sky
+void fgSkyRender( void ) {
+ FGInterface *f;
+ fgLIGHT *l;
+ float inner_color[4];
+ float middle_color[4];
+ float outer_color[4];
+ double diff;
+ int i;
+
+ f = current_aircraft.fdm_state;
+ l = &cur_light_params;
+
+ // printf("Rendering the sky.\n");
+
+ // calculate the proper colors
+ for ( i = 0; i < 3; i++ ) {
+ diff = l->sky_color[i] - l->adj_fog_color[i];
+
+ // printf("sky = %.2f fog = %.2f diff = %.2f\n",
+ // l->sky_color[j], l->adj_fog_color[j], diff);
+
+ inner_color[i] = l->sky_color[i] - diff * 0.3;
+ middle_color[i] = l->sky_color[i] - diff * 0.9;
+ outer_color[i] = l->adj_fog_color[i];
+ }
+ inner_color[3] = middle_color[3] = outer_color[3] = l->adj_fog_color[3];
+
+ xglPushMatrix();
+
+ // Translate to view position
+ Point3D zero_elev = current_view.get_cur_zero_elev();
+ xglTranslatef( zero_elev.x(), zero_elev.y(), zero_elev.z() );
+ // printf(" Translated to %.2f %.2f %.2f\n",
+ // zero_elev.x, zero_elev.y, zero_elev.z );
+
+ // Rotate to proper orientation
+ // printf(" lon = %.2f lat = %.2f\n", FG_Longitude * RAD_TO_DEG,
+ // FG_Latitude * RAD_TO_DEG);
+ xglRotatef( f->get_Longitude() * RAD_TO_DEG, 0.0, 0.0, 1.0 );
+ xglRotatef( 90.0 - f->get_Latitude() * RAD_TO_DEG, 0.0, 1.0, 0.0 );
+ xglRotatef( l->sun_rotation * RAD_TO_DEG, 0.0, 0.0, 1.0 );
+
+ // Draw inner/center section of sky*/
+ xglBegin( GL_TRIANGLE_FAN );
+ xglColor4fv(l->sky_color);
+ xglVertex3f(0.0, 0.0, CENTER_ELEV);
+ for ( i = 11; i >= 0; i-- ) {
+ xglColor4fv( inner_color );
+ xglVertex3fv( inner_vertex[i] );
+ }
+ xglColor4fv( inner_color );
+ xglVertex3fv( inner_vertex[11] );
+ xglEnd();
+
+ // Draw the middle ring
+ xglBegin( GL_TRIANGLE_STRIP );
+ for ( i = 0; i < 12; i++ ) {
+ xglColor4fv( middle_color );
+ // printf("middle_color[%d] = %.2f %.2f %.2f %.2f\n", i,
+ // middle_color[i][0], middle_color[i][1], middle_color[i][2],
+ // middle_color[i][3]);
+ // xglColor4f(1.0, 0.0, 0.0, 1.0);
+ xglVertex3fv( middle_vertex[i] );
+ xglColor4fv( inner_color );
+ // printf("inner_color[%d] = %.2f %.2f %.2f %.2f\n", i,
+ // inner_color[i][0], inner_color[i][1], inner_color[i][2],
+ // inner_color[i][3]);
+ // xglColor4f(0.0, 0.0, 1.0, 1.0);
+ xglVertex3fv( inner_vertex[i] );
+ }
+ xglColor4fv( middle_color );
+ // xglColor4f(1.0, 0.0, 0.0, 1.0);
+ xglVertex3fv( middle_vertex[0] );
+ xglColor4fv( inner_color );
+ // xglColor4f(0.0, 0.0, 1.0, 1.0);
+ xglVertex3fv( inner_vertex[0] );
+ xglEnd();
+
+ // Draw the outer ring
+ xglBegin( GL_TRIANGLE_STRIP );
+ for ( i = 0; i < 12; i++ ) {
+ xglColor4fv( outer_color );
+ xglVertex3fv( outer_vertex[i] );
+ xglColor4fv( middle_color );
+ xglVertex3fv( middle_vertex[i] );
+ }
+ xglColor4fv( outer_color );
+ xglVertex3fv( outer_vertex[0] );
+ xglColor4fv( middle_color );
+ xglVertex3fv( middle_vertex[0] );
+ xglEnd();
+
+ // Draw the bottom skirt
+ xglBegin( GL_TRIANGLE_STRIP );
+ xglColor4fv( outer_color );
+ for ( i = 0; i < 12; i++ ) {
+ xglVertex3fv( bottom_vertex[i] );
+ xglVertex3fv( outer_vertex[i] );
+ }
+ xglVertex3fv( bottom_vertex[0] );
+ xglVertex3fv( outer_vertex[0] );
+ xglEnd();
+
+ xglPopMatrix();
+}
+
+
--- /dev/null
+// sky.hxx -- model sky with an upside down "bowl"
+//
+// Written by Curtis Olson, started December 1997.
+//
+// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com
+//
+// 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$
+
+
+#ifndef _SKY_HXX
+#define _SKY_HXX
+
+
+#ifndef __cplusplus
+# error This library requires C++
+#endif
+
+
+// (Re)generate the display list
+void fgSkyInit( void );
+
+// (Re)calculate the sky colors at each vertex
+void fgSkyColorsInit( void );
+
+// Draw the Sky
+void fgSkyRender( void );
+
+
+#endif // _SKY_HXX
+
+
--- /dev/null
+/**************************************************************************
+ * solarsystem.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$
+ **************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#ifdef HAVE_WINDOWS_H
+# include <windows.h>
+#endif
+
+#ifdef __BORLANDC__
+# define exception c_exception
+#endif
+#include <math.h>
+
+#include <GL/glut.h>
+#include <XGL/xgl.h>
+#include <Debug/logstream.hxx>
+#include <Time/sunpos.hxx>
+#include <Time/moonpos.hxx>
+#include "solarsystem.hxx"
+
+/***************************************************************************
+ * default constructor for class SolarSystem:
+ * or course there can only be one way to create an entire solar system -:) )
+ * the FGTime argument is needed to properly initialize the the current orbital
+ * elements
+ *************************************************************************/
+SolarSystem::SolarSystem(FGTime *t)
+{
+ if (theSolarSystem)
+ {
+ FG_LOG( FG_GENERAL, FG_ALERT, "Error: only one solarsystem allowed" );
+ exit(-1);
+ }
+ theSolarSystem = this;
+ ourSun = new Star(t);
+ earthsMoon = new Moon(t);
+ mercury = new Mercury(t);
+ venus = new Venus(t);
+ mars = new Mars(t);
+ jupiter = new Jupiter(t);
+ saturn = new Saturn(t);
+ uranus = new Uranus(t);
+ neptune = new Neptune(t);
+
+ displayList = 0;
+};
+
+/**************************************************************************
+ * the destructor for class SolarSystem;
+ **************************************************************************/
+SolarSystem::~SolarSystem()
+{
+ delete ourSun;
+ delete earthsMoon;
+ delete mercury;
+ delete venus;
+ delete mars;
+ delete jupiter;
+ delete saturn;
+ delete uranus;
+ delete neptune;
+}
+/****************************************************************************
+ * void SolarSystem::rebuild()
+ *
+ * this member function updates the positions for the sun, moon, and planets,
+ * and then rebuilds the display list.
+ *
+ * arguments: none
+ * return value: none
+ ***************************************************************************/
+void SolarSystem::rebuild()
+{
+ //fgLIGHT *l = &cur_light_params;
+ FGTime *t = FGTime::cur_time_params;
+ //float x, y, z;
+ //double sun_angle;
+ double ra, dec;
+ //double x_2, x_4, x_8, x_10;*/
+ double magnitude;
+ //GLfloat ambient;
+ //GLfloat amb[4];
+
+ glDisable(GL_LIGHTING);
+
+ // Step 1: update all the positions
+ ourSun->updatePosition(t);
+ earthsMoon->updatePosition(t, ourSun);
+ mercury->updatePosition(t, ourSun);
+ venus->updatePosition(t, ourSun);
+ mars->updatePosition(t, ourSun);
+ jupiter->updatePosition(t, ourSun);
+ saturn->updatePosition(t, ourSun);
+ uranus->updatePosition(t, ourSun);
+ neptune->updatePosition(t, ourSun);
+
+ fgUpdateSunPos(); // get the right sun angle (especially important when
+ // running for the first time).
+ fgUpdateMoonPos();
+
+ if (displayList)
+ xglDeleteLists(displayList, 1);
+
+ displayList = xglGenLists(1);
+
+ FG_LOG( FG_ASTRO, FG_INFO, "Rebuilding astro display list" );
+
+ // Step 2: rebuild the display list
+ xglNewList( displayList, GL_COMPILE);
+ {
+ // Step 2a: Add the moon...
+ // Not that it is preferred to draw the moon first, and the sun next, in order to mime a
+ // solar eclipse. This is yet untested though...
+ // Euhh, actually the ecplise doesn't work...
+
+ earthsMoon->newImage();
+ // Step 2b: Add the sun
+ ourSun->newImage();
+ // Step 2c: Add the planets
+ xglBegin(GL_POINTS);
+ mercury->getPos(&ra, &dec, &magnitude);addPlanetToList(ra, dec, magnitude);
+ venus ->getPos(&ra, &dec, &magnitude);addPlanetToList(ra, dec, magnitude);
+ mars ->getPos(&ra, &dec, &magnitude);addPlanetToList(ra, dec, magnitude);
+ jupiter->getPos(&ra, &dec, &magnitude);addPlanetToList(ra, dec, magnitude);
+ saturn ->getPos(&ra, &dec, &magnitude);addPlanetToList(ra, dec, magnitude);
+ uranus ->getPos(&ra, &dec, &magnitude);addPlanetToList(ra, dec, magnitude);
+ neptune->getPos(&ra, &dec, &magnitude);addPlanetToList(ra, dec, magnitude);
+ xglEnd();
+ xglEnable(GL_LIGHTING);
+ }
+ xglEndList();
+}
+
+/*****************************************************************************
+ * double SolarSystem::scaleMagnitude(double magn)
+ * This private member function rescales the original magnitude, as used in the
+ * astronomical sense of the word, into a value used by OpenGL to draw a
+ * convincing Star or planet
+ *
+ * Argument: the astronomical magnitude
+ *
+ * return value: the rescaled magnitude
+ ****************************************************************************/
+double SolarSystem::scaleMagnitude(double magn)
+{
+ double magnitude = (0.0 - magn) / 5.0 + 1.0;
+ magnitude = magnitude * 0.7 + (3 * 0.1);
+ if (magnitude > 1.0) magnitude = 1.0;
+ if (magnitude < 0.0) magnitude = 0.0;
+ return magnitude;
+}
+
+/***************************************************************************
+ * void SolarSytem::addPlanetToList(double ra, double dec, double magn);
+ *
+ * This private member function first causes the magnitude to be properly
+ * rescaled, and then adds the planet to the display list.
+ *
+ * arguments: Right Ascension, declination, and magnitude
+ *
+ * return value: none
+ **************************************************************************/
+void SolarSystem::addPlanetToList(double ra, double dec, double magn)
+{
+ double
+ magnitude = scaleMagnitude ( magn );
+
+ fgLIGHT *l = &cur_light_params;
+
+ if ((double) (l->sun_angle - FG_PI_2) >
+ ((magnitude - 1.0) * - 20 * DEG_TO_RAD))
+ {
+ xglColor3f (magnitude, magnitude, magnitude);
+ xglVertex3f( 50000.0 * cos (ra) * cos (dec),
+ 50000.0 * sin (ra) * cos (dec),
+ 50000.0 * sin (dec));
+ }
+}
+
+
+SolarSystem* SolarSystem::theSolarSystem = 0;
+
+/******************************************************************************
+ * void solarSystemRebuild()
+ * this a just a wrapper function, provided for use as an interface to the
+ * event manager
+ *****************************************************************************/
+void solarSystemRebuild()
+{
+ SolarSystem::theSolarSystem->rebuild();
+}
--- /dev/null
+/**************************************************************************
+ * solarsystem.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$
+ **************************************************************************/
+#ifndef _SOLARSYSTEM_H_
+#define _SOLARSYSTEM_H_
+
+#include <Time/light.hxx>
+#include <Time/fg_time.hxx>
+#include <Main/views.hxx>
+
+#include "star.hxx"
+#include "moon.hxx"
+#include "mercury.hxx"
+#include "venus.hxx"
+#include "mars.hxx"
+#include "jupiter.hxx"
+#include "saturn.hxx"
+#include "uranus.hxx"
+#include "neptune.hxx"
+#include "pluto.hxx"
+
+
+class SolarSystem
+{
+private:
+ Star* ourSun;
+ Moon* earthsMoon;
+ Mercury* mercury;
+ Venus* venus;
+ Mars* mars;
+ Jupiter* jupiter;
+ Saturn* saturn;
+ Uranus* uranus;
+ Neptune* neptune;
+ //Pluto* pluto;
+
+ GLint displayList;
+ double scaleMagnitude(double magn);
+ void addPlanetToList(double ra, double dec, double magn);
+
+
+public:
+ SolarSystem(FGTime *t);
+ CelestialBody *getSun();
+ CelestialBody *getMoon();
+ ~SolarSystem();
+
+ static SolarSystem *theSolarSystem; // thanks to Bernie Bright!
+ void rebuild();
+ friend void solarSystemRebuild();
+ void draw();
+};
+
+inline CelestialBody* SolarSystem::getSun()
+{
+ return ourSun;
+}
+
+inline CelestialBody* SolarSystem::getMoon()
+{
+ return earthsMoon;
+}
+
+inline void SolarSystem::draw()
+{
+ xglCallList(displayList);
+}
+
+extern void solarSystemRebuild();
+
+#endif // _SOLARSYSTEM_H_
--- /dev/null
+/**************************************************************************
+ * star.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$
+ **************************************************************************/
+
+#ifdef __BORLANDC__
+# define exception c_exception
+#endif
+#include <math.h>
+#include <Time/sunpos.hxx>
+#include <Debug/logstream.hxx>
+#include <Time/light.hxx>
+#include <Main/options.hxx>
+#include "star.hxx"
+
+/*************************************************************************
+ * Star::Star(FGTime *t)
+ * Public constructor for class Star
+ * Argument: The current time.
+ * the hard coded orbital elements our sun are passed to
+ * CelestialBody::CelestialBody();
+ * note that the word sun is avoided, in order to prevent some compilation
+ * problems on sun systems
+ ************************************************************************/
+Star::Star(FGTime *t) :
+ CelestialBody (0.000000, 0.0000000000,
+ 0.0000, 0.00000,
+ 282.9404, 4.7093500E-5,
+ 1.0000000, 0.000000,
+ 0.016709, -1.151E-9,
+ 356.0470, 0.98560025850, t)
+{
+
+ FG_LOG( FG_GENERAL, FG_INFO, "Initializing Sun Texture");
+#ifdef GL_VERSION_1_1
+ xglGenTextures(1, &sun_texid);
+ xglBindTexture(GL_TEXTURE_2D, sun_texid);
+#elif GL_EXT_texture_object
+ xglGenTexturesEXT(1, &sun_texid);
+ xglBindTextureEXT(GL_TEXTURE_2D, sun_texid);
+#else
+# error port me
+#endif
+
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ setTexture();
+ glTexImage2D( GL_TEXTURE_2D,
+ 0,
+ GL_RGBA,
+ 256, 256,
+ 0,
+ GL_RGBA, GL_UNSIGNED_BYTE,
+ sun_texbuf);
+
+ SunObject = gluNewQuadric();
+ if(SunObject == NULL)
+ {
+ printf("gluNewQuadric(SunObject) failed !\n");
+ exit(0);
+ }
+
+ //SunList = 0;
+ distance = 0.0;
+}
+
+Star::~Star()
+{
+ //delete SunObject;
+ delete [] sun_texbuf;
+}
+
+
+
+static int texWidth = 256; /* 64x64 is plenty */
+
+void Star::setTexture()
+{
+ int texSize;
+ //void *textureBuf;
+ GLubyte *p;
+ int i,j;
+ double radius;
+
+ texSize = texWidth*texWidth;
+
+ sun_texbuf = new GLubyte[texSize*4];
+ if (!sun_texbuf)
+ return; // Ugly!
+
+ p = sun_texbuf;
+
+ radius = (double)(texWidth / 2);
+
+ for (i=0; i < texWidth; i++) {
+ for (j=0; j < texWidth; j++) {
+ double x, y, d;
+
+ x = fabs((double)(i - (texWidth / 2)));
+ y = fabs((double)(j - (texWidth / 2)));
+
+ d = sqrt((x * x) + (y * y));
+ if (d < radius)
+ {
+ double t = 1.0 - (d / radius); // t is 1.0 at center, 0.0 at edge */
+ // inverse square looks nice
+ *p = (int)((double)0xff * (t * t));
+ *(p+1) = (int)((double) 0xff * (t*t));
+ *(p+2) = (int)((double) 0xff * (t*t));
+ *(p+3) = (int)((double) 0xff * (t*t));
+ }
+ else
+ {
+ *p = 0x00;
+ *(p+1) = 0x00;
+ *(p+2) = 0x00;
+ *(p+3) = 0x00;
+ }
+ p += 4;
+ }
+ }
+ //gluBuild2DMipmaps(GL_TEXTURE_2D, 1, texWidth, texWidth,
+ // GL_LUMINANCE,
+ // GL_UNSIGNED_BYTE, textureBuf);
+ //free(textureBuf);
+}
+/*************************************************************************
+ * void Jupiter::updatePosition(FGTime *t, Star *ourSun)
+ *
+ * calculates the current position of our sun.
+ *************************************************************************/
+void Star::updatePosition(FGTime *t)
+{
+ double
+ actTime, eccAnom,
+ xv, yv, v, r,
+ xe, ye, ze, ecl;
+
+ updateOrbElements(t);
+
+ actTime = fgCalcActTime(t);
+ ecl = DEG_TO_RAD * (23.4393 - 3.563E-7 * actTime); // Angle in Radians
+ eccAnom = fgCalcEccAnom(M, e); // Calculate the eccentric Anomaly (also known as solving Kepler's equation)
+
+ xv = cos(eccAnom) - e;
+ yv = sqrt (1.0 - e*e) * sin(eccAnom);
+ v = atan2 (yv, xv); // the sun's true anomaly
+ distance = r = sqrt (xv*xv + yv*yv); // and its distance
+
+ lonEcl = v + w; // the sun's true longitude
+ latEcl = 0;
+
+ // convert the sun's true longitude to ecliptic rectangular
+ // geocentric coordinates (xs, ys)
+ xs = r * cos (lonEcl);
+ ys = r * sin (lonEcl);
+
+ // convert ecliptic coordinates to equatorial rectangular
+ // geocentric coordinates
+
+ xe = xs;
+ ye = ys * cos (ecl);
+ ze = ys * sin (ecl);
+
+ // And finally, calculate right ascension and declination
+ rightAscension = atan2 (ye, xe);
+ declination = atan2 (ze, sqrt (xe*xe + ye*ye));
+}
+
+void Star::newImage(void)
+{
+ /*static float stars[3];
+ stars[0] = 0.0;
+ stars[1] = 0.0;
+ stars[2] = 1.0;*/
+
+ fgLIGHT *l = &cur_light_params;
+ float sun_angle = l->sun_angle;
+
+ if( sun_angle*RAD_TO_DEG < 100 ) { // else no need to draw sun
+
+
+ double x_2, x_4, x_8, x_10;
+ GLfloat ambient;
+ GLfloat amb[4];
+ int sun_size = 750;
+
+ // daily variation sun gets larger near horizon
+ /*if(sun_angle*RAD_TO_DEG > 84.0 && sun_angle*RAD_TO_DEG < 95)
+ {
+ double sun_grow = 9*fabs(94-sun_angle*RAD_TO_DEG);
+ sun_size = (int)(sun_size + sun_size * cos(sun_grow*DEG_TO_RAD));
+ }*/
+ x_2 = sun_angle * sun_angle;
+ x_4 = x_2 * x_2;
+ x_8 = x_4 * x_4;
+ x_10 = x_8 * x_2;
+ ambient = (float)(0.4 * pow (1.1, - x_10 / 30.0));
+ if (ambient < 0.3) ambient = 0.3;
+ if (ambient > 1.0) ambient = 1.0;
+
+ amb[0] = ((ambient * 6.0) - 1.0); // minimum value = 0.8
+ amb[1] = ((ambient * 11.0) - 3.0); // minimum value = 0.3
+ amb[2] = ((ambient * 12.0) - 3.6); // minimum value = 0.0
+ amb[3] = 1.00;
+
+ if (amb[0] > 1.0) amb[0] = 1.0;
+ if (amb[1] > 1.0) amb[1] = 1.0;
+ if (amb[2] > 1.0) amb[2] = 1.0;
+ xglColor3fv(amb);
+ glPushMatrix();
+ {
+ xglRotatef(((RAD_TO_DEG * rightAscension)- 90.0), 0.0, 0.0, 1.0);
+ xglRotatef((RAD_TO_DEG * declination), 1.0, 0.0, 0.0);
+ xglTranslatef(0,60000,0);
+ if (current_options.get_textures())
+ {
+ glEnable(GL_TEXTURE_2D); // TEXTURE ENABLED
+ glEnable(GL_BLEND); // BLEND ENABLED
+
+ glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+ glBindTexture(GL_TEXTURE_2D, sun_texid);
+
+ glBegin(GL_QUADS);
+ glTexCoord2f(0.0f, 0.0f); glVertex3f(-5000, 0.0, -5000);
+ glTexCoord2f(1.0f, 0.0f); glVertex3f( 5000, 0.0, -5000);
+ glTexCoord2f(1.0f, 1.0f); glVertex3f( 5000, 0.0, 5000);
+ glTexCoord2f(0.0f, 1.0f); glVertex3f(-5000, 0.0, 5000);
+ glEnd();
+ }
+ xglDisable(GL_TEXTURE_2D); // TEXTURE DISABLED
+ xglDisable(GL_BLEND); // BLEND DISABLED
+ }
+
+ glPopMatrix();
+ glDisable(GL_LIGHTING); //LIGHTING DISABLED
+ glDisable(GL_BLEND); //BLEND DISABLED
+ glPushMatrix();
+ {
+ xglRotatef(((RAD_TO_DEG * rightAscension)- 90.0), 0.0, 0.0, 1.0);
+ xglRotatef((RAD_TO_DEG * declination), 1.0, 0.0, 0.0);
+ xglColor4fv(amb);
+ xglTranslatef(0,60000,0);
+ gluSphere( SunObject, sun_size, 10, 10 );
+ }
+ glPopMatrix();
+ glDisable(GL_TEXTURE_2D); // TEXTURE DISABLED
+ glDisable(GL_BLEND); // BLEND DISABLED
+ }
+}
--- /dev/null
+/**************************************************************************
+ * star.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$
+ **************************************************************************/
+#ifndef _STAR_HXX_
+#define _STAR_HXX_
+
+#include <Time/fg_time.hxx>
+#include "celestialBody.hxx"
+
+
+class Star : public CelestialBody
+{
+private:
+ //double longitude; // the sun's true longitude - this is depreciated by
+ // CelestialBody::lonEcl
+ double xs, ys; // the sun's rectangular geocentric coordinates
+ double distance; // the sun's distance to the earth
+ GLUquadricObj *SunObject;
+ GLuint sun_texid;
+ GLubyte *sun_texbuf;
+
+ void setTexture();
+public:
+ Star (FGTime *t);
+ ~Star();
+ void updatePosition(FGTime *t);
+ double getM();
+ double getw();
+ //double getLon();
+ double getxs();
+ double getys();
+ double getDistance();
+ void newImage();
+};
+
+
+
+inline double Star::getM()
+{
+ return M;
+}
+
+inline double Star::getw()
+{
+ return w;
+}
+
+inline double Star::getxs()
+{
+ return xs;
+}
+
+inline double Star::getys()
+{
+ return ys;
+}
+
+inline double Star::getDistance()
+{
+ return distance;
+}
+
+
+#endif // _STAR_HXX_
+
+
+
+
+
+
+
+
+
+
+
+
+
+
--- /dev/null
+// stars.cxx -- data structures and routines for managing and rendering stars.
+//
+// Written by Curtis Olson, started August 1997.
+//
+// Copyright (C) 1997 Curtis L. Olson - curt@me.umn.edu
+//
+// 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$
+//*************************************************************************/
+
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#ifdef HAVE_WINDOWS_H
+# include <windows.h>
+#endif
+
+#include "Include/compiler.h"
+#ifdef FG_HAVE_STD_INCLUDES
+# include <cmath>
+# include <cstdio>
+# include <cstring>
+# include <ctime>
+#else
+# include <math.h>
+# include <stdio.h>
+# include <string.h>
+# include <time.h>
+#endif
+
+#include <string>
+
+#include <GL/glut.h>
+#include <XGL/xgl.h>
+
+#include <Aircraft/aircraft.hxx>
+#include <Debug/logstream.hxx>
+#include <Include/fg_constants.h>
+#include <Misc/fgpath.hxx>
+#include <Misc/fgstream.hxx>
+#include <Misc/stopwatch.hxx>
+#include <Main/options.hxx>
+#include <Main/views.hxx>
+#include <Time/fg_time.hxx>
+#include "Misc/stopwatch.hxx"
+
+#include "stars.hxx"
+
+FG_USING_STD(getline);
+
+#define EpochStart (631065600)
+#define DaysSinceEpoch(secs) (((secs)-EpochStart)*(1.0/(24*3600)))
+#define FG_MAX_STARS 3500
+
+// Define four structures, each with varying amounts of stars
+static GLint stars[FG_STAR_LEVELS];
+
+
+// Initialize the Star Management Subsystem
+int fgStarsInit( void ) {
+ // -dw- avoid local data > 32k error by dynamic allocation of the
+ // array, problem for some compilers
+ Point3D *starlist = new Point3D[FG_MAX_STARS];
+ // struct CelestialCoord pltPos;
+ double right_ascension, declination, magnitude;
+ double min_magnitude[FG_STAR_LEVELS];
+ // double ra_save, decl_save;
+ // double ra_save1, decl_save1;
+ int i, j, starcount, count;
+
+ FG_LOG( FG_ASTRO, FG_INFO, "Initializing stars" );
+
+ if ( FG_STAR_LEVELS < 4 ) {
+ FG_LOG( FG_ASTRO, FG_ALERT, "Big whups in stars.cxx" );
+ exit(-1);
+ }
+
+ // build the full path name to the stars data base file
+ FGPath path ( current_options.get_fg_root() );
+ path.append( "Astro/stars" );
+ FG_LOG( FG_ASTRO, FG_INFO, " Loading stars from " << path.str() );
+
+ fg_gzifstream in( path.str() );
+ if ( ! in ) {
+ FG_LOG( FG_ASTRO, FG_ALERT, "Cannot open star file: " << path.str() );
+ exit(-1);
+ }
+
+ starcount = 0;
+
+ StopWatch timer;
+ timer.start();
+
+ // read in each line of the file
+ while ( ! in.eof() && starcount < FG_MAX_STARS )
+ {
+ in >> skipcomment;
+ string name;
+ getline( in, name, ',' );
+ in >> starlist[starcount];
+ ++starcount;
+ }
+
+ timer.stop();
+ FG_LOG( FG_ASTRO, FG_INFO,
+ "Loaded " << starcount << " stars in "
+ << timer.elapsedSeconds() << " seconds" );
+
+ min_magnitude[0] = 4.2;
+ min_magnitude[1] = 3.6;
+ min_magnitude[2] = 3.0;
+ min_magnitude[3] = 2.4;
+ min_magnitude[4] = 1.8;
+ min_magnitude[5] = 1.2;
+ min_magnitude[6] = 0.6;
+ min_magnitude[7] = 0.0;
+
+ // build the various star display lists
+ for ( i = 0; i < FG_STAR_LEVELS; i++ ) {
+
+ stars[i] = xglGenLists(1);
+ xglNewList( stars[i], GL_COMPILE );
+ xglBegin( GL_POINTS );
+
+ count = 0;
+
+ for ( j = 0; j < starcount; j++ ) {
+ magnitude = starlist[j].z();
+ // printf("magnitude = %.2f\n", magnitude);
+
+ if ( magnitude < min_magnitude[i] ) {
+ right_ascension = starlist[j].x();
+ declination = starlist[j].y();
+
+ count++;
+
+ // scale magnitudes to (0.0 - 1.0)
+ magnitude = (0.0 - magnitude) / 5.0 + 1.0;
+
+ // scale magnitudes again so they look ok
+ if ( magnitude > 1.0 ) { magnitude = 1.0; }
+ if ( magnitude < 0.0 ) { magnitude = 0.0; }
+ // magnitude =
+ // magnitude * 0.7 + (((FG_STAR_LEVELS - 1) - i) * 0.042);
+
+ magnitude = magnitude * 0.9 +
+ (((FG_STAR_LEVELS - 1) - i) * 0.014);
+ // printf(" Found star: %d %s, %.3f %.3f %.3f\n", count,
+ // name, right_ascension, declination, magnitude);
+
+ xglColor3f( magnitude, magnitude, magnitude );
+ //xglColor3f(0,0,0);*/
+ xglVertex3f( 50000.0*cos(right_ascension)*cos(declination),
+ 50000.0*sin(right_ascension)*cos(declination),
+ 50000.0*sin(declination) );
+ }
+ } // while
+
+ xglEnd();
+
+ /*
+ xglBegin(GL_LINE_LOOP);
+ xglColor3f(1.0, 0.0, 0.0);
+ xglVertex3f( 50000.0 * cos(ra_save-0.2) * cos(decl_save-0.2),
+ 50000.0 * sin(ra_save-0.2) * cos(decl_save-0.2),
+ 50000.0 * sin(decl_save-0.2) );
+ xglVertex3f( 50000.0 * cos(ra_save+0.2) * cos(decl_save-0.2),
+ 50000.0 * sin(ra_save+0.2) * cos(decl_save-0.2),
+ 50000.0 * sin(decl_save-0.2) );
+ xglVertex3f( 50000.0 * cos(ra_save+0.2) * cos(decl_save+0.2),
+ 50000.0 * sin(ra_save+0.2) * cos(decl_save+0.2),
+ 50000.0 * sin(decl_save+0.2) );
+ xglVertex3f( 50000.0 * cos(ra_save-0.2) * cos(decl_save+0.2),
+ 50000.0 * sin(ra_save-0.2) * cos(decl_save+0.2),
+ 50000.0 * sin(decl_save+0.2) );
+ xglEnd();
+ */
+
+ /*
+ xglBegin(GL_LINE_LOOP);
+ xglColor3f(0.0, 1.0, 0.0);
+ xglVertex3f( 50000.0 * cos(ra_save1-0.2) * cos(decl_save1-0.2),
+ 50000.0 * sin(ra_save1-0.2) * cos(decl_save1-0.2),
+ 50000.0 * sin(decl_save1-0.2) );
+ xglVertex3f( 50000.0 * cos(ra_save1+0.2) * cos(decl_save1-0.2),
+ 50000.0 * sin(ra_save1+0.2) * cos(decl_save1-0.2),
+ 50000.0 * sin(decl_save1-0.2) );
+ xglVertex3f( 50000.0 * cos(ra_save1+0.2) * cos(decl_save1+0.2),
+ 50000.0 * sin(ra_save1+0.2) * cos(decl_save1+0.2),
+ 50000.0 * sin(decl_save1+0.2) );
+ xglVertex3f( 50000.0 * cos(ra_save1-0.2) * cos(decl_save1+0.2),
+ 50000.0 * sin(ra_save1-0.2) * cos(decl_save1+0.2),
+ 50000.0 * sin(decl_save1+0.2) );
+ xglEnd();
+ */
+
+ xglEndList();
+
+ FG_LOG( FG_ASTRO, FG_INFO,
+ " Loading " << count << " stars brighter than "
+ << min_magnitude[i] );
+ }
+
+ return 1; // OK, we got here because initialization worked.
+}
+
+
+// Draw the Stars
+void fgStarsRender( void ) {
+ FGInterface *f;
+ fgLIGHT *l;
+ FGTime *t;
+ int i;
+
+ f = current_aircraft.fdm_state;
+ l = &cur_light_params;
+ t = FGTime::cur_time_params;
+
+ // FG_PI_2 + 0.1 is about 6 degrees after sundown and before sunrise
+
+ // t->sun_angle = 3.0; // to force stars to be drawn (for testing)
+
+ // render the stars
+ if ( l->sun_angle > (FG_PI_2 + 5 * DEG_TO_RAD ) ) {
+ // determine which star structure to draw
+ if ( l->sun_angle > (FG_PI_2 + 10.0 * DEG_TO_RAD ) ) {
+ i = 0;
+ } else if ( l->sun_angle > (FG_PI_2 + 8.8 * DEG_TO_RAD ) ) {
+ i = 1;
+ } else if ( l->sun_angle > (FG_PI_2 + 7.5 * DEG_TO_RAD ) ) {
+ i = 2;
+ } else if ( l->sun_angle > (FG_PI_2 + 7.0 * DEG_TO_RAD ) ) {
+ i = 3;
+ } else if ( l->sun_angle > (FG_PI_2 + 6.5 * DEG_TO_RAD ) ) {
+ i = 4;
+ } else if ( l->sun_angle > (FG_PI_2 + 6.0 * DEG_TO_RAD ) ) {
+ i = 5;
+ } else if ( l->sun_angle > (FG_PI_2 + 5.5 * DEG_TO_RAD ) ) {
+ i = 6;
+ } else {
+ i = 7;
+ }
+
+ // printf("RENDERING STARS = %d (night)\n", i);
+
+ xglCallList(stars[i]);
+ } else {
+ // printf("not RENDERING STARS (day)\n");
+ }
+}
+
+
--- /dev/null
+// stars.hxx -- data structures and routines for managing and rendering stars.
+//
+// Written by Curtis Olson, started August 1997.
+//
+// Copyright (C) 1997 Curtis L. Olson - curt@me.umn.edu
+//
+// 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$
+
+
+#ifndef _STARS_HXX
+#define _STARS_HXX
+
+
+#ifndef __cplusplus
+# error This library requires C++
+#endif
+
+#include <Time/fg_time.hxx>
+
+#define FG_STAR_LEVELS 8 // how many star transitions
+
+// Initialize the Star Management Subsystem
+int fgStarsInit( void );
+
+// Draw the Stars
+void fgStarsRender( void );
+
+// [no longer used?] extern FGTime cur_time_params;
+
+
+#endif // _STARS_HXX
+
+
--- /dev/null
+/**************************************************************************
+ * uranus.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$
+ **************************************************************************/
+
+#ifdef __BORLANDC__
+# define exception c_exception
+#endif
+#include <math.h>
+
+#include "uranus.hxx"
+
+/*************************************************************************
+ * Uranus::Uranus(FGTime *t)
+ * Public constructor for class Uranus
+ * Argument: The current time.
+ * the hard coded orbital elements for Uranus are passed to
+ * CelestialBody::CelestialBody();
+ ************************************************************************/
+Uranus::Uranus(FGTime *t) :
+ CelestialBody(74.00050, 1.3978000E-5,
+ 0.7733, 1.900E-8,
+ 96.66120, 3.0565000E-5,
+ 19.181710, -1.55E-8,
+ 0.047318, 7.450E-9,
+ 142.5905, 0.01172580600, t)
+{
+}
+
+/*************************************************************************
+ * void Uranus::updatePosition(FGTime *t, Star *ourSun)
+ *
+ * calculates the current position of Uranus, by calling the base class,
+ * CelestialBody::updatePosition(); The current magnitude is calculated using
+ * a Uranus specific equation
+ *************************************************************************/
+void Uranus::updatePosition(FGTime *t, Star *ourSun)
+{
+ CelestialBody::updatePosition(t, ourSun);
+ magnitude = -7.15 + 5*log10( r*R) + 0.001 * FV;
+}
--- /dev/null
+/**************************************************************************
+ * uranus.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$
+ **************************************************************************/
+#ifndef _URANUS_HXX_
+#define _URANUS_HXX_
+
+#include <Time/fg_time.hxx>
+#include "celestialBody.hxx"
+#include "star.hxx"
+
+class Uranus : public CelestialBody
+{
+public:
+ Uranus ( FGTime *t);
+ void updatePosition(FGTime *t, Star *ourSun);
+};
+
+#endif // _URANUS_HXX_
--- /dev/null
+/**************************************************************************
+ * venus.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$
+ **************************************************************************/
+
+#ifdef __BORLANDC__
+# define exception c_exception
+#endif
+#include <math.h>
+
+#include "venus.hxx"
+
+/*************************************************************************
+ * Venus::Venus(FGTime *t)
+ * Public constructor for class Venus
+ * Argument: The current time.
+ * the hard coded orbital elements for Venus are passed to
+ * CelestialBody::CelestialBody();
+ ************************************************************************/
+Venus::Venus(FGTime *t) :
+ CelestialBody(76.67990, 2.4659000E-5,
+ 3.3946, 2.75E-8,
+ 54.89100, 1.3837400E-5,
+ 0.7233300, 0.000000,
+ 0.006773, -1.302E-9,
+ 48.00520, 1.60213022440, t)
+{
+}
+
+/*************************************************************************
+ * void Venus::updatePosition(FGTime *t, Star *ourSun)
+ *
+ * calculates the current position of Venus, by calling the base class,
+ * CelestialBody::updatePosition(); The current magnitude is calculated using
+ * a Venus specific equation
+ *************************************************************************/
+void Venus::updatePosition(FGTime *t, Star *ourSun)
+{
+ CelestialBody::updatePosition(t, ourSun);
+ magnitude = -4.34 + 5*log10( r*R ) + 0.013 * FV + 4.2E-07 * pow(FV,3);
+}
--- /dev/null
+/**************************************************************************
+ * venus.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$
+ **************************************************************************/
+#ifndef _VENUS_HXX_
+#define _VENUS_HXX_
+
+#include <Time/fg_time.hxx>
+#include "celestialBody.hxx"
+#include "star.hxx"
+
+class Venus : public CelestialBody
+{
+public:
+ Venus ( FGTime *t);
+ void updatePosition(FGTime *t, Star *ourSun);
+};
+
+#endif // _VENUS_HXX_