From cb90785810af302b95487b6fad58828e7c339bc1 Mon Sep 17 00:00:00 2001 From: Stuart Buchanan Date: Wed, 13 Jan 2021 20:29:00 +0000 Subject: [PATCH] WS3.0: Place airports based on apt.dat entry Previously WS3.0 airports could be placed via .stg file. Now they are OBJECT entries rather than OBJECT_STATIC and the placement information is taken from the apt.dat file. Also added as elevation constraint for WS3.0 terrain. --- src/Airports/AirportBuilder.cxx | 42 ++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/src/Airports/AirportBuilder.cxx b/src/Airports/AirportBuilder.cxx index 79434c304..810c4b87e 100644 --- a/src/Airports/AirportBuilder.cxx +++ b/src/Airports/AirportBuilder.cxx @@ -29,15 +29,21 @@ #include #include +#include +#include #include #include +#include #include +#include #include #include -#include +#include #include +#include
+#include #include "airport.hxx" #include "runways.hxx" #include "pavement.hxx" @@ -86,14 +92,14 @@ osgDB::ReaderWriter::ReadResult AirportBuilder::readNode(const std::string& file const FGAirport* airport = aptLoader.loadAirportFromFile(airportId, aptFile); if (! airport) return ReadResult::FILE_NOT_HANDLED; - SG_LOG( SG_GENERAL, SG_DEBUG, "Building airport : " << airportId << " " << airport->getName()); - SG_LOG( SG_GENERAL, SG_DEBUG, "Lat/Lon : " << airport->getLatitude() << ", " << airport->getLongitude()); - SG_LOG( SG_GENERAL, SG_DEBUG, "Elevation : " << airport->getElevation()); - SG_LOG( SG_GENERAL, SG_DEBUG, "Runways : " << airport->numRunways()); - SG_LOG( SG_GENERAL, SG_DEBUG, "Helipads : " << airport->numHelipads()); - SG_LOG( SG_GENERAL, SG_DEBUG, "Taxiways : " << airport->numTaxiways()); - SG_LOG( SG_GENERAL, SG_DEBUG, "Pavements : " << airport->numPavements()); - SG_LOG( SG_GENERAL, SG_DEBUG, "Line Features : " << airport->numLineFeatures()); + SG_LOG( SG_TERRAIN, SG_DEBUG, "Building airport : " << airportId << " " << airport->getName()); + SG_LOG( SG_TERRAIN, SG_DEBUG, "Lat/Lon : " << airport->getLatitude() << ", " << airport->getLongitude()); + SG_LOG( SG_TERRAIN, SG_DEBUG, "Elevation : " << airport->getElevation()); + SG_LOG( SG_TERRAIN, SG_DEBUG, "Runways : " << airport->numRunways()); + SG_LOG( SG_TERRAIN, SG_DEBUG, "Helipads : " << airport->numHelipads()); + SG_LOG( SG_TERRAIN, SG_DEBUG, "Taxiways : " << airport->numTaxiways()); + SG_LOG( SG_TERRAIN, SG_DEBUG, "Pavements : " << airport->numPavements()); + SG_LOG( SG_TERRAIN, SG_DEBUG, "Line Features : " << airport->numLineFeatures()); const SGGeod zeroAltitudeCenter = SGGeod::fromDegM(airport->getLongitude(), airport->getLatitude(), 0.0f); @@ -132,7 +138,21 @@ osgDB::ReaderWriter::ReadResult AirportBuilder::readNode(const std::string& file lineList.end(), [&, mat, center, options] (FGPavementRef p) { group->addChild(this->createLine(mat, center, p, options)); } ); - return group; + // Place the airport in the correct location. + osg::Matrix matrix = makeZUpFrame(SGGeod::fromDegFt(airport->getLongitude(), airport->getLatitude(), airport->getElevation())); + osg::MatrixTransform* matrixTransform; + matrixTransform = new osg::MatrixTransform(matrix); + matrixTransform->setDataVariance(osg::Object::STATIC); + matrixTransform->addChild(group); + + // Create a BVH at this point, as we need it to determine how to flatten the terrain mesh. + BoundingVolumeBuildVisitor bvhBuilder(false); + matrixTransform->accept(bvhBuilder); + + // Add the airport to the list of elevation constraints for the scenery + simgear::VPBTechnique::addElevationConstraint(matrixTransform, globals->get_scenery()->get_terrain_branch()); + + return matrixTransform; } osg::Node* AirportBuilder::createRunway(const osg::Matrixd mat, const SGVec3f center, const FGRunwayRef runway, const osgDB::Options* options) const @@ -594,7 +614,7 @@ osg::ref_ptr AirportBuilder::getMaterialEffect(std::string material, con } SG_LOG( SG_TERRAIN, SG_ALERT, "Unable to get effect for " << material); - makeChild(effectProp, "inherits-from")->setStringValue("Effects/model-default"); + makeChild(effectProp, "inherits-from")->setStringValue("Effects/terrain-default"); effectProp->addChild("default")->setBoolValue(true); effect = makeEffect(effectProp, true, sgOpts); return effect;