]> git.mxchange.org Git - flightgear.git/blob - src/Environment/environment_ctrl.hxx
Move FGEventMgr and FGSubsystemMgr over to SimGear, add SGEventMgr to FlightGear...
[flightgear.git] / src / Environment / environment_ctrl.hxx
1 // environment-ctrl.hxx -- controller for environment information.
2 //
3 // Written by David Megginson, started May 2002.
4 //
5 // Copyright (C) 2002  David Megginson - david@megginson.com
6 //
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.
11 //
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.
16 //
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.
20 //
21 // $Id$
22
23 #ifndef _ENVIRONMENT_CTRL_HXX
24 #define _ENVIRONMENT_CTRL_HXX
25
26 #include <simgear/compiler.h>
27 #include <simgear/structure/subsystem_mgr.hxx>
28
29 #ifdef SG_HAVE_STD_INCLUDES
30 #  include <cmath>
31 #else
32 #  include <math.h>
33 #endif
34
35 #include <vector>
36
37 SG_USING_STD(vector);
38
39 class SGPropertyNode;
40
41 #include "environment.hxx"
42
43
44 \f
45 /**
46  * Interface to control environment information for a specific location.
47  */
48 class FGEnvironmentCtrl : public SGSubsystem
49 {
50
51 public:
52
53   FGEnvironmentCtrl ();
54   virtual ~FGEnvironmentCtrl ();
55
56   virtual void setEnvironment (FGEnvironment * environment);
57
58   virtual FGEnvironment * getEnvironment () const { return _environment; }
59
60   virtual void setLongitudeDeg (double lon_deg);
61   virtual void setLatitudeDeg (double lat_deg);
62   virtual void setElevationFt (double elev_ft);
63   virtual void setPosition (double lon_deg, double lat_deg, double elev_ft);
64
65   virtual double getLongitudeDeg () const { return _lon_deg; }
66   virtual double getLatitudeDeg () const { return _lat_deg; }
67   virtual double getElevationFt () const { return _elev_ft; }
68
69 protected:
70
71   FGEnvironment * _environment;
72   double _lon_deg;
73   double _lat_deg;
74   double _elev_ft;
75
76 };
77
78
79 \f
80 /**
81  * Environment controller using user-supplied parameters.
82  */
83 class FGUserDefEnvironmentCtrl : public FGEnvironmentCtrl
84 {
85 public:
86   FGUserDefEnvironmentCtrl ();
87   virtual ~FGUserDefEnvironmentCtrl ();
88
89   virtual void init ();
90   virtual void update (double dt);
91
92 private:
93
94   SGPropertyNode * _base_wind_speed_node;
95   SGPropertyNode * _gust_wind_speed_node;
96
97   double _current_wind_speed_kt;
98   double _delta_wind_speed_kt;
99
100 };
101
102
103 \f
104 /**
105  * Interplation controller using user-supplied parameters.
106  */
107 class FGInterpolateEnvironmentCtrl : public FGEnvironmentCtrl
108 {
109 public:
110     FGInterpolateEnvironmentCtrl ();
111     virtual ~FGInterpolateEnvironmentCtrl ();
112     
113     virtual void init ();
114     virtual void reinit ();
115     virtual void update (double delta_time_sec);
116
117 private:
118     
119     struct bucket {
120         double altitude_ft;
121         FGEnvironment environment;
122         bool operator< (const bucket &b) const;
123     };
124
125     void read_table (const SGPropertyNode * node, vector<bucket *> &table);
126     void do_interpolate (vector<bucket *> &table, double altitude_ft,
127                          FGEnvironment * environment);
128
129     FGEnvironment env1, env2;   // temporaries
130
131     vector<bucket *> _boundary_table;
132     vector<bucket *> _aloft_table;
133 };
134
135
136 #endif // _ENVIRONMENT_CTRL_HXX