1 // environment-mgr.cxx -- manager for natural environment information.
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.
23 #include <simgear/debug/logstream.hxx>
25 #include <Main/fg_props.hxx>
26 #include <Aircraft/aircraft.hxx>
28 #include "environment.hxx"
29 #include "environment_ctrl.hxx"
30 #include "environment_mgr.hxx"
33 FGEnvironmentMgr::FGEnvironmentMgr ()
34 : _environment(new FGEnvironment),
35 _controller(new FGUserDefEnvironmentCtrl)
39 FGEnvironmentMgr::~FGEnvironmentMgr ()
46 FGEnvironmentMgr::init ()
48 SG_LOG( SG_GENERAL, SG_INFO, "Initializing environment subsystem");
49 _controller->setEnvironment(_environment);
55 FGEnvironmentMgr::bind ()
57 fgTie("/environment/visibility-m", _environment,
58 &FGEnvironment::get_visibility_m, &FGEnvironment::set_visibility_m);
59 fgSetArchivable("/environment/visibility-m");
60 fgTie("/environment/temperature-sea-level-degc", _environment,
61 &FGEnvironment::get_temperature_sea_level_degc,
62 &FGEnvironment::set_temperature_sea_level_degc);
63 fgSetArchivable("/environment/temperature-sea-level-degc");
64 fgTie("/environment/temperature-degc", _environment,
65 &FGEnvironment::get_temperature_degc,
66 &FGEnvironment::set_temperature_degc);
67 fgSetArchivable("/environment/temperature-degc");
68 fgTie("/environment/pressure-sea-level-inhg", _environment,
69 &FGEnvironment::get_pressure_sea_level_inhg,
70 &FGEnvironment::set_pressure_sea_level_inhg);
71 fgSetArchivable("/environment/pressure-sea-level-inhg");
72 fgTie("/environment/pressure-inhg", _environment,
73 &FGEnvironment::get_pressure_inhg,
74 &FGEnvironment::set_pressure_inhg);
75 fgSetArchivable("/environment/pressure-inhg");
76 fgTie("/environment/density-sea-level-slugft3", _environment,
77 &FGEnvironment::get_density_sea_level_slugft3,
78 &FGEnvironment::set_density_sea_level_slugft3);
79 fgSetArchivable("/environment/density-sea-level-slugft3");
80 fgTie("/environment/density-slugft3", _environment,
81 &FGEnvironment::get_density_slugft3,
82 &FGEnvironment::set_density_slugft3);
83 fgSetArchivable("/environment/density-inhg");
84 fgTie("/environment/wind-from-heading-deg", _environment,
85 &FGEnvironment::get_wind_from_heading_deg,
86 &FGEnvironment::set_wind_from_heading_deg);
87 fgTie("/environment/wind-speed-kt", _environment,
88 &FGEnvironment::get_wind_speed_kt, &FGEnvironment::set_wind_speed_kt);
89 fgTie("/environment/wind-from-north-fps", _environment,
90 &FGEnvironment::get_wind_from_north_fps,
91 &FGEnvironment::set_wind_from_north_fps);
92 fgSetArchivable("/environment/wind-from-north-fps");
93 fgTie("/environment/wind-from-east-fps", _environment,
94 &FGEnvironment::get_wind_from_east_fps,
95 &FGEnvironment::set_wind_from_east_fps);
96 fgSetArchivable("/environment/wind-from-east-fps");
97 fgTie("/environment/wind-from-down-fps", _environment,
98 &FGEnvironment::get_wind_from_down_fps,
99 &FGEnvironment::set_wind_from_down_fps);
100 fgSetArchivable("/environment/wind-from-down-fps");
104 FGEnvironmentMgr::unbind ()
106 fgUntie("/environment/visibility-m");
107 fgUntie("/environment/wind-from-heading-deg");
108 fgUntie("/environment/wind-speed-kt");
109 fgUntie("/environment/wind-from-north-fps");
110 fgUntie("/environment/wind-from-east-fps");
111 fgUntie("/environment/wind-from-down-fps");
115 FGEnvironmentMgr::update (double dt)
117 _controller->update(dt);
118 // FIXME: the FDMs should update themselves
119 current_aircraft.fdm_state
120 ->set_Velocities_Local_Airmass(_environment->get_wind_from_north_fps(),
121 _environment->get_wind_from_east_fps(),
122 _environment->get_wind_from_down_fps());
123 _environment->set_elevation_ft(fgGetDouble("/position/altitude-ft"));
129 FGEnvironmentMgr::getEnvironment () const
131 return *_environment;
135 FGEnvironmentMgr::getEnvironment (double lat, double lon, double alt) const
137 // Always returns the same environment
138 // for now; we'll make it interesting
140 FGEnvironment env = *_environment;
141 env.set_elevation_ft(alt);
146 FGEnvironmentMgr::_update_fdm () const
149 // Pass atmosphere on to FDM
150 // FIXME: have FDMs read properties directly.
152 if (fgGetBool("/environment/params/control-fdm-atmosphere")) {
153 // convert from Rankine to Celsius
155 ->set_Static_temperature((9.0/5.0)
156 * _environment->get_temperature_degc() + 492.0);
157 // convert from inHG to PSF
159 ->set_Static_pressure(_environment->get_pressure_inhg() * 70.726566);
160 // keep in slugs/ft^3
162 ->set_Density(_environment->get_density_slugft3());
166 // end of environment-mgr.cxx