mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 23:25:53 +08:00
[xswiftbus] getElevationAtPosition also returns latitude and longitude
This commit is contained in:
@@ -166,14 +166,16 @@ namespace BlackSimPlugin
|
||||
{
|
||||
std::function<void(QDBusPendingCallWatcher *)> callback = [ = ](QDBusPendingCallWatcher * watcher)
|
||||
{
|
||||
QDBusPendingReply<QString, double> reply = *watcher;
|
||||
QDBusPendingReply<QString, double, double, double> reply = *watcher;
|
||||
if (!reply.isError())
|
||||
{
|
||||
const CCallsign cs(reply.argumentAt<0>());
|
||||
const double elevationMeters = reply.argumentAt<1>();
|
||||
const double latitudeDegrees = reply.argumentAt<2>();
|
||||
const double longitudeDegrees = reply.argumentAt<3>();
|
||||
const CAltitude elevationAlt = std::isnan(elevationMeters) ? CAltitude::null() : CAltitude(elevationMeters, CLengthUnit::m(), CLengthUnit::ft());
|
||||
const CElevationPlane elevation(CLatitude(latitudeDeg, CAngleUnit::deg()),
|
||||
CLongitude(longitudeDeg, CAngleUnit::deg()),
|
||||
const CElevationPlane elevation(CLatitude(latitudeDegrees, CAngleUnit::deg()),
|
||||
CLongitude(longitudeDegrees, CAngleUnit::deg()),
|
||||
elevationAlt, CElevationPlane::singlePointRadius());
|
||||
setter(elevation, cs);
|
||||
}
|
||||
|
||||
@@ -88,6 +88,8 @@ R"XML(<node>
|
||||
<arg name="altitudeMeters" type="d" direction="in"/>
|
||||
<arg type="s" direction="out"/>
|
||||
<arg type="d" direction="out"/>
|
||||
<arg type="d" direction="out"/>
|
||||
<arg type="d" direction="out"/>
|
||||
</method>
|
||||
<method name="setFollowedAircraft">
|
||||
<arg name="callsign" type="s" direction="in"/>
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "utils.h"
|
||||
#include <XPLM/XPLMGraphics.h>
|
||||
#include <limits>
|
||||
#include <cmath>
|
||||
|
||||
namespace XSwiftBus
|
||||
{
|
||||
@@ -17,7 +18,7 @@ namespace XSwiftBus
|
||||
|
||||
CTerrainProbe::~CTerrainProbe() { XPLMDestroyProbe(m_ref); }
|
||||
|
||||
double CTerrainProbe::getElevation(double degreesLatitude, double degreesLongitude, double metersAltitude, const std::string &callsign) const
|
||||
std::array<double, 3> CTerrainProbe::getElevation(double degreesLatitude, double degreesLongitude, double metersAltitude, const std::string &callsign) const
|
||||
{
|
||||
double x, y, z;
|
||||
XPLMWorldToLocal(degreesLatitude, degreesLongitude, metersAltitude, &x, &y, &z);
|
||||
@@ -37,15 +38,20 @@ namespace XSwiftBus
|
||||
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(), degreesLatitude, degreesLongitude }};
|
||||
}
|
||||
XPLMLocalToWorld(probe.locationX, probe.locationY, probe.locationZ, °reesLatitude, °reesLongitude, &metersAltitude);
|
||||
|
||||
if (probe.is_wet && m_logMessageCount < 100)
|
||||
{
|
||||
m_logMessageCount++;
|
||||
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, °reesLatitude, °reesLongitude, &metersAltitude);
|
||||
return metersAltitude;
|
||||
if (std::isnan(metersAltitude) && m_logMessageCount < 100)
|
||||
{
|
||||
m_logMessageCount++;
|
||||
DEBUG_LOG(callsign + " probe returned NaN at " + std::to_string(degreesLatitude) + ", " + std::to_string(degreesLongitude) + ", " + std::to_string(metersAltitude));
|
||||
}
|
||||
return {{ metersAltitude, degreesLatitude, degreesLongitude }};
|
||||
}
|
||||
} // ns
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
#include <XPLM/XPLMScenery.h>
|
||||
#include <string>
|
||||
#include <array>
|
||||
|
||||
namespace XSwiftBus
|
||||
{
|
||||
@@ -35,7 +36,7 @@ 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.
|
||||
double getElevation(double degreesLatitude, double degreesLongitude, double metersAltitude, const std::string &callsign) const;
|
||||
std::array<double, 3> getElevation(double degreesLatitude, double degreesLongitude, double metersAltitude, const std::string &callsign) const;
|
||||
|
||||
private:
|
||||
XPLMProbeRef m_ref = nullptr;
|
||||
|
||||
@@ -512,7 +512,7 @@ namespace XSwiftBus
|
||||
double groundElevation = 0.0;
|
||||
if (getSettings().isTerrainProbeEnabled())
|
||||
{
|
||||
groundElevation = plane->terrainProbe.getElevation(latDeg, lonDeg, plane->position.elevation, requestedCallsign);
|
||||
groundElevation = plane->terrainProbe.getElevation(latDeg, lonDeg, plane->position.elevation, requestedCallsign).front();
|
||||
if (std::isnan(groundElevation)) { groundElevation = 0.0; }
|
||||
}
|
||||
double fudgeFactor = 3.0;
|
||||
@@ -526,9 +526,9 @@ namespace XSwiftBus
|
||||
}
|
||||
}
|
||||
|
||||
double CTraffic::getElevationAtPosition(const std::string &callsign, double latitudeDeg, double longitudeDeg, double altitudeMeters) const
|
||||
std::array<double, 3> CTraffic::getElevationAtPosition(const std::string &callsign, double latitudeDeg, double longitudeDeg, double altitudeMeters) const
|
||||
{
|
||||
if (!getSettings().isTerrainProbeEnabled()) { return std::numeric_limits<double>::quiet_NaN(); }
|
||||
if (!getSettings().isTerrainProbeEnabled()) { return {{ std::numeric_limits<double>::quiet_NaN(), latitudeDeg, longitudeDeg }}; }
|
||||
|
||||
auto planeIt = m_planesByCallsign.find(callsign);
|
||||
if (planeIt != m_planesByCallsign.end())
|
||||
@@ -822,11 +822,13 @@ namespace XSwiftBus
|
||||
message.getArgument(altitudeMeters);
|
||||
queueDBusCall([ = ]()
|
||||
{
|
||||
double elevation = getElevationAtPosition(callsign, latitudeDeg, longitudeDeg, altitudeMeters);
|
||||
const auto elevation = getElevationAtPosition(callsign, latitudeDeg, longitudeDeg, altitudeMeters);
|
||||
CDBusMessage reply = CDBusMessage::createReply(sender, serial);
|
||||
reply.beginArgumentWrite();
|
||||
reply.appendArgument(callsign);
|
||||
reply.appendArgument(elevation);
|
||||
reply.appendArgument(elevation[0]);
|
||||
reply.appendArgument(elevation[1]);
|
||||
reply.appendArgument(elevation[2]);
|
||||
sendDBusMessage(reply);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ namespace XSwiftBus
|
||||
std::vector<double> &elevationsM, std::vector<double> &verticalOffsets) const;
|
||||
|
||||
//! Get the ground elevation at an arbitrary position
|
||||
double getElevationAtPosition(const std::string &callsign, double latitudeDeg, double longitudeDeg, double altitudeMeters) const;
|
||||
std::array<double, 3> getElevationAtPosition(const std::string &callsign, double latitudeDeg, double longitudeDeg, double altitudeMeters) const;
|
||||
|
||||
//! Sets the aircraft with callsign to be followed in plane view
|
||||
void setFollowedAircraft(const std::string &callsign);
|
||||
|
||||
Reference in New Issue
Block a user