]> git.mxchange.org Git - flightgear.git/blobdiff - src/Time/fg_time.cxx
Start of code to load, manage, and query the navaid database.
[flightgear.git] / src / Time / fg_time.cxx
index daabe0e3ec0ebd014538acfc3a2e5791f6a184ad..297c28f53e8cc7a207ae4316c79cdd3bc3d8bf10 100644 (file)
 
 #include <simgear/constants.h>
 #include <simgear/debug/logstream.hxx>
+#include <simgear/magvar/magvar.hxx>
 #include <simgear/misc/fgpath.hxx>
 
-// #include <Astro/skydome.hxx>
-#include <Astro/solarsystem.hxx>
 #include <FDM/flight.hxx>
 #include <Main/options.hxx>
 #include <Time/light.hxx>
@@ -62,6 +61,8 @@
 #include "fg_time.hxx"
 #include "timezone.h"
 #include "lowleveltime.h"
+#include "moonpos.hxx"
+#include "sunpos.hxx"
 
 
 #define DEGHR(x)        ((x)/15.)
@@ -101,7 +102,7 @@ FGTime::~FGTime()
 void FGTime::updateLocal()
 {
   FGInterface* f;
-  f = current_aircraft.fdm_state;
+  f = cur_fdm_state;
   time_t currGMT;
   time_t aircraftLocalTime;
   GeoCoord location(RAD_TO_DEG * f->get_Latitude(),
@@ -122,8 +123,7 @@ void FGTime::updateLocal()
 
 // Initialize the time dependent variables (maybe I'll put this in the
 // constructor later)
-void FGTime::init(const FGInterface& f) 
-{
+void FGTime::init( double lon, double lat ) {
     FG_LOG( FG_EVENT, FG_INFO, "Initializing Time" );
     gst_diff = -9999.0;
     FG_LOG( FG_EVENT, FG_DEBUG, 
@@ -143,8 +143,7 @@ void FGTime::init(const FGInterface& f)
     // printf ("Current greenwich mean time = %24s", asctime(gmtime(&cur_time)));
     // printf ("Current local time          = %24s", asctime(localtime(&cur_time)));
     // time_t tmp = cur_time;
-    GeoCoord location(RAD_TO_DEG * f.get_Latitude(), 
-                     RAD_TO_DEG * f.get_Longitude());
+    GeoCoord location( RAD_TO_DEG * lat, RAD_TO_DEG * lon );
 
     GeoCoord* nearestTz = tzContainer->getNearest(location);
 
@@ -338,8 +337,7 @@ double FGTime::sidereal_course(double lng)
 
 
 // Update time variables such as gmt, julian date, and sidereal time
-void FGTime::update(const FGInterface& f) 
-{
+void FGTime::update( double lon, double lat, double alt_m ) {
     double gst_precise, gst_course;
 
     FG_LOG( FG_EVENT, FG_DEBUG, "Updating time" );
@@ -390,17 +388,24 @@ void FGTime::update(const FGInterface& f)
       
        gst_diff = gst_precise - gst_course;
 
-       lst = sidereal_course(-(f.get_Longitude() * RAD_TO_DEG)) + gst_diff;
+       lst = sidereal_course(-(lon * 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;
+       gst = sidereal_course( 0.00 ) + gst_diff;
+       lst = sidereal_course( -(lon * RAD_TO_DEG)) + gst_diff;
     }
+
+    // Calculate local magnetic variation
+    double field[6];
+    // cout << "alt_m = " << alt_m << endl;
+    magvar = SGMagVar( lat, lon, alt_m / 1000.0, jd, field );
+    magdip = atan(field[5]/pow(field[3]*field[3]+field[4]*field[4],0.5));
+
     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)) 
+           << sidereal_precise(-(lon * RAD_TO_DEG)) 
            << ") (diff = " << gst_diff << ")" );
 }
 
@@ -531,12 +536,9 @@ char* FGTime::format_time( const struct tm* p, char* buf )
 
 // Force an update of the sky and lighting parameters
 void FGTime::local_update_sky_and_lighting_params( void ) {
-    // fgSunInit();
-    SolarSystem::theSolarSystem->rebuild();
+    fgUpdateSunPos();
+    fgUpdateMoonPos();
     cur_light_params.Update();
-    /* current_sky.repaint( cur_light_params.sky_color,
-                        cur_light_params.fog_color,
-                        cur_light_params.sun_angle ); */
 }