]> git.mxchange.org Git - flightgear.git/blobdiff - src/Scenery/scenery.cxx
Fix the temperature computation.
[flightgear.git] / src / Scenery / scenery.cxx
index bb3b83c9634a09d1a77c559876c9409f024688b6..73c53733aa7f07ea1a36707e164104059d660115 100644 (file)
@@ -143,7 +143,7 @@ FGScenery::get_elevation_m(const SGGeod& geod, double& alt,
   osgUtil::IntersectVisitor intersectVisitor;
   intersectVisitor.setTraversalMask(SG_NODEMASK_TERRAIN_BIT);
   osg::ref_ptr<osg::LineSegment> lineSegment;
-  lineSegment = new osg::LineSegment(start.osg(), end.osg());
+  lineSegment = new osg::LineSegment(toOsg(start), toOsg(end));
   intersectVisitor.addLineSegment(lineSegment.get());
   get_scene_graph()->accept(intersectVisitor);
   bool hits = false;
@@ -157,20 +157,20 @@ 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;
         hits = true;
-        if (material) {
-          *material = 0;
-          const EffectGeode* eg
-            = dynamic_cast<const EffectGeode*>(hit.getGeode());
-          if (eg)
-            *material = SGMaterialLib::findMaterial(eg->getEffect());
-        }
+        if (material)
+          *material = SGMaterialLib::findMaterial(hit.getGeode());
       }
     }
   }
@@ -195,7 +195,7 @@ FGScenery::get_cart_ground_intersection(const SGVec3d& pos, const SGVec3d& dir,
   osgUtil::IntersectVisitor intersectVisitor;
   intersectVisitor.setTraversalMask(SG_NODEMASK_TERRAIN_BIT);
   osg::ref_ptr<osg::LineSegment> lineSegment;
-  lineSegment = new osg::LineSegment(start.osg(), end.osg());
+  lineSegment = new osg::LineSegment(toOsg(start), toOsg(end));
   intersectVisitor.addLineSegment(lineSegment.get());
   get_scene_graph()->accept(intersectVisitor);
   bool hits = false;
@@ -209,12 +209,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,9 +232,10 @@ 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);
+    simgear::CheckSceneryVisitor csnv(getPagerSingleton(), toOsg(p), range_m);
     // currently the PagedLODs will not be loaded by the DatabasePager
     // while the splashscreen is there, so CheckSceneryVisitor force-loads
     // missing objects in the main thread