]> git.mxchange.org Git - simgear.git/blob - simgear/environment/visual_enviro.hxx
Merge branch 'next' of git.mxchange.org:/var/cache/git/repos/simgear into next
[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 <string>
27 #include <vector>
28
29 #include <simgear/math/SGMath.hxx>
30
31 class SGLightning;
32 class SGSampleGroup;
33
34 /**
35  * Simulate some echo on a weather radar.
36  * Container class for the wx radar instrument.
37  */
38 class SGWxRadarEcho {
39 public:
40         SGWxRadarEcho(float _heading, float _alt, float _radius, float _dist,
41                         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 std::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         SGVec4f fog_color;
82         SGMatrixf transform;
83         double last_lon, last_lat, last_alt;
84         SGSampleGroup   *sampleGroup;
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         static SGVec3f min_light;
94         static float streak_bright_nearmost_layer,
95                                    streak_bright_farmost_layer,
96                                    streak_period_max,
97                                    streak_period_change_per_kt,
98                                    streak_period_min,
99                                    streak_length_min,
100                                    streak_length_change_per_kt,
101                                    streak_length_max;
102         static int streak_count_min, streak_count_max;
103         static float cone_base_radius,
104                                    cone_height;
105
106 public:
107         SGEnviro();
108         ~SGEnviro();
109
110         /** Read the config from the precipitation rendering config properties.
111          * @param precip_rendering_cfgNode "/sim/rendering/precipitation" in fg
112          * Set from whatever info present in the
113          * subnodes passed, substituting hardwired defaults for missing fields.
114          * If NULL is given, do nothing.
115          */
116         void config(const class SGPropertyNode* precip_rendering_cfgNode);
117
118     /**
119      * Forward a few states used for renderings.
120      */
121         void startOfFrame( SGVec3f p, SGVec3f up, double lon, double lat, double alt, double delta_time);
122
123         void endOfFrame(void);
124
125 #if 0
126     /**
127      * Whenever a cloud is drawn we check his 'impact' on the environment.
128      * @param heading direction of cloud in radians
129      * @param alt asl of cloud in meters
130      * @param radius radius of cloud in meters
131      * @param family cloud family
132      * @param dist  squared dist to cloud in meters
133      */
134         void callback_cloud(float heading, float alt, float radius, int family, float dist, int cloudId);
135 #endif
136         void drawRain(double pitch, double roll, double heading, double hspeed, double rain_norm);
137     /**
138      * Draw rain or snow precipitation around the viewer.
139      * @param rain_norm rain normalized intensity given by metar class
140      * @param snow_norm snow normalized intensity given by metar class
141      * @param hail_norm hail normalized intensity given by metar class
142      * @param pitch pitch rotation of viewer
143      * @param roll roll rotation of viewer
144      * @param hspeed moving horizontal speed of viewer in kt
145      */
146         void drawPrecipitation(double rain_norm, double snow_norm, double hail_norm,
147                                                         double pitch, double roll, double heading, double hspeed);
148
149     /**
150      * Draw the lightnings spawned by cumulo nimbus.
151      */
152         void drawLightning(void);
153
154     /**
155      * Forward the fog color used by the rain rendering.
156      * @param adj_fog_color color of the fog
157      */
158         void setLight(SGVec4f adj_fog_color);
159
160         // this can be queried to add some turbulence for example
161         bool is_view_in_cloud(void) const;
162         void set_view_in_cloud(bool incloud);
163         double get_cloud_turbulence(void) const;
164
165         // Clouds
166         // return the size of the memory pool used by texture impostors
167         int get_clouds_CacheSize(void) const;
168         int get_CacheResolution(void) const;
169         float get_clouds_visibility(void) const;
170         float get_clouds_density(void) const;
171         bool get_clouds_enable_state(void) const;
172         bool get_turbulence_enable_state(void) const;
173
174     /**
175      * Set the size of the impostor texture cache for 3D clouds.
176      * @param sizeKb size of the texture pool in Kb
177      */
178         void set_clouds_CacheSize(int sizeKb);
179     /**
180      * Set the resolution of the impostor texture for 3D clouds.
181      * @param resolutionPixels size of each texture in pixels (64|128|256)
182      */
183         void set_CacheResolution(int resolutionPixels);
184     /**
185      * Set the maximum range used when drawing clouds.
186          * Clouds are blended from totaly transparent at max range to totaly opaque around the viewer
187      * @param distance in meters
188      */
189         void set_clouds_visibility(float distance);
190     /**
191      * Set the proportion of clouds that will be rendered to limit drop in FPS.
192      * @param density 0..100 no clouds drawn when density == 0, all are drawn when density == 100
193      */
194         void set_clouds_density(float density);
195     /**
196      * Enable or disable the use of 3D clouds.
197      * @param enable when false we draw the 2D layers
198      */
199         void set_clouds_enable_state(bool enable);
200     /**
201      * Enable or disable the use of proximity cloud turbulence.
202      * @param enable when true the turbulence is computed based on type of cloud around the AC
203      */
204         void set_turbulence_enable_state(bool enable);
205
206         // rain/snow
207         float get_precipitation_density(void) const;
208         bool get_precipitation_enable_state(void) const;
209
210         /** 
211          * Decrease the precipitation density to the given percentage.
212          * (Only show the given percentage of rain streaks etc.)
213          * Default precipitation density upon construction is 100.0.
214          * @param density 0.0 to 100.0
215          */
216         void set_precipitation_density(float density);
217     /**
218      * Enable or disable the rendering of precipitation around the viewer.
219      * @param enable when true we will draw precipitation depending on metar data
220      */
221         void set_precipitation_enable_state(bool enable);
222
223         // others
224         bool get_lightning_enable_state(void) const;
225     /**
226      * Enable or disable the rendering of lightning and the thunder sound.
227      * @param enable when true we will draw lightning spwaned by cumulonimbus
228      */
229         void set_lightning_enable_state(bool enable);
230
231     /**
232      * Spawn a new lighning at specified lon/lat.
233      * @param lon position of the new lightning
234      * @param lat position of the new lightning
235      * @param alt asl of the starting point of the lightning in meters
236      */
237         void addLightning(double lon, double lat, double alt);
238
239     /**
240      * Forward the sound manager instance to be able to play samples.
241      * @param mgr a running sound manager
242      */
243         void set_sampleGroup(SGSampleGroup *sgr);
244
245         void setFOV( float w, float h );
246         void getFOV( float &w, float &h );
247
248         list_of_SGWxRadarEcho *get_radar_echo(void);
249
250         SGMatrixf *get_transform(void) { return &transform; }
251 };
252
253 extern SGEnviro sgEnviro;
254
255 #endif // _VISUAL_ENVIRO_HXX