From 65ac9452812d24d96b0b0e660c01c626ce04d0d8 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Fri, 31 Mar 2017 23:45:28 +0100 Subject: [PATCH] refs #925 Animate landing gear by linear interpolation. --- src/xbus/traffic.cpp | 13 ++++++++++++- src/xbus/traffic.h | 2 ++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/xbus/traffic.cpp b/src/xbus/traffic.cpp index 6a7553965..58c2401d9 100644 --- a/src/xbus/traffic.cpp +++ b/src/xbus/traffic.cpp @@ -281,7 +281,7 @@ namespace XBus const auto surfaces = std::make_pair(relativeTime + QDateTime::currentMSecsSinceEpoch(), [ = ](Plane *plane) { plane->hasSurfaces = true; - plane->surfaces.gearPosition = gear; + plane->targetGearPosition = gear; plane->surfaces.flapRatio = flap; plane->surfaces.spoilerRatio = spoiler; plane->surfaces.speedBrakeRatio = speedBrake; @@ -381,9 +381,20 @@ namespace XBus const auto currentTime = QDateTime::currentMSecsSinceEpoch(); while (! plane->pendingSurfaces.isEmpty() && plane->pendingSurfaces.front().first <= currentTime) { + //! \todo if gear is currently retracted, look ahead and pull gear position from pendingSurfaces up to 5 seconds in the future plane->pendingSurfaces.front().second(plane); plane->pendingSurfaces.pop_front(); } + if (plane->surfaces.gearPosition != plane->targetGearPosition) + { + // interpolate gear position + constexpr float gearMoveTimeMs = 5000; + const auto gearPositionDiffRemaining = plane->targetGearPosition - plane->surfaces.gearPosition; + const auto gearPositionDiffThisFrame = (currentTime - plane->prevSurfacesLerpTime) / gearMoveTimeMs; + plane->surfaces.gearPosition += std::copysign(gearPositionDiffThisFrame, gearPositionDiffRemaining); + plane->surfaces.gearPosition = qBound(0.0f, plane->surfaces.gearPosition, 1.0f); + } + plane->prevSurfacesLerpTime = currentTime; const auto io_surfaces = static_cast(io_data); if (memcmpPayload(io_surfaces, &plane->surfaces)) diff --git a/src/xbus/traffic.h b/src/xbus/traffic.h index e84f4163b..4df696f76 100644 --- a/src/xbus/traffic.h +++ b/src/xbus/traffic.h @@ -141,6 +141,8 @@ namespace XBus BlackMisc::Simulation::CInterpolationHints hints(); XPMPPlaneSurfaces_t surfaces; QVector>> pendingSurfaces; + float targetGearPosition = 0; + qint64 prevSurfacesLerpTime = 0; XPMPPlaneRadar_t xpdr; Plane(void *id_, QString callsign_, QString aircraftIcao_, QString airlineIcao_, QString livery_); };