]> git.mxchange.org Git - simgear.git/blob - simgear/environment/visual_enviro.hxx
- new FSF addresses
[simgear.git] / simgear / environment / visual_enviro.hxx
1 // Visual environment helper class
2 //
3 // Written by Harald JOHNSEN, started April 2005.
4 //
5 // Copyright (C) 2005  Harald JOHNSEN - hjohnsen@evc.net
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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 //
21 //
22 #ifndef _VISUAL_ENVIRO_HXX
23 #define _VISUAL_ENVIRO_HXX
24
25 #include <simgear/compiler.h>
26 #include STL_STRING
27 #include <vector>
28
29 SG_USING_STD(vector);
30 SG_USING_STD(string);
31
32 class SGLightning;
33 class SGSoundMgr;
34
35 /**
36  * Simulate some echo on a weather radar.
37  * Container class for the wx radar instrument.
38  */
39 class SGWxRadarEcho {
40 public:
41         SGWxRadarEcho(float _heading, float _alt, float _radius, float _dist, double _LWC, bool _lightning, int _cloudId) :
42           heading( _heading ),
43           alt ( _alt ),
44           radius ( _radius ),
45           dist ( _dist ),
46           LWC ( _LWC ),
47           lightning ( _lightning ),
48           cloudId ( _cloudId )
49         {}
50
51         /** the heading in radian is versus north */
52         float heading;
53         float alt, radius, dist;
54         /** reflectivity converted to liquid water content. */
55         double LWC;
56         /** if true then this data is for a lightning else it is for water echo. */
57         bool   lightning;
58         /** Unique identifier of cloud */
59         int cloudId;
60 };
61
62 typedef vector<SGWxRadarEcho> list_of_SGWxRadarEcho;
63
64 /**
65  * Visual environment helper class.
66  */
67 class SGEnviro {
68 friend class SGLightning;
69 private:
70         void DrawCone2(float baseRadius, float height, int slices, bool down, double rain_norm, double speed);
71         void lt_update(void);
72
73         bool view_in_cloud;
74         bool precipitation_enable_state;
75         float precipitation_density;
76         float precipitation_max_alt;
77         bool turbulence_enable_state;
78         double last_cloud_turbulence, cloud_turbulence;
79         bool lightning_enable_state;
80         double elapsed_time, dt;
81         sgVec4  fog_color;
82         sgMat4 transform;
83         double last_lon, last_lat, last_alt;
84         SGSoundMgr      *soundMgr;
85         bool            snd_active, snd_playing;
86         double          snd_timer, snd_wait, snd_pos_lat, snd_pos_lon, snd_dist;
87         double          min_time_before_lt;
88
89         float fov_width, fov_height;
90
91         /** a list of all the radar echo. */
92         list_of_SGWxRadarEcho radarEcho;
93
94 public:
95         SGEnviro();
96         ~SGEnviro();
97
98     /**
99      * Forward a few states used for renderings.
100      */
101         void startOfFrame( sgVec3 p, sgVec3 up, double lon, double lat, double alt, double delta_time);
102
103         void endOfFrame(void);
104
105     /**
106      * Whenever a cloud is drawn we check his 'impact' on the environment.
107      * @param heading direction of cloud in radians
108      * @param alt asl of cloud in meters
109      * @param radius radius of cloud in meters
110      * @param familly cloud familly
111      * @param dist  squared dist to cloud in meters
112      */
113         void callback_cloud(float heading, float alt, float radius, int familly, float dist, int cloudId);
114
115         void drawRain(double pitch, double roll, double heading, double speed, double rain_norm);
116     /**
117      * Draw rain or snow precipitation around the viewer.
118      * @param rain_norm rain normalized intensity given by metar class
119      * @param snow_norm snow normalized intensity given by metar class
120      * @param hail_norm hail normalized intensity given by metar class
121      * @param pitch pitch rotation of viewer
122      * @param roll roll rotation of viewer
123      * @param speed moving speed of viewer in kt
124      */
125         void drawPrecipitation(double rain_norm, double snow_norm, double hail_norm,
126                                                         double pitch, double roll, double heading, double speed);
127
128     /**
129      * Draw the lightnings spawned by cumulo nimbus.
130      */
131         void drawLightning(void);
132
133     /**
134      * Forward the fog color used by the rain rendering.
135      * @param adj_fog_color color of the fog
136      */
137         void setLight(sgVec4 adj_fog_color);
138
139         // this can be queried to add some turbulence for example
140         bool is_view_in_cloud(void) const;
141         void set_view_in_cloud(bool incloud);
142         double get_cloud_turbulence(void) const;
143
144         // Clouds
145         // return the size of the memory pool used by texture impostors
146         int get_clouds_CacheSize(void) const;
147         int get_CacheResolution(void) const;
148         float get_clouds_visibility(void) const;
149         float get_clouds_density(void) const;
150         bool get_clouds_enable_state(void) const;
151         bool get_turbulence_enable_state(void) const;
152
153     /**
154      * Set the size of the impostor texture cache for 3D clouds.
155      * @param sizeKb size of the texture pool in Kb
156      */
157         void set_clouds_CacheSize(int sizeKb);
158     /**
159      * Set the resolution of the impostor texture for 3D clouds.
160      * @param resolutionPixels size of each texture in pixels (64|128|256)
161      */
162         void set_CacheResolution(int resolutionPixels);
163     /**
164      * Set the maximum range used when drawing clouds.
165          * Clouds are blended from totaly transparent at max range to totaly opaque around the viewer
166      * @param distance in meters
167      */
168         void set_clouds_visibility(float distance);
169     /**
170      * Set the proportion of clouds that will be rendered to limit drop in FPS.
171      * @param density 0..100 no clouds drawn when density == 0, all are drawn when density == 100
172      */
173         void set_clouds_density(float density);
174     /**
175      * Enable or disable the use of 3D clouds.
176      * @param enable when false we draw the 2D layers
177      */
178         void set_clouds_enable_state(bool enable);
179     /**
180      * Enable or disable the use of proximity cloud turbulence.
181      * @param enable when true the turbulence is computed based on type of cloud around the AC
182      */
183         void set_turbulence_enable_state(bool enable);
184
185         // rain/snow
186         float get_precipitation_density(void) const;
187         bool get_precipitation_enable_state(void) const;
188
189         void set_precipitation_density(float density);
190     /**
191      * Enable or disable the rendering of precipitation around the viewer.
192      * @param enable when true we will draw precipitation depending on metar data
193      */
194         void set_precipitation_enable_state(bool enable);
195
196         // others
197         bool get_lightning_enable_state(void) const;
198     /**
199      * Enable or disable the rendering of lightning and the thunder sound.
200      * @param enable when true we will draw lightning spwaned by cumulonimbus
201      */
202         void set_lightning_enable_state(bool enable);
203
204     /**
205      * Spawn a new lighning at specified lon/lat.
206      * @param lon position of the new lightning
207      * @param lat position of the new lightning
208      * @param alt asl of the starting point of the lightning in meters
209      */
210         void addLightning(double lon, double lat, double alt);
211
212     /**
213      * Forward the sound manager instance to be able to play samples.
214      * @param mgr a running sound manager
215      */
216         void set_soundMgr(SGSoundMgr *mgr);
217
218         void setFOV( float w, float h );
219         void getFOV( float &w, float &h );
220
221         list_of_SGWxRadarEcho *get_radar_echo(void);
222
223         sgMat4 *get_transform(void) { return &transform; }
224 };
225
226 extern SGEnviro sgEnviro;
227
228 #endif // _VISUAL_ENVIRO_HXX