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 wind_from_heading_deg(0),
44 wind_from_north_fps(0),
45 wind_from_east_fps(0),
51 FGEnvironment::~FGEnvironment()
57 FGEnvironment::set_visibility_m (double v)
63 FGEnvironment::set_wind_from_heading_deg (double h)
65 wind_from_heading_deg = h;
70 FGEnvironment::set_wind_speed_kt (double s)
77 FGEnvironment::set_wind_from_north_fps (double n)
79 wind_from_north_fps = n;
84 FGEnvironment::set_wind_from_east_fps (double e)
86 wind_from_east_fps = e;
91 FGEnvironment::set_wind_from_down_fps (double d)
93 wind_from_down_fps = d;
98 FGEnvironment::_recalc_hdgspd ()
102 if (wind_from_east_fps == 0) {
103 angle_rad = (wind_from_north_fps >= 0 ? SGD_PI/2 : -SGD_PI/2);
105 angle_rad = atan(wind_from_north_fps/wind_from_east_fps);
107 wind_from_heading_deg = angle_rad * SGD_RADIANS_TO_DEGREES;
108 if (wind_from_east_fps >= 0)
109 wind_from_heading_deg = 90 - wind_from_heading_deg;
111 wind_from_heading_deg = 270 - wind_from_heading_deg;
113 wind_speed_kt = fabs(wind_from_east_fps
114 * SG_METER_TO_NM * SG_FEET_TO_METER * 3600);
116 wind_speed_kt = (wind_from_north_fps / sin(angle_rad))
117 * SG_METER_TO_NM * SG_FEET_TO_METER * 3600;
121 FGEnvironment::_recalc_ne ()
124 wind_speed_kt * SG_NM_TO_METER * SG_METER_TO_FEET * (1.0/3600);
126 wind_from_north_fps = speed_fps *
127 cos(wind_from_heading_deg * SGD_DEGREES_TO_RADIANS);
128 wind_from_east_fps = speed_fps *
129 sin(wind_from_heading_deg * SGD_DEGREES_TO_RADIANS);
132 // end of environment.cxx