From fcfbba74dbf5702945f7df6e235ce51ffc6f092d Mon Sep 17 00:00:00 2001 From: curt <curt> Date: Thu, 8 Apr 1999 19:53:46 +0000 Subject: [PATCH] Changed contributed by Durk Talsma: - Converted struct fgTIME to class FGTime - Don't draw textured moon/sun halos when --disable-textures requested --- Simulator/Astro/celestialBody.cxx | 2 +- Simulator/Astro/celestialBody.hxx | 22 +- Simulator/Astro/jupiter.cxx | 8 +- Simulator/Astro/jupiter.hxx | 4 +- Simulator/Astro/mars.cxx | 8 +- Simulator/Astro/mars.hxx | 4 +- Simulator/Astro/mercury.cxx | 8 +- Simulator/Astro/mercury.hxx | 4 +- Simulator/Astro/moon.cxx | 50 +++-- Simulator/Astro/moon.hxx | 4 +- Simulator/Astro/neptune.cxx | 8 +- Simulator/Astro/neptune.hxx | 4 +- Simulator/Astro/pluto.hxx | 2 +- Simulator/Astro/saturn.cxx | 8 +- Simulator/Astro/saturn.hxx | 4 +- Simulator/Astro/solarsystem.cxx | 6 +- Simulator/Astro/solarsystem.hxx | 2 +- Simulator/Astro/star.cxx | 51 +++-- Simulator/Astro/star.hxx | 4 +- Simulator/Astro/stars.cxx | 4 +- Simulator/Astro/stars.hxx | 3 +- Simulator/Astro/uranus.cxx | 8 +- Simulator/Astro/uranus.hxx | 4 +- Simulator/Astro/venus.cxx | 8 +- Simulator/Astro/venus.hxx | 4 +- Simulator/Main/3dfx.sh | 2 +- Simulator/Main/GLUTkey.cxx | 14 +- Simulator/Main/GLUTmain.cxx | 20 +- Simulator/Main/fg_init.cxx | 12 +- Simulator/Main/fg_serial.cxx | 50 +++-- Simulator/Time/fg_time.cxx | 338 ++++++++++++++++-------------- Simulator/Time/fg_time.hxx | 60 ++++-- Simulator/Time/light.cxx | 4 +- Simulator/Time/moonpos.cxx | 8 +- Simulator/Time/sunpos.cxx | 8 +- 35 files changed, 401 insertions(+), 349 deletions(-) diff --git a/Simulator/Astro/celestialBody.cxx b/Simulator/Astro/celestialBody.cxx index 5f13edb5f..715cd6133 100644 --- a/Simulator/Astro/celestialBody.cxx +++ b/Simulator/Astro/celestialBody.cxx @@ -50,7 +50,7 @@ * return value: none * *************************************************************************/ -void CelestialBody::updatePosition(fgTIME *t, Star *ourSun) +void CelestialBody::updatePosition(FGTime *t, Star *ourSun) { double eccAnom, v, ecl, actTime, xv, yv, xh, yh, zh, xg, yg, zg, xe, ye, ze; diff --git a/Simulator/Astro/celestialBody.hxx b/Simulator/Astro/celestialBody.hxx index 31eaa5cc5..3deccc09f 100644 --- a/Simulator/Astro/celestialBody.hxx +++ b/Simulator/Astro/celestialBody.hxx @@ -61,8 +61,8 @@ protected: // make the data protected, in order to give the inherit double lonEcl, latEcl; double fgCalcEccAnom(double M, double e); - double fgCalcActTime(fgTIME *t); - void updateOrbElements(fgTIME *t); + double fgCalcActTime(FGTime *t); + void updateOrbElements(FGTime *t); public: CelestialBody(double Nf, double Ns, @@ -70,12 +70,12 @@ public: double wf, double ws, double af, double as, double ef, double es, - double Mf, double Ms, fgTIME *t); + 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); + void updatePosition(FGTime *t, Star *ourSun); }; /***************************************************************************** @@ -103,7 +103,7 @@ inline CelestialBody::CelestialBody(double Nf, double Ns, double wf, double ws, double af, double as, double ef, double es, - double Mf, double Ms, fgTIME *t) + double Mf, double Ms, FGTime *t) { NFirst = Nf; NSec = Ns; iFirst = If; iSec = Is; @@ -115,15 +115,15 @@ inline CelestialBody::CelestialBody(double Nf, double Ns, }; /**************************************************************************** - * inline void CelestialBody::updateOrbElements(fgTIME *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: + * Arguments: FGTime *t: the current time: * * return value: none ***************************************************************************/ -inline void CelestialBody::updateOrbElements(fgTIME *t) +inline void CelestialBody::updateOrbElements(FGTime *t) { double actTime = fgCalcActTime(t); M = DEG_TO_RAD * (MFirst + (MSec * actTime)); @@ -134,7 +134,7 @@ inline void CelestialBody::updateOrbElements(fgTIME *t) a = aFirst + (aSec * actTime); } /***************************************************************************** - * inline double CelestialBody::fgCalcActTime(fgTIME *t) + * 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). * @@ -142,9 +142,9 @@ inline void CelestialBody::updateOrbElements(fgTIME *t) * * return value: the (fractional) number of days until Jan 1, 2000. ****************************************************************************/ -inline double CelestialBody::fgCalcActTime(fgTIME *t) +inline double CelestialBody::fgCalcActTime(FGTime *t) { - return (t->mjd - 36523.5); + return (t->getMjd() - 36523.5); } /***************************************************************************** diff --git a/Simulator/Astro/jupiter.cxx b/Simulator/Astro/jupiter.cxx index 2f65504d4..668b586fb 100644 --- a/Simulator/Astro/jupiter.cxx +++ b/Simulator/Astro/jupiter.cxx @@ -31,13 +31,13 @@ #include "jupiter.hxx" /************************************************************************* - * Jupiter::Jupiter(fgTIME *t) + * 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) : +Jupiter::Jupiter(FGTime *t) : CelestialBody(100.4542, 2.7685400E-5, 1.3030, -1.557E-7, 273.8777, 1.6450500E-5, @@ -48,13 +48,13 @@ Jupiter::Jupiter(fgTIME *t) : } /************************************************************************* - * void Jupiter::updatePosition(fgTIME *t, Star *ourSun) + * 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) +void Jupiter::updatePosition(FGTime *t, Star *ourSun) { CelestialBody::updatePosition(t, ourSun); magnitude = -9.25 + 5*log10( r*R ) + 0.014 * FV; diff --git a/Simulator/Astro/jupiter.hxx b/Simulator/Astro/jupiter.hxx index d230b5679..fe8aadbf3 100644 --- a/Simulator/Astro/jupiter.hxx +++ b/Simulator/Astro/jupiter.hxx @@ -31,8 +31,8 @@ class Jupiter : public CelestialBody { public: - Jupiter (fgTIME *t); - void updatePosition(fgTIME *t, Star *ourSun); + Jupiter (FGTime *t); + void updatePosition(FGTime *t, Star *ourSun); }; #endif // _JUPITER_HXX_ diff --git a/Simulator/Astro/mars.cxx b/Simulator/Astro/mars.cxx index 1e2d79103..b5d269e6f 100644 --- a/Simulator/Astro/mars.cxx +++ b/Simulator/Astro/mars.cxx @@ -30,13 +30,13 @@ #include "mars.hxx" /************************************************************************* - * Mars::Mars(fgTIME *t) + * 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) : +Mars::Mars(FGTime *t) : CelestialBody(49.55740, 2.1108100E-5, 1.8497, -1.78E-8, 286.5016, 2.9296100E-5, @@ -46,13 +46,13 @@ Mars::Mars(fgTIME *t) : { } /************************************************************************* - * void Mars::updatePosition(fgTIME *t, Star *ourSun) + * 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) +void Mars::updatePosition(FGTime *t, Star *ourSun) { CelestialBody::updatePosition(t, ourSun); magnitude = -1.51 + 5*log10( r*R ) + 0.016 * FV; diff --git a/Simulator/Astro/mars.hxx b/Simulator/Astro/mars.hxx index 678a2fc35..2cc47c0c7 100644 --- a/Simulator/Astro/mars.hxx +++ b/Simulator/Astro/mars.hxx @@ -31,8 +31,8 @@ class Mars : public CelestialBody { public: - Mars ( fgTIME *t); - void updatePosition(fgTIME *t, Star *ourSun); + Mars ( FGTime *t); + void updatePosition(FGTime *t, Star *ourSun); }; #endif // _MARS_HXX_ diff --git a/Simulator/Astro/mercury.cxx b/Simulator/Astro/mercury.cxx index d58db1b74..e100dd989 100644 --- a/Simulator/Astro/mercury.cxx +++ b/Simulator/Astro/mercury.cxx @@ -30,13 +30,13 @@ #include "mercury.hxx" /************************************************************************* - * Mercury::Mercury(fgTIME *t) + * 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) : +Mercury::Mercury(FGTime *t) : CelestialBody (48.33130, 3.2458700E-5, 7.0047, 5.00E-8, 29.12410, 1.0144400E-5, @@ -46,13 +46,13 @@ Mercury::Mercury(fgTIME *t) : { } /************************************************************************* - * void Mercury::updatePosition(fgTIME *t, Star *ourSun) + * 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) +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); diff --git a/Simulator/Astro/mercury.hxx b/Simulator/Astro/mercury.hxx index b2d97c67d..914370b9d 100644 --- a/Simulator/Astro/mercury.hxx +++ b/Simulator/Astro/mercury.hxx @@ -31,8 +31,8 @@ class Mercury : public CelestialBody { public: - Mercury ( fgTIME *t); - void updatePosition(fgTIME *t, Star* ourSun); + Mercury ( FGTime *t); + void updatePosition(FGTime *t, Star* ourSun); }; #endif // _MERURY_HXX_ diff --git a/Simulator/Astro/moon.cxx b/Simulator/Astro/moon.cxx index a29c64c8d..4df64ae12 100644 --- a/Simulator/Astro/moon.cxx +++ b/Simulator/Astro/moon.cxx @@ -29,6 +29,7 @@ #include <Debug/logstream.hxx> #include <Objects/texload.h> +#include <Main/options.hxx> #ifdef __BORLANDC__ # define exception c_exception @@ -37,14 +38,14 @@ /************************************************************************* - * Moon::Moon(fgTIME *t) + * 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) : +Moon::Moon(FGTime *t) : CelestialBody(125.1228, -0.0529538083, 5.1454, 0.00000, 318.0634, 0.1643573223, @@ -184,12 +185,12 @@ void Moon::setHalo() /***************************************************************************** - * void Moon::updatePosition(fgTIME *t, Star *ourSun) + * 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) +void Moon::updatePosition(FGTime *t, Star *ourSun) { double eccAnom, ecl, actTime, @@ -279,7 +280,7 @@ void Moon::updatePosition(fgTIME *t, Star *ourSun) if (geoRa < 0) geoRa += (2*FG_PI); - HA = t->lst - (3.8197186 * geoRa); + HA = t->getLst() - (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); @@ -341,19 +342,22 @@ void Moon::newImage() "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(); + glEnable(GL_BLEND); // BLEND ENABLED + + 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 ); @@ -368,10 +372,12 @@ void Moon::newImage() 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 ); + if (current_options.get_textures()) + { + 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 diff --git a/Simulator/Astro/moon.hxx b/Simulator/Astro/moon.hxx index c27cbd3d8..62451601e 100644 --- a/Simulator/Astro/moon.hxx +++ b/Simulator/Astro/moon.hxx @@ -46,9 +46,9 @@ private: void setHalo(); public: - Moon ( fgTIME *t); + Moon ( FGTime *t); ~Moon(); - void updatePosition(fgTIME *t, Star *ourSun); + void updatePosition(FGTime *t, Star *ourSun); void newImage(); }; diff --git a/Simulator/Astro/neptune.cxx b/Simulator/Astro/neptune.cxx index cd4d2d71d..bbb5df6c7 100644 --- a/Simulator/Astro/neptune.cxx +++ b/Simulator/Astro/neptune.cxx @@ -30,13 +30,13 @@ #include "neptune.hxx" /************************************************************************* - * Neptune::Neptune(fgTIME *t) + * 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) : +Neptune::Neptune(FGTime *t) : CelestialBody(131.7806, 3.0173000E-5, 1.7700, -2.550E-7, 272.8461, -6.027000E-6, @@ -46,13 +46,13 @@ Neptune::Neptune(fgTIME *t) : { } /************************************************************************* - * void Neptune::updatePosition(fgTIME *t, Star *ourSun) + * 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) +void Neptune::updatePosition(FGTime *t, Star *ourSun) { CelestialBody::updatePosition(t, ourSun); magnitude = -6.90 + 5*log10 (r*R) + 0.001 *FV; diff --git a/Simulator/Astro/neptune.hxx b/Simulator/Astro/neptune.hxx index 98390c71e..8a8d00f1f 100644 --- a/Simulator/Astro/neptune.hxx +++ b/Simulator/Astro/neptune.hxx @@ -31,8 +31,8 @@ class Neptune : public CelestialBody { public: - Neptune ( fgTIME *t); - void updatePosition(fgTIME *t, Star *ourSun); + Neptune ( FGTime *t); + void updatePosition(FGTime *t, Star *ourSun); }; #endif // _NEPTUNE_HXX_ diff --git a/Simulator/Astro/pluto.hxx b/Simulator/Astro/pluto.hxx index 282e8684f..2f8393aab 100644 --- a/Simulator/Astro/pluto.hxx +++ b/Simulator/Astro/pluto.hxx @@ -30,7 +30,7 @@ class Pluto : public CelestialBody { public: - Pluto ( fgTIME t); + Pluto ( FGTime t); }; #endif // _PLUTO_HXX_ diff --git a/Simulator/Astro/saturn.cxx b/Simulator/Astro/saturn.cxx index 6a8a43cbb..10cce47d9 100644 --- a/Simulator/Astro/saturn.cxx +++ b/Simulator/Astro/saturn.cxx @@ -30,13 +30,13 @@ #include "saturn.hxx" /************************************************************************* - * Saturn::Saturn(fgTIME *t) + * 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) : +Saturn::Saturn(FGTime *t) : CelestialBody(113.6634, 2.3898000E-5, 2.4886, -1.081E-7, 339.3939, 2.9766100E-5, @@ -47,13 +47,13 @@ Saturn::Saturn(fgTIME *t) : } /************************************************************************* - * void Saturn::updatePosition(fgTIME *t, Star *ourSun) + * 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) +void Saturn::updatePosition(FGTime *t, Star *ourSun) { CelestialBody::updatePosition(t, ourSun); diff --git a/Simulator/Astro/saturn.hxx b/Simulator/Astro/saturn.hxx index 22bce6ccb..4cf4d004e 100644 --- a/Simulator/Astro/saturn.hxx +++ b/Simulator/Astro/saturn.hxx @@ -31,8 +31,8 @@ class Saturn : public CelestialBody { public: - Saturn ( fgTIME *t); - void updatePosition(fgTIME *t, Star *ourSun); + Saturn ( FGTime *t); + void updatePosition(FGTime *t, Star *ourSun); }; #endif // _SATURN_HXX_ diff --git a/Simulator/Astro/solarsystem.cxx b/Simulator/Astro/solarsystem.cxx index 08917b4d1..33bbe5456 100644 --- a/Simulator/Astro/solarsystem.cxx +++ b/Simulator/Astro/solarsystem.cxx @@ -45,10 +45,10 @@ /*************************************************************************** * 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 + * the FGTime argument is needed to properly initialize the the current orbital * elements *************************************************************************/ -SolarSystem::SolarSystem(fgTIME *t) +SolarSystem::SolarSystem(FGTime *t) { if (theSolarSystem) { @@ -96,7 +96,7 @@ SolarSystem::~SolarSystem() void SolarSystem::rebuild() { //fgLIGHT *l = &cur_light_params; - fgTIME *t = &cur_time_params; + FGTime *t = FGTime::cur_time_params; //float x, y, z; //double sun_angle; double ra, dec; diff --git a/Simulator/Astro/solarsystem.hxx b/Simulator/Astro/solarsystem.hxx index 9b60c47bb..fe713d076 100644 --- a/Simulator/Astro/solarsystem.hxx +++ b/Simulator/Astro/solarsystem.hxx @@ -60,7 +60,7 @@ private: public: - SolarSystem(fgTIME *t); + SolarSystem(FGTime *t); CelestialBody *getSun(); CelestialBody *getMoon(); ~SolarSystem(); diff --git a/Simulator/Astro/star.cxx b/Simulator/Astro/star.cxx index 4752093df..8fa7fa906 100644 --- a/Simulator/Astro/star.cxx +++ b/Simulator/Astro/star.cxx @@ -29,10 +29,11 @@ #include <Time/sunpos.hxx> #include <Debug/logstream.hxx> #include <Time/light.hxx> +#include <Main/options.hxx> #include "star.hxx" /************************************************************************* - * Star::Star(fgTIME *t) + * Star::Star(FGTime *t) * Public constructor for class Star * Argument: The current time. * the hard coded orbital elements our sun are passed to @@ -40,7 +41,7 @@ * note that the word sun is avoided, in order to prevent some compilation * problems on sun systems ************************************************************************/ -Star::Star(fgTIME *t) : +Star::Star(FGTime *t) : CelestialBody (0.000000, 0.0000000000, 0.0000, 0.00000, 282.9404, 4.7093500E-5, @@ -144,11 +145,11 @@ void Star::setTexture() //free(textureBuf); } /************************************************************************* - * void Jupiter::updatePosition(fgTIME *t, Star *ourSun) + * void Jupiter::updatePosition(FGTime *t, Star *ourSun) * * calculates the current position of our sun. *************************************************************************/ -void Star::updatePosition(fgTIME *t) +void Star::updatePosition(FGTime *t) { double actTime, eccAnom, @@ -232,27 +233,29 @@ void Star::newImage(void) 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); + if (current_options.get_textures()) + { + 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(); + 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); + glDisable(GL_BLEND); } glPopMatrix(); - xglDisable(GL_TEXTURE_2D); - glDisable(GL_BLEND); glPushMatrix(); { xglRotatef(((RAD_TO_DEG * rightAscension)- 90.0), 0.0, 0.0, 1.0); @@ -265,7 +268,3 @@ void Star::newImage(void) glDisable(GL_BLEND); // BLEND DISABLED } } - - - - diff --git a/Simulator/Astro/star.hxx b/Simulator/Astro/star.hxx index 811c1f46f..6eb7a4c90 100644 --- a/Simulator/Astro/star.hxx +++ b/Simulator/Astro/star.hxx @@ -41,9 +41,9 @@ private: void setTexture(); public: - Star (fgTIME *t); + Star (FGTime *t); ~Star(); - void updatePosition(fgTIME *t); + void updatePosition(FGTime *t); double getM(); double getw(); //double getLon(); diff --git a/Simulator/Astro/stars.cxx b/Simulator/Astro/stars.cxx index 7cabd43b4..05bab930a 100644 --- a/Simulator/Astro/stars.cxx +++ b/Simulator/Astro/stars.cxx @@ -221,12 +221,12 @@ int fgStarsInit( void ) { void fgStarsRender( void ) { FGInterface *f; fgLIGHT *l; - fgTIME *t; + FGTime *t; int i; f = current_aircraft.fdm_state; l = &cur_light_params; - t = &cur_time_params; + t = FGTime::cur_time_params; // FG_PI_2 + 0.1 is about 6 degrees after sundown and before sunrise diff --git a/Simulator/Astro/stars.hxx b/Simulator/Astro/stars.hxx index b27d1b8d7..79a72c52f 100644 --- a/Simulator/Astro/stars.hxx +++ b/Simulator/Astro/stars.hxx @@ -39,8 +39,7 @@ int fgStarsInit( void ); // Draw the Stars void fgStarsRender( void ); -// [no longer used?] extern struct OrbElements pltOrbElements[9]; -extern fgTIME cur_time_params; +// [no longer used?] extern FGTime cur_time_params; #endif // _STARS_HXX diff --git a/Simulator/Astro/uranus.cxx b/Simulator/Astro/uranus.cxx index 4e0ae2313..c749a105a 100644 --- a/Simulator/Astro/uranus.cxx +++ b/Simulator/Astro/uranus.cxx @@ -30,13 +30,13 @@ #include "uranus.hxx" /************************************************************************* - * Uranus::Uranus(fgTIME *t) + * 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) : +Uranus::Uranus(FGTime *t) : CelestialBody(74.00050, 1.3978000E-5, 0.7733, 1.900E-8, 96.66120, 3.0565000E-5, @@ -47,13 +47,13 @@ Uranus::Uranus(fgTIME *t) : } /************************************************************************* - * void Uranus::updatePosition(fgTIME *t, Star *ourSun) + * 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) +void Uranus::updatePosition(FGTime *t, Star *ourSun) { CelestialBody::updatePosition(t, ourSun); magnitude = -7.15 + 5*log10( r*R) + 0.001 * FV; diff --git a/Simulator/Astro/uranus.hxx b/Simulator/Astro/uranus.hxx index 06f2d9fc8..ed55a144c 100644 --- a/Simulator/Astro/uranus.hxx +++ b/Simulator/Astro/uranus.hxx @@ -31,8 +31,8 @@ class Uranus : public CelestialBody { public: - Uranus ( fgTIME *t); - void updatePosition(fgTIME *t, Star *ourSun); + Uranus ( FGTime *t); + void updatePosition(FGTime *t, Star *ourSun); }; #endif // _URANUS_HXX_ diff --git a/Simulator/Astro/venus.cxx b/Simulator/Astro/venus.cxx index e2254a41d..95be711b8 100644 --- a/Simulator/Astro/venus.cxx +++ b/Simulator/Astro/venus.cxx @@ -30,13 +30,13 @@ #include "venus.hxx" /************************************************************************* - * Venus::Venus(fgTIME *t) + * 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) : +Venus::Venus(FGTime *t) : CelestialBody(76.67990, 2.4659000E-5, 3.3946, 2.75E-8, 54.89100, 1.3837400E-5, @@ -47,13 +47,13 @@ Venus::Venus(fgTIME *t) : } /************************************************************************* - * void Venus::updatePosition(fgTIME *t, Star *ourSun) + * 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) +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); diff --git a/Simulator/Astro/venus.hxx b/Simulator/Astro/venus.hxx index 4fd2f648f..ba498c84a 100644 --- a/Simulator/Astro/venus.hxx +++ b/Simulator/Astro/venus.hxx @@ -31,8 +31,8 @@ class Venus : public CelestialBody { public: - Venus ( fgTIME *t); - void updatePosition(fgTIME *t, Star *ourSun); + Venus ( FGTime *t); + void updatePosition(FGTime *t, Star *ourSun); }; #endif // _VENUS_HXX_ diff --git a/Simulator/Main/3dfx.sh b/Simulator/Main/3dfx.sh index 9f15e8f53..cb766b743 100755 --- a/Simulator/Main/3dfx.sh +++ b/Simulator/Main/3dfx.sh @@ -1,6 +1,6 @@ #!/bin/sh -WINDOW=NO +WINDOW=YES if [ $WINDOW = "YES" ]; then # in a window (slow hack) diff --git a/Simulator/Main/GLUTkey.cxx b/Simulator/Main/GLUTkey.cxx index 51eccfa4e..ecab98f2e 100644 --- a/Simulator/Main/GLUTkey.cxx +++ b/Simulator/Main/GLUTkey.cxx @@ -69,14 +69,14 @@ static void local_update_sky_and_lighting_params( void ) { // Handle keyboard events void GLUTkey(unsigned char k, int x, int y) { FGInterface *f; - fgTIME *t; + FGTime *t; FGView *v; FGWeather *w; float fov, tmp; static bool winding_ccw = true; f = current_aircraft.fdm_state; - t = &cur_time_params; + t = FGTime::cur_time_params; v = ¤t_view; w = ¤t_weather; @@ -141,11 +141,11 @@ void GLUTkey(unsigned char k, int x, int y) { fgHUDInit2(¤t_aircraft); return; case 77: // M key - t->warp -= 60; + t->adjust_warp(-60); local_update_sky_and_lighting_params(); return; case 84: // T key - t->warp_delta -= 30; + t->adjust_warp_delta(-30); local_update_sky_and_lighting_params(); return; case 87: // W key @@ -248,11 +248,11 @@ void GLUTkey(unsigned char k, int x, int y) { fgHUDInit(¤t_aircraft); // normal HUD return; case 109: // m key - t->warp += 60; + t->adjust_warp (+60); local_update_sky_and_lighting_params(); return; case 112: // p key - t->pause = !t->pause; + t->togglePauseMode(); // printf position and attitude information FG_LOG( FG_INPUT, FG_INFO, "Lon = " << f->get_Longitude() * RAD_TO_DEG @@ -264,7 +264,7 @@ void GLUTkey(unsigned char k, int x, int y) { << " Pitch = " << f->get_Theta() * RAD_TO_DEG ); return; case 116: // t key - t->warp_delta += 30; + t->adjust_warp_delta (+30); local_update_sky_and_lighting_params(); return; case 120: // X key diff --git a/Simulator/Main/GLUTmain.cxx b/Simulator/Main/GLUTmain.cxx index 9442b981a..f50784ec4 100644 --- a/Simulator/Main/GLUTmain.cxx +++ b/Simulator/Main/GLUTmain.cxx @@ -225,7 +225,7 @@ static void fgUpdateInstrViewParams( void ) { // Update all Visuals (redraws anything graphics related) static void fgRenderFrame( void ) { fgLIGHT *l = &cur_light_params; - fgTIME *t = &cur_time_params; + FGTime *t = FGTime::cur_time_params; FGView *v = ¤t_view; double angle; @@ -298,7 +298,7 @@ static void fgRenderFrame( void ) { xglTranslatef( view_pos.x(), view_pos.y(), view_pos.z() ); // Rotate based on gst (sidereal time) // note: constant should be 15.041085, Curt thought it was 15 - angle = t->gst * 15.041085; + angle = t->getGst() * 15.041085; // printf("Rotating astro objects by %.2f degrees\n",angle); xglRotatef( angle, 0.0, 0.0, -1.0 ); @@ -363,7 +363,7 @@ static void fgRenderFrame( void ) { void fgUpdateTimeDepCalcs(int multi_loop, int remainder) { FGInterface *f = current_aircraft.fdm_state; fgLIGHT *l = &cur_light_params; - fgTIME *t = &cur_time_params; + FGTime *t = FGTime::cur_time_params; FGView *v = ¤t_view; int i; @@ -372,7 +372,7 @@ void fgUpdateTimeDepCalcs(int multi_loop, int remainder) { multi_loop = DEFAULT_MULTILOOP; } - if ( !t->pause ) { + if ( !t->getPause() ) { // run Autopilot system fgAPRun(); @@ -442,7 +442,7 @@ static const double alt_adjust_m = alt_adjust_ft * FEET_TO_METER; // for the next move and update the display? static void fgMainLoop( void ) { FGInterface *f; - fgTIME *t; + FGTime *t; static long remainder = 0; long elapsed, multi_loop; // int i; @@ -451,7 +451,7 @@ static void fgMainLoop( void ) { static int frames = 0; f = current_aircraft.fdm_state; - t = &cur_time_params; + t = FGTime::cur_time_params; FG_LOG( FG_ALL, FG_DEBUG, "Running Main Loop"); FG_LOG( FG_ALL, FG_DEBUG, "======= ==== ===="); @@ -500,7 +500,7 @@ static void fgMainLoop( void ) { f->get_Altitude() * FEET_TO_METER); */ // update "time" - fgTimeUpdate(f, t); + t->update(f); // Get elapsed time (in usec) for this past frame elapsed = fgGetTimeInterval(); @@ -509,13 +509,13 @@ static void fgMainLoop( void ) { << ", previous remainder is = " << remainder ); // Calculate frame rate average - if ( (t->cur_time != last_time) && (last_time > 0) ) { + if ( (t->get_cur_time() != last_time) && (last_time > 0) ) { general.set_frame_rate( frames ); FG_LOG( FG_ALL, FG_DEBUG, "--> Frame rate is = " << general.get_frame_rate() ); frames = 0; } - last_time = t->cur_time; + last_time = t->get_cur_time(); ++frames; /* old fps calculation @@ -995,5 +995,3 @@ int main( int argc, char **argv ) { // we never actually get here ... but just in case ... :-) return(0); } - - diff --git a/Simulator/Main/fg_init.cxx b/Simulator/Main/fg_init.cxx index 98c92ccd0..7b88af033 100644 --- a/Simulator/Main/fg_init.cxx +++ b/Simulator/Main/fg_init.cxx @@ -167,7 +167,7 @@ int fgInitGeneral( void ) { } #endif - return ( 1 ); + return 1; } @@ -177,9 +177,11 @@ int fgInitGeneral( void ) { // Returns non-zero if a problem encountered. int fgInitSubsystems( void ) { + FGTime::cur_time_params = new FGTime(); + FGInterface *f; // assigned later fgLIGHT *l = &cur_light_params; - fgTIME *t = &cur_time_params; + FGTime *t = FGTime::cur_time_params; FGView *v = ¤t_view; FG_LOG( FG_GENERAL, FG_INFO, "Initialize Subsystems"); @@ -301,8 +303,8 @@ int fgInitSubsystems( void ) fgEVENT::FG_EVENT_READY, 60000 ); // Initialize the time dependent variables - fgTimeInit(t); - fgTimeUpdate(f, t); + t->init(); + t->update(f); // Initialize view parameters FG_LOG( FG_GENERAL, FG_DEBUG, "Before v->init()"); @@ -412,5 +414,3 @@ int fgInitSubsystems( void ) return(1); } - - diff --git a/Simulator/Main/fg_serial.cxx b/Simulator/Main/fg_serial.cxx index 0433b995c..03dc8e864 100644 --- a/Simulator/Main/fg_serial.cxx +++ b/Simulator/Main/fg_serial.cxx @@ -231,23 +231,23 @@ static void send_nmea_out( fgIOCHANNEL *p ) { int deg; double min; FGInterface *f; - fgTIME *t; - - // run once every two seconds - if ( p->last_time == cur_time_params.cur_time ) { - return; - } - p->last_time = cur_time_params.cur_time; - if ( cur_time_params.cur_time % 2 != 0 ) { - return; - } + FGTime *t; f = current_aircraft.fdm_state; - t = &cur_time_params; + t = FGTime::cur_time_params; + + // run once every two seconds + if ( p->last_time == t->get_cur_time() ) { + return; + } + p->last_time = t->get_cur_time(); + if ( t->get_cur_time() % 2 != 0 ) { + return; + } char utc[10]; sprintf( utc, "%02d%02d%02d", - t->gmt->tm_hour, t->gmt->tm_min, t->gmt->tm_sec ); + t->getGmt()->tm_hour, t->getGmt()->tm_min, t->getGmt()->tm_sec ); char lat[20]; double latd = f->get_Latitude() * RAD_TO_DEG; @@ -286,8 +286,8 @@ static void send_nmea_out( fgIOCHANNEL *p ) { sprintf( altitude_ft, "%02d", (int)f->get_Altitude() ); char date[10]; - sprintf( date, "%02d%02d%02d", - t->gmt->tm_mday, t->gmt->tm_mon+1, t->gmt->tm_year ); + sprintf( date, "%02d%02d%02d", t->getGmt()->tm_mday, + t->getGmt()->tm_mon+1, t->getGmt()->tm_year ); // $GPRMC,HHMMSS,A,DDMM.MMM,N,DDDMM.MMM,W,XXX.X,XXX.X,DDMMYY,XXX.X,E*XX sprintf( rmc, "GPRMC,%s,A,%s,%s,%s,%s,%s,0.000,E", @@ -330,23 +330,23 @@ static void send_garmin_out( fgIOCHANNEL *p ) { int deg; double min; FGInterface *f; - fgTIME *t; + FGTime *t; + + f = current_aircraft.fdm_state; + t = FGTime::cur_time_params; // run once per second - if ( p->last_time == cur_time_params.cur_time ) { + if ( p->last_time == t->get_cur_time() ) { return; } - p->last_time = cur_time_params.cur_time; - if ( cur_time_params.cur_time % 2 != 0 ) { + p->last_time = t->get_cur_time(); + if ( t->get_cur_time() % 2 != 0 ) { return; } - f = current_aircraft.fdm_state; - t = &cur_time_params; - char utc[10]; sprintf( utc, "%02d%02d%02d", - t->gmt->tm_hour, t->gmt->tm_min, t->gmt->tm_sec ); + t->getGmt()->tm_hour, t->getGmt()->tm_min, t->getGmt()->tm_sec ); char lat[20]; double latd = f->get_Latitude() * RAD_TO_DEG; @@ -385,8 +385,8 @@ static void send_garmin_out( fgIOCHANNEL *p ) { sprintf( altitude_ft, "%02d", (int)f->get_Altitude() ); char date[10]; - sprintf( date, "%02d%02d%02d", - t->gmt->tm_mday, t->gmt->tm_mon+1, t->gmt->tm_year ); + sprintf( date, "%02d%02d%02d", t->getGmt()->tm_mday, + t->getGmt()->tm_mon+1, t->getGmt()->tm_year ); // $GPRMC,HHMMSS,A,DDMM.MMM,N,DDDMM.MMM,W,XXX.X,XXX.X,DDMMYY,XXX.X,E*XX sprintf( rmc, "GPRMC,%s,A,%s,%s,%s,%s,%s,000.0,E", @@ -463,5 +463,3 @@ void fgSerialProcess() { } } } - - diff --git a/Simulator/Time/fg_time.cxx b/Simulator/Time/fg_time.cxx index 16ec630d0..e57d1a590 100644 --- a/Simulator/Time/fg_time.cxx +++ b/Simulator/Time/fg_time.cxx @@ -63,35 +63,38 @@ #define DEGHR(x) ((x)/15.) #define RADHR(x) DEGHR(x*RAD_TO_DEG) + // #define MK_TIME_IS_GMT 0 // default value // #define TIME_ZONE_OFFSET_WORK 0 // default value -fgTIME cur_time_params; +FGTime::FGTime() +{ + if (cur_time_params) { + FG_LOG( FG_GENERAL, FG_ALERT, + "Error: only one instance of FGTime allowed" ); + exit(-1); + } + + cur_time_params = this; +} -// Force an update of the sky and lighting parameters -static void local_update_sky_and_lighting_params( void ) { - // fgSunInit(); - SolarSystem::theSolarSystem->rebuild(); - cur_light_params.Update(); - fgSkyColorsInit(); +FGTime::~FGTime() +{ } // Initialize the time dependent variables -void fgTimeInit(fgTIME *t) { +void FGTime::init() +{ FG_LOG( FG_EVENT, FG_INFO, "Initializing Time" ); - - t->gst_diff = -9999.0; - + gst_diff = -9999.0; FG_LOG( FG_EVENT, FG_DEBUG, "time offset = " << current_options.get_time_offset() ); - - t->warp = current_options.get_time_offset(); - t->warp_delta = 0; - - t->pause = current_options.get_pause(); + warp = current_options.get_time_offset(); + warp_delta = 0; + pause = current_options.get_pause(); } @@ -99,25 +102,26 @@ void fgTimeInit(fgTIME *t) { // modified Julian date (number of days elapsed since 1900 jan 0.5), // mjd. Adapted from Xephem. -double cal_mjd (int mn, double dy, int yr) { - static double last_mjd, last_dy; - double mjd; - static int last_mn, last_yr; +void FGTime::cal_mjd (int mn, double dy, int yr) +{ + //static double last_mjd, last_dy; + //double mjd; + //static int last_mn, last_yr; int b, d, m, y; long c; - + if (mn == last_mn && yr == last_yr && dy == last_dy) { mjd = last_mjd; - return(mjd); + //return(mjd); } - + m = mn; y = (yr < 0) ? yr + 1 : yr; if (mn < 3) { m += 12; y -= 1; } - + if (yr < 1582 || (yr == 1582 && (mn < 10 || (mn == 10 && dy < 15)))) { b = 0; } else { @@ -125,30 +129,29 @@ double cal_mjd (int mn, double dy, int yr) { a = y/100; b = 2 - a + a/4; } - + if (y < 0) { c = (long)((365.25*y) - 0.75) - 694025L; } else { c = (long)(365.25*y) - 694025L; } - + d = (int)(30.6001*(m+1)); - + mjd = b + c + d + dy - 0.5; - + last_mn = mn; last_dy = dy; last_yr = yr; last_mjd = mjd; - - return(mjd); + + //return(mjd); } -// given an mjd, return greenwich mean sidereal time, gst - -double utc_gst (double mjd) { - double gst; +// given an mjd, calculate greenwich mean sidereal time, gst +void FGTime::utc_gst () +{ double day = floor(mjd-0.5)+0.5; double hr = (mjd-day)*24.0; double T, x; @@ -159,20 +162,18 @@ double utc_gst (double mjd) { gst = (1.0/SIDRATE)*hr + x; FG_LOG( FG_EVENT, FG_DEBUG, " gst => " << gst ); - - return(gst); } -// given Julian Date and Longitude (decimal degrees West) compute and -// return Local Sidereal Time, in decimal hours. +// given Julian Date and Longitude (decimal degrees West) compute +// Local Sidereal Time, in decimal hours. // // Provided courtesy of ecdowney@noao.edu (Elwood Downey) -// -double sidereal_precise (double mjd, double lng) { +double FGTime::sidereal_precise (double lng) +{ double gst; - double lst; + double lstTmp; /* printf ("Current Lst on JD %13.5f at %8.4f degrees West: ", mjd + MJD0, lng); */ @@ -181,29 +182,131 @@ double sidereal_precise (double mjd, double lng) { lng *= DEG_TO_RAD; // compute LST and print - gst = utc_gst (mjd); - lst = gst - RADHR (lng); - lst -= 24.0*floor(lst/24.0); + //gst = utc_gst (); + utc_gst(); + lstTmp = gst - RADHR (lng); + lstTmp -= 24.0*floor(lst/24.0); // printf ("%7.4f\n", lst); // that's all - return (lst); + return (lstTmp); } -// Fix up timezone if using ftime() -long int fix_up_timezone( long int timezone_orig ) { -#if !defined( HAVE_GETTIMEOFDAY ) && defined( HAVE_FTIME ) - // ftime() needs a little extra help finding the current timezone - struct timeb current; - ftime(¤t); - return( current.timezone * 60 ); -#else - return( timezone_orig ); -#endif +// return a courser but cheaper estimate of sidereal time +double FGTime::sidereal_course(double lng) +{ + //struct tm *gmt; + //double lstTmp; + time_t start_gmt, now; + double diff, part, days, hours, lstTmp; + char tbuf[64]; + + //gmt = t->gmt; + //now = t->cur_time; + now = cur_time; + start_gmt = get_start_gmt(gmt->tm_year); + + FG_LOG( FG_EVENT, FG_DEBUG, " COURSE: GMT = " << format_time(gmt, tbuf) ); + FG_LOG( FG_EVENT, FG_DEBUG, " March 21 noon (GMT) = " << start_gmt ); + + diff = (now - start_gmt) / (3600.0 * 24.0); + + FG_LOG( FG_EVENT, FG_DEBUG, + " Time since 3/21/" << gmt->tm_year << " GMT = " << diff ); + + part = fmod(diff, 1.0); + days = diff - part; + hours = gmt->tm_hour + gmt->tm_min/60.0 + gmt->tm_sec/3600.0; + + lstTmp = (days - lng)/15.0 + hours - 12; + + while ( lstTmp < 0.0 ) { + lstTmp += 24.0; + } + + FG_LOG( FG_EVENT, FG_DEBUG, + " days = " << days << " hours = " << hours << " lon = " + << lng << " lst = " << lstTmp ); + + return(lstTmp); } +// Update time variables such as gmt, julian date, and sidereal time +void FGTime::update(FGInterface *f) +{ + double gst_precise, gst_course; + + FG_LOG( FG_EVENT, FG_DEBUG, "Updating time" ); + + // get current Unix calendar time (in seconds) + warp += warp_delta; + cur_time = time(NULL) + warp; + FG_LOG( FG_EVENT, FG_DEBUG, + " Current Unix calendar time = " << cur_time + << " warp = " << warp << " delta = " << warp_delta ); + + if ( warp_delta ) { + // time is changing so force an update + local_update_sky_and_lighting_params(); + } + + // get GMT break down for current time + gmt = gmtime(&cur_time); + FG_LOG( FG_EVENT, FG_DEBUG, + " Current GMT = " << gmt->tm_mon+1 << "/" + << gmt->tm_mday << "/" << gmt->tm_year << " " + << gmt->tm_hour << ":" << gmt->tm_min << ":" + << gmt->tm_sec ); + + // calculate modified Julian date + // t->mjd = cal_mjd ((int)(t->gmt->tm_mon+1), (double)t->gmt->tm_mday, + // (int)(t->gmt->tm_year + 1900)); + cal_mjd ((int)(gmt->tm_mon+1), (double)gmt->tm_mday, + (int)(gmt->tm_year + 1900)); + + // add in partial day + mjd += (gmt->tm_hour / 24.0) + (gmt->tm_min / (24.0 * 60.0)) + + (gmt->tm_sec / (24.0 * 60.0 * 60.0)); + + // convert "back" to Julian date + partial day (as a fraction of one) + jd = mjd + MJD0; + FG_LOG( FG_EVENT, FG_DEBUG, " Current Julian Date = " << jd ); + + // printf(" Current Longitude = %.3f\n", FG_Longitude * RAD_TO_DEG); + + // Calculate local side real time + if ( gst_diff < -100.0 ) { + // first time through do the expensive calculation & cheap + // calculation to get the difference. + FG_LOG( FG_EVENT, FG_INFO, " First time, doing precise gst" ); + gst_precise = gst = sidereal_precise(0.00); + gst_course = sidereal_course(0.00); + + gst_diff = gst_precise - gst_course; + + lst = sidereal_course(-(f->get_Longitude() * RAD_TO_DEG)) + gst_diff; + } else { + // course + difference should drift off very slowly + gst = sidereal_course( 0.00 ) + gst_diff; + lst = sidereal_course( -(f->get_Longitude() * RAD_TO_DEG)) + gst_diff; + } + FG_LOG( FG_EVENT, FG_DEBUG, + " Current lon=0.00 Sidereal Time = " << gst ); + FG_LOG( FG_EVENT, FG_DEBUG, + " Current LOCAL Sidereal Time = " << lst << " (" + << sidereal_precise(-(f->get_Longitude() * RAD_TO_DEG)) + << ") (diff = " << gst_diff << ")" ); +} + + +/****************************************************************** + * The following are some functions that were included as FGTime + * members, although they currenty don't make used of any of the + * class's variables. Maybe this'll change in the future + *****************************************************************/ + // Return time_t for Sat Mar 21 12:00:00 GMT // // I believe the mktime() has a SYSV vs. BSD behavior difference. @@ -218,7 +321,7 @@ long int fix_up_timezone( long int timezone_orig ) { // If you are having problems with incorrectly positioned astronomical // bodies, this is a really good place to start looking. -time_t get_start_gmt(int year) { +time_t FGTime::get_start_gmt(int year) { struct tm mt; // For now we assume that if daylight is not defined in @@ -284,8 +387,21 @@ time_t get_start_gmt(int year) { # endif // ! defined ( MK_TIME_IS_GMT ) } -static char* -format_time( const struct tm* p, char* buf ) +// Fix up timezone if using ftime() +long int FGTime::fix_up_timezone( long int timezone_orig ) +{ +#if !defined( HAVE_GETTIMEOFDAY ) && defined( HAVE_FTIME ) + // ftime() needs a little extra help finding the current timezone + struct timeb current; + ftime(¤t); + return( current.timezone * 60 ); +#else + return( timezone_orig ); +#endif +} + + +char* FGTime::format_time( const struct tm* p, char* buf ) { sprintf( buf, "%d/%d/%2d %d:%02d:%02d", p->tm_mon, p->tm_mday, p->tm_year, @@ -293,106 +409,14 @@ format_time( const struct tm* p, char* buf ) return buf; } -// return a courser but cheaper estimate of sidereal time -double sidereal_course(fgTIME *t, double lng) { - struct tm *gmt; - time_t start_gmt, now; - double diff, part, days, hours, lst; - char tbuf[64]; - gmt = t->gmt; - now = t->cur_time; - start_gmt = get_start_gmt(gmt->tm_year); - - FG_LOG( FG_EVENT, FG_DEBUG, " COURSE: GMT = " << format_time(gmt, tbuf) ); - FG_LOG( FG_EVENT, FG_DEBUG, " March 21 noon (GMT) = " << start_gmt ); - - diff = (now - start_gmt) / (3600.0 * 24.0); - - FG_LOG( FG_EVENT, FG_DEBUG, - " Time since 3/21/" << gmt->tm_year << " GMT = " << diff ); - - part = fmod(diff, 1.0); - days = diff - part; - hours = gmt->tm_hour + gmt->tm_min/60.0 + gmt->tm_sec/3600.0; - - lst = (days - lng)/15.0 + hours - 12; - - while ( lst < 0.0 ) { - lst += 24.0; - } - - FG_LOG( FG_EVENT, FG_DEBUG, - " days = " << days << " hours = " << hours << " lon = " - << lng << " lst = " << lst ); - - return(lst); -} - - -// Update time variables such as gmt, julian date, and sidereal time -void fgTimeUpdate(FGInterface *f, fgTIME *t) { - double gst_precise, gst_course; - - FG_LOG( FG_EVENT, FG_DEBUG, "Updating time" ); - - // get current Unix calendar time (in seconds) - t->warp += t->warp_delta; - t->cur_time = time(NULL) + t->warp; - FG_LOG( FG_EVENT, FG_DEBUG, - " Current Unix calendar time = " << t->cur_time - << " warp = " << t->warp << " delta = " << t->warp_delta ); - - if ( t->warp_delta ) { - // time is changing so force an update - local_update_sky_and_lighting_params(); - } - - // get GMT break down for current time - t->gmt = gmtime(&t->cur_time); - FG_LOG( FG_EVENT, FG_DEBUG, - " Current GMT = " << t->gmt->tm_mon+1 << "/" - << t->gmt->tm_mday << "/" << t->gmt->tm_year << " " - << t->gmt->tm_hour << ":" << t->gmt->tm_min << ":" - << t->gmt->tm_sec ); - - // calculate modified Julian date - t->mjd = cal_mjd ((int)(t->gmt->tm_mon+1), (double)t->gmt->tm_mday, - (int)(t->gmt->tm_year + 1900)); - - // add in partial day - t->mjd += (t->gmt->tm_hour / 24.0) + (t->gmt->tm_min / (24.0 * 60.0)) + - (t->gmt->tm_sec / (24.0 * 60.0 * 60.0)); - - // convert "back" to Julian date + partial day (as a fraction of one) - t->jd = t->mjd + MJD0; - FG_LOG( FG_EVENT, FG_DEBUG, " Current Julian Date = " << t->jd ); - - // printf(" Current Longitude = %.3f\n", FG_Longitude * RAD_TO_DEG); - - // Calculate local side real time - if ( t->gst_diff < -100.0 ) { - // first time through do the expensive calculation & cheap - // calculation to get the difference. - FG_LOG( FG_EVENT, FG_INFO, " First time, doing precise gst" ); - t->gst = gst_precise = sidereal_precise(t->mjd, 0.00); - gst_course = sidereal_course(t, 0.00); - t->gst_diff = gst_precise - gst_course; - - t->lst = - sidereal_course(t, -(f->get_Longitude() * RAD_TO_DEG)) + t->gst_diff; - } else { - // course + difference should drift off very slowly - t->gst = sidereal_course(t, 0.00) + t->gst_diff; - t->lst = sidereal_course(t, -(f->get_Longitude() * RAD_TO_DEG)) + - t->gst_diff; - } - FG_LOG( FG_EVENT, FG_DEBUG, - " Current lon=0.00 Sidereal Time = " << t->gst ); - FG_LOG( FG_EVENT, FG_DEBUG, - " Current LOCAL Sidereal Time = " << t->lst << " (" - << sidereal_precise(t->mjd, -(f->get_Longitude() * RAD_TO_DEG)) - << ") (diff = " << t->gst_diff << ")" ); +// Force an update of the sky and lighting parameters +void FGTime::local_update_sky_and_lighting_params( void ) { + // fgSunInit(); + SolarSystem::theSolarSystem->rebuild(); + cur_light_params.Update(); + fgSkyColorsInit(); } +FGTime* FGTime::cur_time_params = 0; diff --git a/Simulator/Time/fg_time.hxx b/Simulator/Time/fg_time.hxx index 29f42d552..96a151cdc 100644 --- a/Simulator/Time/fg_time.hxx +++ b/Simulator/Time/fg_time.hxx @@ -1,4 +1,3 @@ -// // fg_time.hxx -- data structures and routines for managing time related stuff. // // Written by Curtis Olson, started August 1997. @@ -52,8 +51,10 @@ // Define a structure containing global time parameters -typedef struct { - // the date/time in various forms +class FGTime { + +private: + // Unix "calendar" time in seconds time_t cur_time; @@ -66,6 +67,9 @@ typedef struct { // modified Julian date double mjd; + double last_mjd, last_dy; + int last_mn, last_yr; + // side real time at prime meridian double gst; @@ -73,8 +77,8 @@ typedef struct { double lst; // the difference between the precise sidereal time algorithm - // result and the course result. - // course + diff has good accuracy for the short term + // result and the course result. course + diff has good accuracy + // for the short term double gst_diff; // An offset in seconds from the true time. Allows us to adjust @@ -83,23 +87,47 @@ typedef struct { // How much to change the value of warp each iteration. Allows us // to make time progress faster than normal. - long int warp_delta; + long int warp_delta; - // Paused (0 = no, 1 = yes) - int pause; -} fgTIME; + // Paused? + bool pause; + + void local_update_sky_and_lighting_params( void ); -extern fgTIME cur_time_params; +public: + FGTime(); + ~FGTime(); -// Update time variables such as gmt, julian date, and sidereal time -void fgTimeInit(fgTIME *t); + inline double getMjd() const { return mjd; }; + inline double getLst() const { return lst; }; + inline double getGst() const { return gst; }; + inline time_t get_cur_time() const { return cur_time; }; + inline struct tm* getGmt()const { return gmt; }; + inline bool getPause() const { return pause; }; + + void adjust_warp(int val) { warp += val; }; + void adjust_warp_delta(int val) { warp_delta += val; }; + void togglePauseMode() { pause = !pause; }; + // Initialize the time dependent variables + void init(); -// Update the time dependent variables -void fgTimeUpdate(FGInterface *f, fgTIME *t); + // Update the time dependent variables + void update(FGInterface *f); + + void cal_mjd (int mn, double dy, int yr); + void utc_gst(); + double sidereal_precise (double lng); + double sidereal_course(double lng); + static FGTime *cur_time_params; + + // Some other stuff which were changed to FGTime members on + // questionable grounds -:) + time_t get_start_gmt(int year); + char* format_time( const struct tm* p, char* buf ); + long int fix_up_timezone( long int timezone_orig ); +}; #endif // _FG_TIME_HXX - - diff --git a/Simulator/Time/light.cxx b/Simulator/Time/light.cxx index 4260fd619..92c3916c9 100644 --- a/Simulator/Time/light.cxx +++ b/Simulator/Time/light.cxx @@ -96,7 +96,7 @@ void fgLIGHT::Init( void ) { // update lighting parameters based on current sun position void fgLIGHT::Update( void ) { FGInterface *f; - fgTIME *t; + FGTime *t; // if the 4th field is 0.0, this specifies a direction ... GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 }; // base sky color @@ -106,7 +106,7 @@ void fgLIGHT::Update( void ) { double deg, ambient, diffuse, sky_brightness; f = current_aircraft.fdm_state; - t = &cur_time_params; + t = FGTime::cur_time_params; FG_LOG( FG_EVENT, FG_INFO, "Updating light parameters." ); diff --git a/Simulator/Time/moonpos.cxx b/Simulator/Time/moonpos.cxx index a4fcf4932..6379ccab3 100644 --- a/Simulator/Time/moonpos.cxx +++ b/Simulator/Time/moonpos.cxx @@ -337,7 +337,7 @@ static void fgMoonPositionGST(double gst, double *lon, double *lat) { // update the cur_time_params structure with the current moon position void fgUpdateMoonPos( void ) { fgLIGHT *l; - fgTIME *t; + FGTime *t; FGView *v; MAT3vec nup, nmoon, v0, surface_to_moon; Point3D p, rel_moonpos; @@ -346,21 +346,21 @@ void fgUpdateMoonPos( void ) { double ntmp; l = &cur_light_params; - t = &cur_time_params; + t = FGTime::cur_time_params; v = ¤t_view; FG_LOG( FG_EVENT, FG_INFO, " Updating Moon position" ); // (not sure why there was two) // fgMoonPosition(t->cur_time, &l->moon_lon, &moon_gd_lat); - fgMoonPositionGST(t->gst, &l->moon_lon, &moon_gd_lat); + fgMoonPositionGST(t->getGst(), &l->moon_lon, &moon_gd_lat); fgGeodToGeoc(moon_gd_lat, 0.0, &sl_radius, &l->moon_gc_lat); p = Point3D( l->moon_lon, l->moon_gc_lat, sl_radius ); l->fg_moonpos = fgPolarToCart3d(p); - FG_LOG( FG_EVENT, FG_INFO, " t->cur_time = " << t->cur_time ); + FG_LOG( FG_EVENT, FG_INFO, " t->cur_time = " << t->get_cur_time() ); FG_LOG( FG_EVENT, FG_INFO, " Moon Geodetic lat = " << moon_gd_lat << " Geocentric lat = " << l->moon_gc_lat ); diff --git a/Simulator/Time/sunpos.cxx b/Simulator/Time/sunpos.cxx index bb8082239..eb06ffd30 100644 --- a/Simulator/Time/sunpos.cxx +++ b/Simulator/Time/sunpos.cxx @@ -242,7 +242,7 @@ static void fgSunPositionGST(double gst, double *lon, double *lat) { // update the cur_time_params structure with the current sun position void fgUpdateSunPos( void ) { fgLIGHT *l; - fgTIME *t; + FGTime *t; FGView *v; MAT3vec nup, nsun, v0, surface_to_sun; Point3D p, rel_sunpos; @@ -251,21 +251,21 @@ void fgUpdateSunPos( void ) { double ntmp; l = &cur_light_params; - t = &cur_time_params; + t = FGTime::cur_time_params; v = ¤t_view; FG_LOG( FG_EVENT, FG_INFO, " Updating Sun position" ); // (not sure why there was two) // fgSunPosition(t->cur_time, &l->sun_lon, &sun_gd_lat); - fgSunPositionGST(t->gst, &l->sun_lon, &sun_gd_lat); + fgSunPositionGST(t->getGst(), &l->sun_lon, &sun_gd_lat); fgGeodToGeoc(sun_gd_lat, 0.0, &sl_radius, &l->sun_gc_lat); p = Point3D( l->sun_lon, l->sun_gc_lat, sl_radius ); l->fg_sunpos = fgPolarToCart3d(p); - FG_LOG( FG_EVENT, FG_INFO, " t->cur_time = " << t->cur_time ); + FG_LOG( FG_EVENT, FG_INFO, " t->cur_time = " << t->get_cur_time() ); FG_LOG( FG_EVENT, FG_INFO, " Sun Geodetic lat = " << sun_gd_lat << " Geocentric lat = " << l->sun_gc_lat );