object rather than a pointer.
FGEnvironment now has the beginning of an atmospheric model, and will
recalculate temperature (not pressure or density, yet) based on
elevation.
FGEnvironment has a copy constructor.
{
}
+FGEnvironment::FGEnvironment (const FGEnvironment &env)
+ : elevation_ft(env.elevation_ft),
+ visibility_m(env.visibility_m),
+ temperature_sea_level_degc(env.temperature_sea_level_degc),
+ pressure_sea_level_inhg(env.pressure_sea_level_inhg),
+ wind_from_heading_deg(env.wind_from_heading_deg),
+ wind_speed_kt(env.wind_speed_kt),
+ wind_from_north_fps(env.wind_from_north_fps),
+ wind_from_east_fps(env.wind_from_east_fps),
+ wind_from_down_fps(env.wind_from_down_fps)
+{
+}
FGEnvironment::~FGEnvironment()
{
return temperature_sea_level_degc;
}
+double
+FGEnvironment::get_temperature_degc () const
+{
+ return temperature_degc;
+}
+
double
FGEnvironment::get_pressure_sea_level_inhg () const
{
return pressure_sea_level_inhg;
}
+double
+FGEnvironment::get_pressure_inhg () const
+{
+ return pressure_inhg;
+}
+
double
FGEnvironment::get_wind_from_heading_deg () const
{
return wind_from_down_fps;
}
+double
+FGEnvironment::get_elevation_ft () const
+{
+ return elevation_ft;
+}
+
void
FGEnvironment::set_temperature_sea_level_degc (double t)
{
temperature_sea_level_degc = t;
+ _recalc_alt_temp();
+}
+
+void
+FGEnvironment::set_temperature_degc (double t)
+{
+ temperature_degc = t;
+ _recalc_sl_temp();
}
void
FGEnvironment::set_pressure_sea_level_inhg (double p)
{
pressure_sea_level_inhg = p;
+ _recalc_alt_press();
+}
+
+void
+FGEnvironment::set_pressure_inhg (double p)
+{
+ pressure_inhg = p;
+ _recalc_sl_press();
}
void
_recalc_hdgspd();
}
+void
+FGEnvironment::set_elevation_ft (double e)
+{
+ elevation_ft = e;
+ _recalc_alt_temp();
+ _recalc_alt_press();
+}
+
void
FGEnvironment::_recalc_hdgspd ()
{
sin(wind_from_heading_deg * SGD_DEGREES_TO_RADIANS);
}
+void
+FGEnvironment::_recalc_sl_temp ()
+{
+ // Earth atmosphere model from
+ // http://www.grc.nasa.gov/WWW/K-12/airplane/atmos.html
+
+ // Stratospheric temperatures are not really reversible, so use 15degC.
+
+ if (elevation_ft < 36152) // Troposphere
+ temperature_sea_level_degc =
+ temperature_degc + (.00649 * SG_FEET_TO_METER * elevation_ft);
+ // If we're in the stratosphere, leave sea-level temp alone
+}
+
+void
+FGEnvironment::_recalc_alt_temp ()
+{
+ // Earth atmosphere model from
+ // http://www.grc.nasa.gov/WWW/K-12/airplane/atmos.html
+
+ if (elevation_ft < 36152) // Troposphere
+ temperature_degc =
+ temperature_sea_level_degc - (.00649 * SG_FEET_TO_METER * elevation_ft);
+ else if (elevation_ft < 82345) // Lower Stratosphere
+ temperature_degc = -56.46;
+ else
+ temperature_degc = -131.21 + (.00299 * SG_FEET_TO_METER * elevation_ft);
+}
+
+void
+FGEnvironment::_recalc_sl_press ()
+{
+ // FIXME: calculate properly
+ pressure_sea_level_inhg = pressure_inhg;
+}
+
+void
+FGEnvironment::_recalc_alt_press ()
+{
+ // FIXME: calculate properly
+ pressure_inhg = pressure_sea_level_inhg;
+}
+
// end of environment.cxx
public:
FGEnvironment();
+ FGEnvironment (const FGEnvironment &environment);
virtual ~FGEnvironment();
virtual double get_visibility_m () const;
virtual double get_temperature_sea_level_degc () const;
+ virtual double get_temperature_degc () const;
virtual double get_pressure_sea_level_inhg () const;
+ virtual double get_pressure_inhg () const;
virtual double get_wind_from_heading_deg () const;
virtual double get_wind_speed_kt () const;
virtual double get_wind_from_north_fps () const;
virtual void set_visibility_m (double v);
virtual void set_temperature_sea_level_degc (double t);
+ virtual void set_temperature_degc (double t);
virtual void set_pressure_sea_level_inhg (double p);
+ virtual void set_pressure_inhg (double p);
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);
+protected:
+
+ friend class FGEnvironmentMgr;
+
+ virtual double get_elevation_ft () const;
+ virtual void set_elevation_ft (double elevation_ft);
+
private:
void _recalc_hdgspd ();
void _recalc_ne ();
+ void _recalc_sl_temp ();
+ void _recalc_alt_temp ();
+ void _recalc_sl_press ();
+ void _recalc_alt_press ();
+
+ double elevation_ft;
double visibility_m;
double temperature_sea_level_degc;
+ double temperature_degc;
double pressure_sea_level_inhg;
+ double pressure_inhg;
double wind_from_heading_deg;
double wind_speed_kt;
&FGEnvironment::get_temperature_sea_level_degc,
&FGEnvironment::set_temperature_sea_level_degc);
fgSetArchivable("/environment/temperature-sea-level-degc");
+ fgTie("/environment/temperature-degc", _environment,
+ &FGEnvironment::get_temperature_degc,
+ &FGEnvironment::set_temperature_degc);
+ fgSetArchivable("/environment/temperature-degc");
fgTie("/environment/pressure-sea-level-inhg", _environment,
&FGEnvironment::get_pressure_sea_level_inhg,
&FGEnvironment::set_pressure_sea_level_inhg);
fgSetArchivable("/environment/pressure-sea-level-inhg");
+ fgTie("/environment/pressure-inhg", _environment,
+ &FGEnvironment::get_pressure_inhg,
+ &FGEnvironment::set_pressure_inhg);
+ fgSetArchivable("/environment/pressure-inhg");
fgTie("/environment/wind-from-heading-deg", _environment,
&FGEnvironment::get_wind_from_heading_deg,
&FGEnvironment::set_wind_from_heading_deg);
->set_Velocities_Local_Airmass(_environment->get_wind_from_north_fps(),
_environment->get_wind_from_east_fps(),
_environment->get_wind_from_down_fps());
+ _environment->set_elevation_ft(fgGetDouble("/position/altitude-ft"));
}
-const FGEnvironment *
+FGEnvironment
FGEnvironmentMgr::getEnvironment () const
{
- return _environment;
+ return *_environment;
}
-const FGEnvironment *
+FGEnvironment
FGEnvironmentMgr::getEnvironment (double lat, double lon, double alt) const
{
// Always returns the same environment
// for now; we'll make it interesting
// later.
- return _environment;
+ FGEnvironment env = *_environment;
+ env.set_elevation_ft(alt);
+ return env;
}
// end of environment-mgr.cxx
/**
* Get the environment information for the plane's current position.
*/
- virtual const FGEnvironment * getEnvironment () const;
+ virtual FGEnvironment getEnvironment () const;
/**
* Get the environment information for another location.
*/
- virtual const FGEnvironment * getEnvironment (double lat, double lon,
- double alt) const;
+ virtual FGEnvironment getEnvironment (double lat, double lon,
+ double alt) const;
private:
}
}
-const FGEnvironment *
-FGGlobals::get_environment () const
-{
- return environment_mgr->getEnvironment();
-}
-
-const FGEnvironment *
-FGGlobals::get_environment (double lat, double lon, double alt) const
-{
- return environment_mgr->getEnvironment(lat, lon, alt);
-}
-
FGViewer *
FGGlobals::get_current_view () const
{
inline void set_environment_mgr(FGEnvironmentMgr * mgr) {
environment_mgr = mgr;
}
- const FGEnvironment * get_environment() const;
- const FGEnvironment * get_environment(double lat, double lon,
- double alt) const;
inline FGATCMgr *get_ATC_mgr() const { return ATC_mgr; }
inline void set_ATC_mgr( FGATCMgr *a ) {ATC_mgr = a; }