]> git.mxchange.org Git - flightgear.git/blob - src/WeatherCM/FGLocalWeatherDatabase.h
38ffa6625e4d3f94fda5c3ea340f1718edfe3aa1
[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 *****************************************************************************/
38
39 /****************************************************************************/
40 /* SENTRY                                                                   */
41 /****************************************************************************/
42 #ifndef FGLocalWeatherDatabase_H
43 #define FGLocalWeatherDatabase_H
44
45 /****************************************************************************/
46 /* INCLUDES                                                                 */
47 /****************************************************************************/
48 //This is only here for smoother code change. In the end the WD should be clean
49 //of *any* OpenGL:
50 #ifdef HAVE_WINDOWS_H
51 #  include <windows.h>
52 #endif
53 #include <GL/glut.h>
54 #include <XGL/xgl.h>
55
56 #include "FGPhysicalProperties.h"
57 #include "FGGlobalWeatherDatabase.h"
58 #include "FGMicroWeather.h"
59 #include "FGWeatherFeature.h"
60 #include "FGWeatherDefs.h"
61 #include <vector>
62
63 /****************************************************************************/
64 /* DEFINES                                                                  */
65 /****************************************************************************/
66 FG_USING_STD(vector);
67 FG_USING_NAMESPACE(std);
68
69 /****************************************************************************/
70 /* CLASS DECLARATION                                                        */
71 /****************************************************************************/
72 class FGLocalWeatherDatabase
73 {
74 private:
75 protected:
76     FGGlobalWeatherDatabase *global;    //point to the global database
77
78     typedef vector<FGMicroWeather> FGMicroWeatherList;
79     typedef FGMicroWeatherList::iterator FGMicroWeatherListIt;
80
81     typedef vector<Point2D> pointVector;
82     typedef vector<pointVector> tileVector;
83
84     /************************************************************************/
85     /* make tiles out of points on a 2D plane                               */
86     /************************************************************************/
87     void tileLocalWeather(const FGPhysicalProperties2DVector& EntryList);
88
89     FGMicroWeatherList WeatherAreas;
90
91     WeatherPrecition WeatherVisibility; //how far do I need to simulate the
92                                         //local weather? Unit: metres
93     Point3D last_known_position;
94
95 public:
96     static FGLocalWeatherDatabase *theFGLocalWeatherDatabase;  
97     
98     enum DatabaseWorkingType {
99         use_global,     //use global database for data
100         manual,         //use only user inputs
101         distant,        //use distant information, e.g. like LAN when used in
102                         //a multiplayer environment
103         random,         //generate weather randomly
104         default_mode    //use only default values
105     };
106
107 protected:
108     DatabaseWorkingType DatabaseStatus;
109
110     /************************************************************************/
111     /* return the index of the area with point p                            */
112     /************************************************************************/
113     unsigned int AreaWith(const Point2D& p) const;
114
115 public:
116     /************************************************************************/
117     /* Constructor and Destructor                                           */
118     /************************************************************************/
119     FGLocalWeatherDatabase(
120         const Point3D& posititon,
121         const WeatherPrecition& visibility = DEFAULT_WEATHER_VISIBILIY,
122         const DatabaseWorkingType& type = PREFERED_WORKING_TYPE);
123     ~FGLocalWeatherDatabase();
124
125     /************************************************************************/
126     /* reset the whole database                                             */
127     /************************************************************************/
128     void reset(const DatabaseWorkingType& type = PREFERED_WORKING_TYPE);
129
130     /************************************************************************/
131     /* update the database. Since the last call we had dt seconds           */
132     /************************************************************************/
133     void update(const WeatherPrecition& dt);                    //time has changed
134     void update(const Point3D& p);                              //position has  changed
135     void update(const Point3D& p, const WeatherPrecition& dt);  //time and/or position has changed
136
137     /************************************************************************/
138     /* Get the physical properties on the specified point p                 */
139     /************************************************************************/
140     FGPhysicalProperty get(const Point3D& p) const;
141     WeatherPrecition getAirDensity(const Point3D& p) const;
142     
143     /************************************************************************/
144     /* Add a weather feature at the point p and surrounding area            */
145     /************************************************************************/
146
147     void addWind(const FGWindItem& x, const Point2D& p);
148     void addTurbulence(const FGTurbulenceItem& x, const Point2D& p);
149     void addTemperature(const FGTemperatureItem& x, const Point2D& p);
150     void addAirPressure(const FGAirPressureItem& x, const Point2D& p);
151     void addVaporPressure(const FGVaporPressureItem& x, const Point2D& p);
152     void addCloud(const FGCloudItem& x, const Point2D& p);
153
154     void setSnowRainIntensity(const WeatherPrecition& x, const Point2D& p);
155     void setSnowRainType(const SnowRainType& x, const Point2D& p);
156     void setLightningProbability(const WeatherPrecition& x, const Point2D& p);
157
158     void addProperties(const FGPhysicalProperties2D& x);    //add a property
159     void setProperties(const FGPhysicalProperties2D& x);    //change a property
160
161     /************************************************************************/
162     /* get/set weather visibility                                           */
163     /************************************************************************/
164     void setWeatherVisibility(const WeatherPrecition& visibility);
165     WeatherPrecition getWeatherVisibility(void) const;
166 };
167
168 extern FGLocalWeatherDatabase *WeatherDatabase;
169 void fgUpdateWeatherDatabase(void);
170
171 /****************************************************************************/
172 /* get/set weather visibility                                               */
173 /****************************************************************************/
174 void inline FGLocalWeatherDatabase::setWeatherVisibility(const WeatherPrecition& visibility)
175 {
176     if (visibility >= MINIMUM_WEATHER_VISIBILIY)
177         WeatherVisibility = visibility;
178     else
179         WeatherVisibility = MINIMUM_WEATHER_VISIBILIY;
180
181     //This code doesn't belong here as this is the optical visibility and not
182     //the visibility of the weather database (that should be bigger...). The
183     //optical visibility should be calculated from the vapor pressure e.g.
184     //But for the sake of a smoother change from the old way to the new one...
185
186     GLfloat fog_exp_density;
187     GLfloat fog_exp2_density;
188     
189     // for GL_FOG_EXP
190     fog_exp_density = -log(0.01 / WeatherVisibility);
191     
192     // for GL_FOG_EXP2
193     fog_exp2_density = sqrt( -log(0.01) ) / WeatherVisibility;
194     
195     // Set correct opengl fog density
196     xglFogf (GL_FOG_DENSITY, fog_exp2_density);
197     
198     // FG_LOG( FG_INPUT, FG_DEBUG, "Fog density = " << w->fog_density );
199     //cerr << "FGLocalWeatherDatabase::setWeatherVisibility(" << visibility << "):\n";
200     //cerr << "Fog density = " << fog_exp_density << "\n";
201     
202
203 }
204
205 WeatherPrecition inline FGLocalWeatherDatabase::getWeatherVisibility(void) const
206 {
207     //cerr << "FGLocalWeatherDatabase::getWeatherVisibility() = " << WeatherVisibility << "\n";
208     return WeatherVisibility;
209 }
210
211
212 /****************************************************************************/
213 #endif /*FGLocalWeatherDatabase_H*/