1
0
Fork 0

[swift] Adding aircraft to property tree and map

This commit is contained in:
Lars Toenning 2020-01-27 22:27:22 +01:00 committed by James Turner
parent e6a9515b59
commit d14073cd24
6 changed files with 50 additions and 10 deletions

View file

@ -2002,7 +2002,7 @@ MapWidget::DrawAIObject::DrawAIObject(SGPropertyNode* m, const SGGeod& g) :
heading = model->getDoubleValue("orientation/true-heading-deg");
if ((name == "aircraft") || (name == "multiplayer") ||
(name == "wingman") || (name == "tanker"))
(name == "wingman") || (name == "tanker") || (name == "swift"))
{
speedKts = static_cast<int>(model->getDoubleValue("velocities/true-airspeed-kt"));
label = model->getStringValue("callsign", "<>");

View file

@ -42,7 +42,7 @@
#include <Scripting/NasalSys.hxx>
#include <Sound/fg_fx.hxx>
FGSwiftAircraft::FGSwiftAircraft(std::string callsign, std::string modelpath)
FGSwiftAircraft::FGSwiftAircraft(std::string callsign, std::string modelpath, SGPropertyNode* p)
{
using namespace simgear;
_model = SGModelLib::loadModel(modelpath);
@ -52,10 +52,14 @@ FGSwiftAircraft::FGSwiftAircraft(std::string callsign, std::string modelpath)
aip.setVisible(true);
aip.update();
globals->get_scenery()->get_models_branch()->addChild(aip.getSceneGraph());
props = p;
props->setStringValue("callsign", callsign);
props->setBoolValue("valid",true);
}
}
bool FGSwiftAircraft::updatePosition(SGGeod newPosition, SGVec3d orientation)
bool FGSwiftAircraft::updatePosition(SGGeod newPosition, SGVec3d orientation, double groundspeed)
{
position = newPosition;
@ -64,12 +68,32 @@ bool FGSwiftAircraft::updatePosition(SGGeod newPosition, SGVec3d orientation)
aip.setRollDeg(orientation.y());
aip.setHeadingDeg(orientation.z());
aip.update();
//Update props
props->setDoubleValue("orientation/pitch-deg", orientation.x());
props->setDoubleValue("orientation/roll-deg", orientation.y());
props->setDoubleValue("orientation/true-heading-deg", orientation.z());
SGVec3d cartPos = SGVec3d::fromGeod(position);
props->setDoubleValue("position/global-x", cartPos.x());
props->setDoubleValue("position/global-y", cartPos.y());
props->setDoubleValue("position/global-z", cartPos.z());
props->setDoubleValue("position/latitude-deg", position.getLatitudeDeg());
props->setDoubleValue("position/longitude-deg", position.getLongitudeDeg());
props->setDoubleValue("position/altitude-ft", position.getElevationFt());
props->setDoubleValue("velocities/true-airspeed-kt", groundspeed);
return true;
}
FGSwiftAircraft::~FGSwiftAircraft()
{
props->setBoolValue("valid",false);
props->setIntValue("id",-1);
aip.setVisible(false);
}

View file

@ -41,8 +41,8 @@ class PagedLOD;
class FGSwiftAircraft
{
public:
FGSwiftAircraft(std::string callsign, std::string modelpath);
bool updatePosition(SGGeod newPosition, SGVec3d orientation);
FGSwiftAircraft(std::string callsign, std::string modelpath, SGPropertyNode* p);
bool updatePosition(SGGeod newPosition, SGVec3d orientation, double groundspeed);
~FGSwiftAircraft();
std::string getName() { return _model->getName(); };
double getLatDeg();
@ -52,6 +52,7 @@ public:
private:
SGGeod position;
SGPropertyNode* props;
osg::ref_ptr<osg::Node> _model;
SGModelPlacement aip;
inline bool operator<(std::string extCallsign);

View file

@ -19,6 +19,7 @@
#include "SwiftAircraftManager.h"
#include "SwiftAircraft.h"
#include <Main/globals.hxx>
FGSwiftAircraftManager::FGSwiftAircraftManager()
{
@ -33,17 +34,29 @@ bool FGSwiftAircraftManager::addPlane(std::string callsign, std::string modelStr
if (aircraftByCallsign.find(callsign) != aircraftByCallsign.end())
return false;
FGSwiftAircraft* curAircraft = new FGSwiftAircraft(callsign, modelString);
const char* typeString = "swift";
SGPropertyNode* root = globals->get_props()->getNode("ai/models",true);
SGPropertyNode* p;
int i;
for(i = 0; i < 10000; i++){
p = root->getNode(typeString,i,false);
if(!p || !p->getBoolValue("valid",false))
break;
}
p = root->getNode(typeString,i,true);
p->setIntValue("id",i);
FGSwiftAircraft* curAircraft = new FGSwiftAircraft(callsign, modelString, p);
aircraftByCallsign.insert(std::pair<std::string, FGSwiftAircraft*>(callsign, curAircraft));
return true;
}
void FGSwiftAircraftManager::updatePlanes(std::vector<std::string> callsigns, std::vector<SGGeod> positions, std::vector<SGVec3d> orientations, std::vector<bool> onGrounds)
void FGSwiftAircraftManager::updatePlanes(std::vector<std::string> callsigns, std::vector<SGGeod> positions, std::vector<SGVec3d> orientations, std::vector<double> groundspeeds, std::vector<bool> onGrounds)
{
for (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));
it->second->updatePosition(positions.at(i), orientations.at(i), groundspeeds.at(i));
}
}

View file

@ -30,7 +30,7 @@ public:
~FGSwiftAircraftManager();
std::map<std::string, FGSwiftAircraft*> aircraftByCallsign;
bool addPlane(std::string callsign, std::string modelString);
void updatePlanes(std::vector<std::string> callsigns, std::vector<SGGeod> positions, std::vector<SGVec3d> orientations, std::vector<bool> onGrounds);
void updatePlanes(std::vector<std::string> callsigns, std::vector<SGGeod> positions, std::vector<SGVec3d> orientations, std::vector<double> groundspeeds, std::vector<bool> onGrounds);
void getRemoteAircraftData(std::vector<std::string>& callsigns, std::vector<double>& latitudesDeg, std::vector<double>& longitudesDeg,
std::vector<double>& elevationsM, std::vector<double>& verticalOffsets) const;
void removePlane(std::string callsign);

View file

@ -192,6 +192,7 @@ DBusHandlerResult CTraffic::dbusMessageHandler(const CDBusMessage& message_)
std::vector<double> pitches;
std::vector<double> rolls;
std::vector<double> headings;
std::vector<double> groundspeeds;
std::vector<bool> onGrounds;
message.beginArgumentRead();
message.getArgument(callsigns);
@ -201,6 +202,7 @@ DBusHandlerResult CTraffic::dbusMessageHandler(const CDBusMessage& message_)
message.getArgument(pitches);
message.getArgument(rolls);
message.getArgument(headings);
message.getArgument(groundspeeds);
message.getArgument(onGrounds);
queueDBusCall([=]() {
std::vector<SGGeod> positions;
@ -215,7 +217,7 @@ DBusHandlerResult CTraffic::dbusMessageHandler(const CDBusMessage& message_)
positions.push_back(newPos);
orientations.push_back(vec);
}
acm->updatePlanes(callsigns, positions, orientations, onGrounds);
acm->updatePlanes(callsigns, positions, orientations, groundspeeds, onGrounds);
});
} else if (message.getMethodName() == "getRemoteAircraftData") {
std::vector<std::string> requestedcallsigns;