1
0
Fork 0

[swift] Fetching ground elevation for interpolation

This commit is contained in:
Lars Toenning 2020-02-29 14:31:52 +01:00 committed by James Turner
parent 34915125a1
commit aca625eda2
5 changed files with 75 additions and 28 deletions

View file

@ -57,9 +57,10 @@ FGSwiftAircraft::FGSwiftAircraft(const std::string& callsign, const std::string&
props->setStringValue("callsign", callsign);
props->setBoolValue("valid",true);
}
initPos = false;
}
bool FGSwiftAircraft::updatePosition(SGGeod newPosition, SGVec3d orientation, double groundspeed)
bool FGSwiftAircraft::updatePosition(SGGeod newPosition, SGVec3d orientation, double groundspeed, bool initPos)
{
position = newPosition;
@ -69,6 +70,8 @@ bool FGSwiftAircraft::updatePosition(SGGeod newPosition, SGVec3d orientation, do
aip.setHeadingDeg(orientation.z());
aip.update();
this->initPos = initPos;
//Update props
props->setDoubleValue("orientation/pitch-deg", orientation.x());
props->setDoubleValue("orientation/roll-deg", orientation.y());
@ -97,17 +100,17 @@ FGSwiftAircraft::~FGSwiftAircraft()
aip.setVisible(false);
}
double FGSwiftAircraft::getLatDeg()
double FGSwiftAircraft::getLatDeg() const
{
return position.getLatitudeDeg();
}
double FGSwiftAircraft::getLongDeg()
double FGSwiftAircraft::getLongDeg() const
{
return position.getLongitudeDeg();
}
double FGSwiftAircraft::getFudgeFactor()
double FGSwiftAircraft::getFudgeFactor() const
{
return 0;
}
@ -117,10 +120,15 @@ inline bool FGSwiftAircraft::operator<(const std::string& extCallsign)
return _model->getName().compare(extCallsign);
}
double FGSwiftAircraft::getGroundElevation()
double FGSwiftAircraft::getGroundElevation(double latitudeDeg, double longitudeDeg) const
{
double alt;
globals->get_scenery()->get_elevation_m(position,alt,0);
return alt;
if(!initPos) { return std::numeric_limits<double>::quiet_NaN(); }
double alt = 0;
SGGeod pos;
pos.setElevationFt(30000);
pos.setLatitudeDeg(latitudeDeg);
pos.setLongitudeDeg(longitudeDeg);
globals->get_scenery()->get_elevation_m(pos,alt,0,_model.get());
return alt;
}

View file

@ -42,15 +42,16 @@ class FGSwiftAircraft
{
public:
FGSwiftAircraft(const std::string& callsign, const std::string& modelpath, SGPropertyNode* p);
bool updatePosition(SGGeod newPosition, SGVec3d orientation, double groundspeed);
bool updatePosition(SGGeod newPosition, SGVec3d orientation, double groundspeed, bool initPos);
~FGSwiftAircraft();
std::string getName() { return _model->getName(); };
double getLatDeg();
double getLongDeg();
double getGroundElevation();
double getFudgeFactor();
double getLatDeg() const;
double getLongDeg() const;
double getGroundElevation(double, double) const;
double getFudgeFactor() const;
private:
bool initPos;
SGGeod position;
SGPropertyNode* props;
osg::ref_ptr<osg::Node> _model;

View file

@ -55,7 +55,7 @@ void FGSwiftAircraftManager::updatePlanes(std::vector<std::string> callsigns, st
for (long unsigned int i = 0; i < callsigns.size(); i++) {
auto it = aircraftByCallsign.find(callsigns.at(i));
if (it != aircraftByCallsign.end()) {
it->second->updatePosition(positions.at(i), orientations.at(i), groundspeeds.at(i));
it->second->updatePosition(positions.at(i), orientations.at(i), groundspeeds.at(i),true);
}
}
@ -63,6 +63,8 @@ void FGSwiftAircraftManager::updatePlanes(std::vector<std::string> callsigns, st
void FGSwiftAircraftManager::getRemoteAircraftData(std::vector<std::string>& callsigns, std::vector<double>& latitudesDeg, std::vector<double>& longitudesDeg, std::vector<double>& elevationsM, std::vector<double>& verticalOffsets) const
{
if (callsigns.empty() || aircraftByCallsign.empty()) { return; }
const auto requestedCallsigns = callsigns;
callsigns.clear();
latitudesDeg.clear();
@ -71,21 +73,24 @@ void FGSwiftAircraftManager::getRemoteAircraftData(std::vector<std::string>& cal
verticalOffsets.clear();
for (const auto & requestedCallsign : requestedCallsigns) {
auto it = aircraftByCallsign.find(requestedCallsign);
if (it != aircraftByCallsign.end()) {
double latDeg = it->second->getLatDeg();
double lonDeg = it->second->getLongDeg();
double groundElevation = it->second->getGroundElevation();
double fudgeFactor = it->second->getFudgeFactor();
(void)fudgeFactor;
callsigns.push_back(requestedCallsign);
latitudesDeg.push_back(latDeg);
longitudesDeg.push_back(lonDeg);
elevationsM.push_back(groundElevation);
verticalOffsets.push_back(0);
}
}
const auto it = aircraftByCallsign.find(requestedCallsign);
if(it == aircraftByCallsign.end()) { continue; }
const FGSwiftAircraft *aircraft = it->second;
assert(aircraft);
const double latDeg = aircraft->getLatDeg();
const double lonDeg = aircraft->getLongDeg();
double groundElevation = aircraft->getGroundElevation(latDeg, lonDeg);
double fudgeFactor = aircraft->getFudgeFactor();
(void)fudgeFactor;
callsigns.push_back(requestedCallsign);
latitudesDeg.push_back(latDeg);
longitudesDeg.push_back(lonDeg);
elevationsM.push_back(groundElevation);
verticalOffsets.push_back(0);
}
}
void FGSwiftAircraftManager::removePlane(const std::string& callsign)
@ -104,3 +109,13 @@ void FGSwiftAircraftManager::removeAllPlanes()
aircraftByCallsign.erase(it);
}
}
double FGSwiftAircraftManager::getElevationAtPosition(const std::string &callsign, double latitudeDeg,
double longitudeDeg, double altitudeMeters) const
{
auto it = aircraftByCallsign.find(callsign);
if(it != aircraftByCallsign.end()){
return it->second->getGroundElevation(latitudeDeg, longitudeDeg);
}
return std::numeric_limits<double>::quiet_NaN();
}

View file

@ -18,6 +18,7 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "SwiftAircraft.h"
#include <Scenery/scenery.hxx>
#include <vector>
#ifndef FGSWIFTAIRCRAFTMANAGER_H
@ -35,5 +36,6 @@ public:
std::vector<double>& elevationsM, std::vector<double>& verticalOffsets) const;
void removePlane(const std::string& callsign);
void removeAllPlanes();
double getElevationAtPosition(const std::string &callsign, double latitudeDeg, double longitudeDeg, double altitudeMeters) const;
};
#endif

View file

@ -241,6 +241,27 @@ DBusHandlerResult CTraffic::dbusMessageHandler(const CDBusMessage& message_)
reply.appendArgument(verticalOffsets);
sendDBusMessage(reply);
});
}
else if (message.getMethodName() == "getElevationAtPosition")
{
std::string callsign;
double latitudeDeg;
double longitudeDeg;
double altitudeMeters;
message.beginArgumentRead();
message.getArgument(callsign);
message.getArgument(latitudeDeg);
message.getArgument(longitudeDeg);
message.getArgument(altitudeMeters);
queueDBusCall([ = ]()
{
double elevation = acm->getElevationAtPosition(callsign, latitudeDeg, longitudeDeg, altitudeMeters);
CDBusMessage reply = CDBusMessage::createReply(sender, serial);
reply.beginArgumentWrite();
reply.appendArgument(callsign);
reply.appendArgument(elevation);
sendDBusMessage(reply);
});
} else {
// Unknown message. Tell DBus that we cannot handle it
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;