X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FFDM%2Fgroundcache.cxx;h=0b341159aadd04bae91e51e22971dc989d2fd461;hb=2314ccfe13e5e175763000e4c8ba86be79aa3a97;hp=e2414806c96da068a08caa6f6d0075d34c7c21d9;hpb=70be1629e61d9b751a2f73df30b83bb1be6ca4fe;p=flightgear.git diff --git a/src/FDM/groundcache.cxx b/src/FDM/groundcache.cxx index e2414806c..0b341159a 100644 --- a/src/FDM/groundcache.cxx +++ b/src/FDM/groundcache.cxx @@ -41,25 +41,27 @@ #include #include #include +#include #include #include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #ifdef GROUNDCACHE_DEBUG -#include +#include #include
#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 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) @@ -474,11 +484,10 @@ public: if (_id == transform.getId()) { _foundId = true; - return; + } else { + transform.traverse(*this); } - transform.traverse(*this); - if (_foundId) { SGMatrixd toWorld = transform.getToWorldTransform(_time); SGVec3d referencePoint = _bodyToWorld.xformPt(SGVec3d::zeros()); @@ -541,9 +550,9 @@ FGGroundCache::get_body(double t, SGMatrixd& bodyToWorld, SGVec3d& linearVel, class FGGroundCache::CatapultFinder : public BVHVisitor { public: CatapultFinder(const SGSphered& sphere, const double& t) : + _haveLineSegment(false), _sphere(sphere), - _time(t), - _haveLineSegment(false) + _time(t) { } virtual void apply(BVHGroup& leaf) @@ -552,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())) @@ -677,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(); @@ -730,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; @@ -786,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())) @@ -899,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 { @@ -919,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)