mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
refactor: Clarify names of members of CInterpolatorPbh
This commit is contained in:
@@ -260,7 +260,7 @@ namespace BlackMisc::Simulation
|
||||
const CInterpolatorPbh pbh = interpolant.pbh();
|
||||
|
||||
// init interpolated situation
|
||||
currentSituation = this->initInterpolatedSituation(pbh.getOldSituation(), pbh.getNewSituation());
|
||||
currentSituation = this->initInterpolatedSituation(pbh.getStartSituation(), pbh.getEndSituation());
|
||||
|
||||
// Pitch bank heading first, so follow up steps could use those values
|
||||
currentSituation.setHeading(pbh.getHeading());
|
||||
@@ -269,7 +269,7 @@ namespace BlackMisc::Simulation
|
||||
currentSituation.setGroundSpeed(pbh.getGroundSpeed());
|
||||
|
||||
// use derived interpolant function
|
||||
const bool interpolateGndFlag = pbh.getNewSituation().hasGroundDetailsForGndInterpolation() && pbh.getOldSituation().hasGroundDetailsForGndInterpolation();
|
||||
const bool interpolateGndFlag = pbh.getEndSituation().hasGroundDetailsForGndInterpolation() && pbh.getStartSituation().hasGroundDetailsForGndInterpolation();
|
||||
currentSituation = interpolant.interpolatePositionAndAltitude(currentSituation, interpolateGndFlag);
|
||||
if (currentSituation.isNull()) { break; }
|
||||
|
||||
@@ -284,7 +284,7 @@ namespace BlackMisc::Simulation
|
||||
if (!interpolateGndFlag) { CAircraftSituationChange::null().guessOnGround(currentSituation, m_model); }
|
||||
|
||||
// as we now have the position and can interpolate elevation
|
||||
currentSituation.interpolateElevation(pbh.getOldSituation(), pbh.getNewSituation());
|
||||
currentSituation.interpolateElevation(pbh.getStartSituation(), pbh.getEndSituation());
|
||||
if (!currentSituation.hasGroundElevation())
|
||||
{
|
||||
// we still have no elevation
|
||||
|
||||
@@ -12,6 +12,16 @@ using namespace BlackMisc::PhysicalQuantities;
|
||||
|
||||
namespace BlackMisc::Simulation
|
||||
{
|
||||
CInterpolatorPbh::CInterpolatorPbh(double simulationTimeFraction, const Aviation::CAircraftSituation &start, const Aviation::CAircraftSituation &end) : m_simulationTimeFraction(simulationTimeFraction),
|
||||
m_startSituation(start),
|
||||
m_endSituation(end)
|
||||
{
|
||||
if (CBuildConfig::isLocalDeveloperDebugBuild())
|
||||
{
|
||||
BLACK_VERIFY_X(isValidTimeFraction(m_simulationTimeFraction), Q_FUNC_INFO, "Time fraction needs to be within [0;1]");
|
||||
}
|
||||
}
|
||||
|
||||
CAngle CInterpolatorPbh::interpolateAngle(const CAngle &begin, const CAngle &end, double timeFraction0to1)
|
||||
{
|
||||
// determine the right direction (to left, to right) we interpolate towards to
|
||||
@@ -38,37 +48,31 @@ namespace BlackMisc::Simulation
|
||||
{
|
||||
// HINT: VTOL aircraft can change pitch/bank without changing position, planes cannot
|
||||
// Interpolate heading: HDG = (HdgB - HdgA) * t + HdgA
|
||||
const CHeading headingBegin = m_oldSituation.getHeading();
|
||||
const CHeading headingEnd = m_newSituation.getHeading();
|
||||
const CHeading headingStart = m_startSituation.getHeading();
|
||||
const CHeading headingEnd = m_endSituation.getHeading();
|
||||
|
||||
if (CBuildConfig::isLocalDeveloperDebugBuild())
|
||||
{
|
||||
BLACK_VERIFY_X(headingBegin.getReferenceNorth() == headingEnd.getReferenceNorth(), Q_FUNC_INFO, "Need same reference");
|
||||
BLACK_VERIFY_X(headingStart.getReferenceNorth() == headingEnd.getReferenceNorth(), Q_FUNC_INFO, "Need same reference");
|
||||
}
|
||||
return CHeading(interpolateAngle(headingBegin, headingEnd, m_simulationTimeFraction), headingEnd.getReferenceNorth());
|
||||
return CHeading(interpolateAngle(headingStart, headingEnd, m_simulationTimeFraction), headingEnd.getReferenceNorth());
|
||||
}
|
||||
|
||||
CAngle CInterpolatorPbh::getPitch() const
|
||||
{
|
||||
// Interpolate Pitch: Pitch = (PitchB - PitchA) * t + PitchA
|
||||
return interpolateAngle(m_oldSituation.getPitch(), m_newSituation.getPitch(), m_simulationTimeFraction);
|
||||
return interpolateAngle(m_startSituation.getPitch(), m_endSituation.getPitch(), m_simulationTimeFraction);
|
||||
}
|
||||
|
||||
CAngle CInterpolatorPbh::getBank() const
|
||||
{
|
||||
// Interpolate bank: Bank = (BankB - BankA) * t + BankA
|
||||
return interpolateAngle(m_oldSituation.getBank(), m_newSituation.getBank(), m_simulationTimeFraction);
|
||||
return interpolateAngle(m_startSituation.getBank(), m_endSituation.getBank(), m_simulationTimeFraction);
|
||||
}
|
||||
|
||||
CSpeed CInterpolatorPbh::getGroundSpeed() const
|
||||
{
|
||||
return (m_newSituation.getGroundSpeed() - m_oldSituation.getGroundSpeed()) * m_simulationTimeFraction + m_oldSituation.getGroundSpeed();
|
||||
}
|
||||
|
||||
void CInterpolatorPbh::setSituations(const CAircraftSituation &older, const CAircraftSituation &newer)
|
||||
{
|
||||
m_oldSituation = older;
|
||||
m_newSituation = newer;
|
||||
return (m_endSituation.getGroundSpeed() - m_startSituation.getGroundSpeed()) * m_simulationTimeFraction + m_startSituation.getGroundSpeed();
|
||||
}
|
||||
|
||||
void CInterpolatorPbh::setTimeFraction(double tf)
|
||||
|
||||
@@ -14,15 +14,15 @@
|
||||
|
||||
namespace BlackMisc::Simulation
|
||||
{
|
||||
//! Simple interpolator for pitch, bank, heading, groundspeed
|
||||
//! Simple linear interpolator for pitch, bank, heading and groundspeed from start to end situation
|
||||
class BLACKMISC_EXPORT CInterpolatorPbh
|
||||
{
|
||||
public:
|
||||
//! @{
|
||||
//! Constructor
|
||||
CInterpolatorPbh() {}
|
||||
CInterpolatorPbh(const Aviation::CAircraftSituation &older, const Aviation::CAircraftSituation &newer) : m_oldSituation(older), m_newSituation(newer) {}
|
||||
CInterpolatorPbh(double time, const Aviation::CAircraftSituation &older, const Aviation::CAircraftSituation &newer) : m_simulationTimeFraction(time), m_oldSituation(older), m_newSituation(newer) {}
|
||||
CInterpolatorPbh() = default;
|
||||
CInterpolatorPbh(const Aviation::CAircraftSituation &start, const Aviation::CAircraftSituation &end) : m_startSituation(start), m_endSituation(end) {}
|
||||
CInterpolatorPbh(double simulationTimeFraction, const Aviation::CAircraftSituation &start, const Aviation::CAircraftSituation &end);
|
||||
//! @}
|
||||
|
||||
//! @{
|
||||
@@ -31,14 +31,10 @@ namespace BlackMisc::Simulation
|
||||
PhysicalQuantities::CAngle getPitch() const;
|
||||
PhysicalQuantities::CAngle getBank() const;
|
||||
PhysicalQuantities::CSpeed getGroundSpeed() const;
|
||||
const Aviation::CAircraftSituation &getOldSituation() const { return m_oldSituation; }
|
||||
const Aviation::CAircraftSituation &getNewSituation() const { return m_newSituation; }
|
||||
const Aviation::CAircraftSituation &getStartSituation() const { return m_startSituation; }
|
||||
const Aviation::CAircraftSituation &getEndSituation() const { return m_endSituation; }
|
||||
//! @}
|
||||
|
||||
//! Set situations
|
||||
//! \remark mostly needed for UNIT tests
|
||||
void setSituations(const Aviation::CAircraftSituation &older, const Aviation::CAircraftSituation &newer);
|
||||
|
||||
//! Change time fraction
|
||||
void setTimeFraction(double tf);
|
||||
|
||||
@@ -46,9 +42,9 @@ namespace BlackMisc::Simulation
|
||||
//! Interpolate angle
|
||||
static PhysicalQuantities::CAngle interpolateAngle(const PhysicalQuantities::CAngle &begin, const PhysicalQuantities::CAngle &end, double timeFraction0to1);
|
||||
|
||||
double m_simulationTimeFraction = 0.0;
|
||||
Aviation::CAircraftSituation m_oldSituation;
|
||||
Aviation::CAircraftSituation m_newSituation;
|
||||
double m_simulationTimeFraction = 0.0; //!< Value within [0;1] to blend between the situations
|
||||
Aviation::CAircraftSituation m_startSituation;
|
||||
Aviation::CAircraftSituation m_endSituation;
|
||||
};
|
||||
} // namespace
|
||||
#endif // guard
|
||||
|
||||
@@ -68,12 +68,6 @@ namespace BlackMisc::Simulation
|
||||
//! Perform the interpolation
|
||||
Aviation::CAircraftSituation interpolatePositionAndAltitude(const Aviation::CAircraftSituation ¤tSituation, bool interpolateGndFactor) const;
|
||||
|
||||
//! Old situation
|
||||
const Aviation::CAircraftSituation &getOldSituation() const { return pbh().getOldSituation(); }
|
||||
|
||||
//! New situation
|
||||
const Aviation::CAircraftSituation &getNewSituation() const { return pbh().getNewSituation(); }
|
||||
|
||||
//! Set the time values
|
||||
void setTimes(qint64 currentTimeMs, double timeFraction, qint64 interpolatedTimeMs);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user