mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 00:16:51 +08:00
refs #852 CInterpolatorLinear obtains the ground elevation via a lazy computation
in CInterpolationHints and uses this to interpolate between altitude and elevation.
This commit is contained in:
@@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
|
namespace Aviation { class CAircraftSituation; }
|
||||||
|
|
||||||
namespace Simulation
|
namespace Simulation
|
||||||
{
|
{
|
||||||
//! Hints for interpolator such as ground elevation
|
//! Hints for interpolator such as ground elevation
|
||||||
@@ -73,6 +75,15 @@ namespace BlackMisc
|
|||||||
//! Set aircraft parts
|
//! Set aircraft parts
|
||||||
void setAircraftParts(const BlackMisc::Aviation::CAircraftParts &parts) { m_hasParts = true; m_aircraftParts = parts; }
|
void setAircraftParts(const BlackMisc::Aviation::CAircraftParts &parts) { m_hasParts = true; m_aircraftParts = parts; }
|
||||||
|
|
||||||
|
//! Function object that can obtain ground elevation
|
||||||
|
using ElevationProvider = std::function<BlackMisc::PhysicalQuantities::CLength(const BlackMisc::Aviation::CAircraftSituation &)>;
|
||||||
|
|
||||||
|
//! Function object that can obtain ground elevation
|
||||||
|
const ElevationProvider &getElevationProvider() const { return m_elevationProvider; }
|
||||||
|
|
||||||
|
//! Set function object that can obtain ground elevation
|
||||||
|
void setElevationProvider(const ElevationProvider &ep) { m_elevationProvider = ep; }
|
||||||
|
|
||||||
//! \copydoc BlackMisc::Mixin::Index::propertyByIndex
|
//! \copydoc BlackMisc::Mixin::Index::propertyByIndex
|
||||||
CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const;
|
CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const;
|
||||||
|
|
||||||
@@ -91,6 +102,7 @@ namespace BlackMisc
|
|||||||
BlackMisc::PhysicalQuantities::CLength m_cgAboveGround { 0, nullptr }; //!< center of gravity above ground
|
BlackMisc::PhysicalQuantities::CLength m_cgAboveGround { 0, nullptr }; //!< center of gravity above ground
|
||||||
bool m_hasParts = false; //!< Has valid aircraft parts?
|
bool m_hasParts = false; //!< Has valid aircraft parts?
|
||||||
BlackMisc::Aviation::CAircraftParts m_aircraftParts; //!< Aircraft parts
|
BlackMisc::Aviation::CAircraftParts m_aircraftParts; //!< Aircraft parts
|
||||||
|
ElevationProvider m_elevationProvider; //!< Provider of ground elevation (lazy computation)
|
||||||
|
|
||||||
BLACK_METACLASS(
|
BLACK_METACLASS(
|
||||||
CInterpolationHints,
|
CInterpolationHints,
|
||||||
@@ -99,6 +111,7 @@ namespace BlackMisc
|
|||||||
BLACK_METAMEMBER(cgAboveGround),
|
BLACK_METAMEMBER(cgAboveGround),
|
||||||
BLACK_METAMEMBER(hasParts),
|
BLACK_METAMEMBER(hasParts),
|
||||||
BLACK_METAMEMBER(aircraftParts)
|
BLACK_METAMEMBER(aircraftParts)
|
||||||
|
// elevationProvider not included
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -143,6 +143,22 @@ namespace BlackMisc
|
|||||||
+ oldAlt,
|
+ oldAlt,
|
||||||
oldAlt.getReferenceDatum()));
|
oldAlt.getReferenceDatum()));
|
||||||
|
|
||||||
|
// Interpolate between altitude and ground elevation, with proportions weighted according to interpolated onGround flag
|
||||||
|
if (hints.hasAircraftParts())
|
||||||
|
{
|
||||||
|
const double groundFactor = hints.getAircraftParts().isOnGroundInterpolated();
|
||||||
|
if (groundFactor > 0.0)
|
||||||
|
{
|
||||||
|
const auto &groundElevation = hints.getElevationProvider();
|
||||||
|
if (groundElevation)
|
||||||
|
{
|
||||||
|
currentSituation.setAltitude(CAltitude(currentSituation.getAltitude() * (1.0 - groundFactor)
|
||||||
|
+ groundElevation(currentSituation) * groundFactor,
|
||||||
|
oldAlt.getReferenceDatum()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!setup.isForcingFullInterpolation() && !hints.isVtolAircraft() && newVec == oldVec && oldAlt == newAlt)
|
if (!setup.isForcingFullInterpolation() && !hints.isVtolAircraft() && newVec == oldVec && oldAlt == newAlt)
|
||||||
{
|
{
|
||||||
// stop interpolation here, does not work for VTOL aircraft. We need a flag for VTOL aircraft
|
// stop interpolation here, does not work for VTOL aircraft. We need a flag for VTOL aircraft
|
||||||
|
|||||||
Reference in New Issue
Block a user