1
0
Fork 0

Mark's dynamic sun color changes.

This commit is contained in:
durk 2006-07-27 05:16:06 +00:00
parent f30f4b866b
commit a69dfbbc9a
5 changed files with 160 additions and 57 deletions

View file

@ -128,10 +128,13 @@ FGEnvironment::FGEnvironment()
wind_speed_kt(0), wind_speed_kt(0),
wind_from_north_fps(0), wind_from_north_fps(0),
wind_from_east_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(); _setup_tables();
_recalc_density(); _recalc_density();
_recalc_relative_humidity();
} }
FGEnvironment::FGEnvironment (const FGEnvironment &env) FGEnvironment::FGEnvironment (const FGEnvironment &env)
@ -271,6 +274,30 @@ FGEnvironment::get_density_slugft3 () const
return density_slugft3; 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 double
FGEnvironment::get_wind_from_heading_deg () const FGEnvironment::get_wind_from_heading_deg () const
{ {
@ -344,6 +371,7 @@ FGEnvironment::set_temperature_degc (double t)
temperature_degc = t; temperature_degc = t;
_recalc_sl_temperature(); _recalc_sl_temperature();
_recalc_density(); _recalc_density();
_recalc_relative_humidity();
} }
void void
@ -362,6 +390,7 @@ FGEnvironment::set_dewpoint_degc (double t)
dewpoint_degc = t; dewpoint_degc = t;
_recalc_sl_dewpoint(); _recalc_sl_dewpoint();
_recalc_density(); _recalc_density();
_recalc_relative_humidity();
} }
void void
@ -435,8 +464,24 @@ FGEnvironment::set_elevation_ft (double e)
_recalc_alt_dewpoint(); _recalc_alt_dewpoint();
_recalc_alt_pressure(); _recalc_alt_pressure();
_recalc_density(); _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 void
FGEnvironment::_recalc_hdgspd () FGEnvironment::_recalc_hdgspd ()
{ {
@ -558,10 +603,35 @@ FGEnvironment::_recalc_density ()
double virtual_temperature_degr = virtual_temperature_degk * 1.8; double virtual_temperature_degr = virtual_temperature_degk * 1.8;
density_slugft3 = pressure_psf / (virtual_temperature_degr * 1718); 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. // Functions.
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////

View file

@ -65,6 +65,11 @@ public:
virtual double get_pressure_inhg () const; virtual double get_pressure_inhg () const;
virtual double get_density_slugft3 () 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_from_heading_deg () const;
virtual double get_wind_speed_kt () const; virtual double get_wind_speed_kt () const;
virtual double get_wind_from_north_fps () const; virtual double get_wind_from_north_fps () const;
@ -94,6 +99,8 @@ public:
virtual double get_elevation_ft () const; virtual double get_elevation_ft () const;
virtual void set_elevation_ft (double elevation_ft); 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: private:
@ -108,11 +115,13 @@ private:
void _recalc_alt_pressure (); void _recalc_alt_pressure ();
void _recalc_density (); void _recalc_density ();
double elevation_ft; void _recalc_density_tropo_avg_kgm3 ();
void _recalc_relative_humidity ();
double elevation_ft;
double visibility_m; double visibility_m;
// Atmosphere // Atmosphere
double temperature_sea_level_degc; double temperature_sea_level_degc;
double temperature_degc; double temperature_degc;
double dewpoint_sea_level_degc; double dewpoint_sea_level_degc;
@ -121,6 +130,11 @@ private:
double pressure_inhg; double pressure_inhg;
double density_slugft3; 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_magnitude_norm;
double turbulence_rate_hz; double turbulence_rate_hz;

View file

@ -108,6 +108,16 @@ FGEnvironmentMgr::bind ()
&FGEnvironment::get_pressure_inhg); // FIXME: read-only for now &FGEnvironment::get_pressure_inhg); // FIXME: read-only for now
fgTie("/environment/density-slugft3", _environment, fgTie("/environment/density-slugft3", _environment,
&FGEnvironment::get_density_slugft3); // read-only &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, fgTie("/environment/wind-from-heading-deg", _environment,
&FGEnvironment::get_wind_from_heading_deg, &FGEnvironment::get_wind_from_heading_deg,
&FGEnvironment::set_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-sea-level-inhg");
fgUntie("/environment/pressure-inhg"); fgUntie("/environment/pressure-inhg");
fgUntie("/environment/density-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-north-fps");
fgUntie("/environment/wind-from-east-fps"); fgUntie("/environment/wind-from-east-fps");
fgUntie("/environment/wind-from-down-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++) { for (int i = 0; i < MAX_CLOUD_LAYERS; i++) {
char buf[128]; char buf[128];
sprintf(buf, "/environment/clouds/layer[%d]/span-m", i); sprintf(buf, "/environment/clouds/layer[%d]/span-m", i);

View file

@ -808,7 +808,8 @@ static void fgIdleFunction ( void ) {
globals->get_ephem()->getNumPlanets(), globals->get_ephem()->getNumPlanets(),
globals->get_ephem()->getPlanets(), globals->get_ephem()->getPlanets(),
globals->get_ephem()->getNumStars(), globals->get_ephem()->getNumStars(),
globals->get_ephem()->getStars() ); globals->get_ephem()->getStars(),
fgGetNode("/environment", true));
// Initialize MagVar model // Initialize MagVar model
SGMagVar *magvar = new SGMagVar(); SGMagVar *magvar = new SGMagVar();

View file

@ -362,6 +362,43 @@ FGRenderer::update( bool refresh_camera_settings ) {
// update the sky dome // update the sky dome
if ( skyblend ) { if ( skyblend ) {
// 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;
} else {
sun_horiz_eff = moon_horiz_eff = 1.0;
}
static SGSkyState sstate;
sstate.view_pos = current__view->get_view_pos();
sstate.zero_elev = current__view->get_zero_elev();
sstate.view_up = current__view->get_world_up();
sstate.lon = current__view->getLongitude_deg()
* SGD_DEGREES_TO_RADIANS;
sstate.lat = current__view->getLatitude_deg()
* SGD_DEGREES_TO_RADIANS;
sstate.alt = current__view->getAltitudeASL_ft()
* SG_FEET_TO_METER;
sstate.spin = l->get_sun_rotation();
sstate.gst = globals->get_time_params()->getGst();
sstate.sun_ra = globals->get_ephem()->getSunRightAscension();
sstate.sun_dec = globals->get_ephem()->getSunDeclination();
sstate.sun_dist = 50000.0 * sun_horiz_eff;
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 = " SG_LOG( SG_GENERAL, SG_BULK, "thesky->repaint() sky_color = "
<< l->sky_color()[0] << " " << l->sky_color()[0] << " "
@ -391,6 +428,7 @@ FGRenderer::update( bool refresh_camera_settings ) {
scolor.planet_data = globals->get_ephem()->getPlanets(); scolor.planet_data = globals->get_ephem()->getPlanets();
scolor.star_data = globals->get_ephem()->getStars(); scolor.star_data = globals->get_ephem()->getStars();
thesky->reposition( sstate, delta_time_sec );
thesky->repaint( scolor ); thesky->repaint( scolor );
/* /*
@ -412,41 +450,6 @@ FGRenderer::update( bool refresh_camera_settings ) {
<< " moon dec = " << globals->get_ephem()->getMoonDeclination() ); << " 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;
} else {
sun_horiz_eff = moon_horiz_eff = 1.0;
}
static SGSkyState sstate;
sstate.view_pos = current__view->get_view_pos();
sstate.zero_elev = current__view->get_zero_elev();
sstate.view_up = current__view->get_world_up();
sstate.lon = current__view->getLongitude_deg()
* SGD_DEGREES_TO_RADIANS;
sstate.lat = current__view->getLatitude_deg()
* SGD_DEGREES_TO_RADIANS;
sstate.alt = current__view->getAltitudeASL_ft()
* SG_FEET_TO_METER;
sstate.spin = l->get_sun_rotation();
sstate.gst = globals->get_time_params()->getGst();
sstate.sun_ra = globals->get_ephem()->getSunRightAscension();
sstate.sun_dec = globals->get_ephem()->getSunDeclination();
sstate.sun_dist = 50000.0 * sun_horiz_eff;
sstate.moon_ra = globals->get_ephem()->getMoonRightAscension();
sstate.moon_dec = globals->get_ephem()->getMoonDeclination();
sstate.moon_dist = 40000.0 * moon_horiz_eff;
thesky->reposition( sstate, delta_time_sec );
shadows->setupShadows( shadows->setupShadows(
current__view->getLongitude_deg(), current__view->getLongitude_deg(),
current__view->getLatitude_deg(), current__view->getLatitude_deg(),
@ -454,6 +457,7 @@ FGRenderer::update( bool refresh_camera_settings ) {
globals->get_ephem()->getSunRightAscension(), globals->get_ephem()->getSunRightAscension(),
globals->get_ephem()->getSunDeclination(), globals->get_ephem()->getSunDeclination(),
l->get_sun_angle()); l->get_sun_angle());
} }
glEnable( GL_DEPTH_TEST ); glEnable( GL_DEPTH_TEST );