Both of these patches should fix the fog flashing to white(black?) bug. The first one just checks for the Not a Number condition that results from acos(1+small_delta). The second patch uses atan2, but doesn't quite make it near 0 or PI at the edge cases near 1 or -1. I can't really tell the difference between the two, but I'm sure there is one. I suppose a third solution would be to wrap the math.h library and bounds check for all acos asin calls ?

Thoughts, suggestions?

cd $flightgear_root/source/src/Time
patch < sunpos_nan.patch


- Simon.

Simon Hollier
Computer Services
Northeast Health District



Index: sunpos.cxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Time/sunpos.cxx,v
retrieving revision 1.3
diff -r1.3 sunpos.cxx
249c249
<     double dot, east_dot;
---
>     double dot, east_dot, ang;
345c345,348
<       l->set_sun_rotation( acos(dot) );
---
>               ang = acos( dot );
>               // values of dot where dot = 1 + small_delta cause acos to return 
> NaN(not a number)
>               if ( isnan(ang) ) 
>                       ( dot - 0.5 > 0 ) ? ang =  0 : ang = SGD_PI;
347c350,352
<       l->set_sun_rotation( -acos(dot) );
---
>               ang = -acos(dot);
>               if ( isnan(ang) ) 
>                       ( dot - 0.5 > 0 ) ? ang =  0 : ang = -SGD_PI;
349,350c354,356
<     // cout << "  Sky needs to rotate = " << angle << " rads = "
<     //      << angle * SGD_RADIANS_TO_DEGREES << " degrees." << endl;
---
>       l->set_sun_rotation( ang );
>     // cout << "  Sky needs to rotate = " << ang << " rads = "
>     //      << ang * SGD_RADIANS_TO_DEGREES << " degrees." << endl;
Index: sunpos.cxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Time/sunpos.cxx,v
retrieving revision 1.3
diff -r1.3 sunpos.cxx
249c249
<     double dot, east_dot;
---
>     double dot, east_dot, ang;
345c345
<       l->set_sun_rotation( acos(dot) );
---
>               ang = -atan2( dot, SGD_PI / 4 ) + SGD_PI / 2;
347c347
<       l->set_sun_rotation( -acos(dot) );
---
>               ang = atan2( dot, SGD_PI / 4 ) - SGD_PI / 2;
349,350c349,351
<     // cout << "  Sky needs to rotate = " << angle << " rads = "
<     //      << angle * SGD_RADIANS_TO_DEGREES << " degrees." << endl;
---
>       l->set_sun_rotation( ang );
>      //cout << "  Sky needs to rotate = " << ang << " rads = "
>       //    << ang * SGD_RADIANS_TO_DEGREES << " degrees." << endl;
_______________________________________________
Flightgear-devel mailing list
[EMAIL PROTECTED]
http://mail.flightgear.org/mailman/listinfo/flightgear-devel

Reply via email to