]> git.mxchange.org Git - flightgear.git/blob - src/WeatherCM/FGLocalWeatherDatabase.h
aa0c008e0fdfa5a1d7841997ffd8826958964341
[flightgear.git] / src / WeatherCM / FGLocalWeatherDatabase.h
1 /*****************************************************************************
2
3  Header:       FGLocalWeatherDatabase.h 
4  Author:       Christian Mayer
5  Date started: 28.05.99
6
7  ---------- Copyright (C) 1999  Christian Mayer (vader@t-online.de) ----------
8
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
17  details.
18
19  You should have received a copy of the GNU General Public License along with
20  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21  Place - Suite 330, Boston, MA  02111-1307, USA.
22
23  Further information about the GNU General Public License can also be found on
24  the world wide web at http://www.gnu.org.
25
26 FUNCTIONAL DESCRIPTION
27 ------------------------------------------------------------------------------
28 Database for the local weather
29 This database is the only one that gets called from FG
30
31 HISTORY
32 ------------------------------------------------------------------------------
33 28.05.1999 Christian Mayer      Created
34 16.06.1999 Durk Talsma          Portability for Linux
35 20.06.1999 Christian Mayer      added lots of consts
36 30.06.1999 Christian Mayer      STL portability
37 11.10.1999 Christian Mayer      changed set<> to map<> on Bernie Bright's 
38                                 suggestion
39 *****************************************************************************/
40
41 /****************************************************************************/
42 /* SENTRY                                                                   */
43 /****************************************************************************/
44 #ifndef FGLocalWeatherDatabase_H
45 #define FGLocalWeatherDatabase_H
46
47 /****************************************************************************/
48 /* INCLUDES                                                                 */
49 /****************************************************************************/
50 //This is only here for smoother code change. In the end the WD should be clean
51 //of *any* OpenGL:
52 #ifdef HAVE_WINDOWS_H
53 #  include <windows.h>
54 #endif
55 #include <GL/glut.h>
56 #include <XGL/xgl.h>
57
58 #include <vector>
59 #include "sg.h"
60
61 #include "FGPhysicalProperties.h"
62 #include "FGGlobalWeatherDatabase.h"
63 #include "FGMicroWeather.h"
64 #include "FGWeatherFeature.h"
65 #include "FGWeatherDefs.h"
66
67 /****************************************************************************/
68 /* DEFINES                                                                  */
69 /****************************************************************************/
70 FG_USING_STD(vector);
71 FG_USING_NAMESPACE(std);
72
73 /****************************************************************************/
74 /* CLASS DECLARATION                                                        */
75 /****************************************************************************/
76 class FGLocalWeatherDatabase
77 {
78 private:
79 protected:
80     FGGlobalWeatherDatabase *global;    //point to the global database
81
82     typedef vector<FGMicroWeather> FGMicroWeatherList;
83     typedef FGMicroWeatherList::iterator FGMicroWeatherListIt;
84
85     typedef vector<Point2D> pointVector;
86     typedef vector<pointVector> tileVector;
87
88     /************************************************************************/
89     /* make tiles out of points on a 2D plane                               */
90     /************************************************************************/
91     void tileLocalWeather(const FGPhysicalProperties2DVector& EntryList);
92
93     FGMicroWeatherList WeatherAreas;
94
95     WeatherPrecition WeatherVisibility; //how far do I need to simulate the
96                                         //local weather? Unit: metres
97     Point3D last_known_position;
98
99 public:
100     static FGLocalWeatherDatabase *theFGLocalWeatherDatabase;  
101     
102     enum DatabaseWorkingType {
103         use_global,     //use global database for data
104         manual,         //use only user inputs
105         distant,        //use distant information, e.g. like LAN when used in
106                         //a multiplayer environment
107         random,         //generate weather randomly
108         default_mode    //use only default values
109     };
110
111 protected:
112     DatabaseWorkingType DatabaseStatus;
113
114     /************************************************************************/
115     /* return the index of the area with point p                            */
116     /************************************************************************/
117     unsigned int AreaWith(const Point2D& p) const;
118
119 public:
120     /************************************************************************/
121     /* Constructor and Destructor                                           */
122     /************************************************************************/
123     FGLocalWeatherDatabase(
124         const Point3D& posititon,
125         const WeatherPrecition& visibility = DEFAULT_WEATHER_VISIBILIY,
126         const DatabaseWorkingType& type = PREFERED_WORKING_TYPE);
127     ~FGLocalWeatherDatabase();
128
129     /************************************************************************/
130     /* reset the whole database                                             */
131     /************************************************************************/
132     void reset(const DatabaseWorkingType& type = PREFERED_WORKING_TYPE);
133
134     /************************************************************************/
135     /* update the database. Since the last call we had dt seconds           */
136     /************************************************************************/
137     void update(const WeatherPrecition& dt);                    //time has changed
138     void update(const Point3D& p);                              //position has  changed
139     void update(const Point3D& p, const WeatherPrecition& dt);  //time and/or position has changed
140
141     /************************************************************************/
142     /* Get the physical properties on the specified point p                 */
143     /************************************************************************/
144     FGPhysicalProperty get(const Point3D& p) const;
145     FGPhysicalProperty get(const sgVec3& p) const;
146     FGPhysicalProperties get(const sgVec2& p) const;
147
148     WeatherPrecition getAirDensity(const Point3D& p) const;
149     WeatherPrecition getAirDensity(const sgVec3& p) const;
150     
151     /************************************************************************/
152     /* Add a weather feature at the point p and surrounding area            */
153     /************************************************************************/
154
155     void addWind(const WeatherPrecition alt, const Point3D& x, const Point2D& p);
156     void addTurbulence(const WeatherPrecition alt, const Point3D& x, const Point2D& p);
157     void addTemperature(const WeatherPrecition alt, const WeatherPrecition x, const Point2D& p);
158     void addAirPressure(const WeatherPrecition alt, const WeatherPrecition x, const Point2D& p);
159     void addVaporPressure(const WeatherPrecition alt, const WeatherPrecition x, const Point2D& p);
160     void addCloud(const WeatherPrecition alt, const FGCloudItem& x, const Point2D& p);
161
162     void setSnowRainIntensity(const WeatherPrecition& x, const Point2D& p);
163     void setSnowRainType(const SnowRainType& x, const Point2D& p);
164     void setLightningProbability(const WeatherPrecition& x, const Point2D& p);
165
166     void addProperties(const FGPhysicalProperties2D& x);    //add a property
167     void setProperties(const FGPhysicalProperties2D& x);    //change a property
168
169     /************************************************************************/
170     /* get/set weather visibility                                           */
171     /************************************************************************/
172     void setWeatherVisibility(const WeatherPrecition& visibility);
173     WeatherPrecition getWeatherVisibility(void) const;
174 };
175
176 extern FGLocalWeatherDatabase *WeatherDatabase;
177 void fgUpdateWeatherDatabase(void);
178
179 /****************************************************************************/
180 /* get/set weather visibility                                               */
181 /****************************************************************************/
182 void inline FGLocalWeatherDatabase::setWeatherVisibility(const WeatherPrecition& visibility)
183 {
184     if (visibility >= MINIMUM_WEATHER_VISIBILIY)
185         WeatherVisibility = visibility;
186     else
187         WeatherVisibility = MINIMUM_WEATHER_VISIBILIY;
188
189     //This code doesn't belong here as this is the optical visibility and not
190     //the visibility of the weather database (that should be bigger...). The
191     //optical visibility should be calculated from the vapor pressure e.g.
192     //But for the sake of a smoother change from the old way to the new one...
193
194     GLfloat fog_exp_density;
195     GLfloat fog_exp2_density;
196     
197     // for GL_FOG_EXP
198     fog_exp_density = -log(0.01 / WeatherVisibility);
199     
200     // for GL_FOG_EXP2
201     fog_exp2_density = sqrt( -log(0.01) ) / WeatherVisibility;
202     
203     // Set correct opengl fog density
204     xglFogf (GL_FOG_DENSITY, fog_exp2_density);
205     
206     // FG_LOG( FG_INPUT, FG_DEBUG, "Fog density = " << w->fog_density );
207     //cerr << "FGLocalWeatherDatabase::setWeatherVisibility(" << visibility << "):\n";
208     //cerr << "Fog density = " << fog_exp_density << "\n";
209     
210
211 }
212
213 WeatherPrecition inline FGLocalWeatherDatabase::getWeatherVisibility(void) const
214 {
215     //cerr << "FGLocalWeatherDatabase::getWeatherVisibility() = " << WeatherVisibility << "\n";
216     return WeatherVisibility;
217 }
218
219
220 /****************************************************************************/
221 #endif /*FGLocalWeatherDatabase_H*/