]> git.mxchange.org Git - flightgear.git/commitdiff
Environment manager overhaul -- return a copy of an FGEnvironment
authordavid <david>
Sat, 11 May 2002 23:23:42 +0000 (23:23 +0000)
committerdavid <david>
Sat, 11 May 2002 23:23:42 +0000 (23:23 +0000)
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.

src/Environment/environment.cxx
src/Environment/environment.hxx
src/Environment/environment_mgr.cxx
src/Environment/environment_mgr.hxx
src/Main/globals.cxx
src/Main/globals.hxx

index 8a8f13c41edfcdd04ff897fa5718265894daf92f..e9e2b884a264147b873d8a823908b77c6a961231 100644 (file)
@@ -52,6 +52,18 @@ FGEnvironment::FGEnvironment()
 {
 }
 
+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()
 {
@@ -70,12 +82,24 @@ FGEnvironment::get_temperature_sea_level_degc () const
   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
 {
@@ -106,6 +130,12 @@ FGEnvironment::get_wind_from_down_fps () const
   return wind_from_down_fps;
 }
 
+double
+FGEnvironment::get_elevation_ft () const
+{
+  return elevation_ft;
+}
+
 
 
 void
@@ -118,12 +148,28 @@ 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
@@ -161,6 +207,14 @@ FGEnvironment::set_wind_from_down_fps (double d)
   _recalc_hdgspd();
 }
 
+void
+FGEnvironment::set_elevation_ft (double e)
+{
+  elevation_ft = e;
+  _recalc_alt_temp();
+  _recalc_alt_press();
+}
+
 void
 FGEnvironment::_recalc_hdgspd ()
 {
@@ -196,5 +250,48 @@ FGEnvironment::_recalc_ne ()
     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
 
index 111af137eb900b2b5ff8f5d7fbc1cc696998dd65..18a85e7e852bd355a5523d962b5e759942b52d2c 100644 (file)
@@ -49,11 +49,14 @@ class FGEnvironment
 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;
@@ -62,21 +65,38 @@ public:
 
   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;
index 8a4e8d4957a8d65963163cd12bb7b46684fee51c..fc0a1a04f3c28ee3221cd3a9e7f05068ad21e1eb 100644 (file)
@@ -60,10 +60,18 @@ FGEnvironmentMgr::bind ()
        &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);
@@ -103,21 +111,24 @@ FGEnvironmentMgr::update (double dt)
     ->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
index 63d3f725a9b551d59e7fd0923fa534cdd2fe1b9e..393a1518fedede95a79d963abafb1d2b2a45f39f 100644 (file)
@@ -56,14 +56,14 @@ public:
   /**
    * 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:
 
index 4394485eb2ef7908bc4c0ed5a59367ae9679d039..125bfc39b1a631e563bedc5c63e2beaf30194338 100644 (file)
@@ -90,18 +90,6 @@ FGGlobals::restoreInitialState ()
   }
 }
 
-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
 {
index 5a02dbd10c6b6485a7b4a78e5f5ed4affc7480e3..a5ecfd48a6ba83058782f3449d74d92ef87a0f2f 100644 (file)
@@ -228,9 +228,6 @@ public:
     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; }