From 26664aaff0e2f97db916909218d849b51636ccc0 Mon Sep 17 00:00:00 2001 From: Mathias Froehlich Date: Mon, 27 Aug 2012 20:51:16 +0200 Subject: [PATCH] Push SGMaterial use into these classes that need it. --- src/AIModel/AIBallistic.cxx | 5 +++-- src/AIModel/AIBase.cxx | 2 +- src/AIModel/AIBase.hxx | 6 ++++-- src/AIModel/AIEscort.cxx | 5 +++-- src/FDM/JSBSim/JSBSim.cxx | 2 +- src/FDM/YASim/FGGround.cpp | 4 ++-- src/FDM/YASim/FGGround.hpp | 6 ++++-- src/FDM/YASim/Gear.cpp | 5 +++-- src/FDM/YASim/Gear.hpp | 6 ++++-- src/FDM/YASim/Ground.cpp | 4 ++-- src/FDM/YASim/Ground.hpp | 6 ++++-- src/FDM/YASim/Model.cpp | 2 +- src/FDM/flight.cxx | 30 +++++++++++++----------------- src/FDM/flight.hxx | 12 +++++++----- src/FDM/groundcache.cxx | 5 ++--- src/Instrumentation/agradar.cxx | 5 +++-- src/Radio/radio.cxx | 6 ++++-- src/Scenery/scenery.cxx | 7 ++++--- src/Scenery/scenery.hxx | 9 ++++++--- src/Scripting/NasalPositioned.cxx | 5 +++-- 20 files changed, 74 insertions(+), 58 deletions(-) diff --git a/src/AIModel/AIBallistic.cxx b/src/AIModel/AIBallistic.cxx index 6a0565652..fc4ea30c1 100644 --- a/src/AIModel/AIBallistic.cxx +++ b/src/AIModel/AIBallistic.cxx @@ -498,9 +498,10 @@ void FGAIBallistic::setForcePath(const string& p) { } bool FGAIBallistic::getHtAGL(double start){ - const SGMaterial* material = 0; + const simgear::BVHMaterial* mat = 0; if (getGroundElevationM(SGGeod::fromGeodM(pos, start), - _elevation_m, &material)) { + _elevation_m, &mat)) { + const SGMaterial* material = dynamic_cast(mat); _ht_agl_ft = pos.getElevationFt() - _elevation_m * SG_METER_TO_FEET; if (material) { diff --git a/src/AIModel/AIBase.cxx b/src/AIModel/AIBase.cxx index ed6d0a9d9..a17b9e476 100644 --- a/src/AIModel/AIBase.cxx +++ b/src/AIModel/AIBase.cxx @@ -607,7 +607,7 @@ SGVec3d FGAIBase::getCartPos() const { } bool FGAIBase::getGroundElevationM(const SGGeod& pos, double& elev, - const SGMaterial** material) const { + const simgear::BVHMaterial** material) const { return globals->get_scenery()->get_elevation_m(pos, elev, material, _model.get()); } diff --git a/src/AIModel/AIBase.hxx b/src/AIModel/AIBase.hxx index a492b9b2c..3a9426140 100644 --- a/src/AIModel/AIBase.hxx +++ b/src/AIModel/AIBase.hxx @@ -38,7 +38,9 @@ using std::string; -class SGMaterial; +namespace simgear { +class BVHMaterial; +} class FGAIManager; class FGAIFlightPlan; class FGFX; @@ -114,7 +116,7 @@ public: SGVec3d getCartPos() const; bool getGroundElevationM(const SGGeod& pos, double& elev, - const SGMaterial** material) const; + const simgear::BVHMaterial** material) const; double _elevation_m; diff --git a/src/AIModel/AIEscort.cxx b/src/AIModel/AIEscort.cxx index 765cac8db..8012ae923 100644 --- a/src/AIModel/AIEscort.cxx +++ b/src/AIModel/AIEscort.cxx @@ -190,8 +190,9 @@ bool FGAIEscort::getGroundElev(SGGeod inpos) { double height_m ; - const SGMaterial* material = 0; - if (globals->get_scenery()->get_elevation_m(SGGeod::fromGeodM(inpos, 3000), height_m, &material,0)){ + const simgear::BVHMaterial* mat = 0; + if (globals->get_scenery()->get_elevation_m(SGGeod::fromGeodM(inpos, 3000), height_m, &mat, 0)){ + const SGMaterial* material = dynamic_cast(mat); _ht_agl_ft = inpos.getElevationFt() - height_m * SG_METER_TO_FEET; if (material) { diff --git a/src/FDM/JSBSim/JSBSim.cxx b/src/FDM/JSBSim/JSBSim.cxx index c716f7734..d67e57194 100644 --- a/src/FDM/JSBSim/JSBSim.cxx +++ b/src/FDM/JSBSim/JSBSim.cxx @@ -1330,7 +1330,7 @@ FGJSBsim::get_agl_ft(double t, const double pt[3], double alt_off, double contact[3], double normal[3], double vel[3], double angularVel[3], double *agl) { - const SGMaterial* material; + const simgear::BVHMaterial* material; simgear::BVHNode::Id id; if (!FGInterface::get_agl_ft(t, pt, alt_off, contact, normal, vel, angularVel, material, id)) diff --git a/src/FDM/YASim/FGGround.cpp b/src/FDM/YASim/FGGround.cpp index 7085f5677..a2f787b29 100644 --- a/src/FDM/YASim/FGGround.cpp +++ b/src/FDM/YASim/FGGround.cpp @@ -26,7 +26,7 @@ void FGGround::getGroundPlane(const double pos[3], { // Return values for the callback. double cp[3], dvel[3], dangvel[3]; - const SGMaterial* material; + const simgear::BVHMaterial* material; simgear::BVHNode::Id id; _iface->get_agl_m(_toff, pos, 2, cp, plane, dvel, dangvel, material, id); @@ -38,7 +38,7 @@ void FGGround::getGroundPlane(const double pos[3], void FGGround::getGroundPlane(const double pos[3], double plane[4], float vel[3], - const SGMaterial **material) + const simgear::BVHMaterial **material) { // Return values for the callback. double cp[3], dvel[3], dangvel[3]; diff --git a/src/FDM/YASim/FGGround.hpp b/src/FDM/YASim/FGGround.hpp index 5f5c7e946..f3cdadbfb 100644 --- a/src/FDM/YASim/FGGround.hpp +++ b/src/FDM/YASim/FGGround.hpp @@ -4,7 +4,9 @@ #include "Ground.hpp" class FGInterface; -class SGMaterial; +namespace simgear { +class BVHMaterial; +} namespace yasim { @@ -21,7 +23,7 @@ public: virtual void getGroundPlane(const double pos[3], double plane[4], float vel[3], - const SGMaterial **material); + const simgear::BVHMaterial **material); virtual bool caughtWire(const double pos[4][3]); diff --git a/src/FDM/YASim/Gear.cpp b/src/FDM/YASim/Gear.cpp index aa52295ea..6276c4448 100644 --- a/src/FDM/YASim/Gear.cpp +++ b/src/FDM/YASim/Gear.cpp @@ -7,7 +7,8 @@ #include "BodyEnvironment.hpp" #include "RigidBody.hpp" -#include +#include +#include #include #include "Gear.hpp" namespace yasim { @@ -146,7 +147,7 @@ void Gear::setInitialLoad(float l) void Gear::setGlobalGround(double *global_ground, float* global_vel, double globalX, double globalY, - const SGMaterial *material) + const simgear::BVHMaterial *material) { int i; double frictionFactor,rollingFriction,loadCapacity,loadResistance,bumpiness; diff --git a/src/FDM/YASim/Gear.hpp b/src/FDM/YASim/Gear.hpp index 62da887b8..8d8cb3544 100644 --- a/src/FDM/YASim/Gear.hpp +++ b/src/FDM/YASim/Gear.hpp @@ -1,7 +1,9 @@ #ifndef _GEAR_HPP #define _GEAR_HPP -class SGMaterial; +namespace simgear { +class BVHMaterial; +} namespace yasim { @@ -50,7 +52,7 @@ public: void setIgnoreWhileSolving(bool c); void setGlobalGround(double* global_ground, float* global_vel, double globalX, double globalY, - const SGMaterial *material); + const simgear::BVHMaterial *material); void getPosition(float* out); void getCompression(float* out); void getGlobalGround(double* global_ground); diff --git a/src/FDM/YASim/Ground.cpp b/src/FDM/YASim/Ground.cpp index 30d8583a4..955319e68 100644 --- a/src/FDM/YASim/Ground.cpp +++ b/src/FDM/YASim/Ground.cpp @@ -4,7 +4,7 @@ #include "Glue.hpp" -#include +#include #include "Ground.hpp" namespace yasim { @@ -35,7 +35,7 @@ void Ground::getGroundPlane(const double pos[3], void Ground::getGroundPlane(const double pos[3], double plane[4], float vel[3], - const SGMaterial **material) + const simgear::BVHMaterial **material) { getGroundPlane(pos,plane,vel); } diff --git a/src/FDM/YASim/Ground.hpp b/src/FDM/YASim/Ground.hpp index 8b9045357..436c6e757 100644 --- a/src/FDM/YASim/Ground.hpp +++ b/src/FDM/YASim/Ground.hpp @@ -1,7 +1,9 @@ #ifndef _GROUND_HPP #define _GROUND_HPP -class SGMaterial; +namespace simgear { +class BVHMaterial; +} namespace yasim { class Ground { @@ -14,7 +16,7 @@ public: virtual void getGroundPlane(const double pos[3], double plane[4], float vel[3], - const SGMaterial **material); + const simgear::BVHMaterial **material); virtual bool caughtWire(const double pos[4][3]); diff --git a/src/FDM/YASim/Model.cpp b/src/FDM/YASim/Model.cpp index b92aea504..8f33bdbaf 100644 --- a/src/FDM/YASim/Model.cpp +++ b/src/FDM/YASim/Model.cpp @@ -326,7 +326,7 @@ void Model::updateGround(State* s) // Ask for the ground plane in the global coordinate system double global_ground[4]; float global_vel[3]; - const SGMaterial* material; + const simgear::BVHMaterial* material; _ground_cb->getGroundPlane(pt, global_ground, global_vel, &material); g->setGlobalGround(global_ground, global_vel, pt[0], pt[1], material); } diff --git a/src/FDM/flight.cxx b/src/FDM/flight.cxx index 8e1ca2439..9826d6417 100644 --- a/src/FDM/flight.cxx +++ b/src/FDM/flight.cxx @@ -693,13 +693,13 @@ bool FGInterface::get_agl_m(double t, const double pt[3], double max_altoff, double contact[3], double normal[3], double linearVel[3], double angularVel[3], - SGMaterial const*& material, simgear::BVHNode::Id& id) + simgear::BVHMaterial const*& material, simgear::BVHNode::Id& id) { SGVec3d pt_m = SGVec3d(pt) - max_altoff*ground_cache.get_down(); SGVec3d _contact, _normal, _linearVel, _angularVel; - const simgear::BVHMaterial* m = 0; + material = 0; bool ret = ground_cache.get_agl(t, pt_m, _contact, _normal, _linearVel, - _angularVel, id, m); + _angularVel, id, material); // 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 @@ -709,7 +709,6 @@ 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; } @@ -717,15 +716,15 @@ bool FGInterface::get_agl_ft(double t, const double pt[3], double max_altoff, double contact[3], double normal[3], double linearVel[3], double angularVel[3], - SGMaterial const*& material, simgear::BVHNode::Id& id) + simgear::BVHMaterial const*& material, simgear::BVHNode::Id& id) { // Convert units and do the real work. SGVec3d pt_m = SGVec3d(pt) - max_altoff*ground_cache.get_down(); pt_m *= SG_FEET_TO_METER; SGVec3d _contact, _normal, _linearVel, _angularVel; - const simgear::BVHMaterial* m = 0; + material = 0; bool ret = ground_cache.get_agl(t, pt_m, _contact, _normal, _linearVel, - _angularVel, id, m); + _angularVel, id, material); // 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 @@ -736,7 +735,6 @@ 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; } @@ -744,19 +742,18 @@ bool FGInterface::get_nearest_m(double t, const double pt[3], double maxDist, double contact[3], double normal[3], double linearVel[3], double angularVel[3], - SGMaterial const*& material, + simgear::BVHMaterial const*& material, simgear::BVHNode::Id& id) { SGVec3d _contact, _linearVel, _angularVel; - const simgear::BVHMaterial* m = 0; + material = 0; if (!ground_cache.get_nearest(t, SGVec3d(pt), maxDist, _contact, _linearVel, - _angularVel, id, m)) + _angularVel, id, material)) return false; assign(contact, _contact); assign(linearVel, _linearVel); assign(angularVel, _angularVel); - material = dynamic_cast(m); return true; } @@ -764,20 +761,19 @@ bool FGInterface::get_nearest_ft(double t, const double pt[3], double maxDist, double contact[3], double normal[3], double linearVel[3], double angularVel[3], - SGMaterial const*& material, + simgear::BVHMaterial const*& material, simgear::BVHNode::Id& id) { SGVec3d _contact, _linearVel, _angularVel; - const simgear::BVHMaterial* m = 0; + material = 0; if (!ground_cache.get_nearest(t, SG_FEET_TO_METER*SGVec3d(pt), SG_FEET_TO_METER*maxDist, _contact, _linearVel, - _angularVel, id, m)) + _angularVel, id, material)) 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; } @@ -831,7 +827,7 @@ FGInterface::get_groundlevel_m(const SGGeod& geod) } double contact[3], normal[3], vel[3], angvel[3]; - const SGMaterial* material; + const simgear::BVHMaterial* material; simgear::BVHNode::Id id; // Ignore the return value here, since it just tells us if // the returns stem from the groundcache or from the coarse diff --git a/src/FDM/flight.hxx b/src/FDM/flight.hxx index a2047aef9..0cd39520b 100644 --- a/src/FDM/flight.hxx +++ b/src/FDM/flight.hxx @@ -89,7 +89,9 @@ using std::list; using std::vector; using std::string; -class SGMaterial; +namespace simgear { +class BVHMaterial; +} /** * A little helper class to update the track if @@ -693,11 +695,11 @@ public: // contact point. bool get_agl_m(double t, const double pt[3], double max_altoff, double contact[3], double normal[3], double linearVel[3], - double angularVel[3], SGMaterial const*& material, + double angularVel[3], simgear::BVHMaterial const*& material, simgear::BVHNode::Id& id); bool get_agl_ft(double t, const double pt[3], double max_altoff, double contact[3], double normal[3], double linearVel[3], - double angularVel[3], SGMaterial const*& material, + double angularVel[3], simgear::BVHMaterial const*& material, simgear::BVHNode::Id& id); double get_groundlevel_m(double lat, double lon, double alt); double get_groundlevel_m(const SGGeod& geod); @@ -708,11 +710,11 @@ public: // position pt. bool get_nearest_m(double t, const double pt[3], double maxDist, double contact[3], double normal[3], double linearVel[3], - double angularVel[3], SGMaterial const*& material, + double angularVel[3], simgear::BVHMaterial const*& material, simgear::BVHNode::Id& id); bool get_nearest_ft(double t, const double pt[3], double maxDist, double contact[3], double normal[3],double linearVel[3], - double angularVel[3], SGMaterial const*& material, + double angularVel[3], simgear::BVHMaterial const*& material, simgear::BVHNode::Id& id); diff --git a/src/FDM/groundcache.cxx b/src/FDM/groundcache.cxx index fc4fdfaca..73f299ea9 100644 --- a/src/FDM/groundcache.cxx +++ b/src/FDM/groundcache.cxx @@ -382,10 +382,9 @@ FGGroundCache::prepare_ground_cache(double startSimTime, double endSimTime, if (!found_ground) { // Ok, still nothing here?? Last resort ... double alt = 0; - const SGMaterial* m = NULL; + _material = 0; found_ground = globals->get_scenery()-> - get_elevation_m(SGGeod::fromGeodM(geodPt, 10000), alt, &m); - _material = m; + get_elevation_m(SGGeod::fromGeodM(geodPt, 10000), alt, &_material); if (found_ground) _altitude = alt; } diff --git a/src/Instrumentation/agradar.cxx b/src/Instrumentation/agradar.cxx index 23cf6f3eb..768fdea41 100644 --- a/src/Instrumentation/agradar.cxx +++ b/src/Instrumentation/agradar.cxx @@ -210,9 +210,10 @@ agRadar::setUserVec(double az, double el) bool agRadar::getMaterial(){ - const SGMaterial* material = 0; - if (globals->get_scenery()->get_elevation_m(hitpos, _elevation_m, &material)){ + const simgear::BVHMaterial* mat = 0; + if (globals->get_scenery()->get_elevation_m(hitpos, _elevation_m, &mat)){ //_ht_agl_ft = pos.getElevationFt() - _elevation_m * SG_METER_TO_FEET; + const SGMaterial* material = dynamic_cast(mat); if (material) { const std::vector& names = material->get_names(); diff --git a/src/Radio/radio.cxx b/src/Radio/radio.cxx index 169cd322f..62f233edf 100644 --- a/src/Radio/radio.cxx +++ b/src/Radio/radio.cxx @@ -323,10 +323,12 @@ double FGRadioTransmission::ITM_calculate_attenuation(SGGeod pos, double freq, i while (elevations.size() <= e_size) { probe_distance += point_distance; SGGeod probe = SGGeod::fromGeoc(center.advanceRadM( course, probe_distance )); - const SGMaterial *mat = 0; + const simgear::BVHMaterial *material = 0; double elevation_m = 0.0; - if (scenery->get_elevation_m( probe, elevation_m, &mat )) { + if (scenery->get_elevation_m( probe, elevation_m, &material )) { + const SGMaterial *mat; + mat = dynamic_cast(material); if((transmission_type == 3) || (transmission_type == 4)) { elevations.push_back(elevation_m); if(mat) { diff --git a/src/Scenery/scenery.cxx b/src/Scenery/scenery.cxx index c280def19..4b787ddb3 100644 --- a/src/Scenery/scenery.cxx +++ b/src/Scenery/scenery.cxx @@ -262,7 +262,8 @@ void FGScenery::unbind() { bool FGScenery::get_cart_elevation_m(const SGVec3d& pos, double max_altoff, - double& alt, const SGMaterial** material, + double& alt, + const simgear::BVHMaterial** material, const osg::Node* butNotFrom) { SGGeod geod = SGGeod::fromCart(pos); @@ -272,7 +273,7 @@ FGScenery::get_cart_elevation_m(const SGVec3d& pos, double max_altoff, bool FGScenery::get_elevation_m(const SGGeod& geod, double& alt, - const SGMaterial** material, + const simgear::BVHMaterial** material, const osg::Node* butNotFrom) { SGVec3d start = SGVec3d::fromGeod(geod); @@ -291,7 +292,7 @@ FGScenery::get_elevation_m(const SGGeod& geod, double& alt, geodEnd = SGGeod::fromCart(intersectVisitor.getLineSegment().getEnd()); alt = geodEnd.getElevationM(); if (material) - *material = dynamic_cast(intersectVisitor.getMaterial()); + *material = intersectVisitor.getMaterial(); return true; } diff --git a/src/Scenery/scenery.hxx b/src/Scenery/scenery.hxx index b83b8adb9..d53344354 100644 --- a/src/Scenery/scenery.hxx +++ b/src/Scenery/scenery.hxx @@ -38,7 +38,9 @@ #include "SceneryPager.hxx" -class SGMaterial; +namespace simgear { +class BVHMaterial; +} // Define a structure containing global scenery parameters class FGScenery : public SGSubsystem { @@ -72,7 +74,7 @@ public: /// value is undefined. /// All values are meant to be in meters or degrees. bool get_elevation_m(const SGGeod& geod, double& alt, - const SGMaterial** material, + const simgear::BVHMaterial** material, const osg::Node* butNotFrom = 0); /// Compute the elevation of the scenery below the cartesian point pos. @@ -87,7 +89,8 @@ public: /// value is undefined. /// All values are meant to be in meters. bool get_cart_elevation_m(const SGVec3d& pos, double max_altoff, - double& elevation, const SGMaterial** material, + double& elevation, + const simgear::BVHMaterial** material, const osg::Node* butNotFrom = 0); /// Compute the nearest intersection point of the line starting from diff --git a/src/Scripting/NasalPositioned.cxx b/src/Scripting/NasalPositioned.cxx index d2bcd625b..903b0cbb2 100644 --- a/src/Scripting/NasalPositioned.cxx +++ b/src/Scripting/NasalPositioned.cxx @@ -894,10 +894,11 @@ static naRef f_geodinfo(naContext c, naRef me, int argc, naRef* args) double lat = naNumValue(args[0]).num; double lon = naNumValue(args[1]).num; double elev = argc == 3 ? naNumValue(args[2]).num : 10000; - const SGMaterial *mat; + const simgear::BVHMaterial *material; SGGeod geod = SGGeod::fromDegM(lon, lat, elev); - if(!globals->get_scenery()->get_elevation_m(geod, elev, &mat)) + if(!globals->get_scenery()->get_elevation_m(geod, elev, &material)) return naNil(); + const SGMaterial *mat = dynamic_cast(material); naRef vec = naNewVector(c); naVec_append(vec, naNum(elev)); naRef matdata = naNil(); -- 2.39.5