From: david Date: Tue, 19 Feb 2002 01:26:44 +0000 (+0000) Subject: First steps in a weather reorganization. Note especially that X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=3b870192f4dbd3a9adb435f0cf9ca9591eb4f62e;p=flightgear.git First steps in a weather reorganization. Note especially that properties have been renamed from wind-(north|east|down)-fps to wind-from-(north|east|down)-fps, and the FDMs modified appropriately. No other changes should be visible unless FG_OLD_WEATHER is defined. --- diff --git a/src/ATC/atis.cxx b/src/ATC/atis.cxx index a5cd845ee..9a07ea52f 100644 --- a/src/ATC/atis.cxx +++ b/src/ATC/atis.cxx @@ -96,6 +96,7 @@ FGATIS::~FGATIS() { string FGATIS::get_transmission() { //void FGATIS::get_transmission() { +#if !defined(FG_OLD_WEATHER) string transmission = ""; double visibility; @@ -218,4 +219,7 @@ string FGATIS::get_transmission() { // } return(transmission); +#else + return "Station unavailable (not supported by FG_OLD_WEATHER)"; +#endif // FG_OLD_WEATHER } diff --git a/src/FDM/JSBSim.cxx b/src/FDM/JSBSim.cxx index f88072458..425109d46 100644 --- a/src/FDM/JSBSim.cxx +++ b/src/FDM/JSBSim.cxx @@ -326,9 +326,9 @@ bool FGJSBsim::copy_to_JSBsim() { Atmosphere->SetExTemperature(get_Static_temperature()); Atmosphere->SetExPressure(get_Static_pressure()); Atmosphere->SetExDensity(get_Density()); - Atmosphere->SetWindNED(get_V_north_airmass() * -1.0, - get_V_east_airmass() * -1.0, - get_V_down_airmass() * -1.0); + Atmosphere->SetWindNED(get_V_north_airmass(), + get_V_east_airmass(), + get_V_down_airmass()); // SG_LOG(SG_FLIGHT,SG_INFO, "Wind NED: " // << get_V_north_airmass() << ", " // << get_V_east_airmass() << ", " diff --git a/src/FDM/LaRCsim.cxx b/src/FDM/LaRCsim.cxx index 0cadfdd4c..9d70641cb 100644 --- a/src/FDM/LaRCsim.cxx +++ b/src/FDM/LaRCsim.cxx @@ -559,9 +559,9 @@ void FGLaRCsim::set_ls(void) { Latitude=lsic->GetLatitudeGDRadIC(); Longitude=lsic->GetLongitudeRadIC(); Runway_altitude=lsic->GetRunwayAltitudeFtIC(); - V_north_airmass = lsic->GetVnorthAirmassFpsIC(); - V_east_airmass = lsic->GetVeastAirmassFpsIC(); - V_down_airmass = lsic->GetVdownAirmassFpsIC(); + V_north_airmass = lsic->GetVnorthAirmassFpsIC() * -1; + V_east_airmass = lsic->GetVeastAirmassFpsIC() * -1; + V_down_airmass = lsic->GetVdownAirmassFpsIC() * -1; ls_loop(0.0,-1); copy_from_LaRCsim(); } diff --git a/src/FDM/UIUCModel/uiuc_wrapper.cpp b/src/FDM/UIUCModel/uiuc_wrapper.cpp index 87e1d11c1..099298e24 100644 --- a/src/FDM/UIUCModel/uiuc_wrapper.cpp +++ b/src/FDM/UIUCModel/uiuc_wrapper.cpp @@ -230,12 +230,12 @@ void uiuc_force_moment(double dt) vis *= 1.01; WeatherDatabase->setWeatherVisibility( vis ); #else - vis = current_weather->get_visibility(); + vis = current_weather.get_visibility_m(); if (Fog > 0) vis /= 1.01; else vis *= 1.01; - current_weather->set_visibility( vis ); + current_weather.set_visibility_m( vis ); #endif } diff --git a/src/FDM/YASim/YASim.cxx b/src/FDM/YASim/YASim.cxx index 166b56656..55c67366c 100644 --- a/src/FDM/YASim/YASim.cxx +++ b/src/FDM/YASim/YASim.cxx @@ -220,9 +220,9 @@ void YASim::copyToYASim(bool copyState) // Environment float wind[3]; - wind[0] = get_V_north_airmass() * FT2M; - wind[1] = get_V_east_airmass() * FT2M; - wind[2] = get_V_down_airmass() * FT2M; + wind[0] = get_V_north_airmass() * FT2M * -1.0; + wind[1] = get_V_east_airmass() * FT2M * -1.0; + wind[2] = get_V_down_airmass() * FT2M * -1.0; // The ground elevation doesn't come from FGInterface; query it // from the scenery and set it for others to find. diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index 631b3f2be..8dfac625c 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -805,7 +805,8 @@ bool fgInitSubsystems( void ) { global_events.Register( "weather update", fgUpdateWeatherDatabase, fgEVENT::FG_EVENT_READY, 30000); #else - current_weather.Init(); + current_weather.init(); + current_weather.bind(); #endif //////////////////////////////////////////////////////////////////// diff --git a/src/Main/fg_props.cxx b/src/Main/fg_props.cxx index f937887b8..816c5f543 100644 --- a/src/Main/fg_props.cxx +++ b/src/Main/fg_props.cxx @@ -37,7 +37,7 @@ # include #else # include -#endif +#endif // FG_OLD_WEATHER #include #include @@ -52,9 +52,11 @@ SG_USING_STD(istream); SG_USING_STD(ostream); #endif +#if !defined(FG_OLD_WEATHER) static double getWindNorth (); static double getWindEast (); static double getWindDown (); +#endif // FG_OLD_WEATHER // Allow the view to be set from two axes (i.e. a joystick hat) // This needs to be in FGViewer itself, somehow. @@ -888,17 +890,15 @@ setAPThrottleControl (double value) } +#if !defined(FG_OLD_WEATHER) + /** * Get the current visibility (meters). */ static double getVisibility () { -#ifndef FG_OLD_WEATHER return WeatherDatabase->getWeatherVisibility(); -#else - return current_weather.get_visibility(); -#endif } @@ -908,11 +908,7 @@ getVisibility () static void setVisibility (double visibility) { -#ifndef FG_OLD_WEATHER WeatherDatabase->setWeatherVisibility(visibility); -#else - current_weather.set_visibility(visibility); -#endif } /** @@ -980,6 +976,8 @@ setWindDown (double speed) speed); } +#endif // FG_OLD_WEATHER + static double getFOV () { @@ -1154,6 +1152,7 @@ fgInitProps () fgSetArchivable("/autopilot/control-overrides/throttle"); // Environment +#if !defined(FG_OLD_WEATHER) fgTie("/environment/visibility-m", getVisibility, setVisibility); fgSetArchivable("/environment/visibility-m"); fgTie("/environment/wind-north-fps", getWindNorth, setWindNorth); @@ -1162,6 +1161,7 @@ fgInitProps () fgSetArchivable("/environment/wind-east-fps"); fgTie("/environment/wind-down-fps", getWindDown, setWindDown); fgSetArchivable("/environment/wind-down-fps"); +#endif fgTie("/environment/magnetic-variation-deg", getMagVar); fgTie("/environment/magnetic-dip-deg", getMagDip); diff --git a/src/Main/main.cxx b/src/Main/main.cxx index fe96a00f7..f52d42a90 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -556,7 +556,7 @@ void fgRenderFrame( void ) { #ifndef FG_OLD_WEATHER thesky->set_visibility( WeatherDatabase->getWeatherVisibility() ); #else - thesky->set_visibility( current_weather.get_visibility() ); + thesky->set_visibility( current_weather.get_visibility_m() ); #endif thesky->modify_vis( cur_fdm_state->get_Altitude() * SG_FEET_TO_METER, @@ -1043,7 +1043,7 @@ static void fgMainLoop( void ) { #endif #ifdef FG_OLD_WEATHER - current_weather.Update(); + current_weather.update(0); // FIXME: use real delta time #endif // Fix elevation. I'm just sticking this here for now, it should diff --git a/src/Main/options.cxx b/src/Main/options.cxx index f2c9cbb5d..6ed75c849 100644 --- a/src/Main/options.cxx +++ b/src/Main/options.cxx @@ -904,13 +904,14 @@ parse_option (const string& arg) // convert to fps speed *= SG_NM_TO_METER * SG_METER_TO_FEET * (1.0/3600); - dir += 180; - if (dir >= 360) + while (dir > 360) dir -= 360; + while (dir <= 0) + dir += 360; dir *= SGD_DEGREES_TO_RADIANS; - fgSetDouble("/environment/wind-north-fps", + fgSetDouble("/environment/wind-from-north-fps", speed * cos(dir)); - fgSetDouble("/environment/wind-east-fps", + fgSetDouble("/environment/wind-from-east-fps", speed * sin(dir)); } else if ( arg.find( "--wp=" ) == 0 ) { parse_wp( arg.substr( 5 ) ); diff --git a/src/Scenery/tilemgr.cxx b/src/Scenery/tilemgr.cxx index 0238f3215..2b07a132f 100644 --- a/src/Scenery/tilemgr.cxx +++ b/src/Scenery/tilemgr.cxx @@ -175,7 +175,7 @@ void FGTileMgr::schedule_needed() { vis = 16000; } #else - vis = current_weather.get_visibility(); + vis = current_weather.get_visibility_m(); #endif // cout << "visibility = " << vis << endl; @@ -416,7 +416,7 @@ void FGTileMgr::prep_ssg_nodes() { vis = 16000; } #else - vis = current_weather.get_visibility(); + vis = current_weather.get_visibility_m(); #endif // cout << "visibility = " << vis << endl; diff --git a/src/Weather/weather.cxx b/src/Weather/weather.cxx index 178ab4134..b69951093 100644 --- a/src/Weather/weather.cxx +++ b/src/Weather/weather.cxx @@ -37,6 +37,7 @@ #include #include +#include
#include #include @@ -45,36 +46,142 @@ FGWeather current_weather; -FGWeather::FGWeather() { +FGWeather::FGWeather() + : visibility_m(32000), + wind_from_heading_deg(0), + wind_speed_kt(0), + wind_from_north_fps(0), + wind_from_east_fps(0), + wind_from_down_fps(0), + fog_exp_density(0), + fog_exp2_density(0) +{ } -FGWeather::~FGWeather() { +FGWeather::~FGWeather() +{ } // Initialize the weather modeling subsystem -void FGWeather::Init( ) { +void FGWeather::init () +{ SG_LOG( SG_GENERAL, SG_INFO, "Initializing weather subsystem"); +} + + +void +FGWeather::bind () +{ + fgTie("/environment/visibility-m", this, + &FGWeather::get_visibility_m, &FGWeather::set_visibility_m); + fgTie("/environment/wind-from-heading-deg", this, + &FGWeather::get_wind_from_heading_deg, + &FGWeather::set_wind_from_heading_deg); + fgTie("/environment/wind-speed-kt", this, + &FGWeather::get_wind_speed_kt, &FGWeather::set_wind_speed_kt); + fgTie("/environment/wind-from-north-fps", this, + &FGWeather::get_wind_from_north_fps, + &FGWeather::set_wind_from_north_fps); + fgTie("/environment/wind-from-east-fps", this, + &FGWeather::get_wind_from_east_fps, + &FGWeather::set_wind_from_east_fps); + fgTie("/environment/wind-from-down-fps", this, + &FGWeather::get_wind_from_down_fps, + &FGWeather::set_wind_from_down_fps); +} + +void +FGWeather::unbind () +{ + fgUntie("/environment/visibility-m"); + fgUntie("/environment/wind-from-heading-deg"); + fgUntie("/environment/wind-speed-kt"); + fgUntie("/environment/wind-from-north-fps"); + fgUntie("/environment/wind-from-east-fps"); + fgUntie("/environment/wind-from-down-fps"); +} + +void FGWeather::update (int dt) +{ + // FIXME: the FDMs should update themselves + current_aircraft.fdm_state + ->set_Velocities_Local_Airmass(wind_from_north_fps, + wind_from_east_fps, + wind_from_down_fps); +} + +void +FGWeather::set_visibility_m (double v) +{ + glMatrixMode(GL_MODELVIEW); + // in meters + visibility_m = v; + + // for GL_FOG_EXP + fog_exp_density = -log(0.01 / visibility_m); - // Configure some wind - // FG_V_north_airmass = 15; // ft/s =~ 10mph + // for GL_FOG_EXP2 + fog_exp2_density = sqrt( -log(0.01) ) / visibility_m; - // set_visibility( 45000.0 ); // in meters - set_visibility( 32000.0 ); // about 20 miles (in meters) + // Set correct opengl fog density + glFogf (GL_FOG_DENSITY, fog_exp2_density); + glFogi( GL_FOG_MODE, GL_EXP2 ); + + // SG_LOG( SG_INPUT, SG_DEBUG, "Fog density = " << fog_density ); + // SG_LOG( SG_INPUT, SG_INFO, + // "Fog exp2 density = " << fog_exp2_density ); +} + +void +FGWeather::set_wind_from_heading_deg (double h) +{ + wind_from_heading_deg = h; + _recalc_ne(); +} + +void +FGWeather::set_wind_speed_kt (double s) +{ + wind_speed_kt = s; + _recalc_ne(); } +void +FGWeather::set_wind_from_north_fps (double n) +{ + wind_from_north_fps = n; + _recalc_hdgspd(); +} -// Update the weather parameters for the current position -void FGWeather::Update( void ) { - FGInterface *f; +void +FGWeather::set_wind_from_east_fps (double e) +{ + wind_from_east_fps = e; + _recalc_hdgspd(); +} - f = current_aircraft.fdm_state; +void +FGWeather::set_wind_from_down_fps (double d) +{ + wind_from_down_fps = d; + _recalc_hdgspd(); +} + +void +FGWeather::_recalc_hdgspd () +{ + wind_from_heading_deg = acos(wind_from_north_fps / wind_speed_kt); + wind_speed_kt = asin(wind_from_north_fps / wind_speed_kt); +} - // Add some random turbulence - // f->set_U_gust( fg_random() * 5.0 - 2.5 ); - // f->set_V_gust( fg_random() * 5.0 - 2.5 ); - // f->set_W_gust( fg_random() * 5.0 - 2.5 ); +void +FGWeather::_recalc_ne () +{ + wind_from_north_fps = wind_speed_kt * cos(wind_from_heading_deg); + wind_from_east_fps = wind_speed_kt * sin(wind_from_heading_deg); } +// end of weather.cxx diff --git a/src/Weather/weather.hxx b/src/Weather/weather.hxx index c8728e854..34ee2d309 100644 --- a/src/Weather/weather.hxx +++ b/src/Weather/weather.hxx @@ -29,6 +29,8 @@ #include +#include
+ #ifdef SG_HAVE_STD_INCLUDES # include #else @@ -36,48 +38,61 @@ #endif // holds the current weather values -class FGWeather { - -private: - - double visibility; - GLfloat fog_exp_density; - GLfloat fog_exp2_density; +class FGWeather : public FGSubsystem +{ public: - FGWeather(); - ~FGWeather(); - - void Init(); - void Update(); + FGWeather(); + virtual ~FGWeather(); + + virtual void init (); + virtual void bind (); + virtual void unbind (); + virtual void update (int dt); - inline double get_visibility() const { return visibility; } + inline virtual double get_visibility_m () const { return visibility_m; } + inline virtual double get_wind_from_heading_deg () const { + return wind_from_heading_deg; + } + inline virtual double get_wind_speed_kt () const { return wind_speed_kt; } + inline virtual double get_wind_from_north_fps () const { + return wind_from_north_fps; + } + inline virtual double get_wind_from_east_fps () const { + return wind_from_east_fps; + } + inline virtual double get_wind_from_down_fps () const { + return wind_from_down_fps; + } + + virtual void set_visibility_m (double v); + virtual void set_wind_from_heading_deg (double h); + virtual void set_wind_speed_kt (double s); + virtual void set_wind_from_north_fps (double n); + virtual void set_wind_from_east_fps (double e); + virtual void set_wind_from_down_fps (double d); - inline void set_visibility( double v ) { - glMatrixMode(GL_MODELVIEW); - // in meters - visibility = v; +private: - // for GL_FOG_EXP - fog_exp_density = -log(0.01 / visibility); + void _recalc_hdgspd (); + void _recalc_ne (); - // for GL_FOG_EXP2 - fog_exp2_density = sqrt( -log(0.01) ) / visibility; + double visibility_m; - // Set correct opengl fog density - glFogf (GL_FOG_DENSITY, fog_exp2_density); - glFogi( GL_FOG_MODE, GL_EXP2 ); + double wind_from_heading_deg; + double wind_speed_kt; + + double wind_from_north_fps; + double wind_from_east_fps; + double wind_from_down_fps; + + // Do these belong here? + GLfloat fog_exp_density; + GLfloat fog_exp2_density; - // SG_LOG( SG_INPUT, SG_DEBUG, "Fog density = " << fog_density ); - // SG_LOG( SG_INPUT, SG_INFO, - // "Fog exp2 density = " << fog_exp2_density ); - } }; extern FGWeather current_weather; - #endif // _WEATHER_HXX - -