]> git.mxchange.org Git - simgear.git/blob - simgear/environment/visual_enviro.cxx
MSVC fix.
[simgear.git] / simgear / environment / visual_enviro.cxx
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, 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
20 //
21 //
22
23 #ifdef HAVE_CONFIG_H
24 #  include <simgear_config.h>
25 #endif
26
27 #include <plib/sg.h>
28 #include <simgear/constants.h>
29 #include <simgear/math/sg_random.h>
30 #include <simgear/math/sg_geodesy.hxx>
31 #include <simgear/math/point3d.hxx>
32 #include <simgear/math/polar3d.hxx>
33 #include <simgear/sound/soundmgr_openal.hxx>
34 #include <simgear/scene/sky/cloudfield.hxx>
35 #include <simgear/scene/sky/newcloud.hxx>
36 #include "visual_enviro.hxx"
37
38 #include <vector>
39
40 SG_USING_STD(vector);
41
42
43 typedef struct {
44         Point3D         pt;
45         int                     depth;
46         int                     prev;
47 } lt_tree_seg;
48
49 #define MAX_RAIN_SLICE  200
50 static float rainpos[MAX_RAIN_SLICE];
51 #define MAX_LT_TREE_SEG 400
52
53 /**
54  * A class to render lightnings.
55  */
56 class SGLightning {
57 public:
58     /**
59      * Build a new lightning.
60      * The lightning has a limited life time. It will also play a thunder sounder once.
61      * @param lon lon longitude in degree
62      * @param lat lat latitude in degree
63      * @param alt asl of top of lightning
64      */
65         SGLightning(double lon, double lat, double alt);
66         ~SGLightning();
67         void lt_Render(void);
68         void lt_build(void);
69         void lt_build_tree_branch(int tree_nr, Point3D &start, float energy, int nbseg, float segsize);
70
71         // contains all the segments of the lightning
72         lt_tree_seg lt_tree[MAX_LT_TREE_SEG];
73         // segment count
74         int             nb_tree;
75         // position of lightning
76         double  lon, lat, alt;
77         int             sequence_count;
78         // time to live
79         double  age;
80 };
81
82 typedef vector<SGLightning *> list_of_lightning;
83 static list_of_lightning lightnings;
84
85 SGEnviro sgEnviro;
86
87 SGEnviro::SGEnviro(void) :
88         view_in_cloud(false),
89         turbulence_enable_state(false),
90         precipitation_enable_state(true),
91         lightning_enable_state(false),
92         soundMgr(NULL),
93         snd_active(false),
94         snd_dist(0.0),
95         last_cloud_turbulence(0.0),
96         cloud_turbulence(0.0),
97         elapsed_time(0.0),
98         dt(0.0),
99         min_time_before_lt(0.0),
100         fov_width(55.0),
101         fov_height(55.0),
102         precipitation_density(100.0)
103
104 {
105         for(int i = 0; i < MAX_RAIN_SLICE ; i++)
106                 rainpos[i] = sg_random();
107
108 }
109
110 SGEnviro::~SGEnviro(void) {
111         list_of_lightning::iterator iLightning;
112         for( iLightning = lightnings.begin() ; iLightning != lightnings.end() ; iLightning++ ) {
113                 delete (*iLightning);
114         }
115         lightnings.clear();
116 }
117
118 void SGEnviro::startOfFrame( sgVec3 p, sgVec3 up, double lon, double lat, double alt, double delta_time) {
119         view_in_cloud = false;
120         // ask the impostor cache to do some cleanup
121         if(SGNewCloud::cldCache)
122                 SGNewCloud::cldCache->startNewFrame();
123         last_cloud_turbulence = cloud_turbulence;
124         cloud_turbulence = 0.0;
125         elapsed_time += delta_time;
126         min_time_before_lt -= delta_time;
127         dt = delta_time;
128
129         sgMat4 T1, LON, LAT;
130     sgVec3 axis;
131
132     sgMakeTransMat4( T1, p );
133
134     sgSetVec3( axis, 0.0, 0.0, 1.0 );
135     sgMakeRotMat4( LON, lon, axis );
136
137     sgSetVec3( axis, 0.0, 1.0, 0.0 );
138     sgMakeRotMat4( LAT, 90.0 - lat, axis );
139
140     sgMat4 TRANSFORM;
141
142     sgCopyMat4( TRANSFORM, T1 );
143     sgPreMultMat4( TRANSFORM, LON );
144     sgPreMultMat4( TRANSFORM, LAT );
145
146     sgCoord pos;
147     sgSetCoord( &pos, TRANSFORM );
148
149         sgMakeCoordMat4( transform, &pos );
150     last_lon = lon;
151     last_lat = lat;
152         last_alt = alt;
153 }
154
155 void SGEnviro::endOfFrame(void) {
156 }
157
158 double SGEnviro::get_cloud_turbulence(void) const {
159         return last_cloud_turbulence;
160 }
161
162 // this can be queried to add some turbulence for example
163 bool SGEnviro::is_view_in_cloud(void) const {
164         return view_in_cloud;
165 }
166 void SGEnviro::set_view_in_cloud(bool incloud) {
167         view_in_cloud = incloud;
168 }
169
170 int SGEnviro::get_CacheResolution(void) const {
171         return SGCloudField::get_CacheResolution();
172 }
173
174 int SGEnviro::get_clouds_CacheSize(void) const {
175         return SGCloudField::get_CacheSize();
176 }
177 float SGEnviro::get_clouds_visibility(void) const {
178         return SGCloudField::get_CloudVis();
179 }
180 float SGEnviro::get_clouds_density(void) const {
181         return SGCloudField::get_density();
182 }
183 bool SGEnviro::get_clouds_enable_state(void) const {
184         return SGCloudField::get_enable3dClouds();
185 }
186
187 bool SGEnviro::get_turbulence_enable_state(void) const {
188         return turbulence_enable_state;
189 }
190
191 void SGEnviro::set_CacheResolution(int resolutionPixels) {
192         SGCloudField::set_CacheResolution(resolutionPixels);
193 }
194
195 void SGEnviro::set_clouds_CacheSize(int sizeKb) {
196         SGCloudField::set_CacheSize(sizeKb);
197 }
198 void SGEnviro::set_clouds_visibility(float distance) {
199         SGCloudField::set_CloudVis(distance);
200 }
201 void SGEnviro::set_clouds_density(float density) {
202         SGCloudField::set_density(density);
203 }
204 void SGEnviro::set_clouds_enable_state(bool enable) {
205         SGCloudField::set_enable3dClouds(enable);
206 }
207 void SGEnviro::set_turbulence_enable_state(bool enable) {
208         turbulence_enable_state = enable;
209 }
210 // rain/snow
211 float SGEnviro::get_precipitation_density(void) const {
212         return precipitation_density;
213 }
214 bool SGEnviro::get_precipitation_enable_state(void) const {
215         return precipitation_enable_state;
216 }
217
218 void SGEnviro::set_precipitation_density(float density) {
219         precipitation_density = density;
220 }
221 void SGEnviro::set_precipitation_enable_state(bool enable) {
222         precipitation_enable_state = enable;
223 }
224
225 // others
226 bool SGEnviro::get_lightning_enable_state(void) const {
227         return lightning_enable_state;
228 }
229
230 void SGEnviro::set_lightning_enable_state(bool enable) {
231         lightning_enable_state = enable;
232         if( ! enable ) {
233                 // TODO:cleanup
234         }
235 }
236
237 void SGEnviro::setLight(sgVec4 adj_fog_color) {
238         sgCopyVec4( fog_color, adj_fog_color );
239         if( false ) {
240         //    ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, l->scene_diffuse() );
241         }
242 }
243
244 void SGEnviro::callback_cloud(float heading, float alt, float radius, int familly, float dist) {
245         // send data to wx radar
246         // compute turbulence
247         // draw precipitation
248         // draw lightning
249         // compute illumination
250
251         // http://www.pilotfriend.com/flight_training/weather/THUNDERSTORM%20HAZARDS1.htm
252         double turbulence = 0.0;
253         if( dist < radius * radius * 2.25f ) {
254                 switch(familly) {
255                         case SGNewCloud::CLFamilly_st:
256                                 turbulence = 0.2;
257                                 break;
258                         case SGNewCloud::CLFamilly_ci:
259                         case SGNewCloud::CLFamilly_cs:
260                         case SGNewCloud::CLFamilly_cc:
261                         case SGNewCloud::CLFamilly_ac:
262                         case SGNewCloud::CLFamilly_as:
263                                 turbulence = 0.1;
264                                 break;
265                         case SGNewCloud::CLFamilly_sc:
266                                 turbulence = 0.3;
267                                 break;
268                         case SGNewCloud::CLFamilly_ns:
269                                 turbulence = 0.4;
270                                 break;
271                         case SGNewCloud::CLFamilly_cu:
272                                 turbulence = 0.5;
273                                 break;
274                         case SGNewCloud::CLFamilly_cb:
275                                 turbulence = 0.6;
276                                 break;
277                 }
278                 // full turbulence inside cloud, half in the vicinity
279                 if( dist > radius * radius )
280                         turbulence *= 0.5;
281                 if( turbulence > cloud_turbulence )
282                         cloud_turbulence = turbulence;
283                 // we can do 'local' precipitations too
284         }
285
286         // convert to LWC for radar (experimental)
287         // http://www-das.uwyo.edu/~geerts/cwx/notes/chap08/moist_cloud.html
288         double LWC = 0.0;
289         switch(familly) {
290                 case SGNewCloud::CLFamilly_st:
291                         LWC = 0.29;
292                         break;
293                 case SGNewCloud::CLFamilly_cu:
294                         LWC = 0.27;
295                         break;
296                 case SGNewCloud::CLFamilly_cb:
297                         LWC = 2.0;
298                         break;
299                 case SGNewCloud::CLFamilly_sc:
300                         LWC = 0.44;
301                         break;
302                 case SGNewCloud::CLFamilly_ci:
303                         LWC = 0.03;
304                         break;
305                 // no data
306                 case SGNewCloud::CLFamilly_cs:
307                 case SGNewCloud::CLFamilly_cc:
308                 case SGNewCloud::CLFamilly_ac:
309                 case SGNewCloud::CLFamilly_as:
310                         LWC = 0.03;
311                         break;
312                 case SGNewCloud::CLFamilly_ns:
313                         LWC = 0.29*2.0;
314                         break;
315         }
316         // TODO:send data to radar antenna
317         // NB:data valid only from cockpit view
318
319         // spawn a new lightning
320         if(min_time_before_lt <= 0.0 && (familly == SGNewCloud::CLFamilly_cb) &&
321                 dist < 15000.0 * 15000.0 && sg_random() > 0.9f) {
322                 double lat, lon;
323                 Point3D orig, dest;
324                 orig.setlat(last_lat * SG_DEGREES_TO_RADIANS );
325                 orig.setlon(last_lon * SG_DEGREES_TO_RADIANS );
326                 orig.setelev(0.0);
327                 dist = sgSqrt(dist);
328                 dest = calc_gc_lon_lat(orig, heading, dist);
329                 lon = dest.lon() * SG_RADIANS_TO_DEGREES;
330                 lat = dest.lat() * SG_RADIANS_TO_DEGREES;
331                 addLightning( lon, lat, alt );
332
333                 // reset timer
334                 min_time_before_lt = 5.0 + sg_random() * 30;
335                 // DEBUG only
336 //              min_time_before_lt = 1.0;
337         }
338 }
339
340 // precipitation rendering code
341 void SGEnviro::DrawCone2(float baseRadius, float height, int slices, bool down, double rain_norm, double speed) {
342
343         sgVec3 light;
344         sgVec3 min_light = {0.35, 0.35, 0.35};
345         sgAddVec3( light, fog_color, min_light );
346         float da = SG_PI * 2.0f / (float) slices;
347         // low number = faster
348         float speedf = 2.5f - speed / 200.0;
349         if( speedf < 1.0f )
350                 speedf = 1.0f;
351         float lenf = 0.03f + speed / 2000.0;
352         if( lenf > 0.10f )
353                 lenf = 0.10f;
354     float t = fmod((float) elapsed_time, speedf) / speedf;
355 //      t = 0.1f;
356         if( !down )
357                 t = 1.0f - t;
358         float angle = 0.0f;
359         glColor4f(1.0f, 0.7f, 0.7f, 0.9f);
360         glBegin(GL_LINES);
361         int rainpos_indice = 0;
362         for( int i = 0 ; i < slices ; i++ ) {
363                 float x = cos(angle) * baseRadius;
364                 float y = sin(angle) * baseRadius;
365                 angle += da;
366                 sgVec3 dir = {x, -height, y};
367
368                 // rain drops at 2 different speed to simulate depth
369                 float t1 = (i & 1 ? t : t + t) + rainpos[rainpos_indice];
370                 if(t1 > 1.0f)   t1 -= 1.0f;
371                 if(t1 > 1.0f)   t1 -= 1.0f;
372
373                 // distant raindrops are more transparent
374                 float c = (i & 1 ? t1 * 0.5f : t1 * 0.9f);
375                 glColor4f(c * light[0], c * light[1], c * light[2], c);
376                 sgVec3 p1, p2;
377                 sgScaleVec3(p1, dir, t1);
378                 // distant raindrops are shorter
379                 float t2 = t1 + (i & 1 ? lenf : lenf+lenf);
380                 sgScaleVec3(p2, dir, t2);
381
382                 glVertex3f(p1[0], p1[1] + height, p1[2]);
383                 glVertex3f(p2[0], p2[1] + height, p2[2]);
384                 if( ++rainpos_indice >= MAX_RAIN_SLICE )
385                         rainpos_indice = 0;
386         }
387         glEnd();
388 }
389
390 // TODO:check alt vs layer
391 void SGEnviro::drawRain(double pitch, double roll, double speed, double rain_norm) {
392
393         glBindTexture(GL_TEXTURE_2D, 0);
394
395         glDisable(GL_DEPTH_TEST);
396         glShadeModel(GL_SMOOTH);
397         glEnable(GL_BLEND);
398         glBlendFunc( GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
399         glDisable( GL_FOG );
400         glDisable(GL_LIGHTING);
401
402         int slice_count = (40.0 + rain_norm*150.0)* precipitation_density / 100.0;
403
404         float angle = speed;
405         if( angle > 90.0 )
406                 angle = 90.0;
407
408         glPushMatrix();
409                 // TODO:find the real view orientation, not the AC one
410                 // the cone rotate with speed
411                 angle = -pitch - angle;
412                 glRotatef(angle, 1.0, 0.0, 0.0);
413                 glRotatef(roll, 0.0, 1.0, 0.0);
414
415                 // up cone
416                 DrawCone2(15.0, 30.0, slice_count, true, rain_norm, speed);
417                 // down cone (usually not visible)
418                 if(angle > 0.0)
419                         DrawCone2(15.0, -30.0, slice_count, false, rain_norm, speed);
420
421         glPopMatrix();
422
423         glEnable(GL_LIGHTING);
424         glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
425         glEnable( GL_FOG );
426         glEnable(GL_DEPTH_TEST);
427
428 }
429
430 void SGEnviro::set_soundMgr(SGSoundMgr *mgr) {
431         soundMgr = mgr;
432 }
433
434 void SGEnviro::drawPrecipitation(double rain_norm, double snow_norm, double hail_norm, double pitch, double roll, double speed) {
435         // TODO:check alt with right layer (wich layer ?)
436         if( precipitation_enable_state && rain_norm > 0.0)
437                 drawRain(pitch, roll, speed, rain_norm);
438 }
439
440
441 SGLightning::SGLightning(double _lon, double _lat, double _alt) :
442         lon(_lon),
443         lat(_lat),
444         alt(_alt),
445         age(1.0 + sg_random() * 4.0),
446         nb_tree(0)
447 {
448 //      sequence_count = 1 + sg_random() * 5.0;
449         lt_build();
450 }
451
452 SGLightning::~SGLightning() {
453 }
454
455 // lightning rendering code
456 void SGLightning::lt_build_tree_branch(int tree_nr, Point3D &start, float energy, int nbseg, float segsize) {
457
458         sgVec3 dir, newdir;
459         int nseg = 0;
460         Point3D pt = start;
461         if( nbseg == 50 )
462                 sgSetVec3( dir, 0.0, -1.0, 0.0 );
463         else {
464                 sgSetVec3( dir, sg_random() - 0.5f, sg_random() - 0.5f, sg_random() - 0.5f);
465                 sgNormaliseVec3(dir);
466         }
467         if( nb_tree >= MAX_LT_TREE_SEG )
468                 return;
469
470         lt_tree[nb_tree].depth = tree_nr;
471         nseg = 0;
472         lt_tree[nb_tree].pt = pt;
473         lt_tree[nb_tree].prev = -1;
474         nb_tree ++;
475
476         // TODO:check agl
477         while(nseg < nbseg && pt.y() > 0.0) {
478         int prev = nb_tree - 1;
479         nseg++;
480                 // add a branch
481         if( energy * sg_random() > 0.8f )
482                         lt_build_tree_branch(tree_nr + 1, pt, energy * 0.9f, nbseg == 50 ? 10 : nbseg * 0.4f, segsize * 0.7f);
483
484                 if( nb_tree >= MAX_LT_TREE_SEG )
485                         return;
486                 sgSetVec3(newdir, (sg_random() - 0.5f), (sg_random() - 0.5f) - (nbseg == 50 ? 0.5f : 0.0), (sg_random() - 0.5f));
487                 sgNormaliseVec3(newdir);
488                 sgAddVec3( dir, newdir);
489                 sgNormaliseVec3(dir);
490                 sgVec3 scaleDir;
491                 sgScaleVec3( scaleDir, dir, segsize * energy * 0.5f );
492                 pt[PX] += scaleDir[0];
493                 pt[PY] += scaleDir[1];
494                 pt[PZ] += scaleDir[2];
495
496                 lt_tree[nb_tree].depth = tree_nr;
497                 lt_tree[nb_tree].pt = pt;
498                 lt_tree[nb_tree].prev = prev;
499                 nb_tree ++;
500         }
501 }
502
503 void SGLightning::lt_build(void) {
504     Point3D top;
505     nb_tree = 0;
506     top[PX] = 0 ;
507     top[PY] = alt;
508     top[PZ] = 0;
509     lt_build_tree_branch(0, top, 1.0, 50, top[PY] / 8.0);
510         if( ! sgEnviro.soundMgr )
511                 return;
512         Point3D start( sgEnviro.last_lon*SG_DEGREES_TO_RADIANS, sgEnviro.last_lat*SG_DEGREES_TO_RADIANS, 0.0 );
513         Point3D dest( lon*SG_DEGREES_TO_RADIANS, lat*SG_DEGREES_TO_RADIANS, 0.0 );
514         double course = 0.0, dist = 0.0;
515         calc_gc_course_dist( dest, start, &course, &dist );
516         if( dist < 10000.0 && ! sgEnviro.snd_playing && (dist < sgEnviro.snd_dist || ! sgEnviro.snd_active) ) {
517                 sgEnviro.snd_timer = 0.0;
518                 sgEnviro.snd_wait  = dist / 340;
519                 sgEnviro.snd_dist  = dist;
520                 sgEnviro.snd_pos_lat = lat;
521                 sgEnviro.snd_pos_lon = lon;
522                 sgEnviro.snd_active = true;
523                 sgEnviro.snd_playing = false;
524         }
525 }
526
527
528 void SGLightning::lt_Render(void) {
529         float flash = 0.5;
530         if( fmod(sgEnviro.elapsed_time*100.0, 100.0) > 50.0 )
531                 flash = sg_random() * 0.75f + 0.25f;
532     float h = lt_tree[0].pt[PY];
533         sgVec4 col={0.62f, 0.83f, 1.0f, 1.0f};
534         sgVec4 c;
535
536 #define DRAW_SEG() \
537                         {glBegin(GL_LINES); \
538                                 glColor4fv(c); \
539                 glVertex3f(lt_tree[n].pt[PX], lt_tree[n].pt[PZ], lt_tree[n].pt[PY]); \
540                 glVertex3f(lt_tree[lt_tree[n].prev].pt[PX], lt_tree[lt_tree[n].prev].pt[PZ], lt_tree[lt_tree[n].prev].pt[PY]); \
541                         glEnd();}
542
543         glDepthMask( GL_FALSE );
544         glEnable(GL_BLEND);
545         glBlendFunc( GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
546         glBindTexture(GL_TEXTURE_2D, 0);
547
548         glDisable(GL_LIGHTING);
549         glDisable( GL_FOG );
550         glPushMatrix();
551         sgMat4 modelview, tmp;
552     ssgGetModelviewMatrix( modelview );
553         sgCopyMat4( tmp, sgEnviro.transform );
554     sgPostMultMat4( tmp, modelview );
555     ssgLoadModelviewMatrix( tmp );
556
557     Point3D start( sgEnviro.last_lon*SG_DEGREES_TO_RADIANS, sgEnviro.last_lat*SG_DEGREES_TO_RADIANS, 0.0 );
558     Point3D dest( lon*SG_DEGREES_TO_RADIANS, lat*SG_DEGREES_TO_RADIANS, 0.0 );
559     double course = 0.0, dist = 0.0;
560     calc_gc_course_dist( dest, start, &course, &dist );
561     double ax = 0.0, ay = 0.0;
562     ax = cos(course) * dist;
563     ay = sin(course) * dist;
564
565         glTranslatef( ax, ay, -sgEnviro.last_alt );
566 //      glTranslatef( ax, ay, 0 );
567
568         for( int n = 0 ; n < nb_tree ; n++ ) {
569         if( lt_tree[n].prev < 0 )
570                         continue;
571
572         float t1 = sgLerp(0.5, 1.0, lt_tree[n].pt[PY] / h);
573                 t1 *= flash;
574                 if( lt_tree[n].depth >= 2 ) {
575             glLineWidth(3);
576                         sgScaleVec4(c, col, t1 * 0.6f);
577                         DRAW_SEG();
578                 } else {
579                         if( lt_tree[n].depth == 0 ) {
580                 glLineWidth(12);
581                                 sgScaleVec4(c, col, t1 * 0.5f);
582                                 DRAW_SEG();
583
584                 glLineWidth(6);
585                                 sgScaleVec4(c, col, t1);
586                                 DRAW_SEG();
587                         } else {
588                 glLineWidth(6);
589                                 sgScaleVec4(c, col, t1 * 0.7f);
590                                 DRAW_SEG();
591                         }
592
593             if( lt_tree[n].depth == 0 ) 
594                 glLineWidth(3);
595                         else
596                 glLineWidth(2);
597
598             sgSetVec4(c, t1, t1, t1, t1);
599                         DRAW_SEG();
600                 }
601
602         }
603     glLineWidth(1);
604         glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
605         glPopMatrix();
606         glDepthMask( GL_TRUE ); 
607         glEnable( GL_FOG );
608         glEnable(GL_LIGHTING);
609 }
610
611 void SGEnviro::addLightning(double lon, double lat, double alt) {
612         if( lightnings.size() > 10)
613                 return;
614         SGLightning *lt= new SGLightning(lon, lat, alt);
615         lightnings.push_back(lt);
616 }
617
618 void SGEnviro::drawLightning(void) {
619         list_of_lightning::iterator iLightning;
620         // play 'thunder' for lightning
621         if( snd_active )
622                 if( !snd_playing ) {
623                         // wait until sound has reached us
624                         snd_timer += dt;
625                         if( snd_timer >= snd_wait ) {
626                                 snd_playing = true;
627                                 // compute relative position of lightning
628                                 Point3D start( sgEnviro.last_lon*SG_DEGREES_TO_RADIANS, sgEnviro.last_lat*SG_DEGREES_TO_RADIANS, 0.0 );
629                                 Point3D dest( snd_pos_lon*SG_DEGREES_TO_RADIANS, snd_pos_lat*SG_DEGREES_TO_RADIANS, 0.0 );
630                                 double course = 0.0, dist = 0.0;
631                                 calc_gc_course_dist( dest, start, &course, &dist );
632                                 double ax = 0.0, ay = 0.0;
633                                 ax = cos(course) * dist;
634                                 ay = sin(course) * dist;
635                                 SGSoundSample *snd = soundMgr->find("thunder");
636                                 if( snd ) {
637                                         ALfloat pos[3]={ax, ay, -sgEnviro.last_alt };
638                                         snd->set_source_pos(pos);
639                                         snd->play_once();
640                                 }
641                         }
642                 } else {
643                         if( !soundMgr->is_playing("thunder") ) {
644                                 snd_active = false;
645                                 snd_playing = false;
646                         }
647                 }
648
649         if( ! lightning_enable_state )
650                 return;
651
652         for( iLightning = lightnings.begin() ; iLightning != lightnings.end() ; iLightning++ ) {
653                 if( dt )
654                         if( sg_random() > 0.95f )
655                                 (*iLightning)->lt_build();
656                 (*iLightning)->lt_Render();
657                 (*iLightning)->age -= dt;
658                 if( (*iLightning)->age < 0.0 ) {
659                         delete (*iLightning);
660                         lightnings.erase( iLightning );
661                         break;
662                 }
663         }
664
665 }
666
667
668 void SGEnviro::setFOV( float w, float h ) {
669         fov_width = w;
670         fov_height = h;
671 }
672
673 void SGEnviro::getFOV( float &w, float &h ) {
674         w = fov_width;
675         h = fov_height;
676 }