]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/groundcache.cxx
Developer-warnings
[flightgear.git] / src / FDM / groundcache.cxx
index ad56fc90f94ad9c8f7a6a0ad35c8efa2a32ed71e..0b341159aadd04bae91e51e22971dc989d2fd461 100644 (file)
 #include <simgear/constants.h>
 #include <simgear/debug/logstream.hxx>
 #include <simgear/math/SGMisc.hxx>
+#include <simgear/scene/material/mat.hxx>
 #include <simgear/scene/util/SGNodeMasks.hxx>
 #include <simgear/scene/util/SGSceneUserData.hxx>
-
-#include <simgear/scene/bvh/BVHNode.hxx>
-#include <simgear/scene/bvh/BVHGroup.hxx>
-#include <simgear/scene/bvh/BVHTransform.hxx>
-#include <simgear/scene/bvh/BVHMotionTransform.hxx>
-#include <simgear/scene/bvh/BVHLineGeometry.hxx>
-#include <simgear/scene/bvh/BVHStaticGeometry.hxx>
-#include <simgear/scene/bvh/BVHStaticData.hxx>
-#include <simgear/scene/bvh/BVHStaticNode.hxx>
-#include <simgear/scene/bvh/BVHStaticTriangle.hxx>
-#include <simgear/scene/bvh/BVHStaticBinary.hxx>
-#include <simgear/scene/bvh/BVHSubTreeCollector.hxx>
-#include <simgear/scene/bvh/BVHLineSegmentVisitor.hxx>
-#include <simgear/scene/bvh/BVHNearestPointVisitor.hxx>
+#include <simgear/scene/util/OsgMath.hxx>
+
+#include <simgear/bvh/BVHNode.hxx>
+#include <simgear/bvh/BVHGroup.hxx>
+#include <simgear/bvh/BVHTransform.hxx>
+#include <simgear/bvh/BVHMotionTransform.hxx>
+#include <simgear/bvh/BVHLineGeometry.hxx>
+#include <simgear/bvh/BVHStaticGeometry.hxx>
+#include <simgear/bvh/BVHStaticData.hxx>
+#include <simgear/bvh/BVHStaticNode.hxx>
+#include <simgear/bvh/BVHStaticTriangle.hxx>
+#include <simgear/bvh/BVHStaticBinary.hxx>
+#include <simgear/bvh/BVHSubTreeCollector.hxx>
+#include <simgear/bvh/BVHLineSegmentVisitor.hxx>
+#include <simgear/bvh/BVHNearestPointVisitor.hxx>
 
 #ifdef GROUNDCACHE_DEBUG
-#include <simgear/scene/bvh/BVHDebugCollectVisitor.hxx>
+#include <simgear/scene/model/BVHDebugCollectVisitor.hxx>
 #include <Main/fg_props.hxx>
 #endif
 
@@ -148,11 +150,11 @@ public:
         SGVec3d down = _down;
         double radius = _radius;
         bool haveHit = _haveHit;
-        const SGMaterial* material = _material;
+        const simgear::BVHMaterial* material = _material;
 
         _haveHit = false;
-        _center = SGVec3d(inverseMatrix.preMult(_center.osg()));
-        _down = SGVec3d(osg::Matrix::transform3x3(_down.osg(), inverseMatrix));
+        _center = toSG(inverseMatrix.preMult(toOsg(_center)));
+        _down = toSG(osg::Matrix::transform3x3(toOsg(_down), inverseMatrix));
         if (velocity) {
             SGVec3d staticCenter(_center);
 
@@ -208,7 +210,7 @@ public:
                 _sceneryHit = ori.transform(_sceneryHit);
                 _sceneryHit += dt*velocity->linear;
             }
-            _sceneryHit = SGVec3d(matrix.preMult(_sceneryHit.osg()));
+            _sceneryHit = toSG(matrix.preMult(toOsg(_sceneryHit)));
         } else {
             _material = material;
             _haveHit = haveHit;
@@ -263,7 +265,8 @@ public:
 
         SGLineSegmentd downSeg(_center, _center + _maxDown*_down);
         double maxDist = bound._radius + _radius;
-        return distSqr(downSeg, SGVec3d(bound._center)) <= maxDist*maxDist;
+        SGVec3d boundCenter(toVec3d(toSG(bound._center)));
+        return distSqr(downSeg, boundCenter) <= maxDist*maxDist;
     }
     
     SGSharedPtr<simgear::BVHNode> getBVHNode() const
@@ -273,7 +276,7 @@ public:
     { return _haveHit; }
     double getElevationBelowCache() const
     { return SGGeod::fromCart(_sceneryHit).getElevationM(); }
-    const SGMaterial* getMaterialBelowCache() const
+    const simgear::BVHMaterial* getMaterialBelowCache() const
     { return _material; }
     
 private:
@@ -286,7 +289,7 @@ private:
     simgear::BVHSubTreeCollector mSubTreeCollector;
     SGVec3d _sceneryHit;
     double _maxDown;
-    const SGMaterial* _material;
+    const simgear::BVHMaterial* _material;
     bool _haveHit;
 };
 
@@ -327,7 +330,7 @@ FGGroundCache::prepare_ground_cache(double startSimTime, double endSimTime,
     SGGeod geodPt = SGGeod::fromCart(pt);
     // Don't blow away the cache ground_radius and stuff if there's no
     // scenery
-    if (!globals->get_tile_mgr()->scenery_available(geodPt, rad)) {
+    if (!globals->get_tile_mgr()->schedule_scenery(geodPt, rad, 1.0)) {
         SG_LOG(SG_FLIGHT, SG_WARN, "prepare_ground_cache(): scenery_available "
                "returns false at " << geodPt << " " << pt << " " << rad);
         return false;
@@ -379,6 +382,7 @@ FGGroundCache::prepare_ground_cache(double startSimTime, double endSimTime,
     if (!found_ground) {
         // Ok, still nothing here?? Last resort ...
         double alt = 0;
+        _material = 0;
         found_ground = globals->get_scenery()->
             get_elevation_m(SGGeod::fromGeodM(geodPt, 10000), alt, &_material);
         if (found_ground)
@@ -454,6 +458,12 @@ public:
             return;
         leaf.traverse(*this);
     }
+    virtual void apply(BVHPageNode& leaf)
+    {
+        if (_foundId)
+            return;
+        leaf.traverse(*this);
+    }
     virtual void apply(BVHTransform& transform)
     {
         if (_foundId)
@@ -551,6 +561,12 @@ public:
             return;
         leaf.traverse(*this);
     }
+    virtual void apply(BVHPageNode& leaf)
+    {
+        if (!intersects(_sphere, leaf.getBoundingSphere()))
+            return;
+        leaf.traverse(*this);
+    }
     virtual void apply(BVHTransform& transform)
     {
         if (!intersects(_sphere, transform.getBoundingSphere()))
@@ -676,7 +692,7 @@ FGGroundCache::get_cat(double t, const SGVec3d& pt,
 bool
 FGGroundCache::get_agl(double t, const SGVec3d& pt, SGVec3d& contact,
                        SGVec3d& normal, SGVec3d& linearVel, SGVec3d& angularVel,
-                       simgear::BVHNode::Id& id, const SGMaterial*& material)
+                       simgear::BVHNode::Id& id, const simgear::BVHMaterial*& material)
 {
 #ifdef GROUNDCACHE_DEBUG
     SGTimeStamp t0 = SGTimeStamp::now();
@@ -729,7 +745,7 @@ bool
 FGGroundCache::get_nearest(double t, const SGVec3d& pt, double maxDist,
                            SGVec3d& contact, SGVec3d& linearVel,
                            SGVec3d& angularVel, simgear::BVHNode::Id& id,
-                           const SGMaterial*& material)
+                           const simgear::BVHMaterial*& material)
 {
     if (!_localBvhTree)
         return false;
@@ -785,6 +801,13 @@ public:
 
         leaf.traverse(*this);
     }
+    virtual void apply(BVHPageNode& leaf)
+    {
+        if (!_intersects(leaf.getBoundingSphere()))
+            return;
+
+        leaf.traverse(*this);
+    }
     virtual void apply(BVHTransform& transform)
     {
         if (!_intersects(transform.getBoundingSphere()))
@@ -898,7 +921,7 @@ bool FGGroundCache::caught_wire(double t, const SGVec3d pt[4])
         _localBvhTree->accept(wireIntersector);
     
     _wire = wireIntersector.getWire();
-    return _wire;
+    return (_wire != NULL);
 }
 
 class FGGroundCache::WireFinder : public BVHVisitor {
@@ -918,6 +941,12 @@ public:
             return;
         leaf.traverse(*this);
     }
+    virtual void apply(BVHPageNode& leaf)
+    {
+        if (_haveLineSegment)
+            return;
+        leaf.traverse(*this);
+    }
     virtual void apply(BVHTransform& transform)
     {
         if (_haveLineSegment)