1 // Visual environment helper class
3 // Written by Harald JOHNSEN, started April 2005.
5 // Copyright (C) 2005 Harald JOHNSEN - hjohnsen@evc.net
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.
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.
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.
22 #ifndef _VISUAL_ENVIRO_HXX
23 #define _VISUAL_ENVIRO_HXX
27 #include <simgear/compiler.h>
38 * Simulate some echo on a weather radar.
39 * Container class for the wx radar instrument.
43 SGWxRadarEcho(float _heading, float _alt, float _radius, float _dist,
44 double _LWC, bool _lightning, int _cloudId ) :
50 lightning ( _lightning ),
54 /** the heading in radian is versus north */
56 float alt, radius, dist;
57 /** reflectivity converted to liquid water content. */
59 /** if true then this data is for a lightning else it is for water echo. */
61 /** Unique identifier of cloud */
65 typedef vector<SGWxRadarEcho> list_of_SGWxRadarEcho;
68 * Visual environment helper class.
71 friend class SGLightning;
73 void DrawCone2(float baseRadius, float height, int slices, bool down, double rain_norm, double speed);
77 bool precipitation_enable_state;
78 float precipitation_density;
79 float precipitation_max_alt;
80 bool turbulence_enable_state;
81 double last_cloud_turbulence, cloud_turbulence;
82 bool lightning_enable_state;
83 double elapsed_time, dt;
86 double last_lon, last_lat, last_alt;
88 bool snd_active, snd_playing;
89 double snd_timer, snd_wait, snd_pos_lat, snd_pos_lon, snd_dist;
90 double min_time_before_lt;
92 float fov_width, fov_height;
94 /** a list of all the radar echo. */
95 list_of_SGWxRadarEcho radarEcho;
96 static sgVec3 min_light;
97 static SGfloat streak_bright_nearmost_layer,
98 streak_bright_farmost_layer,
100 streak_period_change_per_kt,
103 streak_length_change_per_kt,
105 static int streak_count_min, streak_count_max;
106 static SGfloat cone_base_radius,
113 /** Read the config from the precipitation rendering config properties.
114 * @param precip_rendering_cfgNode "/sim/rendering/precipitation" in fg
115 * Set from whatever info present in the
116 * subnodes passed, substituting hardwired defaults for missing fields.
117 * If NULL is given, do nothing.
119 void config(const class SGPropertyNode* precip_rendering_cfgNode);
122 * Forward a few states used for renderings.
124 void startOfFrame( sgVec3 p, sgVec3 up, double lon, double lat, double alt, double delta_time);
126 void endOfFrame(void);
129 * Whenever a cloud is drawn we check his 'impact' on the environment.
130 * @param heading direction of cloud in radians
131 * @param alt asl of cloud in meters
132 * @param radius radius of cloud in meters
133 * @param family cloud family
134 * @param dist squared dist to cloud in meters
136 void callback_cloud(float heading, float alt, float radius, int family, float dist, int cloudId);
138 void drawRain(double pitch, double roll, double heading, double hspeed, double rain_norm);
140 * Draw rain or snow precipitation around the viewer.
141 * @param rain_norm rain normalized intensity given by metar class
142 * @param snow_norm snow normalized intensity given by metar class
143 * @param hail_norm hail normalized intensity given by metar class
144 * @param pitch pitch rotation of viewer
145 * @param roll roll rotation of viewer
146 * @param hspeed moving horizontal speed of viewer in kt
148 void drawPrecipitation(double rain_norm, double snow_norm, double hail_norm,
149 double pitch, double roll, double heading, double hspeed);
152 * Draw the lightnings spawned by cumulo nimbus.
154 void drawLightning(void);
157 * Forward the fog color used by the rain rendering.
158 * @param adj_fog_color color of the fog
160 void setLight(sgVec4 adj_fog_color);
162 // this can be queried to add some turbulence for example
163 bool is_view_in_cloud(void) const;
164 void set_view_in_cloud(bool incloud);
165 double get_cloud_turbulence(void) const;
168 // return the size of the memory pool used by texture impostors
169 int get_clouds_CacheSize(void) const;
170 int get_CacheResolution(void) const;
171 float get_clouds_visibility(void) const;
172 float get_clouds_density(void) const;
173 bool get_clouds_enable_state(void) const;
174 bool get_turbulence_enable_state(void) const;
177 * Set the size of the impostor texture cache for 3D clouds.
178 * @param sizeKb size of the texture pool in Kb
180 void set_clouds_CacheSize(int sizeKb);
182 * Set the resolution of the impostor texture for 3D clouds.
183 * @param resolutionPixels size of each texture in pixels (64|128|256)
185 void set_CacheResolution(int resolutionPixels);
187 * Set the maximum range used when drawing clouds.
188 * Clouds are blended from totaly transparent at max range to totaly opaque around the viewer
189 * @param distance in meters
191 void set_clouds_visibility(float distance);
193 * Set the proportion of clouds that will be rendered to limit drop in FPS.
194 * @param density 0..100 no clouds drawn when density == 0, all are drawn when density == 100
196 void set_clouds_density(float density);
198 * Enable or disable the use of 3D clouds.
199 * @param enable when false we draw the 2D layers
201 void set_clouds_enable_state(bool enable);
203 * Enable or disable the use of proximity cloud turbulence.
204 * @param enable when true the turbulence is computed based on type of cloud around the AC
206 void set_turbulence_enable_state(bool enable);
209 float get_precipitation_density(void) const;
210 bool get_precipitation_enable_state(void) const;
213 * Decrease the precipitation density to the given percentage.
214 * (Only show the given percentage of rain streaks etc.)
215 * Default precipitation density upon construction is 100.0.
216 * @param density 0.0 to 100.0
218 void set_precipitation_density(float density);
220 * Enable or disable the rendering of precipitation around the viewer.
221 * @param enable when true we will draw precipitation depending on metar data
223 void set_precipitation_enable_state(bool enable);
226 bool get_lightning_enable_state(void) const;
228 * Enable or disable the rendering of lightning and the thunder sound.
229 * @param enable when true we will draw lightning spwaned by cumulonimbus
231 void set_lightning_enable_state(bool enable);
234 * Spawn a new lighning at specified lon/lat.
235 * @param lon position of the new lightning
236 * @param lat position of the new lightning
237 * @param alt asl of the starting point of the lightning in meters
239 void addLightning(double lon, double lat, double alt);
242 * Forward the sound manager instance to be able to play samples.
243 * @param mgr a running sound manager
245 void set_soundMgr(SGSoundMgr *mgr);
247 void setFOV( float w, float h );
248 void getFOV( float &w, float &h );
250 list_of_SGWxRadarEcho *get_radar_echo(void);
252 sgMat4 *get_transform(void) { return &transform; }
255 extern SGEnviro sgEnviro;
257 #endif // _VISUAL_ENVIRO_HXX