[xswiftbus] log message when terrain probe fails to find ground elevation

This commit is contained in:
Mat Sutcliffe
2020-01-19 18:09:17 +00:00
parent e1a894f81a
commit 90b307d868
3 changed files with 17 additions and 5 deletions

View File

@@ -7,6 +7,7 @@
*/ */
#include "terrainprobe.h" #include "terrainprobe.h"
#include "utils.h"
#include <XPLM/XPLMGraphics.h> #include <XPLM/XPLMGraphics.h>
#include <limits> #include <limits>
@@ -16,7 +17,7 @@ namespace XSwiftBus
CTerrainProbe::~CTerrainProbe() { XPLMDestroyProbe(m_ref); } CTerrainProbe::~CTerrainProbe() { XPLMDestroyProbe(m_ref); }
double CTerrainProbe::getElevation(double degreesLatitude, double degreesLongitude, double metersAltitude) const double CTerrainProbe::getElevation(double degreesLatitude, double degreesLongitude, double metersAltitude, const std::string &callsign) const
{ {
double x, y, z; double x, y, z;
XPLMWorldToLocal(degreesLatitude, degreesLongitude, metersAltitude, &x, &y, &z); XPLMWorldToLocal(degreesLatitude, degreesLongitude, metersAltitude, &x, &y, &z);
@@ -26,8 +27,18 @@ namespace XSwiftBus
auto result = XPLMProbeTerrainXYZ(m_ref, static_cast<float>(x), static_cast<float>(y), static_cast<float>(z), &probe); auto result = XPLMProbeTerrainXYZ(m_ref, static_cast<float>(x), static_cast<float>(y), static_cast<float>(z), &probe);
if (result != xplm_ProbeHitTerrain) if (result != xplm_ProbeHitTerrain)
{ {
std::string error;
if (result == xplm_ProbeError) { error = "probe error"; }
else if (result == xplm_ProbeMissed) { error = "probe missed"; }
else { error = "unknown probe result"; }
WARNING_LOG(callsign + " " + error + " at " + std::to_string(degreesLatitude) + ", " + std::to_string(degreesLongitude) + ", " + std::to_string(metersAltitude));
return std::numeric_limits<double>::quiet_NaN(); return std::numeric_limits<double>::quiet_NaN();
} }
if (probe.is_wet)
{
DEBUG_LOG(callsign + " probe hit water at " + std::to_string(degreesLatitude) + ", " + std::to_string(degreesLongitude) + ", " + std::to_string(metersAltitude));
}
XPLMLocalToWorld(probe.locationX, probe.locationY, probe.locationZ, &degreesLatitude, &degreesLongitude, &metersAltitude); XPLMLocalToWorld(probe.locationX, probe.locationY, probe.locationZ, &degreesLatitude, &degreesLongitude, &metersAltitude);
return metersAltitude; return metersAltitude;

View File

@@ -10,6 +10,7 @@
#define BLACKSIM_XSWIFTBUS_ELEVATIONPROVIDER_H #define BLACKSIM_XSWIFTBUS_ELEVATIONPROVIDER_H
#include <XPLM/XPLMScenery.h> #include <XPLM/XPLMScenery.h>
#include <string>
namespace XSwiftBus namespace XSwiftBus
{ {
@@ -34,7 +35,7 @@ namespace XSwiftBus
//! Get the elevation in meters at the given point in OpenGL space. //! 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. //! \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. //! \return NaN if no ground was detected.
double getElevation(double degreesLatitude, double degreesLongitude, double metersAltitude) const; double getElevation(double degreesLatitude, double degreesLongitude, double metersAltitude, const std::string &callsign) const;
private: private:
XPLMProbeRef m_ref = nullptr; XPLMProbeRef m_ref = nullptr;

View File

@@ -509,7 +509,7 @@ namespace XSwiftBus
const double latDeg = plane->position.lat; const double latDeg = plane->position.lat;
const double lonDeg = plane->position.lon; const double lonDeg = plane->position.lon;
double groundElevation = plane->terrainProbe.getElevation(latDeg, lonDeg, plane->position.elevation); double groundElevation = plane->terrainProbe.getElevation(latDeg, lonDeg, plane->position.elevation, requestedCallsign);
if (std::isnan(groundElevation)) { groundElevation = 0.0; } if (std::isnan(groundElevation)) { groundElevation = 0.0; }
double fudgeFactor = 3.0; double fudgeFactor = 3.0;
bool hasOffset = XPMPGetVerticalOffset(plane->id, &fudgeFactor); bool hasOffset = XPMPGetVerticalOffset(plane->id, &fudgeFactor);
@@ -528,11 +528,11 @@ namespace XSwiftBus
if (planeIt != m_planesByCallsign.end()) if (planeIt != m_planesByCallsign.end())
{ {
const Plane *plane = planeIt->second; const Plane *plane = planeIt->second;
return plane->terrainProbe.getElevation(latitudeDeg, longitudeDeg, altitudeMeters); return plane->terrainProbe.getElevation(latitudeDeg, longitudeDeg, altitudeMeters, callsign);
} }
else else
{ {
return m_terrainProbe.getElevation(latitudeDeg, longitudeDeg, altitudeMeters); return m_terrainProbe.getElevation(latitudeDeg, longitudeDeg, altitudeMeters, callsign + " (plane not found)");
} }
} }