mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-02 15:15:39 +08:00
refs #925 Animate landing gear by linear interpolation.
This commit is contained in:
@@ -281,7 +281,7 @@ namespace XBus
|
|||||||
const auto surfaces = std::make_pair(relativeTime + QDateTime::currentMSecsSinceEpoch(), [ = ](Plane *plane)
|
const auto surfaces = std::make_pair(relativeTime + QDateTime::currentMSecsSinceEpoch(), [ = ](Plane *plane)
|
||||||
{
|
{
|
||||||
plane->hasSurfaces = true;
|
plane->hasSurfaces = true;
|
||||||
plane->surfaces.gearPosition = gear;
|
plane->targetGearPosition = gear;
|
||||||
plane->surfaces.flapRatio = flap;
|
plane->surfaces.flapRatio = flap;
|
||||||
plane->surfaces.spoilerRatio = spoiler;
|
plane->surfaces.spoilerRatio = spoiler;
|
||||||
plane->surfaces.speedBrakeRatio = speedBrake;
|
plane->surfaces.speedBrakeRatio = speedBrake;
|
||||||
@@ -381,9 +381,20 @@ namespace XBus
|
|||||||
const auto currentTime = QDateTime::currentMSecsSinceEpoch();
|
const auto currentTime = QDateTime::currentMSecsSinceEpoch();
|
||||||
while (! plane->pendingSurfaces.isEmpty() && plane->pendingSurfaces.front().first <= currentTime)
|
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.front().second(plane);
|
||||||
plane->pendingSurfaces.pop_front();
|
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<XPMPPlaneSurfaces_t *>(io_data);
|
const auto io_surfaces = static_cast<XPMPPlaneSurfaces_t *>(io_data);
|
||||||
|
|
||||||
if (memcmpPayload(io_surfaces, &plane->surfaces))
|
if (memcmpPayload(io_surfaces, &plane->surfaces))
|
||||||
|
|||||||
@@ -141,6 +141,8 @@ namespace XBus
|
|||||||
BlackMisc::Simulation::CInterpolationHints hints();
|
BlackMisc::Simulation::CInterpolationHints hints();
|
||||||
XPMPPlaneSurfaces_t surfaces;
|
XPMPPlaneSurfaces_t surfaces;
|
||||||
QVector<std::pair<qint64, std::function<void(Plane *)>>> pendingSurfaces;
|
QVector<std::pair<qint64, std::function<void(Plane *)>>> pendingSurfaces;
|
||||||
|
float targetGearPosition = 0;
|
||||||
|
qint64 prevSurfacesLerpTime = 0;
|
||||||
XPMPPlaneRadar_t xpdr;
|
XPMPPlaneRadar_t xpdr;
|
||||||
Plane(void *id_, QString callsign_, QString aircraftIcao_, QString airlineIcao_, QString livery_);
|
Plane(void *id_, QString callsign_, QString aircraftIcao_, QString airlineIcao_, QString livery_);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user