diff --git a/CMakeModules/FindSimGear.cmake b/CMakeModules/FindSimGear.cmake index 448ff70e9..4fd155021 100644 --- a/CMakeModules/FindSimGear.cmake +++ b/CMakeModules/FindSimGear.cmake @@ -151,6 +151,7 @@ else(SIMGEAR_SHARED) environment nasal tsync + bvh bucket io serial @@ -172,7 +173,6 @@ else(SIMGEAR_SHARED) tgdb model screen - bvh util sound) diff --git a/src/AIModel/AIBallistic.cxx b/src/AIModel/AIBallistic.cxx index f7a2fc7d6..6a0565652 100644 --- a/src/AIModel/AIBallistic.cxx +++ b/src/AIModel/AIBallistic.cxx @@ -498,16 +498,16 @@ void FGAIBallistic::setForcePath(const string& p) { } bool FGAIBallistic::getHtAGL(double start){ - + const SGMaterial* material = 0; if (getGroundElevationM(SGGeod::fromGeodM(pos, start), - _elevation_m, &_material)) { + _elevation_m, &material)) { _ht_agl_ft = pos.getElevationFt() - _elevation_m * SG_METER_TO_FEET; - if (_material) { - const vector& names = _material->get_names(); - _solid = _material->get_solid(); - _load_resistance = _material->get_load_resistance(); - _frictionFactor =_material->get_friction_factor(); + if (material) { + const vector& names = material->get_names(); + _solid = material->get_solid(); + _load_resistance = material->get_load_resistance(); + _frictionFactor = material->get_friction_factor(); if (!names.empty()) props->setStringValue("material/name", names[0].c_str()); diff --git a/src/AIModel/AIBallistic.hxx b/src/AIModel/AIBallistic.hxx index 63d55bd95..9b28efdae 100644 --- a/src/AIModel/AIBallistic.hxx +++ b/src/AIModel/AIBallistic.hxx @@ -219,8 +219,6 @@ private: string _force_path; string _contents_path; - const SGMaterial* _material; - void handle_collision(); void handle_expiry(); void handle_impact(); diff --git a/src/AIModel/AIBase.cxx b/src/AIModel/AIBase.cxx index 90bf34f4d..ed6d0a9d9 100644 --- a/src/AIModel/AIBase.cxx +++ b/src/AIModel/AIBase.cxx @@ -729,7 +729,7 @@ double FGAIBase::_getAltitude() const { double FGAIBase::_getAltitudeAGL(SGGeod inpos, double start){ getGroundElevationM(SGGeod::fromGeodM(inpos, start), - _elevation_m, &_material); + _elevation_m, NULL); return inpos.getElevationFt() - _elevation_m * SG_METER_TO_FEET; } diff --git a/src/AIModel/AIBase.hxx b/src/AIModel/AIBase.hxx index 8c3601b6d..a492b9b2c 100644 --- a/src/AIModel/AIBase.hxx +++ b/src/AIModel/AIBase.hxx @@ -117,7 +117,6 @@ public: const SGMaterial** material) const; double _elevation_m; - const SGMaterial* _material; double _getCartPosX() const; double _getCartPosY() const; diff --git a/src/AIModel/AIEscort.cxx b/src/AIModel/AIEscort.cxx index afe0ee8c9..765cac8db 100644 --- a/src/AIModel/AIEscort.cxx +++ b/src/AIModel/AIEscort.cxx @@ -190,13 +190,14 @@ bool FGAIEscort::getGroundElev(SGGeod inpos) { double height_m ; - if (globals->get_scenery()->get_elevation_m(SGGeod::fromGeodM(inpos, 3000), height_m, &_material,0)){ + const SGMaterial* material = 0; + if (globals->get_scenery()->get_elevation_m(SGGeod::fromGeodM(inpos, 3000), height_m, &material,0)){ _ht_agl_ft = inpos.getElevationFt() - height_m * SG_METER_TO_FEET; - if (_material) { - const vector& names = _material->get_names(); + if (material) { + const vector& names = material->get_names(); - _solid = _material->get_solid(); + _solid = material->get_solid(); if (!names.empty()) props->setStringValue("material/name", names[0].c_str()); diff --git a/src/AIModel/AIEscort.hxx b/src/AIModel/AIEscort.hxx index 380a92f28..38531eb55 100644 --- a/src/AIModel/AIEscort.hxx +++ b/src/AIModel/AIEscort.hxx @@ -89,8 +89,6 @@ private: double _max_speed; - const SGMaterial* _material; - bool _MPControl, _patrol, _stn_deg_true; // std::string _parent; diff --git a/src/AIModel/AIGroundVehicle.cxx b/src/AIModel/AIGroundVehicle.cxx index f5f2b8832..b813b3c82 100644 --- a/src/AIModel/AIGroundVehicle.cxx +++ b/src/AIModel/AIGroundVehicle.cxx @@ -237,13 +237,13 @@ bool FGAIGroundVehicle::getPitch() { //double max_alt = 10000; if (globals->get_scenery()->get_elevation_m(SGGeod::fromGeodM(geodFront, 3000), - elev_front, &_material, 0)){ + elev_front, NULL, 0)){ front_elev_m = elev_front + _z_offset_m; } else return false; if (globals->get_scenery()->get_elevation_m(SGGeod::fromGeodM(geodRear, 3000), - elev_rear, &_material, 0)){ + elev_rear, NULL, 0)){ rear_elev_m = elev_rear; } else return false; diff --git a/src/AIModel/AIGroundVehicle.hxx b/src/AIModel/AIGroundVehicle.hxx index 2e4a2349f..fcb822a3c 100644 --- a/src/AIModel/AIGroundVehicle.hxx +++ b/src/AIModel/AIGroundVehicle.hxx @@ -93,8 +93,6 @@ private: double _hitch_x_offset_m, _hitch_y_offset_m, _hitch_z_offset_m; double _dt_count, _next_run, _break_count; - const SGMaterial* _material; - }; #endif // FG_AIGROUNDVEHICLE_HXX diff --git a/src/AIModel/AIShip.cxx b/src/AIModel/AIShip.cxx index 9ecc89175..3d2263629 100644 --- a/src/AIModel/AIShip.cxx +++ b/src/AIModel/AIShip.cxx @@ -1050,7 +1050,7 @@ void FGAIShip::setWPPos() { if (curr->getOn_ground()){ if (globals->get_scenery()->get_elevation_m(SGGeod::fromGeodM(wppos, 3000), - elevation_m, &_material, 0)){ + elevation_m, NULL, 0)){ wppos.setElevationM(elevation_m); } diff --git a/src/AIModel/AIShip.hxx b/src/AIModel/AIShip.hxx index 74a5ca2e7..34038db90 100644 --- a/src/AIModel/AIShip.hxx +++ b/src/AIModel/AIShip.hxx @@ -107,8 +107,6 @@ private: SGGeod wppos; - const SGMaterial* _material; - double getRange(double lat, double lon, double lat2, double lon2) const; double getCourse(double lat, double lon, double lat2, double lon2) const; double getDaySeconds(); diff --git a/src/FDM/flight.cxx b/src/FDM/flight.cxx index 5fd06bad9..8e1ca2439 100644 --- a/src/FDM/flight.cxx +++ b/src/FDM/flight.cxx @@ -29,6 +29,7 @@ #include #include #include +#include #include #include
@@ -696,9 +697,9 @@ FGInterface::get_agl_m(double t, const double pt[3], double max_altoff, { SGVec3d pt_m = SGVec3d(pt) - max_altoff*ground_cache.get_down(); SGVec3d _contact, _normal, _linearVel, _angularVel; - material = 0; + const simgear::BVHMaterial* m = 0; bool ret = ground_cache.get_agl(t, pt_m, _contact, _normal, _linearVel, - _angularVel, id, material); + _angularVel, id, m); // correct the linear velocity, since the line intersector delivers // values for the start point and the get_agl function should // traditionally deliver for the contact point @@ -708,6 +709,7 @@ FGInterface::get_agl_m(double t, const double pt[3], double max_altoff, assign(normal, _normal); assign(linearVel, _linearVel); assign(angularVel, _angularVel); + material = dynamic_cast(m); return ret; } @@ -721,9 +723,9 @@ FGInterface::get_agl_ft(double t, const double pt[3], double max_altoff, SGVec3d pt_m = SGVec3d(pt) - max_altoff*ground_cache.get_down(); pt_m *= SG_FEET_TO_METER; SGVec3d _contact, _normal, _linearVel, _angularVel; - material = 0; + const simgear::BVHMaterial* m = 0; bool ret = ground_cache.get_agl(t, pt_m, _contact, _normal, _linearVel, - _angularVel, id, material); + _angularVel, id, m); // correct the linear velocity, since the line intersector delivers // values for the start point and the get_agl function should // traditionally deliver for the contact point @@ -734,6 +736,7 @@ FGInterface::get_agl_ft(double t, const double pt[3], double max_altoff, assign( normal, _normal ); assign( linearVel, SG_METER_TO_FEET*_linearVel ); assign( angularVel, _angularVel ); + material = dynamic_cast(m); return ret; } @@ -745,13 +748,15 @@ FGInterface::get_nearest_m(double t, const double pt[3], double maxDist, simgear::BVHNode::Id& id) { SGVec3d _contact, _linearVel, _angularVel; + const simgear::BVHMaterial* m = 0; if (!ground_cache.get_nearest(t, SGVec3d(pt), maxDist, _contact, _linearVel, - _angularVel, id, material)) + _angularVel, id, m)) return false; assign(contact, _contact); assign(linearVel, _linearVel); assign(angularVel, _angularVel); + material = dynamic_cast(m); return true; } @@ -763,14 +768,16 @@ FGInterface::get_nearest_ft(double t, const double pt[3], double maxDist, simgear::BVHNode::Id& id) { SGVec3d _contact, _linearVel, _angularVel; + const simgear::BVHMaterial* m = 0; if (!ground_cache.get_nearest(t, SG_FEET_TO_METER*SGVec3d(pt), SG_FEET_TO_METER*maxDist, _contact, _linearVel, - _angularVel, id, material)) + _angularVel, id, m)) return false; assign(contact, SG_METER_TO_FEET*_contact); assign(linearVel, SG_METER_TO_FEET*_linearVel); assign(angularVel, _angularVel); + material = dynamic_cast(m); return true; } diff --git a/src/FDM/flight.hxx b/src/FDM/flight.hxx index 9c312f33d..a2047aef9 100644 --- a/src/FDM/flight.hxx +++ b/src/FDM/flight.hxx @@ -89,6 +89,8 @@ using std::list; using std::vector; using std::string; +class SGMaterial; + /** * A little helper class to update the track if * the position has changed. In the constructor, diff --git a/src/FDM/groundcache.cxx b/src/FDM/groundcache.cxx index 21d2816d6..0e2d43b5b 100644 --- a/src/FDM/groundcache.cxx +++ b/src/FDM/groundcache.cxx @@ -45,22 +45,22 @@ #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 @@ -149,7 +149,7 @@ public: SGVec3d down = _down; double radius = _radius; bool haveHit = _haveHit; - const SGMaterial* material = _material; + const simgear::BVHMaterial* material = _material; _haveHit = false; _center = toSG(inverseMatrix.preMult(toOsg(_center))); @@ -275,7 +275,7 @@ public: { return _haveHit; } double getElevationBelowCache() const { return SGGeod::fromCart(_sceneryHit).getElevationM(); } - const SGMaterial* getMaterialBelowCache() const + const simgear::BVHMaterial* getMaterialBelowCache() const { return _material; } private: @@ -288,7 +288,7 @@ private: simgear::BVHSubTreeCollector mSubTreeCollector; SGVec3d _sceneryHit; double _maxDown; - const SGMaterial* _material; + const simgear::BVHMaterial* _material; bool _haveHit; }; @@ -381,8 +381,10 @@ FGGroundCache::prepare_ground_cache(double startSimTime, double endSimTime, if (!found_ground) { // Ok, still nothing here?? Last resort ... double alt = 0; + const SGMaterial* m = NULL; found_ground = globals->get_scenery()-> - get_elevation_m(SGGeod::fromGeodM(geodPt, 10000), alt, &_material); + get_elevation_m(SGGeod::fromGeodM(geodPt, 10000), alt, &m); + _material = m; if (found_ground) _altitude = alt; } @@ -456,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) @@ -553,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())) @@ -678,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(); @@ -731,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; @@ -787,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())) @@ -920,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) diff --git a/src/FDM/groundcache.hxx b/src/FDM/groundcache.hxx index 145561a9c..9319666a6 100644 --- a/src/FDM/groundcache.hxx +++ b/src/FDM/groundcache.hxx @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include // #define GROUNDCACHE_DEBUG @@ -37,9 +37,9 @@ #include #endif -class SGMaterial; namespace simgear { class BVHLineGeometry; +class BVHMaterial; } class FGGroundCache { @@ -89,11 +89,13 @@ public: // 0 and 1 which can be used to model lower friction with wet runways. bool 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); bool get_nearest(double t, const SGVec3d& pt, double maxDist, SGVec3d& contact, SGVec3d& linearVel, SGVec3d& angularVel, - simgear::BVHNode::Id& id, const SGMaterial*& material); + simgear::BVHNode::Id& id, + const simgear::BVHMaterial*& material); // Return 1 if the hook intersects with a wire. // That test is done by checking if the quad spanned by the points pt* @@ -120,7 +122,7 @@ private: // In case the aircraft is too high above ground. double _altitude; // the simgear material reference, contains friction coeficients ... - const SGMaterial* _material; + const simgear::BVHMaterial* _material; // The time reference for later call to intersection test routines. // Is required since we will have moving triangles in carriers. double cache_ref_time; diff --git a/src/Instrumentation/agradar.cxx b/src/Instrumentation/agradar.cxx index e5be21b86..23cf6f3eb 100644 --- a/src/Instrumentation/agradar.cxx +++ b/src/Instrumentation/agradar.cxx @@ -210,18 +210,19 @@ agRadar::setUserVec(double az, double el) bool agRadar::getMaterial(){ - if (globals->get_scenery()->get_elevation_m(hitpos, _elevation_m, &_material)){ + const SGMaterial* material = 0; + if (globals->get_scenery()->get_elevation_m(hitpos, _elevation_m, &material)){ //_ht_agl_ft = pos.getElevationFt() - _elevation_m * SG_METER_TO_FEET; - if (_material) { - const std::vector& names = _material->get_names(); + if (material) { + const std::vector& names = material->get_names(); - _solid = _material->get_solid(); - _load_resistance = _material->get_load_resistance(); - _frictionFactor =_material->get_friction_factor(); - _bumpinessFactor = _material->get_bumpiness(); + _solid = material->get_solid(); + _load_resistance = material->get_load_resistance(); + _frictionFactor = material->get_friction_factor(); + _bumpinessFactor = material->get_bumpiness(); if (!names.empty()) - _mat_name = names[0].c_str(); + _mat_name = names[0]; else _mat_name = ""; diff --git a/src/Instrumentation/agradar.hxx b/src/Instrumentation/agradar.hxx index 609f54f41..dda152e0b 100644 --- a/src/Instrumentation/agradar.hxx +++ b/src/Instrumentation/agradar.hxx @@ -53,8 +53,6 @@ public: double _elevation_m; // ground elevation in meters bool _solid; // if true ground is solid for FDMs - const SGMaterial* _material; - std::string _mat_name; // ground material SGVec3d getCartUserPos() const; diff --git a/src/Scenery/scenery.cxx b/src/Scenery/scenery.cxx index ba67e1f8f..9c6ef2796 100644 --- a/src/Scenery/scenery.cxx +++ b/src/Scenery/scenery.cxx @@ -43,8 +43,8 @@ #include #include #include -#include -#include +#include +#include #include #include
@@ -92,7 +92,7 @@ public: { return _haveHit; } const SGLineSegmentd& getLineSegment() const { return _lineSegment; } - const SGMaterial* getMaterial() const + const simgear::BVHMaterial* getMaterial() const { return _material; } virtual void apply(osg::Node& node) @@ -152,7 +152,7 @@ private: SGLineSegmentd lineSegment = _lineSegment; bool haveHit = _haveHit; - const SGMaterial* material = _material; + const simgear::BVHMaterial* material = _material; _haveHit = false; _lineSegment = lineSegment.transform(SGMatrixd(inverseMatrix.ptr())); @@ -205,7 +205,7 @@ private: SGLineSegmentd _lineSegment; const osg::Node* _skipNode; - const SGMaterial* _material; + const simgear::BVHMaterial* _material; bool _haveHit; }; @@ -290,7 +290,7 @@ FGScenery::get_elevation_m(const SGGeod& geod, double& alt, geodEnd = SGGeod::fromCart(intersectVisitor.getLineSegment().getEnd()); alt = geodEnd.getElevationM(); if (material) - *material = intersectVisitor.getMaterial(); + *material = dynamic_cast(intersectVisitor.getMaterial()); return true; } diff --git a/utils/fgelev/fgelev.cxx b/utils/fgelev/fgelev.cxx index e2f4f9f4f..20a093e35 100644 --- a/utils/fgelev/fgelev.cxx +++ b/utils/fgelev/fgelev.cxx @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -41,9 +42,8 @@ #include #include #include -#include -#include -#include +#include +#include class FGSceneryIntersect : public osg::NodeVisitor { public: