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.
23 # include <simgear_config.h>
26 #include <simgear/constants.h>
27 #include <simgear/structure/SGReferenced.hxx>
28 #include <simgear/structure/SGSharedPtr.hxx>
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 <simgear/props/props.hxx>
37 #include "visual_enviro.hxx"
50 #define MAX_RAIN_SLICE 200
51 static float rainpos[MAX_RAIN_SLICE];
52 #define MAX_LT_TREE_SEG 400
54 #define DFL_MIN_LIGHT 0.35
55 sgVec3 SGEnviro::min_light = {DFL_MIN_LIGHT, DFL_MIN_LIGHT, DFL_MIN_LIGHT};
56 #define DFL_STREAK_BRIGHT_NEARMOST_LAYER 0.9
57 SGfloat SGEnviro::streak_bright_nearmost_layer = DFL_STREAK_BRIGHT_NEARMOST_LAYER;
58 #define DFL_STREAK_BRIGHT_FARMOST_LAYER 0.5
59 SGfloat SGEnviro::streak_bright_farmost_layer = DFL_STREAK_BRIGHT_FARMOST_LAYER;
60 #define DFL_STREAK_PERIOD_MAX 2.5
61 SGfloat SGEnviro::streak_period_max = DFL_STREAK_PERIOD_MAX;
62 #define DFL_STREAK_PERIOD_CHANGE_PER_KT 0.005
63 SGfloat SGEnviro::streak_period_change_per_kt = DFL_STREAK_PERIOD_CHANGE_PER_KT;
64 #define DFL_STREAK_PERIOD_MIN 1.0
65 SGfloat SGEnviro::streak_period_min = DFL_STREAK_PERIOD_MIN;
66 #define DFL_STREAK_LENGTH_MIN 0.03
67 SGfloat SGEnviro::streak_length_min = DFL_STREAK_LENGTH_MIN;
68 #define DFL_STREAK_LENGTH_CHANGE_PER_KT 0.0005
69 SGfloat SGEnviro::streak_length_change_per_kt = DFL_STREAK_LENGTH_CHANGE_PER_KT;
70 #define DFL_STREAK_LENGTH_MAX 0.1
71 SGfloat SGEnviro::streak_length_max = DFL_STREAK_LENGTH_MAX;
72 #define DFL_STREAK_COUNT_MIN 40
73 int SGEnviro::streak_count_min = DFL_STREAK_COUNT_MIN;
74 #define DFL_STREAK_COUNT_MAX 190
75 #if (DFL_STREAK_COUNT_MAX > MAX_RAIN_SLICE)
78 int SGEnviro::streak_count_max = DFL_STREAK_COUNT_MAX;
79 #define DFL_CONE_BASE_RADIUS 15.0
80 SGfloat SGEnviro::cone_base_radius = DFL_CONE_BASE_RADIUS;
81 #define DFL_CONE_HEIGHT 30.0
82 SGfloat SGEnviro::cone_height = DFL_CONE_HEIGHT;
85 void SGEnviro::config(const SGPropertyNode* n)
90 const float ml = n->getFloatValue("min-light", DFL_MIN_LIGHT);
91 sgSetVec3(min_light, ml, ml, ml);
93 streak_bright_nearmost_layer = n->getFloatValue(
94 "streak-brightness-nearmost-layer",
95 DFL_STREAK_BRIGHT_NEARMOST_LAYER);
96 streak_bright_farmost_layer = n->getFloatValue(
97 "streak-brightness-farmost-layer",
98 DFL_STREAK_BRIGHT_FARMOST_LAYER);
100 streak_period_max = n->getFloatValue(
102 DFL_STREAK_PERIOD_MAX);
103 streak_period_min = n->getFloatValue(
105 DFL_STREAK_PERIOD_MIN);
106 streak_period_change_per_kt = n->getFloatValue(
107 "streak-period-change-per-kt",
108 DFL_STREAK_PERIOD_CHANGE_PER_KT);
110 streak_length_max = n->getFloatValue(
112 DFL_STREAK_LENGTH_MAX);
113 streak_length_min = n->getFloatValue(
115 DFL_STREAK_LENGTH_MIN);
116 streak_length_change_per_kt = n->getFloatValue(
117 "streak-length-change-per-kt",
118 DFL_STREAK_LENGTH_CHANGE_PER_KT);
120 streak_count_min = n->getIntValue(
121 "streak-count-min", DFL_STREAK_COUNT_MIN);
122 streak_count_max = n->getIntValue(
123 "streak-count-max", DFL_STREAK_COUNT_MAX);
124 if (streak_count_max > MAX_RAIN_SLICE)
125 streak_count_max = MAX_RAIN_SLICE;
127 cone_base_radius = n->getFloatValue(
128 "cone-base-radius", DFL_CONE_BASE_RADIUS);
129 cone_height = n->getFloatValue("cone_height", DFL_CONE_HEIGHT);
134 * A class to render lightnings.
139 * Build a new lightning.
140 * The lightning has a limited life time. It will also play a thunder sounder once.
141 * @param lon lon longitude in degree
142 * @param lat lat latitude in degree
143 * @param alt asl of top of lightning
145 SGLightning(double lon, double lat, double alt);
147 void lt_Render(void);
149 void lt_build_tree_branch(int tree_nr, Point3D &start, float energy, int nbseg, float segsize);
151 // contains all the segments of the lightning
152 lt_tree_seg lt_tree[MAX_LT_TREE_SEG];
155 // position of lightning
156 double lon, lat, alt;
162 typedef vector<SGLightning *> list_of_lightning;
163 static list_of_lightning lightnings;
167 SGEnviro::SGEnviro() :
168 view_in_cloud(false),
169 precipitation_enable_state(true),
170 precipitation_density(100.0),
171 precipitation_max_alt(0.0),
172 turbulence_enable_state(false),
173 last_cloud_turbulence(0.0),
174 cloud_turbulence(0.0),
175 lightning_enable_state(false),
181 min_time_before_lt(0.0),
186 for(int i = 0; i < MAX_RAIN_SLICE ; i++)
187 rainpos[i] = sg_random();
188 radarEcho.reserve(100);
191 SGEnviro::~SGEnviro(void) {
192 list_of_lightning::iterator iLightning;
193 for( iLightning = lightnings.begin() ; iLightning != lightnings.end() ; iLightning++ ) {
194 delete (*iLightning);
199 void SGEnviro::startOfFrame( sgVec3 p, sgVec3 up, double lon, double lat, double alt, double delta_time) {
200 view_in_cloud = false;
201 // ask the impostor cache to do some cleanup
202 if(SGNewCloud::cldCache)
203 SGNewCloud::cldCache->startNewFrame();
204 last_cloud_turbulence = cloud_turbulence;
205 cloud_turbulence = 0.0;
206 elapsed_time += delta_time;
207 min_time_before_lt -= delta_time;
213 sgMakeTransMat4( T1, p );
215 sgSetVec3( axis, 0.0, 0.0, 1.0 );
216 sgMakeRotMat4( LON, lon, axis );
218 sgSetVec3( axis, 0.0, 1.0, 0.0 );
219 sgMakeRotMat4( LAT, 90.0 - lat, axis );
223 sgCopyMat4( TRANSFORM, T1 );
224 sgPreMultMat4( TRANSFORM, LON );
225 sgPreMultMat4( TRANSFORM, LAT );
228 sgSetCoord( &pos, TRANSFORM );
230 sgMakeCoordMat4( transform, &pos );
236 precipitation_max_alt = 400.0;
239 void SGEnviro::endOfFrame(void) {
242 double SGEnviro::get_cloud_turbulence(void) const {
243 return last_cloud_turbulence;
246 // this can be queried to add some turbulence for example
247 bool SGEnviro::is_view_in_cloud(void) const {
248 return view_in_cloud;
250 void SGEnviro::set_view_in_cloud(bool incloud) {
251 view_in_cloud = incloud;
254 int SGEnviro::get_CacheResolution(void) const {
255 return SGCloudField::get_CacheResolution();
258 int SGEnviro::get_clouds_CacheSize(void) const {
259 return SGCloudField::get_CacheSize();
261 float SGEnviro::get_clouds_visibility(void) const {
262 return SGCloudField::get_CloudVis();
264 float SGEnviro::get_clouds_density(void) const {
265 return SGCloudField::get_density();
267 bool SGEnviro::get_clouds_enable_state(void) const {
268 return SGCloudField::get_enable3dClouds();
271 bool SGEnviro::get_turbulence_enable_state(void) const {
272 return turbulence_enable_state;
275 void SGEnviro::set_CacheResolution(int resolutionPixels) {
276 SGCloudField::set_CacheResolution(resolutionPixels);
279 void SGEnviro::set_clouds_CacheSize(int sizeKb) {
280 SGCloudField::set_CacheSize(sizeKb);
282 void SGEnviro::set_clouds_visibility(float distance) {
283 SGCloudField::set_CloudVis(distance);
285 void SGEnviro::set_clouds_density(float density) {
286 SGCloudField::set_density(density);
288 void SGEnviro::set_clouds_enable_state(bool enable) {
289 SGCloudField::set_enable3dClouds(enable);
291 void SGEnviro::set_turbulence_enable_state(bool enable) {
292 turbulence_enable_state = enable;
295 float SGEnviro::get_precipitation_density(void) const {
296 return precipitation_density;
298 bool SGEnviro::get_precipitation_enable_state(void) const {
299 return precipitation_enable_state;
302 void SGEnviro::set_precipitation_density(float density) {
303 precipitation_density = density;
305 void SGEnviro::set_precipitation_enable_state(bool enable) {
306 precipitation_enable_state = enable;
310 bool SGEnviro::get_lightning_enable_state(void) const {
311 return lightning_enable_state;
314 void SGEnviro::set_lightning_enable_state(bool enable) {
315 lightning_enable_state = enable;
321 void SGEnviro::setLight(sgVec4 adj_fog_color) {
322 sgCopyVec4( fog_color, adj_fog_color );
324 // ssgGetLight( 0 ) -> setColour( GL_DIFFUSE, l->scene_diffuse() );
328 void SGEnviro::callback_cloud(float heading, float alt, float radius, int family, float dist, int cloudId) {
329 // send data to wx radar
330 // compute turbulence
331 // draw precipitation
333 // compute illumination
335 // http://www.pilotfriend.com/flight_training/weather/THUNDERSTORM%20HAZARDS1.htm
336 double turbulence = 0.0;
337 if( dist < radius * radius * 2.25f ) {
339 case SGNewCloud::CLFamilly_st:
342 case SGNewCloud::CLFamilly_ci:
343 case SGNewCloud::CLFamilly_cs:
344 case SGNewCloud::CLFamilly_cc:
345 case SGNewCloud::CLFamilly_ac:
346 case SGNewCloud::CLFamilly_as:
349 case SGNewCloud::CLFamilly_sc:
352 case SGNewCloud::CLFamilly_ns:
355 case SGNewCloud::CLFamilly_cu:
358 case SGNewCloud::CLFamilly_cb:
362 // full turbulence inside cloud, half in the vicinity
363 if( dist > radius * radius )
365 if( turbulence > cloud_turbulence )
366 cloud_turbulence = turbulence;
367 // we can do 'local' precipitations too
370 // convert to LWC for radar (experimental)
371 // http://www-das.uwyo.edu/~geerts/cwx/notes/chap08/moist_cloud.html
374 case SGNewCloud::CLFamilly_st:
377 case SGNewCloud::CLFamilly_cu:
380 case SGNewCloud::CLFamilly_cb:
383 case SGNewCloud::CLFamilly_sc:
386 case SGNewCloud::CLFamilly_ci:
390 case SGNewCloud::CLFamilly_cs:
391 case SGNewCloud::CLFamilly_cc:
392 case SGNewCloud::CLFamilly_ac:
393 case SGNewCloud::CLFamilly_as:
396 case SGNewCloud::CLFamilly_ns:
400 // add to the list for the wxRadar instrument
402 radarEcho.push_back( SGWxRadarEcho ( heading, alt, radius, dist, LWC, false, cloudId ) );
404 // NB:data valid only from cockpit view
406 // spawn a new lightning
407 if(lightning_enable_state && min_time_before_lt <= 0.0 && (family == SGNewCloud::CLFamilly_cb) &&
408 dist < 15000.0 * 15000.0 && sg_random() > 0.9f) {
411 orig.setlat(last_lat * SG_DEGREES_TO_RADIANS );
412 orig.setlon(last_lon * SG_DEGREES_TO_RADIANS );
415 dest = calc_gc_lon_lat(orig, heading, dist);
416 lon = dest.lon() * SG_RADIANS_TO_DEGREES;
417 lat = dest.lat() * SG_RADIANS_TO_DEGREES;
418 addLightning( lon, lat, alt );
421 min_time_before_lt = 5.0 + sg_random() * 30;
423 // min_time_before_lt = 5.0;
425 if( (alt - radius * 0.1) > precipitation_max_alt )
427 case SGNewCloud::CLFamilly_st:
428 case SGNewCloud::CLFamilly_cu:
429 case SGNewCloud::CLFamilly_cb:
430 case SGNewCloud::CLFamilly_ns:
431 case SGNewCloud::CLFamilly_sc:
432 precipitation_max_alt = alt - radius * 0.1;
437 list_of_SGWxRadarEcho *SGEnviro::get_radar_echo(void) {
441 // precipitation rendering code
442 void SGEnviro::DrawCone2(float baseRadius, float height, int slices, bool down, double rain_norm, double speed) {
444 sgAddVec3( light, fog_color, min_light );
445 float da = SG_PI * 2.0f / (float) slices;
446 // low number = faster
447 float speedf = streak_period_max - speed * streak_period_change_per_kt;
448 if( speedf < streak_period_min )
449 speedf = streak_period_min;
450 float lenf = streak_length_min + speed * streak_length_change_per_kt;
451 if( lenf > streak_length_max )
452 lenf = streak_length_max;
453 float t = fmod((float) elapsed_time, speedf) / speedf;
458 //glColor4f(1.0f, 0.7f, 0.7f, 0.9f); // XXX unneeded? overriden below
460 if (slices > MAX_RAIN_SLICE)
461 slices = MAX_RAIN_SLICE; // should never happen
462 for( int i = 0 ; i < slices ; i++ ) {
463 float x = cos(angle) * baseRadius;
464 float y = sin(angle) * baseRadius;
466 sgVec3 dir = {x, -height, y};
468 // rain drops at 2 different speed to simulate depth
469 float t1 = (i & 1 ? t : t + t) + rainpos[i];
470 if(t1 > 1.0f) t1 -= 1.0f;
471 if(t1 > 1.0f) t1 -= 1.0f;
473 // distant raindrops are more transparent
474 float c = t1 * (i & 1 ?
475 streak_bright_farmost_layer
476 : streak_bright_nearmost_layer);
477 glColor4f(c * light[0], c * light[1], c * light[2], c);
479 sgScaleVec3(p1, dir, t1);
480 // distant raindrops are shorter
481 float t2 = t1 + (i & 1 ? lenf : lenf+lenf);
482 sgScaleVec3(p2, dir, t2);
484 glVertex3f(p1[0], p1[1] + height, p1[2]);
485 glVertex3f(p2[0], p2[1] + height, p2[2]);
490 void SGEnviro::drawRain(double pitch, double roll, double heading, double hspeed, double rain_norm) {
493 static int debug_period = 0;
494 if (debug_period++ == 50) {
502 //" angle = " << angle
503 //<< " raindrop(KTS) = " << raindrop_speed_kts
509 glBindTexture(GL_TEXTURE_2D, 0);
511 glDisable(GL_DEPTH_TEST);
512 glShadeModel(GL_SMOOTH);
514 glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA );
516 glDisable(GL_LIGHTING);
518 int slice_count = static_cast<int>(
519 (streak_count_min + rain_norm*(streak_count_max-streak_count_min))
520 * precipitation_density / 100.0);
522 // www.wonderquest.com/falling-raindrops.htm says that
523 // Raindrop terminal velocity is 5 to 20mph
524 // Rather than model it accurately (temp, pressure, diameter), and make it
525 // smaller than terminal when closer to the precipitation cloud base,
526 // we interpolate in the 5-20mph range according to rain_norm.
527 double raindrop_speed_kts
528 = (5.0 + rain_norm*15.0) * SG_MPH_TO_MPS * SG_MPS_TO_KT;
530 float angle = atanf(hspeed / raindrop_speed_kts) * SG_RADIANS_TO_DEGREES;
532 // the cone rotate with hspeed
533 angle = -pitch - angle;
534 glRotatef(roll, 0.0, 0.0, 1.0);
535 glRotatef(heading, 0.0, 1.0, 0.0);
536 glRotatef(angle, 1.0, 0.0, 0.0);
539 DrawCone2(cone_base_radius, cone_height,
540 slice_count, true, rain_norm, hspeed);
541 // down cone (usually not visible)
542 if(angle > 0.0 || heading != 0.0)
543 DrawCone2(cone_base_radius, -cone_height,
544 slice_count, false, rain_norm, hspeed);
548 glEnable(GL_LIGHTING);
549 glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
551 glEnable(GL_DEPTH_TEST);
555 void SGEnviro::set_soundMgr(SGSoundMgr *mgr) {
559 void SGEnviro::drawPrecipitation(double rain_norm, double snow_norm, double hail_norm, double pitch, double roll, double heading, double hspeed) {
560 if( precipitation_enable_state && rain_norm > 0.0)
561 if( precipitation_max_alt >= last_alt )
562 drawRain(pitch, roll, heading, hspeed, rain_norm);
566 SGLightning::SGLightning(double _lon, double _lat, double _alt) :
571 age(1.0 + sg_random() * 4.0)
573 // sequence_count = 1 + sg_random() * 5.0;
577 SGLightning::~SGLightning() {
580 // lightning rendering code
581 void SGLightning::lt_build_tree_branch(int tree_nr, Point3D &start, float energy, int nbseg, float segsize) {
587 sgSetVec3( dir, 0.0, -1.0, 0.0 );
589 sgSetVec3( dir, sg_random() - 0.5f, sg_random() - 0.5f, sg_random() - 0.5f);
590 sgNormaliseVec3(dir);
592 if( nb_tree >= MAX_LT_TREE_SEG )
595 lt_tree[nb_tree].depth = tree_nr;
597 lt_tree[nb_tree].pt = pt;
598 lt_tree[nb_tree].prev = -1;
602 while(nseg < nbseg && pt.y() > 0.0) {
603 int prev = nb_tree - 1;
606 if( energy * sg_random() > 0.8f )
607 lt_build_tree_branch(tree_nr + 1, pt, energy * 0.9f, nbseg == 50 ? 10 : static_cast<int>(nbseg * 0.4f), segsize * 0.7f);
609 if( nb_tree >= MAX_LT_TREE_SEG )
611 sgSetVec3(newdir, (sg_random() - 0.5f), (sg_random() - 0.5f) - (nbseg == 50 ? 0.5f : 0.0), (sg_random() - 0.5f));
612 sgNormaliseVec3(newdir);
613 sgAddVec3( dir, newdir);
614 sgNormaliseVec3(dir);
616 sgScaleVec3( scaleDir, dir, segsize * energy * 0.5f );
617 pt[PX] += scaleDir[0];
618 pt[PY] += scaleDir[1];
619 pt[PZ] += scaleDir[2];
621 lt_tree[nb_tree].depth = tree_nr;
622 lt_tree[nb_tree].pt = pt;
623 lt_tree[nb_tree].prev = prev;
628 void SGLightning::lt_build(void) {
634 lt_build_tree_branch(0, top, 1.0, 50, top[PY] / 8.0);
635 if( ! sgEnviro.soundMgr )
637 Point3D start( sgEnviro.last_lon*SG_DEGREES_TO_RADIANS, sgEnviro.last_lat*SG_DEGREES_TO_RADIANS, 0.0 );
638 Point3D dest( lon*SG_DEGREES_TO_RADIANS, lat*SG_DEGREES_TO_RADIANS, 0.0 );
639 double course = 0.0, dist = 0.0;
640 calc_gc_course_dist( dest, start, &course, &dist );
641 if( dist < 10000.0 && ! sgEnviro.snd_playing && (dist < sgEnviro.snd_dist || ! sgEnviro.snd_active) ) {
642 sgEnviro.snd_timer = 0.0;
643 sgEnviro.snd_wait = dist / 340;
644 sgEnviro.snd_dist = dist;
645 sgEnviro.snd_pos_lat = lat;
646 sgEnviro.snd_pos_lon = lon;
647 sgEnviro.snd_active = true;
648 sgEnviro.snd_playing = false;
653 void SGLightning::lt_Render(void) {
655 if( fmod(sgEnviro.elapsed_time*100.0, 100.0) > 50.0 )
656 flash = sg_random() * 0.75f + 0.25f;
657 float h = lt_tree[0].pt[PY];
658 sgVec4 col={0.62f, 0.83f, 1.0f, 1.0f};
662 {glColorMaterial(GL_FRONT, GL_EMISSION); \
663 glDisable(GL_LINE_SMOOTH); glBegin(GL_LINES); \
665 glVertex3f(lt_tree[n].pt[PX], lt_tree[n].pt[PZ], lt_tree[n].pt[PY]); \
666 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]); \
667 glEnd(); glEnable(GL_LINE_SMOOTH);}
669 glDepthMask( GL_FALSE );
671 glBlendFunc( GL_DST_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
672 glBindTexture(GL_TEXTURE_2D, 0);
674 glDisable(GL_LIGHTING);
677 sgMat4 modelview, tmp;
678 ssgGetModelviewMatrix( modelview );
679 sgCopyMat4( tmp, sgEnviro.transform );
680 sgPostMultMat4( tmp, modelview );
681 ssgLoadModelviewMatrix( tmp );
683 Point3D start( sgEnviro.last_lon*SG_DEGREES_TO_RADIANS, sgEnviro.last_lat*SG_DEGREES_TO_RADIANS, 0.0 );
684 Point3D dest( lon*SG_DEGREES_TO_RADIANS, lat*SG_DEGREES_TO_RADIANS, 0.0 );
685 double course = 0.0, dist = 0.0;
686 calc_gc_course_dist( dest, start, &course, &dist );
687 double ax = 0.0, ay = 0.0;
688 ax = cos(course) * dist;
689 ay = sin(course) * dist;
691 glTranslatef( ax, ay, -sgEnviro.last_alt );
693 sgEnviro.radarEcho.push_back( SGWxRadarEcho ( course, 0.0, 0.0, dist, age, true, 0 ) );
695 for( int n = 0 ; n < nb_tree ; n++ ) {
696 if( lt_tree[n].prev < 0 )
699 float t1 = sgLerp(0.5, 1.0, lt_tree[n].pt[PY] / h);
701 if( lt_tree[n].depth >= 2 ) {
703 sgScaleVec4(c, col, t1 * 0.6f);
706 if( lt_tree[n].depth == 0 ) {
708 sgScaleVec4(c, col, t1 * 0.5f);
712 sgScaleVec4(c, col, t1);
716 sgScaleVec4(c, col, t1 * 0.7f);
720 if( lt_tree[n].depth == 0 )
725 sgSetVec4(c, t1, t1, t1, t1);
731 glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
733 glDepthMask( GL_TRUE );
735 glEnable(GL_LIGHTING);
738 void SGEnviro::addLightning(double lon, double lat, double alt) {
739 if( lightnings.size() > 10)
741 SGLightning *lt= new SGLightning(lon, lat, alt);
742 lightnings.push_back(lt);
745 void SGEnviro::drawLightning(void) {
746 list_of_lightning::iterator iLightning;
747 // play 'thunder' for lightning
750 // wait until sound has reached us
752 if( snd_timer >= snd_wait ) {
754 // compute relative position of lightning
755 Point3D start( sgEnviro.last_lon*SG_DEGREES_TO_RADIANS, sgEnviro.last_lat*SG_DEGREES_TO_RADIANS, 0.0 );
756 Point3D dest( snd_pos_lon*SG_DEGREES_TO_RADIANS, snd_pos_lat*SG_DEGREES_TO_RADIANS, 0.0 );
757 double course = 0.0, dist = 0.0;
758 calc_gc_course_dist( dest, start, &course, &dist );
759 double ax = 0.0, ay = 0.0;
760 ax = cos(course) * dist;
761 ay = sin(course) * dist;
762 SGSharedPtr<SGSoundSample> snd = soundMgr->find("thunder");
764 ALfloat pos[3]={ax, ay, -sgEnviro.last_alt };
765 snd->set_source_pos(pos);
770 if( !soundMgr->is_playing("thunder") ) {
776 if( ! lightning_enable_state )
779 for( iLightning = lightnings.begin() ; iLightning != lightnings.end() ; iLightning++ ) {
781 if( sg_random() > 0.95f )
782 (*iLightning)->lt_build();
783 (*iLightning)->lt_Render();
784 (*iLightning)->age -= dt;
785 if( (*iLightning)->age < 0.0 ) {
786 delete (*iLightning);
787 lightnings.erase( iLightning );
795 void SGEnviro::setFOV( float w, float h ) {
800 void SGEnviro::getFOV( float &w, float &h ) {