string FGATIS::get_transmission() {
//void FGATIS::get_transmission() {
+#if !defined(FG_OLD_WEATHER)
string transmission = "";
double visibility;
// }
return(transmission);
+#else
+ return "Station unavailable (not supported by FG_OLD_WEATHER)";
+#endif // FG_OLD_WEATHER
}
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() << ", "
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();
}
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
}
// 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.
global_events.Register( "weather update", fgUpdateWeatherDatabase,
fgEVENT::FG_EVENT_READY, 30000);
#else
- current_weather.Init();
+ current_weather.init();
+ current_weather.bind();
#endif
////////////////////////////////////////////////////////////////////
# include <WeatherCM/FGLocalWeatherDatabase.h>
#else
# include <Weather/weather.hxx>
-#endif
+#endif // FG_OLD_WEATHER
#include <Objects/matlib.hxx>
#include <GUI/gui.h>
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.
}
+#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
}
static void
setVisibility (double visibility)
{
-#ifndef FG_OLD_WEATHER
WeatherDatabase->setWeatherVisibility(visibility);
-#else
- current_weather.set_visibility(visibility);
-#endif
}
/**
speed);
}
+#endif // FG_OLD_WEATHER
+
static double
getFOV ()
{
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);
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);
#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,
#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
// 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 ) );
vis = 16000;
}
#else
- vis = current_weather.get_visibility();
+ vis = current_weather.get_visibility_m();
#endif
// cout << "visibility = " << vis << endl;
vis = 16000;
}
#else
- vis = current_weather.get_visibility();
+ vis = current_weather.get_visibility_m();
#endif
// cout << "visibility = " << vis << endl;
#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
#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
-
-