]> git.mxchange.org Git - flightgear.git/commitdiff
First steps in a weather reorganization. Note especially that
authordavid <david>
Tue, 19 Feb 2002 01:26:44 +0000 (01:26 +0000)
committerdavid <david>
Tue, 19 Feb 2002 01:26:44 +0000 (01:26 +0000)
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.

12 files changed:
src/ATC/atis.cxx
src/FDM/JSBSim.cxx
src/FDM/LaRCsim.cxx
src/FDM/UIUCModel/uiuc_wrapper.cpp
src/FDM/YASim/YASim.cxx
src/Main/fg_init.cxx
src/Main/fg_props.cxx
src/Main/main.cxx
src/Main/options.cxx
src/Scenery/tilemgr.cxx
src/Weather/weather.cxx
src/Weather/weather.hxx

index a5cd845ee04f81e11ac3822af76c531204b2f3c7..9a07ea52f2feef25350c208dfa1bec496949a71a 100644 (file)
@@ -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
 }
index f880724584a1f027deee930549582231366500a7..425109d46b1da773ab5664ed715a9e0e9481cddc 100644 (file)
@@ -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()  << ", "
index 0cadfdd4c039243ee4fa3351085337f59fac7caa..9d70641cb7967897e74f1b0bafdf26626e16dcd2 100644 (file)
@@ -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();
 }
index 87e1d11c1c4b682788ba3193c03e7305442538d8..099298e2459b1c65f27f0de740af47df831dd555 100644 (file)
@@ -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
    }
  
index 166b56656afccbddc7397582756317fa136b475a..55c67366cb6884b2279cb44e1f775b6531cb7430 100644 (file)
@@ -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.
index 631b3f2be6ff2783747cf46c79f9e1094dd7270f..8dfac625c69ac322cf8c1ff556180ecd8e623413 100644 (file)
@@ -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
 
     ////////////////////////////////////////////////////////////////////
index f937887b8a398b109e9ea12312ba4bc05a711450..816c5f543f4b664566224160c1dec0f21e1be69b 100644 (file)
@@ -37,7 +37,7 @@
 #  include <WeatherCM/FGLocalWeatherDatabase.h>
 #else
 #  include <Weather/weather.hxx>
-#endif
+#endif // FG_OLD_WEATHER
 #include <Objects/matlib.hxx>
 
 #include <GUI/gui.h>
@@ -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);
index fe96a00f78a65b870b5272e9b267b6bb9be3d689..f52d42a9074366d948d50c4cada089fe2a7c6761 100644 (file)
@@ -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
index f2c9cbb5d6c7b99c3b0d9d9d0fd4e41529744c47..6ed75c8497e69bf4817e33cc3c329c18f05b3046 100644 (file)
@@ -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 ) );
index 0238f321527a0dd60ccd82b732b907273594a0b4..2b07a132f024ce1fd00815e0ab75f04474c4d022 100644 (file)
@@ -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;
 
index 178ab4134b3cf6fc9fc9a96af116fb9cdee9d6cb..b6995109302bef29886a367efd3f94fd235d805a 100644 (file)
@@ -37,6 +37,7 @@
 #include <simgear/debug/logstream.hxx>
 #include <simgear/math/sg_random.h>
 
+#include <Main/fg_props.hxx>
 #include <Aircraft/aircraft.hxx>
 #include <Weather/weather.hxx>
 
 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
 
index c8728e85494af9a296ca80128fc015799b925884..34ee2d309cf26ecc7eb3767fd9cec6c81c9b7c30 100644 (file)
@@ -29,6 +29,8 @@
 
 #include <GL/gl.h>
 
+#include <Main/fgfs.hxx>
+
 #ifdef SG_HAVE_STD_INCLUDES
 #  include <cmath>
 #else
 #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
-
-