]> git.mxchange.org Git - flightgear.git/commitdiff
Don't allow negative values as argument to pow().
authortimoore <timoore>
Tue, 28 Oct 2008 12:10:27 +0000 (12:10 +0000)
committertimoore <timoore>
Tue, 28 Oct 2008 12:10:27 +0000 (12:10 +0000)
This was a source of a spew of "NaN" error messages at night when the
sun is at a large angle to the zenith. I don't know why this wasn't a
problem before now.

src/Main/renderer.cxx

index c952faed97b247241ffca1cad3f76f683b3afff1..97fbcb9892dbc1a82209cd4ca3d8d293fa918eb2 100644 (file)
@@ -42,6 +42,7 @@
 #include <osg/LightModel>
 #include <osg/LightSource>
 #include <osg/Material>
+#include <osg/Math>
 #include <osg/NodeCallback>
 #include <osg/Notify>
 #include <osg/PolygonMode>
@@ -612,8 +613,14 @@ FGRenderer::update( bool refresh_camera_settings ) {
 
         double sun_horiz_eff, moon_horiz_eff;
         if (fgGetBool("/sim/rendering/horizon-effect")) {
-           sun_horiz_eff = 0.67+pow(0.5+cos(l->get_sun_angle())*2/2, 0.33)/3;
-           moon_horiz_eff = 0.67+pow(0.5+cos(l->get_moon_angle())*2/2, 0.33)/3;
+            sun_horiz_eff
+                = 0.67 + pow(osg::clampAbove(0.5 + cos(l->get_sun_angle()),
+                                             0.0),
+                             0.33) / 3.0;
+            moon_horiz_eff
+                = 0.67 + pow(osg::clampAbove(0.5 + cos(l->get_moon_angle()),
+                                             0.0),
+                             0.33)/3.0;
         } else {
            sun_horiz_eff = moon_horiz_eff = 1.0;
         }