1 // environment.cxx -- routines to model the natural environment
3 // Written by David Megginson, started February 2002.
5 // Copyright (C) 2002 David Megginson - david@megginson.com
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
34 #include <simgear/debug/logstream.hxx>
36 #include <Main/fg_props.hxx>
37 #include "environment.hxx"
40 FGEnvironment::FGEnvironment()
41 : visibility_m(32000),
42 temperature_sea_level_degc(20),
43 pressure_sea_level_inhg(28),
44 wind_from_heading_deg(0),
46 wind_from_north_fps(0),
47 wind_from_east_fps(0),
53 FGEnvironment::~FGEnvironment()
59 FGEnvironment::get_visibility_m () const
65 FGEnvironment::get_temperature_sea_level_degc () const
67 return temperature_sea_level_degc;
71 FGEnvironment::get_pressure_sea_level_inhg () const
73 return pressure_sea_level_inhg;
77 FGEnvironment::get_wind_from_heading_deg () const
79 return wind_from_heading_deg;
83 FGEnvironment::get_wind_speed_kt () const
89 FGEnvironment::get_wind_from_north_fps () const
91 return wind_from_north_fps;
95 FGEnvironment::get_wind_from_east_fps () const
97 return wind_from_east_fps;
101 FGEnvironment::get_wind_from_down_fps () const
103 return wind_from_down_fps;
109 FGEnvironment::set_visibility_m (double v)
115 FGEnvironment::set_temperature_sea_level_degc (double t)
117 temperature_sea_level_degc = t;
121 FGEnvironment::set_pressure_sea_level_inhg (double p)
123 pressure_sea_level_inhg = p;
127 FGEnvironment::set_wind_from_heading_deg (double h)
129 wind_from_heading_deg = h;
134 FGEnvironment::set_wind_speed_kt (double s)
141 FGEnvironment::set_wind_from_north_fps (double n)
143 wind_from_north_fps = n;
148 FGEnvironment::set_wind_from_east_fps (double e)
150 wind_from_east_fps = e;
155 FGEnvironment::set_wind_from_down_fps (double d)
157 wind_from_down_fps = d;
162 FGEnvironment::_recalc_hdgspd ()
166 if (wind_from_east_fps == 0) {
167 angle_rad = (wind_from_north_fps >= 0 ? SGD_PI/2 : -SGD_PI/2);
169 angle_rad = atan(wind_from_north_fps/wind_from_east_fps);
171 wind_from_heading_deg = angle_rad * SGD_RADIANS_TO_DEGREES;
172 if (wind_from_east_fps >= 0)
173 wind_from_heading_deg = 90 - wind_from_heading_deg;
175 wind_from_heading_deg = 270 - wind_from_heading_deg;
177 wind_speed_kt = fabs(wind_from_east_fps
178 * SG_METER_TO_NM * SG_FEET_TO_METER * 3600);
180 wind_speed_kt = (wind_from_north_fps / sin(angle_rad))
181 * SG_METER_TO_NM * SG_FEET_TO_METER * 3600;
185 FGEnvironment::_recalc_ne ()
188 wind_speed_kt * SG_NM_TO_METER * SG_METER_TO_FEET * (1.0/3600);
190 wind_from_north_fps = speed_fps *
191 cos(wind_from_heading_deg * SGD_DEGREES_TO_RADIANS);
192 wind_from_east_fps = speed_fps *
193 sin(wind_from_heading_deg * SGD_DEGREES_TO_RADIANS);
196 // end of environment.cxx