diff --git a/src/Environment/environment.cxx b/src/Environment/environment.cxx index a1285b80d..f4d21407b 100644 --- a/src/Environment/environment.cxx +++ b/src/Environment/environment.cxx @@ -128,10 +128,13 @@ FGEnvironment::FGEnvironment() wind_speed_kt(0), wind_from_north_fps(0), wind_from_east_fps(0), - wind_from_down_fps(0) + wind_from_down_fps(0), + altitude_half_to_sun_m(1000), + altitude_tropo_top_m(10000) { _setup_tables(); _recalc_density(); + _recalc_relative_humidity(); } FGEnvironment::FGEnvironment (const FGEnvironment &env) @@ -271,6 +274,30 @@ FGEnvironment::get_density_slugft3 () const return density_slugft3; } +double +FGEnvironment::get_relative_humidity () const +{ + return relative_humidity; +} + +double +FGEnvironment::get_density_tropo_avg_kgm3 () const +{ + return density_tropo_avg_kgm3; +} + +double +FGEnvironment::get_altitude_half_to_sun_m () const +{ + return altitude_half_to_sun_m; +} + +double +FGEnvironment::get_altitude_tropo_top_m () const +{ + return altitude_tropo_top_m; +} + double FGEnvironment::get_wind_from_heading_deg () const { @@ -344,6 +371,7 @@ FGEnvironment::set_temperature_degc (double t) temperature_degc = t; _recalc_sl_temperature(); _recalc_density(); + _recalc_relative_humidity(); } void @@ -362,6 +390,7 @@ FGEnvironment::set_dewpoint_degc (double t) dewpoint_degc = t; _recalc_sl_dewpoint(); _recalc_density(); + _recalc_relative_humidity(); } void @@ -435,8 +464,24 @@ FGEnvironment::set_elevation_ft (double e) _recalc_alt_dewpoint(); _recalc_alt_pressure(); _recalc_density(); + _recalc_relative_humidity(); } +void +FGEnvironment::set_altitude_half_to_sun_m (double alt) +{ + altitude_half_to_sun_m = alt; + _recalc_density_tropo_avg_kgm3(); +} + +void +FGEnvironment::set_altitude_tropo_top_m (double alt) +{ + altitude_tropo_top_m = alt; + _recalc_density_tropo_avg_kgm3(); +} + + void FGEnvironment::_recalc_hdgspd () { @@ -558,10 +603,35 @@ FGEnvironment::_recalc_density () double virtual_temperature_degr = virtual_temperature_degk * 1.8; density_slugft3 = pressure_psf / (virtual_temperature_degr * 1718); + _recalc_density_tropo_avg_kgm3(); +} + +// This is used to calculate the average density on the path +// of sunlight to the observer for calculating sun-color +void +FGEnvironment::_recalc_density_tropo_avg_kgm3 () +{ + double pressure_mb = pressure_inhg * 33.86; + double vaporpressure = 6.11 * pow ( 10, ((7.5 * dewpoint_degc) /( 237.7 + dewpoint_degc))); + + double virtual_temp = (temperature_degc + 273.15) / (1 - 0.379 * (vaporpressure/pressure_mb)); + + double density_half = (100* pressure_mb * exp (-altitude_half_to_sun_m / 8000)) / (287.05 * virtual_temp); + double density_tropo = (100* pressure_mb * exp ((-1 * altitude_tropo_top_m) / 8000)) /( 287.05 * virtual_temp); + + density_tropo_avg_kgm3 = ((density_slugft3 * 515.379) + density_half + density_tropo) / 3; +} + +void +FGEnvironment::_recalc_relative_humidity () +{ + double vaporpressure = 6.11 * pow ( 10, ((7.5 * dewpoint_degc) /( 237.7 + dewpoint_degc))); + double sat_vaporpressure = 6.11 * pow ( 10, ((7.5 * temperature_degc) /( 237.7 + temperature_degc)) ); + relative_humidity = 100 *vaporpressure / sat_vaporpressure ; } - + //////////////////////////////////////////////////////////////////////// // Functions. //////////////////////////////////////////////////////////////////////// diff --git a/src/Environment/environment.hxx b/src/Environment/environment.hxx index 11eccd91b..c3794f901 100644 --- a/src/Environment/environment.hxx +++ b/src/Environment/environment.hxx @@ -65,6 +65,11 @@ public: virtual double get_pressure_inhg () const; virtual double get_density_slugft3 () const; + virtual double get_relative_humidity () const; + virtual double get_density_tropo_avg_kgm3 () const; + virtual double get_altitude_half_to_sun_m () const; + virtual double get_altitude_tropo_top_m () const; + virtual double get_wind_from_heading_deg () const; virtual double get_wind_speed_kt () const; virtual double get_wind_from_north_fps () const; @@ -94,6 +99,8 @@ public: virtual double get_elevation_ft () const; virtual void set_elevation_ft (double elevation_ft); + virtual void set_altitude_half_to_sun_m (double alt); + virtual void set_altitude_tropo_top_m (double alt); private: @@ -108,11 +115,13 @@ private: void _recalc_alt_pressure (); void _recalc_density (); - double elevation_ft; + void _recalc_density_tropo_avg_kgm3 (); + void _recalc_relative_humidity (); + double elevation_ft; double visibility_m; - // Atmosphere + // Atmosphere double temperature_sea_level_degc; double temperature_degc; double dewpoint_sea_level_degc; @@ -121,6 +130,11 @@ private: double pressure_inhg; double density_slugft3; + double density_tropo_avg_kgm3; + double relative_humidity; + double altitude_half_to_sun_m; + double altitude_tropo_top_m; + double turbulence_magnitude_norm; double turbulence_rate_hz; diff --git a/src/Environment/environment_mgr.cxx b/src/Environment/environment_mgr.cxx index c0d7ae5f9..6cae314fa 100644 --- a/src/Environment/environment_mgr.cxx +++ b/src/Environment/environment_mgr.cxx @@ -108,6 +108,16 @@ FGEnvironmentMgr::bind () &FGEnvironment::get_pressure_inhg); // FIXME: read-only for now fgTie("/environment/density-slugft3", _environment, &FGEnvironment::get_density_slugft3); // read-only + fgTie("/environment/relative-humidity", _environment, + &FGEnvironment::get_relative_humidity); //ro + fgTie("/environment/atmosphere/density-tropo-avg", _environment, + &FGEnvironment::get_density_tropo_avg_kgm3); //ro + fgTie("/environment/atmosphere/altitude-half-to-sun", _environment, + &FGEnvironment::get_altitude_half_to_sun_m, + &FGEnvironment::set_altitude_half_to_sun_m); + fgTie("/environment/atmosphere/altitude-troposphere-top", _environment, + &FGEnvironment::get_altitude_tropo_top_m, + &FGEnvironment::set_altitude_tropo_top_m); fgTie("/environment/wind-from-heading-deg", _environment, &FGEnvironment::get_wind_from_heading_deg, &FGEnvironment::set_wind_from_heading_deg); @@ -203,9 +213,13 @@ FGEnvironmentMgr::unbind () fgUntie("/environment/pressure-sea-level-inhg"); fgUntie("/environment/pressure-inhg"); fgUntie("/environment/density-inhg"); + fgUntie("/environment/relative_humidity"); + fgUntie("/environment/atmosphere/density_tropo_avg"); fgUntie("/environment/wind-from-north-fps"); fgUntie("/environment/wind-from-east-fps"); fgUntie("/environment/wind-from-down-fps"); + fgUntie("/environment/atmosphere/altitude_half_to_sun"); + fgUntie("/environment/atmosphere/altitude_troposphere_top"); for (int i = 0; i < MAX_CLOUD_LAYERS; i++) { char buf[128]; sprintf(buf, "/environment/clouds/layer[%d]/span-m", i); diff --git a/src/Main/main.cxx b/src/Main/main.cxx index efb3d275a..811747540 100644 --- a/src/Main/main.cxx +++ b/src/Main/main.cxx @@ -808,7 +808,8 @@ static void fgIdleFunction ( void ) { globals->get_ephem()->getNumPlanets(), globals->get_ephem()->getPlanets(), globals->get_ephem()->getNumStars(), - globals->get_ephem()->getStars() ); + globals->get_ephem()->getStars(), + fgGetNode("/environment", true)); // Initialize MagVar model SGMagVar *magvar = new SGMagVar(); diff --git a/src/Main/renderer.cxx b/src/Main/renderer.cxx index 9c46e832c..2d1cd2a63 100644 --- a/src/Main/renderer.cxx +++ b/src/Main/renderer.cxx @@ -362,65 +362,17 @@ FGRenderer::update( bool refresh_camera_settings ) { // update the sky dome if ( skyblend ) { - /* - SG_LOG( SG_GENERAL, SG_BULK, "thesky->repaint() sky_color = " - << l->sky_color()[0] << " " - << l->sky_color()[1] << " " - << l->sky_color()[2] << " " - << l->sky_color()[3] ); - SG_LOG( SG_GENERAL, SG_BULK, " fog = " - << l->fog_color()[0] << " " - << l->fog_color()[1] << " " - << l->fog_color()[2] << " " - << l->fog_color()[3] ); - SG_LOG( SG_GENERAL, SG_BULK, - " sun_angle = " << l->sun_angle - << " moon_angle = " << l->moon_angle ); - */ - - static SGSkyColor scolor; -// FGLight *l = (FGLight *)(globals->get_subsystem("lighting")); - - scolor.sky_color = l->sky_color(); - scolor.fog_color = l->adj_fog_color(); - scolor.cloud_color = l->cloud_color(); - scolor.sun_angle = l->get_sun_angle(); - scolor.moon_angle = l->get_moon_angle(); - scolor.nplanets = globals->get_ephem()->getNumPlanets(); - scolor.nstars = globals->get_ephem()->getNumStars(); - scolor.planet_data = globals->get_ephem()->getPlanets(); - scolor.star_data = globals->get_ephem()->getStars(); - - thesky->repaint( scolor ); - - /* - SG_LOG( SG_GENERAL, SG_BULK, - "thesky->reposition( view_pos = " << view_pos[0] << " " - << view_pos[1] << " " << view_pos[2] ); - SG_LOG( SG_GENERAL, SG_BULK, - " zero_elev = " << zero_elev[0] << " " - << zero_elev[1] << " " << zero_elev[2] - << " lon = " << cur_fdm_state->get_Longitude() - << " lat = " << cur_fdm_state->get_Latitude() ); - SG_LOG( SG_GENERAL, SG_BULK, - " sun_rot = " << l->get_sun_rotation - << " gst = " << SGTime::cur_time_params->getGst() ); - SG_LOG( SG_GENERAL, SG_BULK, - " sun ra = " << globals->get_ephem()->getSunRightAscension() - << " sun dec = " << globals->get_ephem()->getSunDeclination() - << " moon ra = " << globals->get_ephem()->getMoonRightAscension() - << " moon dec = " << globals->get_ephem()->getMoonDeclination() ); - */ // The sun and moon distances are scaled down versions // of the actual distance to get both the moon and the sun // within the range of the far clip plane. // Moon distance: 384,467 kilometers // Sun distance: 150,000,000 kilometers + double sun_horiz_eff, moon_horiz_eff; if (fgGetBool("/sim/rendering/horizon-effect")) { - sun_horiz_eff = 0.67+pow(0.5+cos(l->get_sun_angle())*2/2, 0.33)/3; - moon_horiz_eff = 0.67+pow(0.5+cos(l->get_moon_angle())*2/2, 0.33)/3; + sun_horiz_eff = 0.67+pow(0.5+cos(l->get_sun_angle())*2/2, 0.33)/3; + moon_horiz_eff = 0.67+pow(0.5+cos(l->get_moon_angle())*2/2, 0.33)/3; } else { sun_horiz_eff = moon_horiz_eff = 1.0; } @@ -444,16 +396,68 @@ FGRenderer::update( bool refresh_camera_settings ) { sstate.moon_ra = globals->get_ephem()->getMoonRightAscension(); sstate.moon_dec = globals->get_ephem()->getMoonDeclination(); sstate.moon_dist = 40000.0 * moon_horiz_eff; + sstate.sun_angle = l->get_sun_angle(); + + + /* + SG_LOG( SG_GENERAL, SG_BULK, "thesky->repaint() sky_color = " + << l->sky_color()[0] << " " + << l->sky_color()[1] << " " + << l->sky_color()[2] << " " + << l->sky_color()[3] ); + SG_LOG( SG_GENERAL, SG_BULK, " fog = " + << l->fog_color()[0] << " " + << l->fog_color()[1] << " " + << l->fog_color()[2] << " " + << l->fog_color()[3] ); + SG_LOG( SG_GENERAL, SG_BULK, + " sun_angle = " << l->sun_angle + << " moon_angle = " << l->moon_angle ); + */ + + static SGSkyColor scolor; +// FGLight *l = (FGLight *)(globals->get_subsystem("lighting")); + + scolor.sky_color = l->sky_color(); + scolor.fog_color = l->adj_fog_color(); + scolor.cloud_color = l->cloud_color(); + scolor.sun_angle = l->get_sun_angle(); + scolor.moon_angle = l->get_moon_angle(); + scolor.nplanets = globals->get_ephem()->getNumPlanets(); + scolor.nstars = globals->get_ephem()->getNumStars(); + scolor.planet_data = globals->get_ephem()->getPlanets(); + scolor.star_data = globals->get_ephem()->getStars(); thesky->reposition( sstate, delta_time_sec ); + thesky->repaint( scolor ); - shadows->setupShadows( + /* + SG_LOG( SG_GENERAL, SG_BULK, + "thesky->reposition( view_pos = " << view_pos[0] << " " + << view_pos[1] << " " << view_pos[2] ); + SG_LOG( SG_GENERAL, SG_BULK, + " zero_elev = " << zero_elev[0] << " " + << zero_elev[1] << " " << zero_elev[2] + << " lon = " << cur_fdm_state->get_Longitude() + << " lat = " << cur_fdm_state->get_Latitude() ); + SG_LOG( SG_GENERAL, SG_BULK, + " sun_rot = " << l->get_sun_rotation + << " gst = " << SGTime::cur_time_params->getGst() ); + SG_LOG( SG_GENERAL, SG_BULK, + " sun ra = " << globals->get_ephem()->getSunRightAscension() + << " sun dec = " << globals->get_ephem()->getSunDeclination() + << " moon ra = " << globals->get_ephem()->getMoonRightAscension() + << " moon dec = " << globals->get_ephem()->getMoonDeclination() ); + */ + + shadows->setupShadows( current__view->getLongitude_deg(), current__view->getLatitude_deg(), globals->get_time_params()->getGst(), globals->get_ephem()->getSunRightAscension(), globals->get_ephem()->getSunDeclination(), l->get_sun_angle()); + } glEnable( GL_DEPTH_TEST );