FlightGear next
AISwiftAircraft.cpp
Go to the documentation of this file.
1// AISwiftAircraft.cpp - Derived AIBase class for swift aircraft
2//
3// Copyright (C) 2020 - swift Project Community / Contributors (http://swift-project.org/)
4// Written by Lars Toenning <dev@ltoenning.de> started on April 2020.
5//
6// This program is free software; you can redistribute it and/or
7// modify it under the terms of the GNU General Public License as
8// published by the Free Software Foundation; either version 2 of the
9// License, or (at your option) any later version.
10//
11// This program is distributed in the hope that it will be useful, but
12// WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14// General Public License for more details.
15//
16// You should have received a copy of the GNU General Public License
17// along with this program; if not, write to the Free Software
18// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
20#include "AISwiftAircraft.h"
21#include <Main/globals.hxx>
22
23
24FGAISwiftAircraft::FGAISwiftAircraft(const std::string& callsign, const std::string& modelString) : FGAIBaseAircraft(object_type::otStatic)
25{
26 std::size_t pos = modelString.find("/Aircraft/"); // Only supporting AI models from FGDATA/AI/Aircraft for now
27 if(pos != std::string::npos)
28 model_path.append(modelString.substr(pos));
29 else
30 model_path.append("INVALID_PATH");
31
32 setCallSign(callsign);
34}
35
36void FGAISwiftAircraft::updatePosition(const SGGeod &position, const SGVec3d &orientation, double groundspeed, bool initPos)
37{
38 m_initPos = initPos;
39 _setLatitude(position.getLatitudeDeg());
40 _setLongitude(position.getLongitudeDeg());
41 _setAltitude(position.getElevationFt());
42 setPitch(orientation.x());
43 setBank(orientation.y());
44 setHeading(orientation.z());
45 setSpeed(groundspeed);
46
47}
48
50{
52 Transform();
53}
54
55double FGAISwiftAircraft::getGroundElevation(const SGGeod& pos) const
56{
57 if(!m_initPos) { return std::numeric_limits<double>::quiet_NaN(); }
58 double alt = 0;
59 SGGeod posReq;
60 posReq.setElevationFt(30000);
61 posReq.setLatitudeDeg(pos.getLatitudeDeg());
62 posReq.setLongitudeDeg(pos.getLongitudeDeg());
63 if(this->getGroundElevationM(posReq, alt, nullptr))
64 return alt;
65 return std::numeric_limits<double>::quiet_NaN();
66}
67
69{
70 GearPos(surfaces.gear);
71 FlapsPos(surfaces.flaps);
72 SpoilerPos(surfaces.spoilers);
73 SpeedBrakePos(surfaces.spoilers);
74 BeaconLight(surfaces.beaconLight);
75 LandingLight(surfaces.landingLight);
76 NavLight(surfaces.navLight);
77 StrobeLight(surfaces.strobeLight);
78 TaxiLight(surfaces.taxiLight);
79}
80
82{
83 m_transponderCodeNode->setIntValue(transponder.code);
84 m_transponderCModeNode->setBoolValue(transponder.modeC);
85 m_transponderIdentNode->setBoolValue(transponder.ident);
86}
87
89{
90 // Setup node properties
91 m_transponderCodeNode = _getProps()->getNode("swift/transponder/code", true);
92 m_transponderCModeNode = _getProps()->getNode("swift/transponder/c-mode", true);
93 m_transponderIdentNode = _getProps()->getNode("swift/transponder/ident", true);
94}
bool NavLight() const
double FlapsPos() const
bool LandingLight() const
bool TaxiLight() const
double GearPos() const
double SpeedBrakePos() const
FGAIBaseAircraft(object_type otype=object_type::otAircraft)
bool BeaconLight() const
double SpoilerPos() const
bool StrobeLight() const
void setSpeed(double speed_KTAS)
Definition AIBase.hxx:404
SGGeod pos
Definition AIBase.hxx:212
void setCallSign(const std::string &)
Definition AIBase.hxx:451
void _setAltitude(double _alt)
Definition AIBase.cxx:1044
SGPropertyNode * _getProps() const
Definition AIBase.cxx:1040
std::string model_path
Definition AIBase.hxx:250
bool getGroundElevationM(const SGGeod &pos, double &elev, const simgear::BVHMaterial **material) const
Definition AIBase.cxx:904
void setBank(double bank)
Definition AIBase.hxx:430
virtual void update(double dt)
Definition AIBase.cxx:294
void _setLatitude(double latitude)
Definition AIBase.cxx:945
void Transform()
Definition AIBase.cxx:518
void setHeading(double heading)
Definition AIBase.hxx:414
void _setLongitude(double longitude)
Definition AIBase.cxx:941
void setPitch(double newpitch)
Definition AIBase.hxx:436
ModelSearchOrder _searchOrder
Definition AIBase.hxx:278
void setPlaneSurface(const AircraftSurfaces &surfaces)
void updatePosition(const SGGeod &position, const SGVec3d &orientation, double groundspeed, bool initPos)
void update(double dt) override
void setPlaneTransponder(const AircraftTransponder &transponder)
FGAISwiftAircraft(const std::string &callsign, const std::string &modelString)
double getGroundElevation(const SGGeod &pos) const