1 // util.cxx - general-purpose utility functions.
2 // Copyright (C) 2002 Curtis L. Olson - http://www.flightgear.org/~curt
4 // This program is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU General Public License as
6 // published by the Free Software Foundation; either version 2 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful, but
10 // WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include <simgear/compiler.h>
28 #include <simgear/debug/logstream.hxx>
31 #include "fg_props.hxx"
32 #include "globals.hxx"
35 #ifdef OSG_LIBRARY_STATIC
36 #include "osgDB/Registry"
40 fgDefaultWeatherValue (const char * propname, double value)
44 SGPropertyNode * branch = fgGetNode("/environment/config/boundary", true);
45 vector<SGPropertyNode_ptr> entries = branch->getChildren("entry");
46 for (i = 0; i < entries.size(); i++) {
47 entries[i]->setDoubleValue(propname, value);
50 branch = fgGetNode("/environment/config/aloft", true);
51 entries = branch->getChildren("entry");
52 for (i = 0; i < entries.size(); i++) {
53 entries[i]->setDoubleValue(propname, value);
59 fgSetupWind (double min_hdg, double max_hdg, double speed, double gust)
61 // Initialize to a reasonable state
62 fgDefaultWeatherValue("wind-from-heading-deg", min_hdg);
63 fgDefaultWeatherValue("wind-speed-kt", speed);
65 SG_LOG(SG_GENERAL, SG_INFO, "WIND: " << min_hdg << '@' <<
66 speed << " knots" << endl);
68 // Now, add some variety to the layers
73 fgSetDouble("/environment/config/boundary/entry[1]/wind-from-heading-deg",
75 fgSetDouble("/environment/config/boundary/entry[1]/wind-speed-kt",
82 fgSetDouble("/environment/config/aloft/entry[0]/wind-from-heading-deg",
84 fgSetDouble("/environment/config/aloft/entry[0]/wind-speed-kt",
91 fgSetDouble("/environment/config/aloft/entry[1]/wind-from-heading-deg",
93 fgSetDouble("/environment/config/aloft/entry[1]/wind-speed-kt",
100 fgSetDouble("/environment/config/aloft/entry[2]/wind-from-heading-deg",
102 fgSetDouble("/environment/config/aloft/entry[2]/wind-speed-kt",
110 // remove subsystems first, which need access to other subsystems in their
111 // destructors (e.g. "nasal")
112 SGSubsystem *sub = globals->get_subsystem("ai_model");
113 globals->get_subsystem_mgr()->get_group(SGSubsystemMgr::GENERAL)->remove_subsystem("ai_model");
115 #ifdef OSG_LIBRARY_STATIC
116 osgDB::Registry::instance( true);
119 SG_LOG(SG_GENERAL, SG_INFO, "Exiting FlightGear with status " << status);
124 // Originally written by Alex Perry.
126 fgGetLowPass (double current, double target, double timeratio)
128 if ( timeratio < 0.0 ) {
129 if ( timeratio < -1.0 ) {
130 // time went backwards; kill the filter
133 // ignore mildly negative time
135 } else if ( timeratio < 0.2 ) {
136 // Normal mode of operation; fast
137 // approximation to exp(-timeratio)
138 current = current * (1.0 - timeratio) + target * timeratio;
139 } else if ( timeratio > 5.0 ) {
140 // Huge time step; assume filter has settled
143 // Moderate time step; non linear response
144 double keep = exp(-timeratio);
145 current = current * keep + target * (1.0 - keep);