From 19d2b1a3142ffe7c015e60229014af0e22e9f06c Mon Sep 17 00:00:00 2001 From: curt Date: Wed, 29 Mar 2000 00:15:58 +0000 Subject: [PATCH] Updated for magvar calculations. --- src/Main/Makefile.am | 2 +- src/Main/bfi.cxx | 31 ++++++++++++++++++++++++++++++- src/Main/bfi.hxx | 4 ++++ src/Main/main.cxx | 6 ++++-- src/Time/fg_time.cxx | 10 +++++++++- src/Time/fg_time.hxx | 13 +++++++++++-- 6 files changed, 59 insertions(+), 7 deletions(-) diff --git a/src/Main/Makefile.am b/src/Main/Makefile.am index ac7427c7d..944092c7d 100644 --- a/src/Main/Makefile.am +++ b/src/Main/Makefile.am @@ -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) \ diff --git a/src/Main/bfi.cxx b/src/Main/bfi.cxx index daef36e0a..ee0e108e5 100644 --- a/src/Main/bfi.cxx +++ b/src/Main/bfi.cxx @@ -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) } + +//////////////////////////////////////////////////////////////////////// +// 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 + diff --git a/src/Main/bfi.hxx b/src/Main/bfi.hxx index 8828f7c85..ef514f0c2 100644 --- a/src/Main/bfi.hxx +++ b/src/Main/bfi.hxx @@ -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. diff --git a/src/Main/main.cxx b/src/Main/main.cxx index ab4e23e6a..cb7c9db54 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -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()) { diff --git a/src/Time/fg_time.cxx b/src/Time/fg_time.cxx index 9e93015cf..297c28f53 100644 --- a/src/Time/fg_time.cxx +++ b/src/Time/fg_time.cxx @@ -51,6 +51,7 @@ #include #include +#include #include #include @@ -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, diff --git a/src/Time/fg_time.hxx b/src/Time/fg_time.hxx index bc97a7bd1..467d3930c 100644 --- a/src/Time/fg_time.hxx +++ b/src/Time/fg_time.hxx @@ -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; } };