]> git.mxchange.org Git - simgear.git/blob - simgear/environment/visual_enviro.hxx
8eb8b3e991876ad6c2cc1e833eb57c793b45e285
[simgear.git] / simgear / environment / visual_enviro.hxx
1 // Visual environment helper class
2 //
3 // Written by Harald JOHNSEN, started April 2005.
4 // Minor changes/additions by Vivian Meazza Apr- May 2007
5 //
6 // Ported to OSG by Tim Moore Jun 2007
7 //
8 // Copyright (C) 2005  Harald JOHNSEN - hjohnsen@evc.net
9 //
10 // This program is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU General Public License as
12 // published by the Free Software Foundation; either version 2 of the
13 // License, or (at your option) any later version.
14 //
15 // This program is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 // General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
23 //
24 //
25 #ifndef _VISUAL_ENVIRO_HXX
26 #define _VISUAL_ENVIRO_HXX
27
28 #include <plib/sg.h>
29
30 #include <simgear/compiler.h>
31 #include STL_STRING
32 #include <vector>
33
34 SG_USING_STD(vector);
35 SG_USING_STD(string);
36
37 class SGLightning;
38 class SGSoundMgr;
39
40 /**
41  * Simulate some echo on a weather radar.
42  * Container class for the wx radar instrument.
43  */
44 class SGWxRadarEcho {
45 public:
46         SGWxRadarEcho(float _bearing, float _alt, float _radius, float _dist, float _heading,
47                         double _LWC, bool _lightning, int _cloudId, bool _aircraft) :
48           bearing (_bearing),
49           heading( _heading ),
50           alt ( _alt ),
51           radius ( _radius ),
52           dist ( _dist ),
53           LWC ( _LWC ),
54           lightning ( _lightning ),
55           aircraft ( _aircraft ),
56           cloudId ( _cloudId )
57         {}
58
59         /** the heading and bearing in radian are versus north */
60         float bearing, heading;
61         float alt, radius, dist;
62
63         /** reflectivity converted to liquid water content. */
64         double LWC;
65
66         /** if true then this data is for a lightning else it is for water echo. */
67         bool   lightning;
68
69         /** if true then this data is for an aircraft  */
70         bool aircraft;
71
72         /** Unique identifier of cloud */
73         int cloudId;
74 };
75
76 typedef vector<SGWxRadarEcho> list_of_SGWxRadarEcho;
77
78 /**
79  * Visual environment helper class.
80  */
81 class SGEnviro {
82 friend class SGLightning;
83 private:
84         void DrawCone2(float baseRadius, float height, int slices, bool down, double rain_norm, double speed);
85         void lt_update(void);
86
87         bool view_in_cloud;
88         bool precipitation_enable_state;
89         float precipitation_density;
90         float precipitation_max_alt;
91         bool turbulence_enable_state;
92         double last_cloud_turbulence, cloud_turbulence;
93         bool lightning_enable_state;
94         double elapsed_time, dt;
95         sgVec4  fog_color;
96         sgMat4 transform;
97         double last_lon, last_lat, last_alt;
98         SGSoundMgr      *soundMgr;
99         bool            snd_active, snd_playing;
100         double          snd_timer, snd_wait, snd_pos_lat, snd_pos_lon, snd_dist;
101         double          min_time_before_lt;
102
103         float fov_width, fov_height;
104
105         /** a list of all the radar echo. */
106         list_of_SGWxRadarEcho radarEcho;
107         static sgVec3 min_light;
108         static SGfloat streak_bright_nearmost_layer,
109                                    streak_bright_farmost_layer,
110                                    streak_period_max,
111                                    streak_period_change_per_kt,
112                                    streak_period_min,
113                                    streak_length_min,
114                                    streak_length_change_per_kt,
115                                    streak_length_max;
116         static int streak_count_min, streak_count_max;
117         static SGfloat cone_base_radius,
118                                    cone_height;
119
120 public:
121         SGEnviro();
122         ~SGEnviro();
123
124         /** Read the config from the precipitation rendering config properties.
125          * @param precip_rendering_cfgNode "/sim/rendering/precipitation" in fg
126          * Set from whatever info present in the
127          * subnodes passed, substituting hardwired defaults for missing fields.
128          * If NULL is given, do nothing.
129          */
130         void config(const class SGPropertyNode* precip_rendering_cfgNode);
131
132     /**
133      * Forward a few states used for renderings.
134      */
135         void startOfFrame( sgVec3 p, sgVec3 up, double lon, double lat, double alt, double delta_time);
136
137         void endOfFrame(void);
138
139     /**
140      * Whenever a cloud is drawn we check his 'impact' on the environment.
141      * @param heading direction of cloud in radians
142      * @param alt asl of cloud in meters
143      * @param radius radius of cloud in meters
144      * @param family cloud family
145      * @param dist  squared dist to cloud in meters
146      */
147         void callback_cloud(float heading, float alt, float radius, int family, float dist, int cloudId);
148
149         void drawRain(double pitch, double roll, double heading, double hspeed, double rain_norm);
150     /**
151      * Draw rain or snow precipitation around the viewer.
152      * @param rain_norm rain normalized intensity given by metar class
153      * @param snow_norm snow normalized intensity given by metar class
154      * @param hail_norm hail normalized intensity given by metar class
155      * @param pitch pitch rotation of viewer
156      * @param roll roll rotation of viewer
157      * @param hspeed moving horizontal speed of viewer in kt
158      */
159         void drawPrecipitation(double rain_norm, double snow_norm, double hail_norm,
160                                                         double pitch, double roll, double heading, double hspeed);
161
162     /**
163      * Draw the lightnings spawned by cumulo nimbus.
164      */
165         void drawLightning(void);
166
167     /**
168      * Forward the fog color used by the rain rendering.
169      * @param adj_fog_color color of the fog
170      */
171         void setLight(sgVec4 adj_fog_color);
172
173         // this can be queried to add some turbulence for example
174         bool is_view_in_cloud(void) const;
175         void set_view_in_cloud(bool incloud);
176         double get_cloud_turbulence(void) const;
177
178         // Clouds
179         // return the size of the memory pool used by texture impostors
180         int get_clouds_CacheSize(void) const;
181         int get_CacheResolution(void) const;
182         float get_clouds_visibility(void) const;
183         float get_clouds_density(void) const;
184         bool get_clouds_enable_state(void) const;
185         bool get_turbulence_enable_state(void) const;
186
187     /**
188      * Set the size of the impostor texture cache for 3D clouds.
189      * @param sizeKb size of the texture pool in Kb
190      */
191         void set_clouds_CacheSize(int sizeKb);
192     /**
193      * Set the resolution of the impostor texture for 3D clouds.
194      * @param resolutionPixels size of each texture in pixels (64|128|256)
195      */
196         void set_CacheResolution(int resolutionPixels);
197     /**
198      * Set the maximum range used when drawing clouds.
199          * Clouds are blended from totaly transparent at max range to totaly opaque around the viewer
200      * @param distance in meters
201      */
202         void set_clouds_visibility(float distance);
203     /**
204      * Set the proportion of clouds that will be rendered to limit drop in FPS.
205      * @param density 0..100 no clouds drawn when density == 0, all are drawn when density == 100
206      */
207         void set_clouds_density(float density);
208     /**
209      * Enable or disable the use of 3D clouds.
210      * @param enable when false we draw the 2D layers
211      */
212         void set_clouds_enable_state(bool enable);
213     /**
214      * Enable or disable the use of proximity cloud turbulence.
215      * @param enable when true the turbulence is computed based on type of cloud around the AC
216      */
217         void set_turbulence_enable_state(bool enable);
218
219         // rain/snow
220         float get_precipitation_density(void) const;
221         bool get_precipitation_enable_state(void) const;
222
223         /** 
224          * Decrease the precipitation density to the given percentage.
225          * (Only show the given percentage of rain streaks etc.)
226          * Default precipitation density upon construction is 100.0.
227          * @param density 0.0 to 100.0
228          */
229         void set_precipitation_density(float density);
230     /**
231      * Enable or disable the rendering of precipitation around the viewer.
232      * @param enable when true we will draw precipitation depending on metar data
233      */
234         void set_precipitation_enable_state(bool enable);
235
236         // others
237         bool get_lightning_enable_state(void) const;
238     /**
239      * Enable or disable the rendering of lightning and the thunder sound.
240      * @param enable when true we will draw lightning spwaned by cumulonimbus
241      */
242         void set_lightning_enable_state(bool enable);
243
244     /**
245      * Spawn a new lighning at specified lon/lat.
246      * @param lon position of the new lightning
247      * @param lat position of the new lightning
248      * @param alt asl of the starting point of the lightning in meters
249      */
250         void addLightning(double lon, double lat, double alt);
251
252     /**
253      * Forward the sound manager instance to be able to play samples.
254      * @param mgr a running sound manager
255      */
256         void set_soundMgr(SGSoundMgr *mgr);
257
258         void setFOV( float w, float h );
259         void getFOV( float &w, float &h );
260
261         list_of_SGWxRadarEcho *get_radar_echo(void);
262
263         sgMat4 *get_transform(void) { return &transform; }
264 };
265
266 extern SGEnviro sgEnviro;
267
268 #endif // _VISUAL_ENVIRO_HXX