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.
36 #include <simgear/constants.h>
37 #include <simgear/debug/logstream.hxx>
39 #include <Main/fg_props.hxx>
40 #include "environment.hxx"
43 FGEnvironment::FGEnvironment()
44 : visibility_m(32000),
45 temperature_sea_level_degc(20),
46 pressure_sea_level_inhg(28),
47 wind_from_heading_deg(0),
49 wind_from_north_fps(0),
50 wind_from_east_fps(0),
56 FGEnvironment::~FGEnvironment()
62 FGEnvironment::get_visibility_m () const
68 FGEnvironment::get_temperature_sea_level_degc () const
70 return temperature_sea_level_degc;
74 FGEnvironment::get_pressure_sea_level_inhg () const
76 return pressure_sea_level_inhg;
80 FGEnvironment::get_wind_from_heading_deg () const
82 return wind_from_heading_deg;
86 FGEnvironment::get_wind_speed_kt () const
92 FGEnvironment::get_wind_from_north_fps () const
94 return wind_from_north_fps;
98 FGEnvironment::get_wind_from_east_fps () const
100 return wind_from_east_fps;
104 FGEnvironment::get_wind_from_down_fps () const
106 return wind_from_down_fps;
112 FGEnvironment::set_visibility_m (double v)
118 FGEnvironment::set_temperature_sea_level_degc (double t)
120 temperature_sea_level_degc = t;
124 FGEnvironment::set_pressure_sea_level_inhg (double p)
126 pressure_sea_level_inhg = p;
130 FGEnvironment::set_wind_from_heading_deg (double h)
132 wind_from_heading_deg = h;
137 FGEnvironment::set_wind_speed_kt (double s)
144 FGEnvironment::set_wind_from_north_fps (double n)
146 wind_from_north_fps = n;
151 FGEnvironment::set_wind_from_east_fps (double e)
153 wind_from_east_fps = e;
158 FGEnvironment::set_wind_from_down_fps (double d)
160 wind_from_down_fps = d;
165 FGEnvironment::_recalc_hdgspd ()
169 if (wind_from_east_fps == 0) {
170 angle_rad = (wind_from_north_fps >= 0 ? SGD_PI/2 : -SGD_PI/2);
172 angle_rad = atan(wind_from_north_fps/wind_from_east_fps);
174 wind_from_heading_deg = angle_rad * SGD_RADIANS_TO_DEGREES;
175 if (wind_from_east_fps >= 0)
176 wind_from_heading_deg = 90 - wind_from_heading_deg;
178 wind_from_heading_deg = 270 - wind_from_heading_deg;
180 wind_speed_kt = fabs(wind_from_east_fps
181 * SG_METER_TO_NM * SG_FEET_TO_METER * 3600);
183 wind_speed_kt = (wind_from_north_fps / sin(angle_rad))
184 * SG_METER_TO_NM * SG_FEET_TO_METER * 3600;
188 FGEnvironment::_recalc_ne ()
191 wind_speed_kt * SG_NM_TO_METER * SG_METER_TO_FEET * (1.0/3600);
193 wind_from_north_fps = speed_fps *
194 cos(wind_from_heading_deg * SGD_DEGREES_TO_RADIANS);
195 wind_from_east_fps = speed_fps *
196 sin(wind_from_heading_deg * SGD_DEGREES_TO_RADIANS);
199 // end of environment.cxx