X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FNavaids%2Fnavrecord.cxx;h=2689f3d3bc4a3fb4065574c1718509b09d487ec3;hb=86d1e4ea9dc56ae811337c326b7f83b820221663;hp=c2ab0e9a7706df98c2b24cae498f69ffa10ca41a;hpb=8ad7f4eb70d307bfb6f7b14a1a63ab2331d27183;p=flightgear.git diff --git a/src/Navaids/navrecord.cxx b/src/Navaids/navrecord.cxx index c2ab0e9a7..2689f3d3b 100644 --- a/src/Navaids/navrecord.cxx +++ b/src/Navaids/navrecord.cxx @@ -29,11 +29,12 @@ #include #include #include +#include -#include "Navaids/navrecord.hxx" -#include "Navaids/navdb.hxx" -#include "Airports/runways.hxx" -#include "Main/fg_props.hxx" +#include +#include +#include +#include
FGNavRecord::FGNavRecord(Type aTy, const std::string& aIdent, const std::string& aName, const SGGeod& aPos, @@ -43,6 +44,7 @@ FGNavRecord::FGNavRecord(Type aTy, const std::string& aIdent, range(aRange), multiuse(aMultiuse), _name(aName), + mRunway(NULL), serviceable(true), trans_ident(aIdent) { @@ -82,10 +84,14 @@ void FGNavRecord::initAirportRelation() return; // not airport-located } - FGRunway* runway = getRunwayFromName(_name); + mRunway = getRunwayFromName(_name); // fudge elevation to the runway elevation if it's not specified if (fabs(elevation()) < 0.01) { - mPosition.setElevationFt(runway->elevation()); + mPosition.setElevationFt(mRunway->elevation()); + } + + if (type() == ILS) { + mRunway->setILS(this); } // align localizers with their runway @@ -96,35 +102,29 @@ void FGNavRecord::initAirportRelation() double threshold = fgGetDouble( "/sim/navdb/localizers/auto-align-threshold-deg", 5.0 ); - alignLocaliserWithRunway(runway, threshold); + alignLocaliserWithRunway(threshold); } } -void FGNavRecord::alignLocaliserWithRunway(FGRunway* aRunway, double aThreshold) +void FGNavRecord::alignLocaliserWithRunway(double aThreshold) { // find the distance from the threshold to the localizer - SGGeod runwayThreshold(aRunway->threshold()); + SGGeod runwayThreshold(mRunway->threshold()); double dist, az1, az2; SGGeodesy::inverse(mPosition, runwayThreshold, az1, az2, dist); // back project that distance along the runway center line - SGGeod newPos = aRunway->pointOnCenterline(dist); + SGGeod newPos = mRunway->pointOnCenterline(dist); - double hdg_diff = get_multiuse() - aRunway->headingDeg(); - - // clamp to [-180.0 ... 180.0] - if ( hdg_diff < -180.0 ) { - hdg_diff += 360.0; - } else if ( hdg_diff > 180.0 ) { - hdg_diff -= 360.0; - } + double hdg_diff = get_multiuse() - mRunway->headingDeg(); + SG_NORMALIZE_RANGE(hdg_diff, -180.0, 180.0); if ( fabs(hdg_diff) <= aThreshold ) { mPosition = newPos; - set_multiuse( aRunway->headingDeg() ); + set_multiuse( mRunway->headingDeg() ); } else { SG_LOG(SG_GENERAL, SG_WARN, "localizer:" << ident() << ", aligning with runway " - << aRunway->ident() << " exceeded heading threshold"); + << mRunway->ident() << " exceeded heading threshold"); } }