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 #ifdef OSG_LIBRARY_STATIC
111 osgDB::Registry::instance( true);
114 SG_LOG(SG_GENERAL, SG_INFO, "Exiting FlightGear with status " << status);
119 // Originally written by Alex Perry.
121 fgGetLowPass (double current, double target, double timeratio)
123 if ( timeratio < 0.0 ) {
124 if ( timeratio < -1.0 ) {
125 // time went backwards; kill the filter
128 // ignore mildly negative time
130 } else if ( timeratio < 0.2 ) {
131 // Normal mode of operation; fast
132 // approximation to exp(-timeratio)
133 current = current * (1.0 - timeratio) + target * timeratio;
134 } else if ( timeratio > 5.0 ) {
135 // Huge time step; assume filter has settled
138 // Moderate time step; non linear response
139 double keep = exp(-timeratio);
140 current = current * keep + target * (1.0 - keep);