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., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <simgear/compiler.h>
28 #include <simgear/debug/logstream.hxx>
31 #include "fg_props.hxx"
32 #include "globals.hxx"
37 fgDefaultWeatherValue (const char * propname, double value)
41 SGPropertyNode * branch = fgGetNode("/environment/config/boundary", true);
42 vector<SGPropertyNode_ptr> entries = branch->getChildren("entry");
43 for (i = 0; i < entries.size(); i++) {
44 entries[i]->setDoubleValue(propname, value);
47 branch = fgGetNode("/environment/config/aloft", true);
48 entries = branch->getChildren("entry");
49 for (i = 0; i < entries.size(); i++) {
50 entries[i]->setDoubleValue(propname, value);
56 fgSetupWind (double min_hdg, double max_hdg, double speed, double gust)
58 // Initialize to a reasonable state
59 fgDefaultWeatherValue("wind-from-heading-deg", min_hdg);
60 fgDefaultWeatherValue("wind-speed-kt", speed);
62 SG_LOG(SG_GENERAL, SG_INFO, "WIND: " << min_hdg << '@' <<
63 speed << " knots" << endl);
65 // Now, add some variety to the layers
70 fgSetDouble("/environment/config/boundary/entry[1]/wind-from-heading-deg",
72 fgSetDouble("/environment/config/boundary/entry[1]/wind-speed-kt",
79 fgSetDouble("/environment/config/aloft/entry[0]/wind-from-heading-deg",
81 fgSetDouble("/environment/config/aloft/entry[0]/wind-speed-kt",
88 fgSetDouble("/environment/config/aloft/entry[1]/wind-from-heading-deg",
90 fgSetDouble("/environment/config/aloft/entry[1]/wind-speed-kt",
97 fgSetDouble("/environment/config/aloft/entry[2]/wind-from-heading-deg",
99 fgSetDouble("/environment/config/aloft/entry[2]/wind-speed-kt",
107 SG_LOG(SG_GENERAL, SG_INFO, "Exiting FlightGear with status " << status);
113 // Originally written by Alex Perry.
115 fgGetLowPass (double current, double target, double timeratio)
117 if ( timeratio < 0.0 ) {
118 if ( timeratio < -1.0 ) {
119 // time went backwards; kill the filter
122 // ignore mildly negative time
124 } else if ( timeratio < 0.2 ) {
125 // Normal mode of operation; fast
126 // approximation to exp(-timeratio)
127 current = current * (1.0 - timeratio) + target * timeratio;
128 } else if ( timeratio > 5.0 ) {
129 // Huge time step; assume filter has settled
132 // Moderate time step; non linear response
133 double keep = exp(-timeratio);
134 current = current * keep + target * (1.0 - keep);