1
0
Fork 0

bvh: Adapt to upstream bvh changes in simgear.

This commit is contained in:
Mathias Froehlich 2012-08-24 21:20:44 +02:00
parent cce186a57c
commit e3ad3d3a07
19 changed files with 104 additions and 75 deletions

View file

@ -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)

View file

@ -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<string>& names = _material->get_names();
_solid = _material->get_solid();
_load_resistance = _material->get_load_resistance();
_frictionFactor =_material->get_friction_factor();
if (material) {
const vector<string>& 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());

View file

@ -219,8 +219,6 @@ private:
string _force_path;
string _contents_path;
const SGMaterial* _material;
void handle_collision();
void handle_expiry();
void handle_impact();

View file

@ -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;
}

View file

@ -117,7 +117,6 @@ public:
const SGMaterial** material) const;
double _elevation_m;
const SGMaterial* _material;
double _getCartPosX() const;
double _getCartPosY() const;

View file

@ -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<string>& names = _material->get_names();
if (material) {
const vector<string>& names = material->get_names();
_solid = _material->get_solid();
_solid = material->get_solid();
if (!names.empty())
props->setStringValue("material/name", names[0].c_str());

View file

@ -89,8 +89,6 @@ private:
double _max_speed;
const SGMaterial* _material;
bool _MPControl, _patrol, _stn_deg_true;
// std::string _parent;

View file

@ -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;

View file

@ -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

View file

@ -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);
}

View file

@ -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();

View file

@ -29,6 +29,7 @@
#include <simgear/constants.h>
#include <simgear/debug/logstream.hxx>
#include <simgear/timing/timestamp.hxx>
#include <simgear/scene/material/mat.hxx>
#include <Scenery/scenery.hxx>
#include <Main/globals.hxx>
@ -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<const SGMaterial*>(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<const SGMaterial*>(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<const SGMaterial*>(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<const SGMaterial*>(m);
return true;
}

View file

@ -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,

View file

@ -45,22 +45,22 @@
#include <simgear/scene/util/SGSceneUserData.hxx>
#include <simgear/scene/util/OsgMath.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/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
@ -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)

View file

@ -27,7 +27,7 @@
#include <simgear/constants.h>
#include <simgear/math/SGMath.hxx>
#include <simgear/math/SGGeometry.hxx>
#include <simgear/scene/bvh/BVHNode.hxx>
#include <simgear/bvh/BVHNode.hxx>
#include <simgear/structure/SGSharedPtr.hxx>
// #define GROUNDCACHE_DEBUG
@ -37,9 +37,9 @@
#include <simgear/timing/timestamp.hxx>
#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;

View file

@ -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<std::string>& names = _material->get_names();
if (material) {
const std::vector<std::string>& 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 = "";

View file

@ -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;

View file

@ -43,8 +43,8 @@
#include <simgear/scene/util/OsgMath.hxx>
#include <simgear/scene/util/SGSceneUserData.hxx>
#include <simgear/scene/model/CheckSceneryVisitor.hxx>
#include <simgear/scene/bvh/BVHNode.hxx>
#include <simgear/scene/bvh/BVHLineSegmentVisitor.hxx>
#include <simgear/bvh/BVHNode.hxx>
#include <simgear/bvh/BVHLineSegmentVisitor.hxx>
#include <Viewer/renderer.hxx>
#include <Main/fg_props.hxx>
@ -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<const SGMaterial*>(intersectVisitor.getMaterial());
return true;
}

View file

@ -34,6 +34,7 @@
#include <simgear/props/props.hxx>
#include <simgear/props/props_io.hxx>
#include <simgear/scene/material/matlib.hxx>
#include <simgear/scene/util/OsgMath.hxx>
#include <simgear/scene/util/SGNodeMasks.hxx>
#include <simgear/scene/util/SGReaderWriterOptions.hxx>
#include <simgear/scene/util/SGSceneFeatures.hxx>
@ -41,9 +42,8 @@
#include <simgear/scene/tgdb/userdata.hxx>
#include <simgear/scene/model/ModelRegistry.hxx>
#include <simgear/misc/ResourceManager.hxx>
#include <simgear/scene/bvh/BVHNode.hxx>
#include <simgear/scene/bvh/BVHLineSegmentVisitor.hxx>
#include <simgear/scene/util/OsgMath.hxx>
#include <simgear/bvh/BVHNode.hxx>
#include <simgear/bvh/BVHLineSegmentVisitor.hxx>
class FGSceneryIntersect : public osg::NodeVisitor {
public: