]> git.mxchange.org Git - flightgear.git/commitdiff
Updated for magvar calculations.
authorcurt <curt>
Wed, 29 Mar 2000 00:15:58 +0000 (00:15 +0000)
committercurt <curt>
Wed, 29 Mar 2000 00:15:58 +0000 (00:15 +0000)
src/Main/Makefile.am
src/Main/bfi.cxx
src/Main/bfi.hxx
src/Main/main.cxx
src/Time/fg_time.cxx
src/Time/fg_time.hxx

index ac7427c7d4167a0b6123d289073637d8b5365b1d..944092c7d815a8ba6891a9fa7d33b2c20a2f3781 100644 (file)
@@ -66,7 +66,7 @@ fgfs_LDADD = \
        $(top_builddir)/src/Sky/libSky.a \
        $(top_builddir)/src/Joystick/libJoystick.a \
        $(SERIAL_LIBS) \
-       -lsgscreen -lsgmath -lsgbucket -lsgdebug -lsgmisc \
+       -lsgscreen -lsgmath -lsgbucket -lsgdebug -lsgmagvar -lsgmisc \
        -lplibpu -lplibfnt -lplibssg -lplibsg \
        -lz \
        $(opengl_LIBS) \
index daef36e0a67c765b1f21464fa134586ebd6f0f71..ee0e108e5d77eb74156f736c565576ece4ce1500 100644 (file)
@@ -198,7 +198,10 @@ FGBFI::setTimeGMT (time_t time)
   current_options.set_time_offset_type(fgOPTIONS::FG_TIME_GMT_ABSOLUTE);
   FGTime::cur_time_params->init( cur_fdm_state->get_Longitude(),
                                 cur_fdm_state->get_Latitude() );
-  FGTime::cur_time_params->update( cur_fdm_state->get_Longitude() );
+  FGTime::cur_time_params->update( cur_fdm_state->get_Longitude(),
+                                  cur_fdm_state->get_Latitude(),
+                                  cur_fdm_state->get_Altitude()
+                                  * FEET_TO_METER );
   needReinit();
 }
 
@@ -848,4 +851,30 @@ FGBFI::setVisibility (double visibility)
 }
 
 
+\f
+////////////////////////////////////////////////////////////////////////
+// Time
+////////////////////////////////////////////////////////////////////////
+
+/**
+ * Return the magnetic variation
+ */
+double
+FGBFI::getMagVar ()
+{
+  return FGTime::cur_time_params->getMagVar() * RAD_TO_DEG;
+}
+
+
+/**
+ * Return the magnetic variation
+ */
+double
+FGBFI::getMagDip ()
+{
+  return FGTime::cur_time_params->getMagDip() * RAD_TO_DEG;
+}
+
+
 // end of bfi.cxx
+
index 8828f7c855a278ee993c7af5bf1812fc1635b9de..ef514f0c2d5a22d9ec8ee12b82d21ef0d27c86dd 100644 (file)
@@ -139,6 +139,10 @@ public:
 
   static void setVisibility (double visiblity);
 
+                                // Time (this varies with time) huh, huh
+  static double getMagVar (); 
+  static double getMagDip (); 
+
 
 private:
                                // Will cause a linking error if invoked.
index ab4e23e6a005885684775f9316775b3bf697ecb9..cb7c9db5430c39ffd5c46db5755e891eeddc6af0 100644 (file)
@@ -830,7 +830,9 @@ static void fgMainLoop( void ) {
           cur_fdm_state->get_Altitude() * FEET_TO_METER); */
 
     // update "time"
-    t->update( cur_fdm_state->get_Longitude() );
+    t->update( cur_fdm_state->get_Longitude(),
+              cur_fdm_state->get_Latitude(),
+              cur_fdm_state->get_Altitude()* FEET_TO_METER );
 
     // Get elapsed time (in usec) for this past frame
     elapsed = fgGetTimeInterval();
@@ -1332,7 +1334,7 @@ int main( int argc, char **argv ) {
     //                                cur_fdm_state->get_Latitude() );
     // FGTime::cur_time_params->update( cur_fdm_state->get_Longitude() );
     FGTime::cur_time_params->init( 0.0, 0.0 );
-    FGTime::cur_time_params->update( 0.0 );
+    FGTime::cur_time_params->update( 0.0, 0.0, 0.0 );
 
     // Do some quick general initializations
     if( !fgInitGeneral()) {
index 9e93015cf898d5be4636432305d7906e0b577d45..297c28f53e8cc7a207ae4316c79cdd3bc3d8bf10 100644 (file)
@@ -51,6 +51,7 @@
 
 #include <simgear/constants.h>
 #include <simgear/debug/logstream.hxx>
+#include <simgear/magvar/magvar.hxx>
 #include <simgear/misc/fgpath.hxx>
 
 #include <FDM/flight.hxx>
@@ -336,7 +337,7 @@ double FGTime::sidereal_course(double lng)
 
 
 // Update time variables such as gmt, julian date, and sidereal time
-void FGTime::update( double lon ) {
+void FGTime::update( double lon, double lat, double alt_m ) {
     double gst_precise, gst_course;
 
     FG_LOG( FG_EVENT, FG_DEBUG, "Updating time" );
@@ -393,6 +394,13 @@ void FGTime::update( double lon ) {
        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,
index bc97a7bd18f6d33cc4691484e6e6e3b0054e48c4..467d3930c28d4866929d81e4adc417637f679ce8 100644 (file)
@@ -102,7 +102,11 @@ private:
 
     // Paused?
     bool pause;
-                                     
+
+    // Local magnetic variation and dip in radians
+    double magvar;
+    double magdip;
+
     void local_update_sky_and_lighting_params( void );
 
 public:
@@ -110,6 +114,7 @@ public:
     FGTime();
     ~FGTime();
 
+    inline double getJD() const { return jd; };
     inline double getMjd() const { return mjd; };
     inline double getLst() const { return lst; };
     inline double getGst() const { return gst; };
@@ -125,7 +130,7 @@ public:
     void init( double lon, double lat );
 
     // Update the time dependent variables
-    void update( double lon );
+    void update( double lon, double lat, double alt_m );
     void updateLocal();
 
     void cal_mjd (int mn, double dy, int yr);
@@ -143,6 +148,10 @@ public:
   
     char* format_time( const struct tm* p, char* buf );
     long int fix_up_timezone( long int timezone_orig );
+
+    // Return magnetic variations
+    double getMagVar() const { return magvar; }
+    double getMagDip() const { return magdip; }
 };