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