From e5d45b077db80488d66f00a0b6e02130e1f3e2f6 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Tue, 17 Jan 2017 20:17:22 +0000 Subject: [PATCH] refs #852 Fix for problem with landing aircraft with interim position updates. --- src/blackmisc/simulation/interpolator.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/blackmisc/simulation/interpolator.cpp b/src/blackmisc/simulation/interpolator.cpp index b985ed113..57f84bc23 100644 --- a/src/blackmisc/simulation/interpolator.cpp +++ b/src/blackmisc/simulation/interpolator.cpp @@ -67,12 +67,18 @@ namespace BlackMisc const auto latestTakeoff = std::adjacent_find(partsOlder.begin(), partsOlder.end(), [](auto &&, auto && p) { return p.isOnGround(); }); const auto soonestLanding = std::find_if(partsNewer.begin(), partsNewer.end(), [](auto && p) { return p.isOnGround(); }); + // our clairvoyance is limited by the time offset + const double significantPast = 5.0; + const double predictableFuture = soonestLanding == partsNewer.end() ? 5.0 : std::min(5.0, static_cast(soonestLanding->getTimeOffsetMs()) / 1000.0); + const double secondsSinceTakeoff = latestTakeoff == partsOlder.end() ? 5.0 : (currentTimeMsSinceEpoch - latestTakeoff->getAdjustedMSecsSinceEpoch()) / 1000.0; const double secondsUntilLanding = soonestLanding == partsNewer.end() ? 5.0 : (soonestLanding->getAdjustedMSecsSinceEpoch() - currentTimeMsSinceEpoch) / 1000.0; - const double secondsAirborne = std::min(secondsSinceTakeoff, secondsUntilLanding); - Q_ASSERT(secondsAirborne >= 0.0); + Q_ASSERT(secondsSinceTakeoff >= 0.0); + Q_ASSERT(secondsUntilLanding >= 0.0); - const double airborneFactor = std::min(secondsAirborne / 5.0, 1.0); + const double takeoffFactor = secondsSinceTakeoff / significantPast; + const double landingFactor = secondsUntilLanding / predictableFuture; + const double airborneFactor = std::min(std::min(takeoffFactor, landingFactor), 1.0); currentParts.setOnGroundInterpolated(1.0 - smootherStep(airborneFactor)); return currentParts; }