// environment.cxx -- routines to model the natural environment // // Written by David Megginson, started February 2002. // // Copyright (C) 2002 David Megginson - david@megginson.com // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License as // published by the Free Software Foundation; either version 2 of the // License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // // $Id$ #ifdef HAVE_CONFIG_H # include #endif #ifdef HAVE_WINDOWS_H # include #endif #include #include #include #include #include
#include "environment.hxx" FGEnvironment::FGEnvironment() : visibility_m(32000), temperature_sea_level_degc(20), pressure_sea_level_inhg(28), wind_from_heading_deg(0), wind_speed_kt(0), wind_from_north_fps(0), wind_from_east_fps(0), wind_from_down_fps(0) { } FGEnvironment::~FGEnvironment() { } double FGEnvironment::get_visibility_m () const { return visibility_m; } double FGEnvironment::get_temperature_sea_level_degc () const { return temperature_sea_level_degc; } double FGEnvironment::get_pressure_sea_level_inhg () const { return pressure_sea_level_inhg; } double FGEnvironment::get_wind_from_heading_deg () const { return wind_from_heading_deg; } double FGEnvironment::get_wind_speed_kt () const { return wind_speed_kt; } double FGEnvironment::get_wind_from_north_fps () const { return wind_from_north_fps; } double FGEnvironment::get_wind_from_east_fps () const { return wind_from_east_fps; } double FGEnvironment::get_wind_from_down_fps () const { return wind_from_down_fps; } void FGEnvironment::set_visibility_m (double v) { visibility_m = v; } void FGEnvironment::set_temperature_sea_level_degc (double t) { temperature_sea_level_degc = t; } void FGEnvironment::set_pressure_sea_level_inhg (double p) { pressure_sea_level_inhg = p; } void FGEnvironment::set_wind_from_heading_deg (double h) { wind_from_heading_deg = h; _recalc_ne(); } void FGEnvironment::set_wind_speed_kt (double s) { wind_speed_kt = s; _recalc_ne(); } void FGEnvironment::set_wind_from_north_fps (double n) { wind_from_north_fps = n; _recalc_hdgspd(); } void FGEnvironment::set_wind_from_east_fps (double e) { wind_from_east_fps = e; _recalc_hdgspd(); } void FGEnvironment::set_wind_from_down_fps (double d) { wind_from_down_fps = d; _recalc_hdgspd(); } void FGEnvironment::_recalc_hdgspd () { double angle_rad; if (wind_from_east_fps == 0) { angle_rad = (wind_from_north_fps >= 0 ? SGD_PI/2 : -SGD_PI/2); } else { angle_rad = atan(wind_from_north_fps/wind_from_east_fps); } wind_from_heading_deg = angle_rad * SGD_RADIANS_TO_DEGREES; if (wind_from_east_fps >= 0) wind_from_heading_deg = 90 - wind_from_heading_deg; else wind_from_heading_deg = 270 - wind_from_heading_deg; if (angle_rad == 0) wind_speed_kt = fabs(wind_from_east_fps * SG_METER_TO_NM * SG_FEET_TO_METER * 3600); else wind_speed_kt = (wind_from_north_fps / sin(angle_rad)) * SG_METER_TO_NM * SG_FEET_TO_METER * 3600; } void FGEnvironment::_recalc_ne () { double speed_fps = wind_speed_kt * SG_NM_TO_METER * SG_METER_TO_FEET * (1.0/3600); wind_from_north_fps = speed_fps * cos(wind_from_heading_deg * SGD_DEGREES_TO_RADIANS); wind_from_east_fps = speed_fps * sin(wind_from_heading_deg * SGD_DEGREES_TO_RADIANS); } // end of environment.cxx