diff --git a/src/blackcore/simulator.cpp b/src/blackcore/simulator.cpp index accf2f133..27c883aa6 100644 --- a/src/blackcore/simulator.cpp +++ b/src/blackcore/simulator.cpp @@ -904,14 +904,14 @@ namespace BlackCore m_simulatorInternals.setSimulatorInstallationDirectory(s.getSimulatorDirectoryOrDefault()); } - void ISimulator::rememberElevationAndSimulatorCG(const CCallsign &callsign, const CAircraftModel &model, const CElevationPlane &elevation, const CLength &simulatorCG) + void ISimulator::rememberElevationAndSimulatorCG(const CCallsign &callsign, const CAircraftModel &model, bool likelyOnGroundElevation, const CElevationPlane &elevation, const CLength &simulatorCG) { if (callsign.isEmpty()) { return; } if (elevation.hasMSLGeodeticHeight()) { const int aircraftCount = this->getAircraftInRangeCount(); this->setMaxElevationsRemembered(aircraftCount * 3); // at least 3 elevations per aircraft, even better as not all are requesting elevations - this->rememberGroundElevation(callsign, false, elevation); + this->rememberGroundElevation(callsign, likelyOnGroundElevation, elevation); } const QString modelString = model.getModelString(); diff --git a/src/blackcore/simulator.h b/src/blackcore/simulator.h index 4f624dd31..ec1f10380 100644 --- a/src/blackcore/simulator.h +++ b/src/blackcore/simulator.h @@ -465,7 +465,7 @@ namespace BlackCore //! Set elevation and CG in the providers and for auto publishing //! \sa ISimulator::updateOwnSituationAndGroundElevation - void rememberElevationAndSimulatorCG(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Simulation::CAircraftModel &model, const BlackMisc::Geo::CElevationPlane &elevation, const BlackMisc::PhysicalQuantities::CLength &simulatorCG); + void rememberElevationAndSimulatorCG(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Simulation::CAircraftModel &model, bool likelyOnGroundElevation, const BlackMisc::Geo::CElevationPlane &elevation, const BlackMisc::PhysicalQuantities::CLength &simulatorCG); //! Emit the combined status //! \param oldStatus optionally one can capture and provide the old status for comparison. In case of equal status values no signal will be sent diff --git a/src/plugins/simulator/flightgear/simulatorflightgear.cpp b/src/plugins/simulator/flightgear/simulatorflightgear.cpp index c6a4aa1e8..72a74eb4b 100644 --- a/src/plugins/simulator/flightgear/simulatorflightgear.cpp +++ b/src/plugins/simulator/flightgear/simulatorflightgear.cpp @@ -220,7 +220,7 @@ namespace BlackSimPlugin situation.setPitch({ m_flightgearData.pitchDeg, CAngleUnit::deg() }); situation.setBank({ m_flightgearData.rollDeg, CAngleUnit::deg() }); situation.setGroundSpeed({ m_flightgearData.groundspeedKts, CSpeedUnit::kts() }); - situation.setGroundElevation(CAltitude(m_flightgearData.groundElevation,CAltitude::MeanSeaLevel,CLengthUnit::m()),CAircraftSituation::FromProvider); + situation.setGroundElevation(CAltitude(m_flightgearData.groundElevation, CAltitude::MeanSeaLevel, CLengthUnit::m()), CAircraftSituation::FromProvider); // Updates // Do not update ICAO codes, as this overrides reverse lookups @@ -750,13 +750,20 @@ namespace BlackSimPlugin BLACK_VERIFY_X(fgAircraft.hasCallsign(), Q_FUNC_INFO, "Need callsign"); if (!fgAircraft.hasCallsign()) { continue; } - const double cgValue = verticalOffsetsMeters[i]; // FG offset is swift CG - const CAltitude elevationAlt = std::isnan(elevationsMeters[i]) ? CAltitude::null() : CAltitude(elevationsMeters[i], CLengthUnit::m(), CLengthUnit::ft()); - const CElevationPlane elevation(CLatitude(latitudesDeg[i], CAngleUnit::deg()), CLongitude(longitudesDeg[i], CAngleUnit::deg()), elevationAlt, CElevationPlane::singlePointRadius()); + CElevationPlane elevation = CElevationPlane::null(); + if (!std::isnan(elevationsMeters[i])) + { + const CAltitude elevationAlt = CAltitude(elevationsMeters[i], CLengthUnit::m(), CLengthUnit::ft()); + elevation = CElevationPlane(CLatitude(latitudesDeg[i], CAngleUnit::deg()), CLongitude(longitudesDeg[i], CAngleUnit::deg()), elevationAlt, CElevationPlane::singlePointRadius()); + } + + const double cgValue = verticalOffsetsMeters[i]; // XP offset is swift CG const CLength cg = std::isnan(cgValue) ? CLength::null() : CLength(cgValue, CLengthUnit::m(), CLengthUnit::ft()); - this->rememberElevationAndSimulatorCG(cs, fgAircraft.getAircraftModel(), elevation, cg); + + // if we knew "on ground" here we could set it as parameter of rememberElevationAndSimulatorCG + this->rememberElevationAndSimulatorCG(cs, fgAircraft.getAircraftModel(), false, elevation, cg); // loopback if (logCallsigns.contains(cs)) @@ -827,10 +834,11 @@ namespace BlackSimPlugin bool CSimulatorFlightgear::requestElevation(const BlackMisc::Geo::ICoordinateGeodetic &reference, const BlackMisc::Aviation::CCallsign &callsign) { if (this->isShuttingDownOrDisconnected()) { return false; } - if(reference.isNull()) { return false; } + if (reference.isNull()) { return false; } CCoordinateGeodetic pos(reference); - if(!pos.hasMSLGeodeticHeight()){ + if (!pos.hasMSLGeodeticHeight()) + { // testing showed: height has an influence on the returned result // - the most accurate value seems to be returned if the height is close to the elevation // - in normal scenarios there is no much difference of the results if 0 is used diff --git a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp index 43dd594b4..c01433e0f 100644 --- a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp +++ b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp @@ -836,25 +836,21 @@ namespace BlackSimPlugin // Near ground we use faster updates const CCallsign cs(simObject.getCallsign()); CAircraftSituation lastSituation = m_lastSentSituations[cs]; - const bool moving = lastSituation.isMoving(); + const bool moving = lastSituation.isMoving(); + const bool onGround = remoteAircraftData.isOnGround(); // CElevationPlane: deg, deg, feet // we only remember near ground - CElevationPlane elevation; + const CElevationPlane elevation = CElevationPlane(remoteAircraftData.latitudeDeg, remoteAircraftData.longitudeDeg, remoteAircraftData.elevationFt, CElevationPlane::singlePointRadius()); if (remoteAircraftData.aboveGroundFt() < 250) { const CLength cg(remoteAircraftData.cgToGroundFt, CLengthUnit::ft()); - this->rememberElevationAndSimulatorCG(cs, simObject.getAircraftModel(), elevation, cg); + this->rememberElevationAndSimulatorCG(cs, simObject.getAircraftModel(), onGround, elevation, cg); } const bool log = this->isLogCallsign(cs); if (log) { - if (elevation.isNull()) - { - elevation = CElevationPlane(remoteAircraftData.latitudeDeg, remoteAircraftData.longitudeDeg, remoteAircraftData.elevationFt, CElevationPlane::singlePointRadius()); - } - // update lat/lng/alt with real data from sim const CAltitude alt(remoteAircraftData.altitudeFt, CAltitude::MeanSeaLevel, CAltitude::TrueAltitude, CLengthUnit::ft()); lastSituation.setPosition(elevation); @@ -894,7 +890,7 @@ namespace BlackSimPlugin so.setAircraftModelString(modelString); // update in 2 providers - this->rememberElevationAndSimulatorCG(cs, simObject.getAircraftModel(), CElevationPlane::null(), cg); // env. provider + this->rememberElevationAndSimulatorCG(cs, simObject.getAircraftModel(), false, CElevationPlane::null(), cg); // env. provider this->updateCGAndModelString(cs, cg, modelString); // remote aircraft provider } diff --git a/src/plugins/simulator/xplane/simulatorxplane.cpp b/src/plugins/simulator/xplane/simulatorxplane.cpp index 9b634727d..d714b407c 100644 --- a/src/plugins/simulator/xplane/simulatorxplane.cpp +++ b/src/plugins/simulator/xplane/simulatorxplane.cpp @@ -1064,13 +1064,20 @@ namespace BlackSimPlugin BLACK_VERIFY_X(xpAircraft.hasCallsign(), Q_FUNC_INFO, "Need callsign"); if (!xpAircraft.hasCallsign()) { continue; } + CElevationPlane elevation = CElevationPlane::null(); + if (!std::isnan(elevationsMeters[i])) + { + const CAltitude elevationAlt = CAltitude(elevationsMeters[i], CLengthUnit::m(), CLengthUnit::ft()); + elevation = CElevationPlane(CLatitude(latitudesDeg[i], CAngleUnit::deg()), CLongitude(longitudesDeg[i], CAngleUnit::deg()), elevationAlt, CElevationPlane::singlePointRadius()); + } + const double cgValue = verticalOffsetsMeters[i]; // XP offset is swift CG - const CAltitude elevationAlt = std::isnan(elevationsMeters[i]) ? CAltitude::null() : CAltitude(elevationsMeters[i], CLengthUnit::m(), CLengthUnit::ft()); - const CElevationPlane elevation(CLatitude(latitudesDeg[i], CAngleUnit::deg()), CLongitude(longitudesDeg[i], CAngleUnit::deg()), elevationAlt, CElevationPlane::singlePointRadius()); const CLength cg = std::isnan(cgValue) ? CLength::null() : CLength(cgValue, CLengthUnit::m(), CLengthUnit::ft()); - this->rememberElevationAndSimulatorCG(cs, xpAircraft.getAircraftModel(), elevation, cg); + + // if we knew "on ground" here we could set it as parameter of rememberElevationAndSimulatorCG + this->rememberElevationAndSimulatorCG(cs, xpAircraft.getAircraftModel(), false, elevation, cg); // loopback if (logCallsigns.contains(cs))