[XP] Get the ground elevation under the own aircraft

This commit is contained in:
Mat Sutcliffe
2022-02-03 20:43:23 +00:00
parent f5a9452ec2
commit 2ccee127e9
8 changed files with 42 additions and 0 deletions

View File

@@ -766,6 +766,13 @@ namespace XSwiftBus
sendDBusReply(sender, serial, getAllWheelsOnGround());
});
}
else if (message.getMethodName() == "getGroundElevation")
{
queueDBusCall([ = ]()
{
sendDBusReply(sender, serial, getGroundElevation());
});
}
else if (message.getMethodName() == "getCom1ActiveKhz")
{
queueDBusCall([ = ]()

View File

@@ -19,6 +19,7 @@
#include "datarefs.h"
#include "messages.h"
#include "navdatareference.h"
#include "terrainprobe.h"
#include <XPLM/XPLMNavigation.h>
#include <string>
#include <chrono>
@@ -174,6 +175,9 @@ namespace XSwiftBus
//! Get whether all wheels are on the ground
bool getAllWheelsOnGround() const { return m_onGroundAll.get(); }
//! Get elevation of ground under the plane in meters
double getGroundElevation() const { return m_terrainProbe.getElevation(m_latitude.get(), m_longitude.get(), m_elevation.get())[0]; }
//! COM Selection 6/7
//! @{
int getComSelection() const { return m_comAudioSelection.get(); }
@@ -333,6 +337,7 @@ namespace XSwiftBus
int m_disapperMessageWindowTimeMs = 5000;
std::chrono::system_clock::time_point m_disappearMessageWindowTime;
std::vector<CNavDataReference> m_airports;
CTerrainProbe m_terrainProbe;
void readAirportsDatabase();
std::vector<CNavDataReference> findClosestAirports(int number, double latitude, double longitude);

View File

@@ -18,6 +18,13 @@ namespace XSwiftBus
CTerrainProbe::~CTerrainProbe() { XPLMDestroyProbe(m_ref); }
std::array<double, 3> CTerrainProbe::getElevation(double degreesLatitude, double degreesLongitude, double metersAltitude) const
{
static const std::string callsign = "myself";
bool unused = false;
return getElevation(degreesLatitude, degreesLongitude, metersAltitude, callsign, unused);
}
std::array<double, 3> CTerrainProbe::getElevation(double degreesLatitude, double degreesLongitude, double metersAltitude, const std::string &callsign, bool &o_isWater) const
{
double x, y, z;

View File

@@ -36,7 +36,10 @@ namespace XSwiftBus
//! Get the elevation in meters at the given point in OpenGL space.
//! \note Due to the Earth's curvature, the OpenGL vertical axis may not be exactly perpendicular to the surface of the geoid.
//! \return NaN if no ground was detected.
//! @{
std::array<double, 3> getElevation(double degreesLatitude, double degreesLongitude, double metersAltitude) const;
std::array<double, 3> getElevation(double degreesLatitude, double degreesLongitude, double metersAltitude, const std::string &callsign, bool &o_isWater) const;
//! @}
private:
XPLMProbeRef m_ref = nullptr;