]> git.mxchange.org Git - flightgear.git/commitdiff
Changed contributed by Durk Talsma:
authorcurt <curt>
Thu, 8 Apr 1999 19:53:46 +0000 (19:53 +0000)
committercurt <curt>
Thu, 8 Apr 1999 19:53:46 +0000 (19:53 +0000)
- Converted struct fgTIME to class FGTime
- Don't draw textured moon/sun halos when --disable-textures requested

35 files changed:
Simulator/Astro/celestialBody.cxx
Simulator/Astro/celestialBody.hxx
Simulator/Astro/jupiter.cxx
Simulator/Astro/jupiter.hxx
Simulator/Astro/mars.cxx
Simulator/Astro/mars.hxx
Simulator/Astro/mercury.cxx
Simulator/Astro/mercury.hxx
Simulator/Astro/moon.cxx
Simulator/Astro/moon.hxx
Simulator/Astro/neptune.cxx
Simulator/Astro/neptune.hxx
Simulator/Astro/pluto.hxx
Simulator/Astro/saturn.cxx
Simulator/Astro/saturn.hxx
Simulator/Astro/solarsystem.cxx
Simulator/Astro/solarsystem.hxx
Simulator/Astro/star.cxx
Simulator/Astro/star.hxx
Simulator/Astro/stars.cxx
Simulator/Astro/stars.hxx
Simulator/Astro/uranus.cxx
Simulator/Astro/uranus.hxx
Simulator/Astro/venus.cxx
Simulator/Astro/venus.hxx
Simulator/Main/3dfx.sh
Simulator/Main/GLUTkey.cxx
Simulator/Main/GLUTmain.cxx
Simulator/Main/fg_init.cxx
Simulator/Main/fg_serial.cxx
Simulator/Time/fg_time.cxx
Simulator/Time/fg_time.hxx
Simulator/Time/light.cxx
Simulator/Time/moonpos.cxx
Simulator/Time/sunpos.cxx

index 5f13edb5fca679d4dd33ce9f7267b75ef1202302..715cd61339bfd41461c1d39ccc16c54d19d2bf0f 100644 (file)
@@ -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;
index 31eaa5cc55b6b416d298768a36403d13876da76e..3deccc09f15d7892cd243482fb9b631af1c75c4d 100644 (file)
@@ -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);
 }
 
 /*****************************************************************************
index 2f65504d421881c2fddce03bd023b532e95c6eb1..668b586fba9af48cac32f8e496e83dd182db3e6e 100644 (file)
 #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;
index d230b567917719c7731db0a238b81faf738562f5..fe8aadbf390e23bc6b596fad13891f57b1538e41 100644 (file)
@@ -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_
index 1e2d791038de47ffc31b801e356c9cb1bd99a841..b5d269e6f7ca6c5c4347e06aef7a2fd5f556301b 100644 (file)
 #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;
index 678a2fc353f365598d06776f8a4574f9e4410d1a..2cc47c0c71a247aac72dcbd9e38ddcbecad68ee1 100644 (file)
@@ -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_
index d58db1b7459d6e45aa91ca26903fd6c2070b71d2..e100dd98994deec171885b23f99835695bf9023a 100644 (file)
 #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); 
index b2d97c67d1ba6671a153237d27eb265877dbf628..914370b9ddb2b5c03721e8a1304fbedd3eb58cf2 100644 (file)
@@ -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_
index a29c64c8d5dd08d592fd985e5f87ed204978077f..4df64ae123833216a4556b496ddbfdc899759ff5 100644 (file)
@@ -29,6 +29,7 @@
 
 #include <Debug/logstream.hxx>
 #include <Objects/texload.h>
+#include <Main/options.hxx>
 
 #ifdef __BORLANDC__
 #  define exception c_exception
 
 
 /*************************************************************************
- * 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
index c27cbd3d84fd8b4550f0d02490f319b8991d7f30..62451601e99fd3bd485858d890483d8956a4049c 100644 (file)
@@ -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();
 };
 
index cd4d2d71da2846073581b6e5c9a94eabf3d6f91b..bbb5df6c7ecbc338f244680b4bf441e0115963eb 100644 (file)
 #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;
index 98390c71ef0c089ff26395421455cc8da24517c5..8a8d00f1f5c356f5d3666d573522829e71cda5a7 100644 (file)
@@ -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_
index 282e8684f225e500947b08f6514bf947c03b6b3d..2f8393aabb08761994950dcec0e77c24aa01592c 100644 (file)
@@ -30,7 +30,7 @@
 class Pluto : public CelestialBody
 {
 public:
-  Pluto ( fgTIME t);
+  Pluto ( FGTime t);
 };
 
 #endif // _PLUTO_HXX_
index 6a8a43cbb9b097c359c63845914ac22cc8e9be28..10cce47d9d1fc4528061eb22daedcf2f46ea36a0 100644 (file)
 #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);
   
index 22bce6ccbb864b0471c90e57a939f08aaa592b47..4cf4d004e45bfce7d7b797d1ca05ce0b5b40f9c8 100644 (file)
@@ -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_
index 08917b4d12579116e020689158f026a084fb5df0..33bbe545600bc465b07370dda9c897b0d6f78165 100644 (file)
 /***************************************************************************
  * 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;
index 9b60c47bb8b84e5343a703644fd9bccd223db83f..fe713d07643484dd9199c6210eaf04190ef7146f 100644 (file)
@@ -60,7 +60,7 @@ private:
 
 
 public:
-  SolarSystem(fgTIME *t);
+  SolarSystem(FGTime *t);
   CelestialBody *getSun();
   CelestialBody *getMoon();
   ~SolarSystem();
index 4752093df34af3b032cfbd10ea969c6ee47c3c22..8fa7fa906523bd7aad3352d02d07bb1be0c19f46 100644 (file)
 #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  
   }
 }
-
-  
-  
-  
index 811c1f46f6f1191b348c2a869767a51a32645421..6eb7a4c901c56a95736bf35ef2fe21dd561253a0 100644 (file)
@@ -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();
index 7cabd43b4d523cfebb30330f8941aeea71801563..05bab930a52a6730a5597298df33f1fc767d5fac 100644 (file)
@@ -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
 
index b27d1b8d78cc3298da505e099f4bfbd26b2d3cbd..79a72c52f1ac23bf96fa1dd7541c39454a7e59f8 100644 (file)
@@ -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
index 4e0ae23130c8b96e0fbad3bc232d54244a06925e..c749a105aa4cae338cfeeb5d273e9e9d04f3a3e8 100644 (file)
 #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;
index 06f2d9fc8263c963a9bbf5f04b3533e94895dba8..ed55a144c4d7f7e6ee4ed7f9933cf8f63a8303f0 100644 (file)
@@ -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_
index e2254a41d5841dddf33bc95564d5ecca4b8154bd..95be711b8c9be401f72e7505660cc98086cae3fe 100644 (file)
 #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);
index 4fd2f648f971f0d5fc43f88c3652a4747066251d..ba498c84a45105d799ac9a1a875f884c671e752f 100644 (file)
@@ -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_
index 9f15e8f5304beaccaeb2452b0c0566b4db5a7564..cb766b74398503d3b34d7510e3195a90b14c3432 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/sh
 
-WINDOW=NO
+WINDOW=YES
 
 if [ $WINDOW = "YES" ]; then
     # in a window (slow hack)
index 51eccfa4e64baae1ed3db4aad3fc3b9787de1d05..ecab98f2eebcaf20387919a8e003b89dbb6d6b59 100644 (file)
@@ -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 = &current_view;
     w = &current_weather;
 
@@ -141,11 +141,11 @@ void GLUTkey(unsigned char k, int x, int y) {
            fgHUDInit2(&current_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(&current_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
index 9442b981af7278430e5f3e8d09d2c01e89fb548f..f50784ec49f8c2cfadd7494835ec51691724e782 100644 (file)
@@ -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 = &current_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 = &current_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);
 }
-
-
index 98c92ccd048673ca3735056a8be20ba44acdd812..7b88af0335152547aac738e703312af4be428dd6 100644 (file)
@@ -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 = &current_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);
 }
-
-
index 0433b995c2f136adcfd5b99c6236e0d2cb606d82..03dc8e864436b7229ce990a844c6df6522efd098 100644 (file)
@@ -231,23 +231,23 @@ static void send_nmea_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 every two seconds
-    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;
@@ -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() {
        }
     }
 }
-
-
index 16ec630d07bc5f67a4e0cfa8746ab02f6a81edaf..e57d1a590204df0ca0ae5116ee2440b4f949aab1 100644 (file)
 #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(&current);
-    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(&current);
+    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;
index 29f42d5528dd01e9b9091c96c6fd7809f39bedf2..96a151cdc178badc8131b5588d7bb3b0eaee40cf 100644 (file)
@@ -1,4 +1,3 @@
-//
 // fg_time.hxx -- data structures and routines for managing time related stuff.
 //
 // Written by Curtis Olson, started August 1997.
 
 
 // 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;
 
-#endif // _FG_TIME_HXX
+    // 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
index 4260fd61988dbb5cdf238572c3b6a2229b596407..92c3916c97bcf3014ce6821cfb620187b0459f7d 100644 (file)
@@ -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." );
 
index a4fcf49323cd4e88a5319cde9bcf0cc92d754a60..6379ccab3af4acb21c21d95c412f7a55f3d77c34 100644 (file)
@@ -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 = &current_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 );
index bb80822394bc167331743645d7dd2595debf2e5c..eb06ffd3023774ff629216176ee344ac25be4b0b 100644 (file)
@@ -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 = &current_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 );