Remove leftover headers from plib/sg.
Modified Files:
src/AIModel/AIBase.cxx
src/AIModel/AIFlightPlanCreateCruise.cxx
src/ATCDCL/AIEntity.cxx src/ATCDCL/AIEntity.hxx
src/ATCDCL/AIGAVFRTraffic.cxx src/ATCDCL/AIGAVFRTraffic.hxx
src/ATCDCL/AILocalTraffic.cxx src/ATCDCL/AILocalTraffic.hxx
src/ATCDCL/AIMgr.cxx src/ATCDCL/ATC.hxx
src/ATCDCL/ATCDialog.cxx src/ATCDCL/ATCProjection.cxx
src/ATCDCL/ATCProjection.hxx src/ATCDCL/ATCutils.cxx
src/ATCDCL/ATCutils.hxx src/ATCDCL/approach.cxx
src/ATCDCL/commlist.cxx src/ATCDCL/ground.cxx
src/ATCDCL/ground.hxx src/ATCDCL/tower.cxx
src/ATCDCL/tower.hxx src/Airports/calc_loc.cxx
src/Airports/dynamics.cxx src/Airports/groundnetwork.cxx
src/Airports/parking.cxx src/Airports/runwayprefs.cxx
src/Airports/simple.cxx src/Cockpit/cockpit.cxx
src/Cockpit/hud.hxx src/Cockpit/hud_card.cxx
src/Cockpit/hud_rwy.cxx src/Environment/environment.cxx
src/FDM/UFO.cxx src/FDM/SP/MagicCarpet.cxx src/GUI/dialog.hxx
src/Instrumentation/HUD/HUD.hxx
src/Instrumentation/HUD/HUD_runway.cxx
src/Instrumentation/KLN89/kln89.cxx src/Main/fg_init.cxx
src/Main/viewer.cxx src/Main/viewmgr.cxx
src/Model/panelnode.cxx src/MultiPlayer/mpmessages.hxx
src/Scenery/tilemgr.cxx src/Traffic/SchedFlight.cxx
src/Traffic/TrafficMgr.cxx
#include <osg/Node>
#include <osgDB/FileUtils>
-#include <simgear/math/point3d.hxx>
-#include <simgear/math/polar3d.hxx>
-#include <simgear/math/sg_geodesy.hxx>
+#include <simgear/math/SGMath.hxx>
#include <simgear/misc/sg_path.hxx>
#include <simgear/scene/model/modellib.hxx>
#include <simgear/scene/util/SGNodeMasks.hxx>
#include <iostream>
#include "AIFlightPlan.hxx"
#include "AIAircraft.hxx"
-#include <simgear/math/polar3d.hxx>
-#include <simgear/math/sg_geodesy.hxx>
#include <simgear/route/waypoint.hxx>
#include <Navaids/awynet.hxx>
}
FGAIEntity::~FGAIEntity() {
- //cout << "FGAIEntity dtor called..." << endl;
- //cout << "Removing model from scene graph..." << endl;
- globals->get_scenery()->get_scene_graph()->removeChild(_aip.getSceneGraph());
-
- //cout << "Done!" << endl;
+ globals->get_scenery()->get_scene_graph()->removeChild(_aip.getSceneGraph());
}
void FGAIEntity::SetModel(osg::Node* model) {
- _aip.init(model);
- _aip.setVisible(false);
- globals->get_scenery()->get_scene_graph()->addChild(_aip.getSceneGraph());
-
+ _aip.init(model);
+ _aip.setVisible(false);
+ globals->get_scenery()->get_scene_graph()->addChild(_aip.getSceneGraph());
}
void FGAIEntity::Update(double dt) {
}
const string &FGAIEntity::GetCallsign() {
- static string s = "";
- return(s);
+ static string s = "";
+ return(s);
}
void FGAIEntity::RegisterTransmission(int code) {
// Run the internal calculations
//void FGAIEntity::Update() {
void FGAIEntity::Transform() {
- _aip.setPosition(_pos.lon(), _pos.lat(), _pos.elev() * SG_METER_TO_FEET);
+ _aip.setPosition(_pos);
_aip.setOrientation(_roll, _pitch, _hdg);
_aip.update();
}
#ifndef _FG_AIEntity_HXX
#define _FG_AIEntity_HXX
-#include <simgear/math/point3d.hxx>
+#include <simgear/math/SGMath.hxx>
#include <simgear/scene/model/placement.hxx>
-
/*****************************************************************
*
* FGAIEntity - this class implements the minimum requirement
public:
- FGAIEntity();
+ FGAIEntity();
virtual ~FGAIEntity();
- // Set the 3D model to use (Must be called)
- void SetModel(osg::Node* model);
+ // Set the 3D model to use (Must be called)
+ void SetModel(osg::Node* model);
// Run the internal calculations
virtual void Update(double dt)=0;
-
+
// Send a transmission *TO* the AIEntity.
// FIXME int code is a hack - eventually this will receive Alexander's coded messages.
virtual void RegisterTransmission(int code)=0;
-
- inline const Point3D& GetPos() const { return(_pos); }
-
- virtual const string& GetCallsign()=0;
+
+ const SGGeod& getPos() const
+ { return _pos; }
+
+ virtual const string& GetCallsign()=0;
protected:
-
- Point3D _pos; // WGS84 lat & lon in degrees, elev above sea-level in meters
- double _hdg; //True heading in degrees
+
+ SGGeod _pos; // Geodetic position
+ double _hdg; //True heading in degrees
double _roll; //degrees
double _pitch; //degrees
SGModelPlacement _aip;
double _ground_elevation_m;
-
+
void Transform();
};
# include <config.h>
#endif
+#include <simgear/math/SGMath.hxx>
#include <Airports/runways.hxx>
#include <Main/globals.hxx>
-#include <simgear/math/point3d.hxx>
#include <string>
#include <math.h>
#include "tower.hxx"
// extern from Airports/simple.cxx
-extern Point3D fgGetAirportPos( const std::string& id );
+extern SGGeod fgGetAirportPos( const std::string& id );
FGAIGAVFRTraffic::FGAIGAVFRTraffic() {
ATC = globals->get_ATC_mgr();
// Init en-route to destID at point pt.
// TODO - no idea what to do if pt is above planes ceiling due mountains!!
-bool FGAIGAVFRTraffic::Init(const Point3D& pt, const string& destID, const string& callsign) {
+bool FGAIGAVFRTraffic::Init(const SGGeod& pt, const string& destID, const string& callsign) {
FGAILocalTraffic::Init(callsign, destID, EN_ROUTE);
// TODO FIXME - to get up and running we're going to ignore elev and get FGAIMgr to
// pass in known good values for the test location. Need to fix this!!! (or at least canonically decide who has responsibility for setting elev).
_destID = destID;
_pos = pt;
_destPos = fgGetAirportPos(destID); // TODO - check if we are within the tower catchment area already.
- _cruise_alt = (_destPos.elev() + 2500.0) * SG_FEET_TO_METER; // TODO look at terrain elevation as well
- _pos.setelev(_cruise_alt);
+ _cruise_alt = (_destPos.getElevationM() + 2500.0) * SG_FEET_TO_METER; // TODO look at terrain elevation as well
+ _pos.setElevationM(_cruise_alt);
// initially set waypoint as airport location
_wp = _destPos;
// Set the initial track
// we shouldn't really need this since there's a LOD of 10K on the whole plane anyway I think.
// There are two _aip.setVisible statements set when _local = true that can be removed if the below is removed.
- if(dclGetHorizontalSeparation(_pos, Point3D(fgGetDouble("/position/longitude-deg"), fgGetDouble("/position/latitude-deg"), 0.0)) > 8000) _aip.setVisible(false);
+ if(dclGetHorizontalSeparation(_pos, SGGeod::fromDegM(fgGetDouble("/position/longitude-deg"), fgGetDouble("/position/latitude-deg"), 0.0)) > 8000) _aip.setVisible(false);
else _aip.setVisible(true);
} else if(_local) {
void FGAIGAVFRTraffic::FlyPlane(double dt) {
if(_climbout) {
// Check whether to level off
- if(_pos.elev() >= _cruise_alt) {
+ if(_pos.getElevationM() >= _cruise_alt) {
slope = 0.0;
_pitch = 0.0;
IAS = _cruise_ias; // FIXME - use smooth transistion to new speed and attitude.
// Possibly check whether to start descent before this?
//cout << "." << flush;
//cout << "sep = " << dclGetHorizontalSeparation(_destPos, _pos) / 1600.0 << '\n';
- if(dclGetHorizontalSeparation(_destPos, _pos) / 1600.0 < 8.0) {
+ if(dclGetHorizontalSeparation(_destPos, _pos) / 1600.0 < 8.0) {
//cout << "-" << flush;
if(!_towerContactedIncoming) {
//cout << "_" << flush;
_wp = GetPatternApproachPos();
//_hdg = GetHeadingFromTo(_pos, _wp); // TODO - turn properly!
SetTrack(GetHeadingFromTo(_pos, _wp));
- slope = atan((_wp.elev() - _pos.elev()) / dclGetHorizontalSeparation(_wp, _pos)) * DCL_RADIANS_TO_DEGREES;
+ slope = atan((_wp.getElevationM() - _pos.getElevationM()) / dclGetHorizontalSeparation(_wp, _pos)) * DCL_RADIANS_TO_DEGREES;
double thesh_offset = 0.0;
- Point3D opos = ortho.ConvertToLocal(_pos);
- double angToApt = atan((_pos.elev() - fgGetAirportElev(airportID)) / (opos.y() - thesh_offset)) * DCL_RADIANS_TO_DEGREES;
+ SGVec3d opos = ortho.ConvertToLocal(_pos);
+ double angToApt = atan((_pos.getElevationM() - fgGetAirportElev(airportID)) / (opos.y() - thesh_offset)) * DCL_RADIANS_TO_DEGREES;
//cout << "angToApt = " << angToApt << ' ';
slope = (angToApt > -5.0 ? 0.0 : angToApt);
//cout << "slope = " << slope << '\n';
_incoming = true;
_wp = GetPatternApproachPos();
SetTrack(GetHeadingFromTo(_pos, _wp));
- slope = atan((_wp.elev() - _pos.elev()) / dclGetHorizontalSeparation(_wp, _pos)) * DCL_RADIANS_TO_DEGREES;
+ slope = atan((_wp.getElevationM() - _pos.getElevationM()) / dclGetHorizontalSeparation(_wp, _pos)) * DCL_RADIANS_TO_DEGREES;
//cout << "slope = " << slope << '\n';
pending_transmission = "Report ";
pending_transmission += (patternDirection == 1 ? "right downwind " : "left downwind ");
ConditionalTransmit(4);
}
}
- if(_pos.elev() < (fgGetAirportElev(airportID) + (1000.0 * SG_FEET_TO_METER))) slope = 0.0;
+ if(_pos.getElevationM() < (fgGetAirportElev(airportID) + (1000.0 * SG_FEET_TO_METER))) slope = 0.0;
}
}
if(_incoming) {
//cout << "i" << '\n';
- Point3D orthopos = ortho.ConvertToLocal(_pos);
+ SGVec3d orthopos = ortho.ConvertToLocal(_pos);
// TODO - Check whether to start descent
// become _local after the 3 mile report.
- if(_pos.elev() < (fgGetAirportElev(airportID) + (1000.0 * SG_FEET_TO_METER))) slope = 0.0;
+ if(_pos.getElevationM() < (fgGetAirportElev(airportID) + (1000.0 * SG_FEET_TO_METER))) slope = 0.0;
// TODO - work out why I needed to add the above line to stop the plane going underground!!!
// (Although it's worth leaving it in as a robustness check anyway).
if(_straightIn) {
//cout << "Established at " << orthopos << '\n';
}
double thesh_offset = 30.0;
- //cout << "orthopos.y = " << orthopos.y() << " alt = " << _pos.elev() - fgGetAirportElev(airportID) << '\n';
+ //cout << "orthopos.y = " << orthopos.y() << " alt = " << _pos.getElevationM() - fgGetAirportElev(airportID) << '\n';
if(_established && (orthopos.y() > -5400.0)) {
- slope = atan((_pos.elev() - fgGetAirportElev(airportID)) / (orthopos.y() - thesh_offset)) * DCL_RADIANS_TO_DEGREES;
+ slope = atan((_pos.getElevationM() - fgGetAirportElev(airportID)) / (orthopos.y() - thesh_offset)) * DCL_RADIANS_TO_DEGREES;
//cout << "slope0 = " << slope << '\n';
}
//cout << "slope1 = " << slope << '\n';
} else {
//cout << "D" << flush;
//cout << '\n' << dclGetHorizontalSeparation(_wp, _pos) << '\n';
- //cout << ortho.ConvertToLocal(_pos);
+ //cout << ortho.ConvertToLocal(GetPos());
//cout << ortho.ConvertToLocal(_wp);
if(dclGetHorizontalSeparation(_wp, _pos) < 100.0) {
pending_transmission = "2 miles out for ";
slope = 0.0;
}
// FIXME - lots of hackery in the next six lines!!!!
- //double track = _hdg;
double crab = 0.0; // This is a placeholder for when we take wind into account.
_hdg = track + crab;
double vel = _cruise_ias;
// 1/ A few miles out on extended centreline for straight-in.
// 2/ At an appropriate point on circuit side of rwy for a 45deg entry to downwind.
// 3/ At and appropriate point on non-circuit side of rwy at take-off end for perpendicular entry to circuit overflying end-of-rwy.
-Point3D FGAIGAVFRTraffic::GetPatternApproachPos() {
+SGGeod FGAIGAVFRTraffic::GetPatternApproachPos() {
//cout << "\n\n";
//cout << "Calculating pattern approach pos for " << plane.callsign << '\n';
- Point3D orthopos = ortho.ConvertToLocal(_pos);
- Point3D tmp;
+ SGVec3d orthopos = ortho.ConvertToLocal(_pos);
+ SGVec3d tmp;
//cout << "patternDirection = " << patternDirection << '\n';
if(orthopos.y() >= -1000.0) { // Note that this has to be set the same as the calculation in tower.cxx - at the moment approach type is not transmitted properly between the two.
//cout << "orthopos.x = " << orthopos.x() << '\n';
if((orthopos.x() * patternDirection) > 0.0) { // 45 deg entry
- tmp.setx(2000 * patternDirection);
- tmp.sety((rwy.end2ortho.y() / 2.0) + 2000);
- tmp.setelev(fgGetAirportElev(airportID) + (1000 * SG_FEET_TO_METER));
+ tmp.x() = 2000 * patternDirection;
+ tmp.y() = (rwy.end2ortho.y() / 2.0) + 2000;
+ tmp.z() = (fgGetAirportElev(airportID) + (1000 * SG_FEET_TO_METER));
_e45 = true;
//cout << "45 deg entry... ";
} else {
- tmp.setx(1000 * patternDirection * -1);
- tmp.sety(rwy.end2ortho.y());
- tmp.setelev(fgGetAirportElev(airportID) + (1000 * SG_FEET_TO_METER));
+ tmp.x() = (1000 * patternDirection * -1);
+ tmp.y() = (rwy.end2ortho.y());
+ tmp.z() = (fgGetAirportElev(airportID) + (1000 * SG_FEET_TO_METER));
_e45 = false;
//cout << "90 deg entry... ";
}
} else {
- tmp.setx(0);
- tmp.sety(-5400);
- tmp.setelev((5400.0 / 6.0) + fgGetAirportElev(airportID) + 10.0);
+ tmp.x() = 0;
+ tmp.y() = -5400;
+ tmp.z() = ((5400.0 / 6.0) + fgGetAirportElev(airportID) + 10.0);
//cout << "Straight in... ";
}
//cout << "Waypoint is " << tmp << '\n';
#ifndef _FG_AIGAVFRTraffic_HXX
#define _FG_AIGAVFRTraffic_HXX
-#include <simgear/math/point3d.hxx>
+#include <simgear/math/SGMath.hxx>
#include <Main/fg_props.hxx>
#include "AILocalTraffic.hxx"
~FGAIGAVFRTraffic();
// Init en-route to destID at point pt. (lat, lon, elev) (elev in meters, lat and lon in degrees).
- bool Init(const Point3D& pt, const string& destID, const string& callsign);
+ bool Init(const SGGeod& pt, const string& destID, const string& callsign);
// Init at srcID to fly to destID
bool Init(const string& srcID, const string& destID, const string& callsign, OperatingState state = PARKED);
bool _clearedStraightIn;
bool _downwindEntry;
bool _clearedDownwindEntry;
- Point3D _wp; // Next waypoint (ie. the one we're currently heading for)
+ SGGeod _wp; // Next waypoint (ie. the one we're currently heading for)
bool _enroute;
string _destID;
bool _climbout;
double _cruise_alt;
double _cruise_ias;
double _cruise_climb_ias;
- Point3D _destPos;
+ SGGeod _destPos;
bool _local;
bool _incoming;
bool _established;
int GetQuadrangleAltitude(int dir, int des_alt);
- Point3D GetPatternApproachPos();
+ SGGeod GetPatternApproachPos();
void FlyPlane(double dt);
#include <Main/viewer.hxx>
#include <Scenery/scenery.hxx>
#include <Scenery/tilemgr.hxx>
-#include <simgear/math/point3d.hxx>
-#include <simgear/math/sg_geodesy.hxx>
+#include <simgear/math/SGMath.hxx>
#include <simgear/misc/sg_path.hxx>
#include <string>
#include <math.h>
// move to the +l end/center of the runway
//cout << "Runway center is at " << runway._lon << ", " << runway._lat << '\n';
- Point3D origin = Point3D(runway->longitude(), runway->latitude(), aptElev);
- Point3D ref = origin;
double tshlon, tshlat, tshr;
double tolon, tolat, tor;
rwy.length = runway->lengthM();
rwy.width = runway->widthM();
- geo_direct_wgs_84 ( aptElev, ref.lat(), ref.lon(), other_way,
+ geo_direct_wgs_84 ( aptElev, runway->latitude(), runway->longitude(), other_way,
rwy.length / 2.0 - 25.0, &tshlat, &tshlon, &tshr );
- geo_direct_wgs_84 ( aptElev, ref.lat(), ref.lon(), hdg,
+ geo_direct_wgs_84 ( aptElev, runway->latitude(), runway->longitude(), hdg,
rwy.length / 2.0 - 25.0, &tolat, &tolon, &tor );
// Note - 25 meters in from the runway end is a bit of a hack to put the plane ahead of the user.
// now copy what we need out of runway into rwy
- rwy.threshold_pos = Point3D(tshlon, tshlat, aptElev);
- Point3D takeoff_end = Point3D(tolon, tolat, aptElev);
+ rwy.threshold_pos = SGGeod::fromDegM(tshlon, tshlat, aptElev);
+ SGGeod takeoff_end = SGGeod::fromDegM(tolon, tolat, aptElev);
//cout << "Threshold position = " << tshlon << ", " << tshlat << ", " << aptElev << '\n';
//cout << "Takeoff position = " << tolon << ", " << tolat << ", " << aptElev << '\n';
rwy.hdg = hdg;
//cout << "In Init(), initialState = " << initialState << endl;
operatingState = initialState;
- Point3D orthopos;
+ SGVec3d orthopos;
switch(operatingState) {
case PARKED:
tuned_station = ground;
vel = 0.0;
slope = 0.0;
_pos = ourGate->pos;
- _pos.setelev(aptElev);
+ _pos.setElevationM(aptElev);
_hdg = ourGate->heading;
Transform();
freeTaxi = true;
// Set a position and orientation in an approximate place for hold short.
//cout << "rwy.width = " << rwy.width << '\n';
- orthopos = Point3D((rwy.width / 2.0 + 10.0) * -1.0, 0.0, 0.0);
+ orthopos = SGVec3d((rwy.width / 2.0 + 10.0) * -1.0, 0.0, 0.0);
// TODO - set the x pos to be +ve if a RH parallel rwy.
_pos = ortho.ConvertFromLocal(orthopos);
- _pos.setelev(aptElev);
+ _pos.setElevationM(aptElev);
_hdg = rwy.hdg + 90.0;
// TODO - reset the heading if RH rwy.
_pitch = 0.0;
touchAndGo = false;
if(initialLeg == DOWNWIND) {
- _pos = ortho.ConvertFromLocal(Point3D(1000*patternDirection, 800, 0.0));
- _pos.setelev(rwy.threshold_pos.elev() + 1000 * SG_FEET_TO_METER);
+ _pos = ortho.ConvertFromLocal(SGVec3d(1000*patternDirection, 800, 0.0));
+ _pos.setElevationM(rwy.threshold_pos.getElevationM() + 1000 * SG_FEET_TO_METER);
_hdg = rwy.hdg + 180.0;
leg = DOWNWIND;
elevInitGood = false;
Transform();
} else {
// Default to initial position on threshold for now
- _pos.setlat(rwy.threshold_pos.lat());
- _pos.setlon(rwy.threshold_pos.lon());
- _pos.setelev(rwy.threshold_pos.elev());
+ _pos = rwy.threshold_pos;
_hdg = rwy.hdg;
// Now we've set the position we can do the ground elev
// we shouldn't really need this since there's a LOD of 10K on the whole plane anyway I think.
// At the moment though I need to to avoid DList overflows - the whole plane LOD obviously isn't getting picked up.
if(!_invisible) {
- if(dclGetHorizontalSeparation(_pos, Point3D(fgGetDouble("/position/longitude-deg"), fgGetDouble("/position/latitude-deg"), 0.0)) > 8000) _aip.setVisible(false);
+ if(dclGetHorizontalSeparation(_pos, SGGeod::fromDegM(fgGetDouble("/position/longitude-deg"), fgGetDouble("/position/latitude-deg"), 0.0)) > 8000) _aip.setVisible(false);
else _aip.setVisible(true);
} else {
_aip.setVisible(false);
DoGroundElev();
if(!elevInitGood) {
if(_ground_elevation_m > -9990.0) {
- _pos.setelev(_ground_elevation_m + wheelOffset);
+ _pos.setElevationM(_ground_elevation_m + wheelOffset);
//cout << "TAKEOFF_ROLL, POS = " << pos.lon() << ", " << pos.lat() << ", " << pos.elev() << '\n';
//Transform();
_aip.setVisible(true);
if(!elevInitGood) {
//DoGroundElev();
if(_ground_elevation_m > -9990.0) {
- _pos.setelev(_ground_elevation_m + wheelOffset);
+ _pos.setElevationM(_ground_elevation_m + wheelOffset);
//Transform();
_aip.setVisible(true);
//Transform();
//cout << "C" << endl;
node* np = new node;
np->struct_type = NODE;
- np->pos = ortho.ConvertFromLocal(Point3D(0.0, 10.0, 0.0));
+ np->pos = ortho.ConvertFromLocal(SGVec3d(0.0, 10.0, 0.0));
path.push_back(np);
} else {
//cout << "D" << endl;
if(!elevInitGood) {
DoGroundElev();
if(_ground_elevation_m > -9990.0) {
- _pos.setelev(_ground_elevation_m + wheelOffset);
+ _pos.setElevationM(_ground_elevation_m + wheelOffset);
//Transform();
_aip.setVisible(true);
//Transform();
double turn_time = 60.0; // seconds - TODO - check this guess
double turn_circumference;
double turn_radius;
- Point3D orthopos = ortho.ConvertToLocal(_pos); // ortho position of the plane
- //cout << "runway elev = " << rwy.threshold_pos.elev() << ' ' << rwy.threshold_pos.elev() * SG_METER_TO_FEET << '\n';
+ SGVec3d orthopos = ortho.ConvertToLocal(_pos); // ortho position of the plane
+ //cout << "runway elev = " << rwy.threshold_pos.getElevationM() << ' ' << rwy.threshold_pos.getElevationM() * SG_METER_TO_FEET << '\n';
//cout << "elev = " << _pos.elev() << ' ' << _pos.elev() * SG_METER_TO_FEET << '\n';
// HACK FOR TESTING - REMOVE
vel += dveldt * dt;
}
if(_ground_elevation_m > -9990.0) {
- _pos.setelev(_ground_elevation_m + wheelOffset);
+ _pos.setElevationM(_ground_elevation_m + wheelOffset);
}
IAS = vel + (cos((_hdg - wind_from) * DCL_DEGREES_TO_RADIANS) * wind_speed);
if(IAS >= 70) {
// (decided in FGTower and accessed through GetCrosswindConstraint(...)).
// According to AIM, traffic should climb to within 300ft of pattern altitude before commencing crosswind turn.
// TODO - At hot 'n high airports this may be 500ft AGL though - need to make this a variable.
- if((_pos.elev() - rwy.threshold_pos.elev()) * SG_METER_TO_FEET > 700) {
+ if((_pos.getElevationM() - rwy.threshold_pos.getElevationM()) * SG_METER_TO_FEET > 700) {
double cc = 0.0;
if(tower->GetCrosswindConstraint(cc)) {
if(orthopos.y() > cc) {
}
// Need to check for levelling off in case we can't turn crosswind as soon
// as we would like due to other traffic.
- if((_pos.elev() - rwy.threshold_pos.elev()) * SG_METER_TO_FEET > 1000) {
+ if((_pos.getElevationM() - rwy.threshold_pos.getElevationM()) * SG_METER_TO_FEET > 1000) {
slope = 0.0;
_pitch = 0.0;
IAS = 80.0; // FIXME - use smooth transistion to new speed and attitude.
break;
case CROSSWIND:
goAround = false;
- if((_pos.elev() - rwy.threshold_pos.elev()) * SG_METER_TO_FEET > 1000) {
+ if((_pos.getElevationM() - rwy.threshold_pos.getElevationM()) * SG_METER_TO_FEET > 1000) {
slope = 0.0;
_pitch = 0.0;
IAS = 80.0; // FIXME - use smooth transistion to new speed
case TURN2:
SetTrack(rwy.hdg - (180 * patternDirection));
// just in case we didn't make height on crosswind
- if((_pos.elev() - rwy.threshold_pos.elev()) * SG_METER_TO_FEET > 1000) {
+ if((_pos.getElevationM() - rwy.threshold_pos.getElevationM()) * SG_METER_TO_FEET > 1000) {
slope = 0.0;
_pitch = 0.0;
IAS = 80.0; // FIXME - use smooth transistion to new speed
break;
case DOWNWIND:
// just in case we didn't make height on crosswind
- if(((_pos.elev() - rwy.threshold_pos.elev()) * SG_METER_TO_FEET > 995) && ((_pos.elev() - rwy.threshold_pos.elev()) * SG_METER_TO_FEET < 1015)) {
+ if(((_pos.getElevationM() - rwy.threshold_pos.getElevationM()) * SG_METER_TO_FEET > 995) && ((_pos.getElevationM() - rwy.threshold_pos.getElevationM()) * SG_METER_TO_FEET < 1015)) {
slope = 0.0;
_pitch = 0.0;
IAS = 90.0; // FIXME - use smooth transistion to new speed
}
- if((_pos.elev() - rwy.threshold_pos.elev()) * SG_METER_TO_FEET >= 1015) {
+ if((_pos.getElevationM() - rwy.threshold_pos.getElevationM()) * SG_METER_TO_FEET >= 1015) {
slope = -1.0;
_pitch = -1.0;
IAS = 90.0; // FIXME - use smooth transistion to new speed
if(descending) {
if(orthopos.y() < -50.0) {
double thesh_offset = 30.0;
- slope = atan((_pos.elev() - fgGetAirportElev(airportID)) / (orthopos.y() - thesh_offset)) * DCL_RADIANS_TO_DEGREES;
+ slope = atan((_pos.getElevationM() - fgGetAirportElev(airportID)) / (orthopos.y() - thesh_offset)) * DCL_RADIANS_TO_DEGREES;
//cout << "slope = " << slope << ", elev = " << _pos.elev() << ", apt_elev = " << fgGetAirportElev(airportID) << ", op.y = " << orthopos.y() << '\n';
if(slope < -10.0) slope = -10.0;
_savedSlope = slope;
_pitch = -4.0;
IAS = 70.0;
} else {
- if(_pos.elev() < (rwy.threshold_pos.elev()+10.0+wheelOffset)) {
+ if(_pos.getElevationM() < (rwy.threshold_pos.getElevationM()+10.0+wheelOffset)) {
if(_ground_elevation_m > -9990.0) {
- if(_pos.elev() < (_ground_elevation_m + wheelOffset + 1.0)) {
+ if(_pos.getElevationM() < (_ground_elevation_m + wheelOffset + 1.0)) {
slope = -2.0;
_pitch = 1.0;
IAS = 55.0;
- } else if(_pos.elev() < (_ground_elevation_m + wheelOffset + 5.0)) {
+ } else if(_pos.getElevationM() < (_ground_elevation_m + wheelOffset + 5.0)) {
slope = -4.0;
_pitch = -2.0;
IAS = 60.0;
// Try and track the extended centreline
SetTrack(rwy.hdg - (0.2 * orthopos.x()));
//cout << "orthopos.x() = " << orthopos.x() << " hdg = " << hdg << '\n';
- if(_pos.elev() < (rwy.threshold_pos.elev()+20.0+wheelOffset)) {
+ if(_pos.getElevationM() < (rwy.threshold_pos.getElevationM()+20.0+wheelOffset)) {
DoGroundElev(); // Need to call it here expicitly on final since it's only called
// for us in update(...) when the inAir flag is false.
}
- if(_pos.elev() < (rwy.threshold_pos.elev()+10.0+wheelOffset)) {
+ if(_pos.getElevationM() < (rwy.threshold_pos.getElevationM()+10.0+wheelOffset)) {
//slope = -1.0;
//_pitch = 1.0;
if(_ground_elevation_m > -9990.0) {
- if((_ground_elevation_m + wheelOffset) > _pos.elev()) {
+ if((_ground_elevation_m + wheelOffset) > _pos.getElevationM()) {
slope = 0.0;
_pitch = 0.0;
leg = LANDING_ROLL;
//inAir = false;
descending = false;
if(_ground_elevation_m > -9990.0) {
- _pos.setelev(_ground_elevation_m + wheelOffset);
+ _pos.setElevationM(_ground_elevation_m + wheelOffset);
}
track = rwy.hdg;
dveldt = -5.0;
}
}
-void FGAILocalTraffic::ExitRunway(const Point3D& orthopos) {
+void FGAILocalTraffic::ExitRunway(const SGVec3d& orthopos) {
//cout << "In ExitRunway" << endl;
//cout << "Runway ID is " << rwy.ID << endl;
node* rwyExit = *(exitNodes.begin());
//int gateID; //This might want to be more persistant at some point
while(nItr != exitNodes.end()) {
- d = ortho.ConvertToLocal((*nItr)->pos).y() - ortho.ConvertToLocal(_pos).y(); //FIXME - consider making orthopos a class variable
+ d = ortho.ConvertToLocal((*nItr)->pos).y() - ortho.ConvertToLocal(_pos).y(); //FIXME - consider making orthopos a class variable
if(d > 0.0) {
if(d < dist) {
dist = d;
// If we have reached turning point then get next point and turn onto that heading
// Look out for the finish!!
- //Point3D orthopos = ortho.ConvertToLocal(pos); // ortho position of the plane
- desiredTaxiHeading = GetHeadingFromTo(_pos, nextTaxiNode->pos);
+ desiredTaxiHeading = GetHeadingFromTo(_pos, nextTaxiNode->pos);
bool lastNode = (taxiPathPos == path.size() ? true : false);
if(lastNode) {
_pos = dclUpdatePosition(_pos, track, slope, dist);
//cout << "Updated position...\n";
if(_ground_elevation_m > -9990) {
- _pos.setelev(_ground_elevation_m + wheelOffset);
+ _pos.setElevationM(_ground_elevation_m + wheelOffset);
} // else don't change the elev until we get a valid ground elev again!
} else if(lastNode) {
if(taxiState == TD_LINING_UP) {
_pos = dclUpdatePosition(_pos, track, slope, dist);
//cout << "Updated position...\n";
if(_ground_elevation_m > -9990) {
- _pos.setelev(_ground_elevation_m + wheelOffset);
+ _pos.setElevationM(_ground_elevation_m + wheelOffset);
} // else don't change the elev until we get a valid ground elev again!
if(fabs(_hdg - rwy.hdg) <= 1.0) {
operatingState = IN_PATTERN;
// Only do the proper hitlist stuff if we are within visible range of the viewer.
double visibility_meters = fgGetDouble("/environment/visibility-m");
FGViewer* vw = globals->get_current_view();
- if(dclGetHorizontalSeparation(_pos, Point3D(vw->getLongitude_deg(), vw->getLatitude_deg(), 0.0)) > visibility_meters) {
+ if(dclGetHorizontalSeparation(_pos, SGGeod::fromDegM(vw->getLongitude_deg(), vw->getLatitude_deg(), 0.0)) > visibility_meters) {
_ground_elevation_m = aptElev;
return;
}
#ifndef _FG_AILocalTraffic_HXX
#define _FG_AILocalTraffic_HXX
-#include <simgear/math/point3d.hxx>
+#include <simgear/math/SGMath.hxx>
#include <Main/fg_props.hxx>
#include "AIPlane.hxx"
void CalculateSoD(double base_leg_pos, double downwind_leg_pos, bool pattern_direction);
- void ExitRunway(const Point3D& orthopos);
+ void ExitRunway(const SGVec3d& orthopos);
void StartTaxi();
using namespace simgear;
// extern from Airports/simple.cxx
-extern Point3D fgGetAirportPos( const std::string& id );
+extern SGGeod fgGetAirportPos( const std::string& id );
FGAIMgr::FGAIMgr() {
ATC = globals->get_ATC_mgr();
SearchByPos(15.0);
initDone = true;
-
- //cout << "AIMgr::init done..." << endl;
-
- /*
- // TESTING
- FGATCAlignedProjection ortho;
- ortho.Init(fgGetAirportPos("KEMT"), 205.0); // Guess of rwy19 heading
- //Point3D ip = ortho.ConvertFromLocal(Point3D(6000, 1000, 1000)); // 90 deg entry
- //Point3D ip = ortho.ConvertFromLocal(Point3D(-7000, 3000, 1000)); // 45 deg entry
- Point3D ip = ortho.ConvertFromLocal(Point3D(1000, -7000, 1000)); // straight-in
- ATC->AIRegisterAirport("KEMT");
- FGAIGAVFRTraffic* p = new FGAIGAVFRTraffic();
- p->SetModel(_defaultModel);
- p->Init(ip, "KEMT", GenerateShortForm(GenerateUniqueCallsign()));
- ai_list.push_back(p);
- traffic[ident].push_back(p);
- activated["KEMT"] = 1;
- */
}
void FGAIMgr::bind() {
//cout << activated.size() << '\n';
- Point3D userPos = Point3D(lon_node->getDoubleValue(), lat_node->getDoubleValue(), elev_node->getDoubleValue());
+ SGGeod userPos = SGGeod::fromDegM(lon_node->getDoubleValue(), lat_node->getDoubleValue(), elev_node->getDoubleValue());
// TODO - make these class variables!!
static int i = 0;
//cout << "Size of list is " << (*it).second.size() << " at " << s << '\n';
if((*it).second.size()) {
FGAIEntity* e = *((*it).second.rbegin()); // Get the last airplane currently scheduled to arrive at this airport.
- cd = dclGetHorizontalSeparation(e->GetPos(), fgGetAirportPos(s));
+ cd = dclGetHorizontalSeparation(e->getPos(), fgGetAirportPos(s));
if(cd < (d < 5000 ? 10000 : d + 5000)) {
gen = true;
}
}
*/
- Point3D aptpos = fgGetAirportPos(ident); // TODO - check for elev of -9999
- //cout << "ident = " << ident << ", elev = " << aptpos.elev() << '\n';
+ SGGeod aptpos = fgGetAirportPos(ident); // TODO - check for elev of -9999
+ //cout << "ident = " << ident << ", elev = " << aptpos.getElevationM() << '\n';
// Operate from airports at 3000ft and below only to avoid the default cloud layers and since we don't degrade AI performance with altitude.
- if(aptpos.elev() > 3000) {
+ if(aptpos.getElevationM() > 3000) {
//cout << "High alt airports not yet supported - returning\n";
return;
}
// Get the time and only operate VFR in the (approximate) daytime.
struct tm *t = globals->get_time_params()->getGmt();
- int loc_time = t->tm_hour + int(aptpos.lon() / (360.0 / 24.0));
+ int loc_time = t->tm_hour + int(aptpos.getLongitudeDeg() / (360.0 / 24.0));
while (loc_time < 0)
loc_time += 24;
while (loc_time >= 24)
double visibility;
FGEnvironment stationweather =
((FGEnvironmentMgr *)globals->get_subsystem("environment"))
- ->getEnvironment(aptpos.lat(), aptpos.lon(), aptpos.elev()); // TODO - check whether this should take ft or m for elev.
+ ->getEnvironment(aptpos.getLatitudeDeg(), aptpos.getLongitudeDeg(), aptpos.getElevationM()); // TODO - check whether this should take ft or m for elev.
visibility = stationweather.get_visibility_m();
// Technically we can do VFR down to 1 mile (1600m) but that's pretty murky!
//cout << "vis = " << visibility << '\n';
ATC->AIRegisterAirport(ident);
// Next - get the distance from user to the airport.
- Point3D userpos = Point3D(lon_node->getDoubleValue(), lat_node->getDoubleValue(), elev_node->getDoubleValue());
+ SGGeod userpos = SGGeod::fromDegM(lon_node->getDoubleValue(), lat_node->getDoubleValue(), elev_node->getDoubleValue());
double d = dclGetHorizontalSeparation(userpos, aptpos); // in meters
int lev = fgGetInt("/sim/ai-traffic/level");
FGAIGAVFRTraffic* t = new FGAIGAVFRTraffic();
t->SetModel(cessna ? _defaultModel : _piperModel);
//cout << "Generating VFR traffic " << s << " inbound to " << ident << " " << ad << " meters out from " << dir << " degrees\n";
- Point3D tpos = dclUpdatePosition(aptpos, dir, 6.0, ad);
- if(tpos.elev() > (aptpos.elev() + 3000.0)) tpos.setelev(aptpos.elev() + 3000.0);
+ SGGeod tpos = dclUpdatePosition(aptpos, dir, 6.0, ad);
+ if(tpos.getElevationM() > (aptpos.getElevationM() + 3000.0)) tpos.setElevationM(aptpos.getElevationM() + 3000.0);
t->Init(tpos, ident, s);
ai_list.push_back(t);
}
FGAIGAVFRTraffic* t = new FGAIGAVFRTraffic();
t->SetModel(cessna ? _defaultModel.get() : (_havePiperModel ? _piperModel.get() : _defaultModel.get()));
//cout << "Generating VFR traffic " << s << " inbound to " << ident << " " << ad << " meters out from " << dir << " degrees\n";
- Point3D tpos = dclUpdatePosition(aptpos, dir, 6.0, ad);
- if(tpos.elev() > (aptpos.elev() + 3000.0)) tpos.setelev(aptpos.elev() + 3000.0); // FEET yuk :-(
+ SGGeod tpos = dclUpdatePosition(aptpos, dir, 6.0, ad);
+ if(tpos.getElevationM() > (aptpos.getElevationM() + 3000.0)) tpos.setElevationM(aptpos.getElevationM() + 3000.0); // FEET yuk :-(
t->Init(tpos, ident, s);
ai_list.push_back(t);
traffic[ident].push_back(t);
//double rlon = lon * SGD_DEGREES_TO_RADIANS;
//double rlat = lat * SGD_DEGREES_TO_RADIANS;
- //Point3D aircraft = sgGeodToCart( Point3D(rlon, rlat, elev) );
- //Point3D airport;
for(; current != last; ++current) {
//cout << "Found " << *current << endl;;
if(activated.find(*current) == activated.end()) {
for(twd_itr = towered.begin(); twd_itr != towered.end(); twd_itr++) {
// Only activate the closest airport not already activated each time.
if(activated.find(twd_itr->ident) == activated.end()) {
- double sep = dclGetHorizontalSeparation(Point3D(lon, lat, elev), fgGetAirportPos(twd_itr->ident));
+ double sep = dclGetHorizontalSeparation(SGGeod::fromDegM(lon, lat, elev), fgGetAirportPos(twd_itr->ident));
if(sep < closest) {
closest = sep;
s = twd_itr->ident;
// perhaps we could use an FGRunway instead of this.
// That wouldn't cache the orthopos though.
struct RunwayDetails {
- Point3D threshold_pos;
- Point3D end1ortho; // ortho projection end1 (the threshold ATM)
- Point3D end2ortho; // ortho projection end2 (the take off end in the current hardwired scheme)
+ SGGeod threshold_pos;
+ SGVec3d end1ortho; // ortho projection end1 (the threshold ATM)
+ SGVec3d end2ortho; // ortho projection end2 (the take off end in the current hardwired scheme)
double hdg; // true runway heading
double length; // In *METERS*
double width; // ditto
// cout << a.ident << endl;
// generate cartesian coordinates
- Point3D geod( a.lon * SGD_DEGREES_TO_RADIANS, a.lat * SGD_DEGREES_TO_RADIANS, a.elev );
- Point3D cart = sgGeodToCart( geod );
+ SGVec3d cart = SGVec3d::fromGeod(SGGeod::fromRadM(a.lon, a.lat, a.elev));
a.x = cart.x();
a.y = cart.y();
a.z = cart.z();
double lon = fgGetDouble("/position/longitude-deg");
double lat = fgGetDouble("/position/latitude-deg");
double elev = fgGetDouble("/position/altitude-ft");
- Point3D aircraft = sgGeodToCart(Point3D(lon * SGD_DEGREES_TO_RADIANS,
- lat * SGD_DEGREES_TO_RADIANS, elev));
+ SGVec3d aircraft = SGVec3d::fromGeod(SGGeod::fromDegM(lon, lat, elev));
// search stations in range
int num_stat = current_commlist->FindByPos(lon, lat, elev, 50.0, &atc_stations);
// fill map (sorts by distance and removes duplicates)
comm_list_iterator itr = atc_stations.begin();
for (; itr != atc_stations.end(); ++itr) {
- Point3D station = Point3D(itr->x, itr->y, itr->z);
- double distance = aircraft.distance3Dsquared(station);
+ SGVec3d station(itr->x, itr->y, itr->z);
+ double distance = distSqr(aircraft, station);
uniq[atcdata(itr->ident, itr->name, distance)] = true;
}
// create button per map entry (modified copy of <button-template>)
#include <simgear/constants.h>
FGATCAlignedProjection::FGATCAlignedProjection() {
- _origin.setlat(0.0);
- _origin.setlon(0.0);
- _origin.setelev(0.0);
- _correction_factor = cos(_origin.lat() * SG_DEGREES_TO_RADIANS);
+ _origin.setLatitudeRad(0);
+ _origin.setLongitudeRad(0);
+ _origin.setElevationM(0);
+ _correction_factor = cos(_origin.getLatitudeRad());
}
-FGATCAlignedProjection::FGATCAlignedProjection(const Point3D& centre, double heading) {
+FGATCAlignedProjection::FGATCAlignedProjection(const SGGeod& centre, double heading) {
_origin = centre;
_theta = heading * SG_DEGREES_TO_RADIANS;
- _correction_factor = cos(_origin.lat() * SG_DEGREES_TO_RADIANS);
+ _correction_factor = cos(_origin.getLatitudeRad());
}
FGATCAlignedProjection::~FGATCAlignedProjection() {
}
-void FGATCAlignedProjection::Init(const Point3D& centre, double heading) {
+void FGATCAlignedProjection::Init(const SGGeod& centre, double heading) {
_origin = centre;
_theta = heading * SG_DEGREES_TO_RADIANS;
- _correction_factor = cos(_origin.lat() * SG_DEGREES_TO_RADIANS);
+ _correction_factor = cos(_origin.getLatitudeRad());
}
-Point3D FGATCAlignedProjection::ConvertToLocal(const Point3D& pt) {
+SGVec3d FGATCAlignedProjection::ConvertToLocal(const SGGeod& pt) {
// convert from lat/lon to orthogonal
- double delta_lat = pt.lat() - _origin.lat();
- double delta_lon = pt.lon() - _origin.lon();
- double y = sin(delta_lat * SG_DEGREES_TO_RADIANS) * SG_EQUATORIAL_RADIUS_M;
- double x = sin(delta_lon * SG_DEGREES_TO_RADIANS) * SG_EQUATORIAL_RADIUS_M * _correction_factor;
+ double delta_lat = pt.getLatitudeRad() - _origin.getLatitudeRad();
+ double delta_lon = pt.getLongitudeRad() - _origin.getLongitudeRad();
+ double y = sin(delta_lat) * SG_EQUATORIAL_RADIUS_M;
+ double x = sin(delta_lon) * SG_EQUATORIAL_RADIUS_M * _correction_factor;
// Align
if(_theta != 0.0) {
y = (xbar*sin(_theta)) + (y*cos(_theta));
}
- return(Point3D(x,y,pt.elev()));
+ return SGVec3d(x, y, pt.getElevationM());
}
-Point3D FGATCAlignedProjection::ConvertFromLocal(const Point3D& pt) {
+SGGeod FGATCAlignedProjection::ConvertFromLocal(const SGVec3d& pt) {
// de-align
double thi = _theta * -1.0;
double x = pt.x()*cos(thi) - pt.y()*sin(thi);
double y = (pt.x()*sin(thi)) + (pt.y()*cos(thi));
// convert from orthogonal to lat/lon
- double delta_lat = asin(y / SG_EQUATORIAL_RADIUS_M) * SG_RADIANS_TO_DEGREES;
- double delta_lon = (asin(x / SG_EQUATORIAL_RADIUS_M) * SG_RADIANS_TO_DEGREES) / _correction_factor;
+ double delta_lat = asin(y / SG_EQUATORIAL_RADIUS_M);
+ double delta_lon = asin(x / SG_EQUATORIAL_RADIUS_M) / _correction_factor;
- return(Point3D(_origin.lon()+delta_lon, _origin.lat()+delta_lat, pt.elev()));
+ return SGGeod::fromRadM(_origin.getLongitudeRad()+delta_lon, _origin.getLatitudeRad()+delta_lat, pt.z());
}
#ifndef _FG_ATC_PROJECTION_HXX
#define _FG_ATC_PROJECTION_HXX
-#include <simgear/math/point3d.hxx>
+#include <simgear/math/SGMath.hxx>
// FGATCAlignedProjection - a class to project an area local to a runway onto an orthogonal co-ordinate system
// with the origin at the threshold and the runway aligned with the y axis.
public:
FGATCAlignedProjection();
- FGATCAlignedProjection(const Point3D& centre, double heading);
+ FGATCAlignedProjection(const SGGeod& centre, double heading);
~FGATCAlignedProjection();
- void Init(const Point3D& centre, double heading);
+ void Init(const SGGeod& centre, double heading);
// Convert a lat/lon co-ordinate (degrees) to the local projection (meters)
- Point3D ConvertToLocal(const Point3D& pt);
+ SGVec3d ConvertToLocal(const SGGeod& pt);
// Convert a local projection co-ordinate (meters) to lat/lon (degrees)
- Point3D ConvertFromLocal(const Point3D& pt);
+ SGGeod ConvertFromLocal(const SGVec3d& pt);
private:
- Point3D _origin; // lat/lon of local area origin (the threshold)
+ SGGeod _origin; // lat/lon of local area origin (the threshold)
double _theta; // the rotation angle for alignment in radians
double _correction_factor; // Reduction in surface distance per degree of longitude due to latitude. Saves having to do a cos() every call.
#include <sstream>
-#include <math.h>
-#include <simgear/math/point3d.hxx>
+#include <simgear/math/SGMath.hxx>
#include <simgear/constants.h>
#include <simgear/misc/sg_path.hxx>
#include <simgear/debug/logstream.hxx>
-#include <plib/sg.h>
-//#include <iomanip.h>
#include <Airports/runways.hxx>
#include <Main/globals.hxx>
//================================================================================================================
// Given two positions (lat & lon in degrees), get the HORIZONTAL separation (in meters)
-double dclGetHorizontalSeparation(const Point3D& pos1, const Point3D& pos2) {
+double dclGetHorizontalSeparation(const SGGeod& pos1, const SGGeod& pos2) {
double x; //East-West separation
double y; //North-South separation
double z; //Horizontal separation - z = sqrt(x^2 + y^2)
- double lat1 = pos1.lat() * SG_DEGREES_TO_RADIANS;
- double lon1 = pos1.lon() * SG_DEGREES_TO_RADIANS;
- double lat2 = pos2.lat() * SG_DEGREES_TO_RADIANS;
- double lon2 = pos2.lon() * SG_DEGREES_TO_RADIANS;
+ double lat1 = pos1.getLatitudeRad();
+ double lon1 = pos1.getLongitudeRad();
+ double lat2 = pos2.getLatitudeRad();
+ double lon2 = pos2.getLongitudeRad();
y = sin(fabs(lat1 - lat2)) * SG_EQUATORIAL_RADIUS_M;
x = sin(fabs(lon1 - lon2)) * SG_EQUATORIAL_RADIUS_M * (cos((lat1 + lat2) / 2.0));
// Given a position (lat/lon/elev), heading and vertical angle (degrees), and distance (meters), calculate the new position.
// This function assumes the world is spherical. If geodetic accuracy is required use the functions is sg_geodesy instead!
// Assumes that the ground is not hit!!! Expects heading and angle in degrees, distance in meters.
-Point3D dclUpdatePosition(const Point3D& pos, double heading, double angle, double distance) {
+SGGeod dclUpdatePosition(const SGGeod& pos, double heading, double angle, double distance) {
+ // FIXME: use SGGeodesy instead ...
+
//cout << setprecision(10) << pos.lon() << ' ' << pos.lat() << '\n';
heading *= DCL_DEGREES_TO_RADIANS;
angle *= DCL_DEGREES_TO_RADIANS;
- double lat = pos.lat() * DCL_DEGREES_TO_RADIANS;
- double lon = pos.lon() * DCL_DEGREES_TO_RADIANS;
- double elev = pos.elev();
+ double lat = pos.getLatitudeRad();
+ double lon = pos.getLongitudeRad();
+ double elev = pos.getElevationM();
//cout << setprecision(10) << lon*DCL_RADIANS_TO_DEGREES << ' ' << lat*DCL_RADIANS_TO_DEGREES << '\n';
double horiz_dist = distance * cos(angle);
//cout << setprecision(15) << DCL_DEGREES_TO_RADIANS * DCL_RADIANS_TO_DEGREES << '\n';
- return(Point3D(lon*DCL_RADIANS_TO_DEGREES, lat*DCL_RADIANS_TO_DEGREES, elev));
+ return SGGeod::fromRadM(lon, lat, elev);
}
// Get a heading in degrees from one lat/lon to another.
// This function assumes the world is spherical. If geodetic accuracy is required use the functions is sg_geodesy instead!
// Warning - at the moment we are not checking for identical points - currently it returns 0 in this instance.
-double GetHeadingFromTo(const Point3D& A, const Point3D& B) {
- double latA = A.lat() * DCL_DEGREES_TO_RADIANS;
- double lonA = A.lon() * DCL_DEGREES_TO_RADIANS;
- double latB = B.lat() * DCL_DEGREES_TO_RADIANS;
- double lonB = B.lon() * DCL_DEGREES_TO_RADIANS;
+double GetHeadingFromTo(const SGGeod& A, const SGGeod& B) {
+ double latA = A.getLatitudeRad();
+ double lonA = A.getLongitudeRad();
+ double latB = B.getLatitudeRad();
+ double lonB = B.getLongitudeRad();
double xdist = sin(lonB - lonA) * (double)SG_EQUATORIAL_RADIUS_M * cos((latA+latB)/2.0);
double ydist = sin(latB - latA) * (double)SG_EQUATORIAL_RADIUS_M;
double heading = atan2(xdist, ydist) * DCL_RADIANS_TO_DEGREES;
}
// Runway stuff
-// Given a Point3D (lon/lat/elev) and an FGRunway struct, determine if the point lies on the runway
-bool OnRunway(const Point3D& pt, const FGRunwayBase* rwy) {
+// Given (lon/lat/elev) and an FGRunway struct, determine if the point lies on the runway
+bool OnRunway(const SGGeod& pt, const FGRunwayBase* rwy) {
FGATCAlignedProjection ortho;
- Point3D centre(rwy->longitude(), rwy->latitude(), 0.0); // We don't need the elev
+ SGGeod centre = SGGeod::fromDegM(rwy->longitude(), rwy->latitude(), 0); // We don't need the elev
ortho.Init(centre, rwy->headingDeg());
- Point3D xyc = ortho.ConvertToLocal(centre);
- Point3D xyp = ortho.ConvertToLocal(pt);
+ SGVec3d xyc = ortho.ConvertToLocal(centre);
+ SGVec3d xyp = ortho.ConvertToLocal(pt);
//cout << "Length offset = " << fabs(xyp.y() - xyc.y()) << '\n';
//cout << "Width offset = " << fabs(xyp.x() - xyc.x()) << '\n';
#include <Airports/simple.hxx>
#include <Airports/runways.hxx>
+#include <simgear/math/SGMath.hxx>
#include <math.h>
-#include <simgear/math/point3d.hxx>
#include <string>
using std::string;
********************************/
// Given two positions (lat & lon in degrees), get the HORIZONTAL separation (in meters)
-double dclGetHorizontalSeparation(const Point3D& pos1, const Point3D& pos2);
+double dclGetHorizontalSeparation(const SGGeod& pos1, const SGGeod& pos2);
// Given a point and a line, get the HORIZONTAL shortest distance from the point to a point on the line.
// Expects to be fed orthogonal co-ordinates, NOT lat & lon !
// Given a position (lat/lon/elev), heading, vertical angle, and distance, calculate the new position.
// Assumes that the ground is not hit!!! Expects heading and angle in degrees, distance in meters.
-Point3D dclUpdatePosition(const Point3D& pos, double heading, double angle, double distance);
+SGGeod dclUpdatePosition(const SGGeod& pos, double heading, double angle, double distance);
// Get a heading from one lat/lon to another (in degrees)
-double GetHeadingFromTo(const Point3D& A, const Point3D& B);
+double GetHeadingFromTo(const SGGeod& A, const SGGeod& B);
// Given a heading (in degrees), bound it from 0 -> 360
void dclBoundHeading(double &hdg);
*
****************/
-// Given a Point3D (lon/lat/elev) and an FGRunway struct, determine if the point lies on the runway
-bool OnRunway(const Point3D& pt, const FGRunwayBase* rwy);
+// Given (lon/lat/elev) and an FGRunway struct, determine if the point lies on the runway
+bool OnRunway(const SGGeod& pt, const FGRunwayBase* rwy);
#include <Airports/simple.hxx>
#include <simgear/constants.h>
-#include <simgear/math/polar3d.hxx>
#include <simgear/misc/sg_path.hxx>
#include <Environment/environment_mgr.hxx>
int wpn = planes[i].wpn;
// waypoint 0: Threshold of active runway
- calc_gc_course_dist(Point3D(lon*SGD_DEGREES_TO_RADIANS, lat*SGD_DEGREES_TO_RADIANS, 0.0),
- Point3D(active_rw_lon*SGD_DEGREES_TO_RADIANS,active_rw_lat*SGD_DEGREES_TO_RADIANS, 0.0 ),
- &course, &d);
+ course = SGGeoc::courseRad(SGGeoc::fromDegM(lon, lat, 6e6), SGGeoc::fromDegM(active_rw_lon, active_rw_lat, 6e6));
+ d = SGGeoc::distanceM(SGGeoc::fromDegM(lon, lat, 6e6), SGGeoc::fromDegM(active_rw_lon, active_rw_lat, 6e6));
double d1 = active_rw_hdg+180.0;
if ( d1 > 360.0 ) d1 -=360.0;
calc_cd_head_dist(360.0-course*SGD_RADIANS_TO_DEGREES, d/SG_NM_TO_METER,
planes[i].hdg = hdg_node->getDoubleValue();
planes[i].spd = speed_node->getDoubleValue();
- /*Point3D aircraft = sgGeodToCart( Point3D(planes[i].lon*SGD_DEGREES_TO_RADIANS,
- planes[i].lat*SGD_DEGREES_TO_RADIANS,
- planes[i].alt*SG_FEET_TO_METER) );*/
double course, distance;
- calc_gc_course_dist(Point3D(lon*SGD_DEGREES_TO_RADIANS, lat*SGD_DEGREES_TO_RADIANS, 0.0),
- Point3D(planes[i].lon*SGD_DEGREES_TO_RADIANS,planes[i].lat*SGD_DEGREES_TO_RADIANS, 0.0 ),
- &course, &distance);
+ course = SGGeoc::courseRad(SGGeoc::fromDegM(lon, lat, 6e6), SGGeoc::fromDegM(planes[i].lon, active_rw_lat, 6e6));
+ distance = SGGeoc::distanceM(SGGeoc::fromDegM(lon, lat, 6e6), SGGeoc::fromDegM(planes[i].lon, active_rw_lat, 6e6));
planes[i].dist = distance/SG_NM_TO_METER;
planes[i].brg = 360.0-course*SGD_RADIANS_TO_DEGREES;
#include <Airports/simple.hxx>
#include "commlist.hxx"
-//#include "atislist.hxx"
#include "ATCutils.hxx"
bool FGCommList::FindByFreq( double lon, double lat, double elev, double freq,
ATCData* ad, atc_type tp )
{
- lon *= SGD_DEGREES_TO_RADIANS;
- lat *= SGD_DEGREES_TO_RADIANS;
-
// HACK - if freq > 1000 assume it's in KHz, otherwise assume MHz.
// A bit ugly but it works for now!!!!
comm_list_type stations;
comm_list_iterator last = stations.end();
// double az1, az2, s;
- Point3D aircraft = sgGeodToCart( Point3D(lon, lat, elev) );
- Point3D station;
+ SGVec3d aircraft = SGVec3d::fromGeod(SGGeod::fromDegM(lon, lat, elev));
const double orig_max_d = 1e100;
double max_d = orig_max_d;
- double d;
// TODO - at the moment this loop returns the first match found in range
// We want to return the closest match in the event of a frequency conflict
for ( ; current != last ; ++current ) {
//cout << "testing " << current->get_ident() << endl;
- station = Point3D(current->x, current->y, current->z);
+ SGVec3d station(current->x, current->y, current->z);
//cout << "aircraft = " << aircraft << endl;
//cout << "station = " << station << endl;
- d = aircraft.distance3Dsquared( station );
+ double d = distSqr(aircraft, station);
//cout << " dist = " << sqrt(d)
// << " range = " << current->range * SG_NM_TO_METER << endl;
comm_list_iterator current = Fstations.begin();
comm_list_iterator last = Fstations.end();
- double rlon = lon * SGD_DEGREES_TO_RADIANS;
- double rlat = lat * SGD_DEGREES_TO_RADIANS;
-
// double az1, az2, s;
- Point3D aircraft = sgGeodToCart( Point3D(rlon, rlat, elev) );
- Point3D station;
- double d;
+ SGVec3d aircraft = SGVec3d::fromGeod(SGGeod::fromDegM(lon, lat, elev));
for(; current != last; ++current) {
if((current->type == tp) || (tp == INVALID)) {
- station = Point3D(current->x, current->y, current->z);
- d = aircraft.distance3Dsquared( station );
+ SGVec3d station(current->x, current->y, current->z);
+ double d = distSqr(aircraft, station);
// NOTE The below is squared since we match to distance3Dsquared (above) to avoid a sqrt.
if ( d < (current->range * SG_NM_TO_METER
* current->range * SG_NM_TO_METER ) ) {
double tmp;
for(itr = stations.begin(); itr != stations.end(); ++itr) {
ATCData ad2 = *itr;
- //Point3D p1(*itr.lon, *itr.lat, *itr.elev);
- Point3D p1(ad2.lon, ad2.lat, ad2.elev);
+ SGGeod p1 = SGGeod::fromDegM(ad2.lon, ad2.lat, ad2.elev);
const FGAirport *a = fgFindAirportID(ad2.ident);
if (a) {
- Point3D p2(lon, lat, elev);
+ SGGeod p2 = SGGeod::fromDegM(lon, lat, elev);
tmp = dclGetHorizontalSeparation(p1, p2);
if(tmp <= closest) {
closest = tmp;
fin >> buf;
np->nodeID = atoi(buf);
fin >> buf;
- np->pos.setlon(atof(buf));
+ np->pos.setLongitudeDeg(atof(buf));
fin >> buf;
- np->pos.setlat(atof(buf));
+ np->pos.setLatitudeDeg(atof(buf));
fin >> buf;
- np->pos.setelev(atof(buf));
+ np->pos.setElevationM(atof(buf));
fin >> buf; // node type
if(!strcmp(buf, "J")) {
np->type = JUNCTION;
fin >> buf;
gp->nodeID = atoi(buf);
fin >> buf;
- gp->pos.setlon(atof(buf));
+ gp->pos.setLongitudeDeg(atof(buf));
fin >> buf;
- gp->pos.setlat(atof(buf));
+ gp->pos.setLatitudeDeg(atof(buf));
fin >> buf;
- gp->pos.setelev(atof(buf));
+ gp->pos.setElevationM(atof(buf));
fin >> buf; // gate type - ignore this for now
fin >> buf; // gate heading
gp->heading = atoi(buf);
}
// move to the +l end/center of the runway
//cout << "Runway center is at " << runway._lon << ", " << runway._lat << '\n';
- Point3D origin = Point3D(runway->longitude(), runway->latitude(), aptElev);
- Point3D ref = origin;
- double tshlon, tshlat, tshr;
+ double tshlon, tshlat, tshr;
double tolon, tolat, tor;
rwy.length = runway->lengthM();
- geo_direct_wgs_84 ( aptElev, ref.lat(), ref.lon(), other_way,
- rwy.length / 2.0 - 25.0, &tshlat, &tshlon, &tshr );
- geo_direct_wgs_84 ( aptElev, ref.lat(), ref.lon(), runway->headingDeg(),
- rwy.length / 2.0 - 25.0, &tolat, &tolon, &tor );
+ geo_direct_wgs_84 ( aptElev, runway->latitude(), runway->longitude(), other_way,
+ rwy.length / 2.0 - 25.0, &tshlat, &tshlon, &tshr );
+ geo_direct_wgs_84 ( aptElev, runway->latitude(), runway->longitude(), runway->headingDeg(),
+ rwy.length / 2.0 - 25.0, &tolat, &tolon, &tor );
// Note - 25 meters in from the runway end is a bit of a hack to put the plane ahead of the user.
// now copy what we need out of runway into rwy
- rwy.threshold_pos = Point3D(tshlon, tshlat, aptElev);
- Point3D takeoff_end = Point3D(tolon, tolat, aptElev);
+ rwy.threshold_pos = SGGeod::fromDegM(tshlon, tshlat, aptElev);
+ SGGeod takeoff_end = SGGeod::fromDegM(tolon, tolat, aptElev);
//cout << "Threshold position = " << tshlon << ", " << tshlat << ", " << aptElev << '\n';
//cout << "Takeoff position = " << tolon << ", " << tolat << ", " << aptElev << '\n';
rwy.hdg = runway->headingDeg();
g->cleared = false;
g->incoming = false;
// TODO - need to handle the next 3 as well
- //Point3D current_pos;
//node* destination;
//node* last_clearance;
#include <vector>
#include <list>
-#include <simgear/math/point3d.hxx>
+#include <simgear/math/SGMath.hxx>
#include <simgear/misc/sgstream.hxx>
-#include <simgear/math/sg_geodesy.hxx>
#include <simgear/props/props.hxx>
#include "ATC.hxx"
~node();
unsigned int nodeID; //each node in an airport needs a unique ID number - this is ZERO-BASED to match array position
- Point3D pos;
- Point3D orthoPos;
+ SGGeod pos;
+ SGVec3d orthoPos;
std::string name;
node_type type;
arc_array_type arcs;
// A more specialist plane rec to include ground information
struct GroundRec {
- FGAIEntity* planePtr; // This might move to the planeRec eventually
+ FGAIEntity* planePtr; // This might move to the planeRec eventually
PlaneRec plane;
- Point3D current_pos;
node* destination;
node* last_clearance;
- bool taxiRequestOutstanding; // Plane has requested taxi and we haven't responded yet
- double clearanceCounter; // Hack for communication timing - counter since clearance requested in seconds
+ bool taxiRequestOutstanding; // Plane has requested taxi and we haven't responded yet
+ double clearanceCounter; // Hack for communication timing - counter since clearance requested in seconds
bool cleared; // set true when the plane has been cleared to somewhere
bool incoming; //true for arrivals, false for departures
typedef ground_rec_list::iterator ground_rec_list_itr;
typedef ground_rec_list::const_iterator ground_rec_list_const_itr;
-//////////////////////////////////////////////////////////////////////////////////////////
-
-// Hack
-// perhaps we could use an FGRunway instead of this
-struct GRunwayDetails {
- Point3D threshold_pos;
- Point3D end1ortho; // ortho projection end1 (the threshold ATM)
- Point3D end2ortho; // ortho projection end2 (the take off end in the current hardwired scheme)
- double hdg; // true runway heading
- double length; // In *METERS*
- std::string rwyID;
-};
-
///////////////////////////////////////////////////////////////////////////////
//
// FGGround
plane = p;
}
-TowerPlaneRec::TowerPlaneRec(const Point3D& pt) :
+TowerPlaneRec::TowerPlaneRec(const SGGeod& pt) :
planePtr(NULL),
clearedToLand(false),
clearedToLineUp(false),
isUser(false)
{
plane.callsign = "UNKNOWN";
- pos = pt;
+ pos = pt;
}
-TowerPlaneRec::TowerPlaneRec(const PlaneRec& p, const Point3D& pt) :
+TowerPlaneRec::TowerPlaneRec(const PlaneRec& p, const SGGeod& pt) :
planePtr(NULL),
clearedToLand(false),
clearedToLineUp(false),
isUser(false)
{
plane = p;
- pos = pt;
+ pos = pt;
}
DoRwyDetails();
// TODO - this currently assumes only one active runway.
- rwyOccupied = OnActiveRunway(Point3D(user_lon_node->getDoubleValue(), user_lat_node->getDoubleValue(), 0.0));
+ rwyOccupied = OnActiveRunway(SGGeod::fromDegM(user_lon_node->getDoubleValue(), user_lat_node->getDoubleValue(), 0.0));
- if(!OnAnyRunway(Point3D(user_lon_node->getDoubleValue(), user_lat_node->getDoubleValue(), 0.0), false)) {
+ if(!OnAnyRunway(SGGeod::fromDegM(user_lon_node->getDoubleValue(), user_lat_node->getDoubleValue(), 0.0), false)) {
//cout << ident << " ADD 0\n";
current_atcdialog->add_entry(ident, "@AP Tower, @CS @MI miles @CD of the airport for full stop@AT",
"Contact tower for VFR arrival (full stop)", TOWER,
// Call the base class update for the response time handling.
FGATC::Update(dt);
-
- /*
- if(ident == "KEMT") {
- // For AI debugging convienience - may be removed
- Point3D user_pos;
- user_pos.setlon(user_lon_node->getDoubleValue());
- user_pos.setlat(user_lat_node->getDoubleValue());
- user_pos.setelev(user_elev_node->getDoubleValue());
- Point3D user_ortho_pos = ortho.ConvertToLocal(user_pos);
- fgSetDouble("/AI/user/ortho-x", user_ortho_pos.x());
- fgSetDouble("/AI/user/ortho-y", user_ortho_pos.y());
- fgSetDouble("/AI/user/elev", user_elev_node->getDoubleValue());
- }
- */
-
- //cout << "Done T" << endl;
}
void FGTower::ReceiveUserCallback(int code) {
// Should we clear staight in or for downwind entry?
// For now we'll clear straight in if greater than 1km from a line drawn through the threshold perpendicular to the rwy.
// Later on we might check the actual heading and direct some of those to enter on downwind or base.
- Point3D op = ortho.ConvertToLocal(t->pos);
+ SGVec3d op = ortho.ConvertToLocal(t->pos);
float gp = fgGetFloat("/gear/gear/position-norm");
if(gp < 1)
t->gearWasUp = true; // This will be needed on final to tell "Gear down, ready to land."
trns += " Cleared for take-off" + wtr;
t->clearedToTakeOff = true;
} else {
- if(!OnAnyRunway(Point3D(user_lon_node->getDoubleValue(), user_lat_node->getDoubleValue(), 0.0), true)) {
+ if(!OnAnyRunway(SGGeod::fromDegM(user_lon_node->getDoubleValue(), user_lat_node->getDoubleValue(), 0.0), true)) {
// TODO: Check if any AI Planes on final and tell something like: "After the landing CALLSIGN line up runway two eight right"
trns += " Line up runway " + ConvertRwyNumToSpokenString(activeRwy);
t->clearedToTakeOff = false;
TowerPlaneRec* t = *circuitListItr;
//cout << ident << ' ' << circuitList.size() << ' ' << t->plane.callsign << " " << t->leg << " eta " << t->eta << '\n';
if(t->isUser) {
- t->pos.setlon(user_lon_node->getDoubleValue());
- t->pos.setlat(user_lat_node->getDoubleValue());
- t->pos.setelev(user_elev_node->getDoubleValue());
+ t->pos.setLongitudeDeg(user_lon_node->getDoubleValue());
+ t->pos.setLatitudeDeg(user_lat_node->getDoubleValue());
+ t->pos.setElevationM(user_elev_node->getDoubleValue());
//cout << ident << ' ' << circuitList.size() << ' ' << t->plane.callsign << " " << t->leg << " eta " << t->eta << '\n';
} else {
- t->pos = t->planePtr->GetPos(); // We should probably only set the pos's on one walk through the traffic list in the update function, to save a few CPU should we end up duplicating this.
+ t->pos = t->planePtr->getPos(); // We should probably only set the pos's on one walk through the traffic list in the update function, to save a few CPU should we end up duplicating this.
t->landingType = t->planePtr->GetLandingOption();
//cout << "AI plane landing option is " << t->landingType << '\n';
}
- Point3D tortho = ortho.ConvertToLocal(t->pos);
+ SGVec3d tortho = ortho.ConvertToLocal(t->pos);
if(t->isUser) {
// Need to figure out which leg he's on
//cout << "rwy.hdg = " << rwy.hdg << " user hdg = " << user_hdg_node->getDoubleValue();
rwyListItr = rwyList.begin();
TowerPlaneRec* t = *rwyListItr;
if(t->isUser) {
- t->pos.setlon(user_lon_node->getDoubleValue());
- t->pos.setlat(user_lat_node->getDoubleValue());
- t->pos.setelev(user_elev_node->getDoubleValue());
+ t->pos.setLongitudeDeg(user_lon_node->getDoubleValue());
+ t->pos.setLatitudeDeg(user_lat_node->getDoubleValue());
+ t->pos.setElevationM(user_elev_node->getDoubleValue());
} else {
- t->pos = t->planePtr->GetPos(); // We should probably only set the pos's on one walk through the traffic list in the update function, to save a few CPU should we end up duplicating this.
+ t->pos = t->planePtr->getPos(); // We should probably only set the pos's on one walk through the traffic list in the update function, to save a few CPU should we end up duplicating this.
}
bool on_rwy = OnActiveRunway(t->pos);
if(!on_rwy) {
//cout << "t = " << t << endl;
//cout << "Checking " << t->plane.callsign << endl;
if(t->isUser) {
- t->pos.setlon(user_lon_node->getDoubleValue());
- t->pos.setlat(user_lat_node->getDoubleValue());
- t->pos.setelev(user_elev_node->getDoubleValue());
+ t->pos.setLongitudeDeg(user_lon_node->getDoubleValue());
+ t->pos.setLatitudeDeg(user_lat_node->getDoubleValue());
+ t->pos.setElevationM(user_elev_node->getDoubleValue());
} else {
// TODO - set/update the position if it's an AI plane
}
doThresholdETACalc(); // We need this here because planes in the lists are not guaranteed to *always* have the correct ETA
//cout << "eta is " << t->eta << ", rwy is " << (rwyList.size() ? "occupied " : "clear ") << '\n';
- Point3D tortho = ortho.ConvertToLocal(t->pos);
+ SGVec3d tortho = ortho.ConvertToLocal(t->pos);
if(t->eta < 12 && rwyList.size() && !(t->instructedToGoAround)) {
// TODO - need to make this more sophisticated
// eg. is the plane accelerating down the runway taking off [OK],
//cout << "Dep list, checking " << t->plane.callsign;
double distout; // meters
- if(t->isUser) distout = dclGetHorizontalSeparation(Point3D(lon, lat, elev), Point3D(user_lon_node->getDoubleValue(), user_lat_node->getDoubleValue(), user_elev_node->getDoubleValue()));
- else distout = dclGetHorizontalSeparation(Point3D(lon, lat, elev), t->planePtr->GetPos());
+ if(t->isUser) distout = dclGetHorizontalSeparation(SGGeod::fromDegM(lon, lat, elev), SGGeod::fromDegM(user_lon_node->getDoubleValue(), user_lat_node->getDoubleValue(), user_elev_node->getDoubleValue()));
+ else distout = dclGetHorizontalSeparation(SGGeod::fromDegM(lon, lat, elev), t->planePtr->getPos());
//cout << " distout = " << distout << '\n';
if(t->isUser && !(t->clearedToTakeOff)) { // HACK - we use clearedToTakeOff to check if ATC already contacted with plane (and cleared take-off) or not
- if(!OnAnyRunway(Point3D(user_lon_node->getDoubleValue(), user_lat_node->getDoubleValue(), 0.0), false)) {
+ if(!OnAnyRunway(SGGeod::fromDegM(user_lon_node->getDoubleValue(), user_lat_node->getDoubleValue(), 0.0), false)) {
current_atcdialog->remove_entry(ident, USER_REQUEST_TAKE_OFF, TOWER);
t->clearedToTakeOff = true; // FIXME
}
}
// move to the +l end/center of the runway
//cout << "Runway center is at " << runway._lon << ", " << runway._lat << '\n';
- Point3D origin = Point3D(runway->longitude(), runway->latitude(), aptElev);
- Point3D ref = origin;
- double tshlon, tshlat, tshr;
+ double tshlon, tshlat, tshr;
double tolon, tolat, tor;
rwy.length = runway->lengthM();
- geo_direct_wgs_84 ( aptElev, ref.lat(), ref.lon(), other_way,
- rwy.length / 2.0 - 25.0, &tshlat, &tshlon, &tshr );
- geo_direct_wgs_84 ( aptElev, ref.lat(), ref.lon(), runway->headingDeg(),
- rwy.length / 2.0 - 25.0, &tolat, &tolon, &tor );
-
+ geo_direct_wgs_84 ( aptElev, runway->latitude(), runway->longitude(), other_way,
+ rwy.length / 2.0 - 25.0, &tshlat, &tshlon, &tshr );
+ geo_direct_wgs_84 ( aptElev, runway->latitude(), runway->longitude(), runway->headingDeg(),
+ rwy.length / 2.0 - 25.0, &tolat, &tolon, &tor );
+
// Note - 25 meters in from the runway end is a bit of a hack to put the plane ahead of the user.
// now copy what we need out of runway into rwy
- rwy.threshold_pos = Point3D(tshlon, tshlat, aptElev);
- Point3D takeoff_end = Point3D(tolon, tolat, aptElev);
+ rwy.threshold_pos = SGGeod::fromDegM(tshlon, tshlat, aptElev);
+ SGGeod takeoff_end = SGGeod::fromDegM(tolon, tolat, aptElev);
//cout << "Threshold position = " << tshlon << ", " << tshlat << ", " << aptElev << '\n';
//cout << "Takeoff position = " << tolon << ", " << tolat << ", " << aptElev << '\n';
rwy.hdg = runway->headingDeg();
// Figure out if a given position lies on the active runway
// Might have to change when we consider more than one active rwy.
-bool FGTower::OnActiveRunway(const Point3D& pt) {
+bool FGTower::OnActiveRunway(const SGGeod& pt) {
// TODO - check that the centre calculation below isn't confused by displaced thesholds etc.
- Point3D xyc((rwy.end1ortho.x() + rwy.end2ortho.x())/2.0, (rwy.end1ortho.y() + rwy.end2ortho.y())/2.0, 0.0);
- Point3D xyp = ortho.ConvertToLocal(pt);
+ SGVec3d xyc((rwy.end1ortho.x() + rwy.end2ortho.x())/2.0, (rwy.end1ortho.y() + rwy.end2ortho.y())/2.0, 0.0);
+ SGVec3d xyp = ortho.ConvertToLocal(pt);
//cout << "Length offset = " << fabs(xyp.y() - xyc.y()) << '\n';
//cout << "Width offset = " << fabs(xyp.x() - xyc.x()) << '\n';
// Figure out if a given position lies on any runway or not
// Only call this at startup - reading the runways database is expensive and needs to be fixed!
-bool FGTower::OnAnyRunway(const Point3D& pt, bool onGround) {
+bool FGTower::OnAnyRunway(const SGGeod& pt, bool onGround) {
ATCData ad;
double dist = current_commlist->FindClosest(lon, lat, elev, ad, TOWER, 7.0);
if(dist < 0.0) {
// Sign convention - dist_out is -ve for approaching planes and +ve for departing planes
// dist_across is +ve in the pattern direction - ie a plane correctly on downwind will have a +ve dist_across
- Point3D op = ortho.ConvertToLocal(tpr->pos);
+ SGVec3d op = ortho.ConvertToLocal(tpr->pos);
//if(printout) {
//if(!tpr->isUser) cout << "Orthopos is " << op.x() << ", " << op.y() << ' ';
//cout << "opType is " << tpr->opType << '\n';
// Do the approach list first
for(twrItr = appList.begin(); twrItr != appList.end(); twrItr++) {
TowerPlaneRec* tpr = *twrItr;
- if(!(tpr->isUser)) tpr->pos = tpr->planePtr->GetPos();
+ if(!(tpr->isUser)) tpr->pos = tpr->planePtr->getPos();
//cout << "APP: ";
CalcETA(tpr);
}
//cout << "Circuit list size is " << circuitList.size() << '\n';
for(twrItr = circuitList.begin(); twrItr != circuitList.end(); twrItr++) {
TowerPlaneRec* tpr = *twrItr;
- if(!(tpr->isUser)) tpr->pos = tpr->planePtr->GetPos();
+ if(!(tpr->isUser)) tpr->pos = tpr->planePtr->getPos();
//cout << "CIRC: ";
CalcETA(tpr);
}
t->clearedToLineUp = false;
t->clearedToTakeOff = false;
t->opType = operation;
- t->pos = requestee->GetPos();
+ t->pos = requestee->getPos();
//cout << "Hold Short reported by " << plane.callsign << '\n';
SG_LOG(SG_ATC, SG_BULK, "Hold Short reported by " << plane.callsign);
t->planePtr = ai;
t->opType = op;
t->leg = lg;
- t->pos = ai->GetPos();
+ t->pos = ai->getPos();
CalcETA(t);
//cout << "NOT t\n";
t = new TowerPlaneRec;
t->isUser = true;
- t->pos.setlon(user_lon_node->getDoubleValue());
- t->pos.setlat(user_lat_node->getDoubleValue());
- t->pos.setelev(user_elev_node->getDoubleValue());
+ t->pos.setLongitudeDeg(user_lon_node->getDoubleValue());
+ t->pos.setLatitudeDeg(user_lat_node->getDoubleValue());
+ t->pos.setElevationM(user_elev_node->getDoubleValue());
} else {
//cout << "IS t\n";
// Oops - the plane is already registered with this tower - maybe we took off and flew a giant circuit without
t->plane = plane;
t->planePtr = requestee;
t->landingType = lt;
- t->pos = requestee->GetPos();
+ t->pos = requestee->getPos();
//cout << "Hold Short reported by " << plane.callsign << '\n';
SG_LOG(SG_ATC, SG_BULK, "VFR arrival contact made by " << plane.callsign);
RemoveFromAppList(ID);
t->leg = DOWNWIND;
if(t->isUser) {
- t->pos.setlon(user_lon_node->getDoubleValue());
- t->pos.setlat(user_lat_node->getDoubleValue());
- t->pos.setelev(user_elev_node->getDoubleValue());
+ t->pos.setLongitudeDeg(user_lon_node->getDoubleValue());
+ t->pos.setLatitudeDeg(user_lat_node->getDoubleValue());
+ t->pos.setElevationM(user_elev_node->getDoubleValue());
} else {
// ASSERT(t->planePtr != NULL);
- t->pos = t->planePtr->GetPos();
+ t->pos = t->planePtr->getPos();
}
CalcETA(t);
AddToCircuitList(t);
RemoveFromAppList(ID);
t->leg = CLIMBOUT;
if(t->isUser) {
- t->pos.setlon(user_lon_node->getDoubleValue());
- t->pos.setlat(user_lat_node->getDoubleValue());
- t->pos.setelev(user_elev_node->getDoubleValue());
+ t->pos.setLongitudeDeg(user_lon_node->getDoubleValue());
+ t->pos.setLatitudeDeg(user_lat_node->getDoubleValue());
+ t->pos.setElevationM(user_elev_node->getDoubleValue());
} else {
// ASSERT(t->planePtr != NULL);
- t->pos = t->planePtr->GetPos();
+ t->pos = t->planePtr->getPos();
}
CalcETA(t);
AddToCircuitList(t);
if (rwyOccupied) {
tmp = "Ready for take-off";
} else {
- if (OnAnyRunway(Point3D(user_lon_node->getDoubleValue(),
+ if (OnAnyRunway(SGGeod::fromDegM(user_lon_node->getDoubleValue(),
user_lat_node->getDoubleValue(), 0.0),true)) {
tmp = "Request take-off clearance";
} else {
else if ( strcmp ( tag, "@MI" ) == 0 ) {
char buf[10];
//sprintf( buf, "%3.1f", tpars.miles );
- int dist_miles = (int)dclGetHorizontalSeparation(Point3D(lon, lat, elev), Point3D(user_lon_node->getDoubleValue(), user_lat_node->getDoubleValue(), user_elev_node->getDoubleValue())) / 1600;
+ int dist_miles = (int)dclGetHorizontalSeparation(SGGeod::fromDegM(lon, lat, elev), SGGeod::fromDegM(user_lon_node->getDoubleValue(), user_lat_node->getDoubleValue(), user_elev_node->getDoubleValue())) / 1600;
sprintf(buf, "%i", dist_miles);
strcat( &dum[0], &buf[0] );
}
}
}
else if(strcmp(tag, "@CD") == 0) { // @CD = compass direction
- double h = GetHeadingFromTo(Point3D(lon, lat, elev), Point3D(user_lon_node->getDoubleValue(), user_lat_node->getDoubleValue(), user_elev_node->getDoubleValue()));
+ double h = GetHeadingFromTo(SGGeod::fromDegM(lon, lat, elev), SGGeod::fromDegM(user_lon_node->getDoubleValue(), user_lat_node->getDoubleValue(), user_elev_node->getDoubleValue()));
while(h < 0.0) h += 360.0;
while(h > 360.0) h -= 360.0;
if(h < 22.5 || h > 337.5) {
#define _FG_TOWER_HXX
#include <simgear/compiler.h>
-#include <simgear/math/point3d.hxx>
+#include <simgear/math/SGMath.hxx>
#include <simgear/misc/sgstream.hxx>
-#include <plib/sg.h>
#include <iosfwd>
#include <string>
TowerPlaneRec();
TowerPlaneRec(const PlaneRec& p);
- TowerPlaneRec(const Point3D& pt);
- TowerPlaneRec(const PlaneRec& p, const Point3D& pt);
+ TowerPlaneRec(const SGGeod& pt);
+ TowerPlaneRec(const PlaneRec& p, const SGGeod& pt);
FGAIPlane* planePtr; // This might move to the planeRec eventually
PlaneRec plane;
- Point3D pos;
+ SGGeod pos;
double eta; // seconds
double dist_out; // meters from theshold
bool clearedToLand;
// Figure out if a given position lies on the active runway
// Might have to change when we consider more than one active rwy.
- bool OnActiveRunway(const Point3D& pt);
+ bool OnActiveRunway(const SGGeod& pt);
// Figure out if a given position lies on a runway or not
- bool OnAnyRunway(const Point3D& pt, bool onGround);
+ bool OnAnyRunway(const SGGeod& pt, bool onGround);
// Calculate the eta of a plane to the threshold.
// For ground traffic this is the fastest they can get there.
#include <iostream>
#include <string>
-#include <plib/sg.h>
-
#include <simgear/math/sg_geodesy.hxx>
#include <simgear/compiler.h>
-#include <plib/sg.h>
#include <plib/ul.h>
#include <Environment/environment_mgr.hxx>
FGAIFlightPlan *FGAirportDynamics::getSID(string activeRunway, double heading)
{
return SIDs.getBest(activeRunway, heading);
-}
\ No newline at end of file
+}
#include <math.h>
#include <algorithm>
-//#include <plib/sg.h>
-//#include <plib/ul.h>
-
-//#include <Environment/environment_mgr.hxx>
-//#include <Environment/environment.hxx>
-//#include <simgear/misc/sg_path.hxx>
-//#include <simgear/props/props.hxx>
-//#include <simgear/structure/subsystem_mgr.hxx>
#include <simgear/debug/logstream.hxx>
#include <simgear/route/waypoint.hxx>
-//#include <Main/globals.hxx>
-//#include <Main/fg_props.hxx>
-//#include <Airports/runways.hxx>
#include <Airports/dynamics.hxx>
#include <AIModel/AIFlightPlan.hxx>
-//#include <string>
-
#include "groundnetwork.hxx"
/***************************************************************************
# include <config.h>
#endif
-//#include <algorithm>
-
#include <simgear/compiler.h>
-//#include <plib/sg.h>
-//#include <plib/ul.h>
-
-//#include <Environment/environment_mgr.hxx>
-//#include <Environment/environment.hxx>
-//#include <simgear/misc/sg_path.hxx>
-//#include <simgear/props/props.hxx>
-//#include <simgear/structure/subsystem_mgr.hxx>
-//#include <simgear/debug/logstream.hxx>
-//#include <Main/globals.hxx>
-//#include <Main/fg_props.hxx>
-//#include <Airports/runways.hxx>
-
#include <string>
#include "parking.hxx"
#endif
#include <math.h>
-//#include <algorithm>
#include <simgear/compiler.h>
-//#include <plib/sg.h>
-//#include <plib/ul.h>
-
-//#include <Environment/environment_mgr.hxx>
-//#include <Environment/environment.hxx>
-//#include <simgear/misc/sg_path.hxx>
-//#include <simgear/props/props.hxx>
-//#include <simgear/structure/subsystem_mgr.hxx>
#include <simgear/debug/logstream.hxx>
#include <Main/globals.hxx>
-//#include <Main/fg_props.hxx>
#include <Airports/runways.hxx>
#include "runwayprefs.hxx"
// get airport position
-Point3D fgGetAirportPos( const string& id )
+SGGeod fgGetAirportPos( const string& id )
{
SG_LOG( SG_ATC, SG_BULK,
"Finding position for airport: " << id );
const FGAirport *a = fgFindAirportID( id);
if (a) {
- return Point3D(a->getLongitude(), a->getLatitude(), a->getElevation());
+ return SGGeod::fromDegM(a->getLongitude(), a->getLatitude(), a->getElevation());
} else {
- return Point3D(0.0, 0.0, -9999.0);
+ return SGGeod::fromDegM(0.0, 0.0, -9999.0);
}
}
#include <simgear/constants.h>
#include <simgear/debug/logstream.hxx>
-#include <simgear/math/polar3d.hxx>
#include <simgear/props/props.hxx>
#include <simgear/timing/sg_time.hxx>
#include <Main/globals.hxx>
#include <Main/viewmgr.hxx>
-#include <plib/sg.h>
-
class FGRunway;
using std::deque;
#include <stdlib.h>
#include <stdio.h>
-#include <plib/sg.h>
#include "hud.hxx"
#ifdef USE_HUD_TextList
#include <Aircraft/aircraft.hxx>
#include <Environment/environment.hxx>
#include <Environment/environment_mgr.hxx>
-#include <simgear/math/sg_geodesy.hxx>
-#include <simgear/math/polar3d.hxx>
#include <ATCDCL/ATCutils.hxx>
#include <osg/GLU>
#include <math.h>
-#include <plib/sg.h>
-
#include <simgear/constants.h>
#include <simgear/debug/logstream.hxx>
#include <simgear/math/interpolater.hxx>
#endif
#include <simgear/math/sg_geodesy.hxx>
-#include <simgear/math/polar3d.hxx>
#include <Aircraft/controls.hxx>
#include <Main/globals.hxx>
#endif
#include <simgear/math/sg_geodesy.hxx>
-#include <simgear/math/polar3d.hxx>
#include <Aircraft/controls.hxx>
#include <Main/globals.hxx>
#endif
#include <plib/puAux.h>
-#include <plib/sg.h>
#include <simgear/compiler.h> // for SG_USING_STD
#include <simgear/props/props.hxx>
#include <osg/State>
-#include <plib/sg.h>
-
#include <simgear/math/SGLimits.hxx>
#include <simgear/constants.h>
#include <simgear/structure/subsystem_mgr.hxx>
#include <simgear/compiler.h>
#include <simgear/math/sg_geodesy.hxx>
-#include <simgear/math/polar3d.hxx>
#include <osg/GLU>
#include <Main/globals.hxx>
#include <ATCDCL/ATCProjection.hxx>
#include <Main/fg_props.hxx>
-#include <simgear/math/point3d.hxx>
+#include <simgear/math/SGMath.hxx>
#include "Airports/simple.hxx"
using std::cout;
double mapScaleMeters = _mapScale * (_mapScaleUnits == 0 ? SG_NM_TO_METER : 1000);
// TODO - use an aligned projection when either DTK or TK up!
- FGATCAlignedProjection mapProj(Point3D(_gpsLon * SG_RADIANS_TO_DEGREES, _gpsLat * SG_RADIANS_TO_DEGREES, 0.0), _mapHeading);
+ FGATCAlignedProjection mapProj(SGGeod::fromRad(_gpsLon, _gpsLat), _mapHeading);
double meter_per_pix = (_mapOrientation == 0 ? mapScaleMeters / 20.0f : mapScaleMeters / 29.0f);
- Point3D bottomLeft = mapProj.ConvertFromLocal(Point3D(gps_max(-57.0 * meter_per_pix, -50000), gps_max((_mapOrientation == 0 ? -20.0 * meter_per_pix : -11.0 * meter_per_pix), -25000), 0.0));
- Point3D topRight = mapProj.ConvertFromLocal(Point3D(gps_min(54.0 * meter_per_pix, 50000), gps_min((_mapOrientation == 0 ? 20.0 * meter_per_pix : 29.0 * meter_per_pix), 25000), 0.0));
+ SGGeod bottomLeft = mapProj.ConvertFromLocal(SGVec3d(gps_max(-57.0 * meter_per_pix, -50000), gps_max((_mapOrientation == 0 ? -20.0 * meter_per_pix : -11.0 * meter_per_pix), -25000), 0.0));
+ SGGeod topRight = mapProj.ConvertFromLocal(SGVec3d(gps_min(54.0 * meter_per_pix, 50000), gps_min((_mapOrientation == 0 ? 20.0 * meter_per_pix : 29.0 * meter_per_pix), 25000), 0.0));
// Draw Airport labels first (but not one's that are waypoints)
// Draw Airports first (but not one's that are waypoints)
for(unsigned int i=1; i<_activeFP->waypoints.size(); ++i) {
GPSWaypoint* wp0 = _activeFP->waypoints[i-1];
GPSWaypoint* wp1 = _activeFP->waypoints[i];
- Point3D p0 = mapProj.ConvertToLocal(Point3D(wp0->lon * SG_RADIANS_TO_DEGREES, wp0->lat * SG_RADIANS_TO_DEGREES, 0.0));
- Point3D p1 = mapProj.ConvertToLocal(Point3D(wp1->lon * SG_RADIANS_TO_DEGREES, wp1->lat * SG_RADIANS_TO_DEGREES, 0.0));
+ SGVec3d p0 = mapProj.ConvertToLocal(SGGeod::fromRad(wp0->lon, wp0->lat));
+ SGVec3d p1 = mapProj.ConvertToLocal(SGGeod::fromRad(wp1->lon, wp1->lat));
int mx0 = int(p0.x() / meter_per_pix) + 56;
int my0 = int(p0.y() / meter_per_pix) + (_mapOrientation == 0 ? 19 : 10);
int mx1 = int(p1.x() / meter_per_pix) + 56;
#include <simgear/debug/logstream.hxx>
#include <simgear/structure/exception.hxx>
#include <simgear/structure/event_mgr.hxx>
-#include <simgear/math/polar3d.hxx>
-#include <simgear/math/sg_geodesy.hxx>
#include <simgear/misc/sg_path.hxx>
#include <simgear/misc/interpolator.hxx>
#include <simgear/scene/material/matlib.hxx>
#include <simgear/debug/logstream.hxx>
#include <simgear/constants.h>
-#include <simgear/math/polar3d.hxx>
-#include <simgear/math/sg_geodesy.hxx>
#include <simgear/scene/model/placement.hxx>
#include <simgear/math/vector.hxx>
#include <string.h> // strcmp
-#include <plib/sg.h>
-
#include <simgear/compiler.h>
#include <Model/acmodel.hxx>
#include <vector>
-#include <plib/sg.h>
-
#include <Cockpit/panel.hxx>
#include <Cockpit/panel_io.hxx>
#include "panelnode.hxx"
#include <vector>
-#include <plib/sg.h>
#include <simgear/compiler.h>
#include <simgear/props/props.hxx>
#include <simgear/math/SGMath.hxx>
#include <simgear/constants.h>
#include <simgear/debug/logstream.hxx>
-#include <simgear/math/polar3d.hxx>
-#include <simgear/math/sg_geodesy.hxx>
#include <simgear/math/vector.hxx>
#include <simgear/structure/exception.hxx>
#include <simgear/scene/model/modellib.hxx>
#include <string>
#include <vector>
-#include <plib/sg.h>
-
#include <simgear/compiler.h>
-#include <simgear/math/polar3d.hxx>
-#include <simgear/math/sg_geodesy.hxx>
#include <simgear/props/props.hxx>
#include <simgear/route/waypoint.hxx>
#include <simgear/structure/subsystem_mgr.hxx>
#include <vector>
#include <algorithm>
-#include <plib/sg.h>
#include <plib/ul.h>
#include <simgear/compiler.h>
-#include <simgear/math/polar3d.hxx>
-#include <simgear/math/sg_geodesy.hxx>
#include <simgear/misc/sg_path.hxx>
#include <simgear/props/props.hxx>
#include <simgear/route/waypoint.hxx>