]> git.mxchange.org Git - flightgear.git/commitdiff
Fix a problem introduced with the past vector changes.
authorfrohlich <frohlich>
Mon, 7 Sep 2009 18:01:33 +0000 (18:01 +0000)
committerTim Moore <timoore@redhat.com>
Wed, 9 Sep 2009 06:56:31 +0000 (08:56 +0200)
Fix a potential nan problem with the scenery_available method.

Modified Files:
src/Scenery/scenery.cxx

src/Scenery/scenery.cxx

index bb3b83c9634a09d1a77c559876c9409f024688b6..4004b5b2c6aa74e57adcb8b5eff4d22844852506 100644 (file)
@@ -157,9 +157,14 @@ FGScenery::get_elevation_m(const SGGeod& geod, double& alt,
           std::find(hit.getNodePath().begin(), hit.getNodePath().end(),
                     butNotFrom) != hit.getNodePath().end())
           continue;
-      SGVec3d point;
-      point.osg() = hit.getWorldIntersectPoint();
-      SGGeod geod = SGGeod::fromCart(point);
+
+      // We might need the double variant of the intersection point.
+      // Thus we cannot use the float variant delivered by
+      // hit.getWorldIntersectPoint() but we have to redo that with osg::Vec3d.
+      osg::Vec3d point = hit.getLocalIntersectPoint();
+      if (hit.getMatrix())
+        point = point*(*hit.getMatrix());
+      SGGeod geod = SGGeod::fromCart(toSG(point));
       double elevation = geod.getElevationM();
       if (alt < elevation) {
         alt = elevation;
@@ -209,12 +214,16 @@ FGScenery::get_cart_ground_intersection(const SGVec3d& pos, const SGVec3d& dir,
           std::find(hit.getNodePath().begin(), hit.getNodePath().end(),
                     butNotFrom) != hit.getNodePath().end())
           continue;
-      SGVec3d point;
-      point.osg() = hit.getWorldIntersectPoint();
-      double newdist = length(start - point);
+      // We might need the double variant of the intersection point.
+      // Thus we cannot use the float variant delivered by
+      // hit.getWorldIntersectPoint() but we have to redo that with osg::Vec3d.
+      osg::Vec3d point = hit.getLocalIntersectPoint();
+      if (hit.getMatrix())
+        point = point*(*hit.getMatrix());
+      double newdist = length(start - toSG(point));
       if (newdist < dist) {
         dist = newdist;
-        nearestHit = point;
+        nearestHit = toSG(point);
         hits = true;
       }
     }
@@ -228,7 +237,8 @@ bool FGScenery::scenery_available(const SGGeod& position, double range_m)
   if(globals->get_tile_mgr()->scenery_available(position, range_m))
   {
     double elev;
-    get_elevation_m(SGGeod::fromGeodM(position, SG_MAX_ELEVATION_M), elev, 0);
+    if (!get_elevation_m(SGGeod::fromGeodM(position, SG_MAX_ELEVATION_M), elev, 0, 0))
+      return false;
     SGVec3f p = SGVec3f::fromGeod(SGGeod::fromGeodM(position, elev));
     simgear::CheckSceneryVisitor csnv(getPagerSingleton(), p.osg(), range_m);
     // currently the PagedLODs will not be loaded by the DatabasePager