1
0
Fork 0

Use an SGGeod inside FGAIFlightPlan::Waypoint.

This allows incremental refactoring to move away from discrete lat/lon use in favour of SGGeod.
This commit is contained in:
James Turner 2012-10-08 15:52:06 +01:00
parent fd23f5dee5
commit 607e7d7bf3
2 changed files with 49 additions and 26 deletions

View file

@ -46,9 +46,6 @@
using std::cerr;
FGAIWaypoint::FGAIWaypoint() {
latitude = 0;
longitude = 0;
altitude = 0;
speed = 0;
crossat = 0;
finished = 0;
@ -68,6 +65,36 @@ bool FGAIWaypoint::contains(string target) {
return true;
}
double FGAIWaypoint::getLatitude()
{
return pos.getLatitudeDeg();
}
double FGAIWaypoint::getLongitude()
{
return pos.getLongitudeDeg();
}
double FGAIWaypoint::getAltitude()
{
return pos.getElevationFt();
}
void FGAIWaypoint::setLatitude(double lat)
{
pos.setLatitudeDeg(lat);
}
void FGAIWaypoint::setLongitude(double lon)
{
pos.setLongitudeDeg(lon);
}
void FGAIWaypoint::setAltitude(double alt)
{
pos.setElevationFt(alt);
}
FGAIFlightPlan::FGAIFlightPlan()
{
sid = 0;
@ -345,8 +372,7 @@ void FGAIFlightPlan::eraseLastWaypoint()
// gives distance in feet from a position to a waypoint
double FGAIFlightPlan::getDistanceToGo(double lat, double lon, FGAIWaypoint* wp) const{
return SGGeodesy::distanceM(SGGeod::fromDeg(lon, lat),
SGGeod::fromDeg(wp->getLongitude(), wp->getLatitude()));
return SGGeodesy::distanceM(SGGeod::fromDeg(lon, lat), wp->getPos());
}
// sets distance in feet from a lead point to the current waypoint
@ -394,14 +420,15 @@ void FGAIFlightPlan::setLeadDistance(double distance_ft){
}
double FGAIFlightPlan::getBearing(FGAIWaypoint* first, FGAIWaypoint* second) const{
return getBearing(first->getLatitude(), first->getLongitude(), second);
double FGAIFlightPlan::getBearing(FGAIWaypoint* first, FGAIWaypoint* second) const
{
return SGGeodesy::courseDeg(first->getPos(), second->getPos());
}
double FGAIFlightPlan::getBearing(double lat, double lon, FGAIWaypoint* wp) const{
return SGGeodesy::courseDeg(SGGeod::fromDeg(lon, lat),
SGGeod::fromDeg(wp->getLongitude(), wp->getLatitude()));
double FGAIFlightPlan::getBearing(double lat, double lon, FGAIWaypoint* wp) const
{
return SGGeodesy::courseDeg(SGGeod::fromDeg(lon, lat), wp->getPos());
}
void FGAIFlightPlan::deleteWaypoints()
@ -423,10 +450,7 @@ void FGAIFlightPlan::resetWaypoints()
wpt_vector_iterator i = waypoints.end();
i--;
wpt->setName ( (*i)->getName() );
wpt->setLatitude ( (*i)->getLatitude() );
wpt->setLongitude ( (*i)->getLongitude() );
wpt->setAltitude ( (*i)->getAltitude() );
wpt->setSpeed ( (*i)->getSpeed() );
wpt->setPos ( (*i)->getPos() );
wpt->setCrossat ( (*i)->getCrossat() );
wpt->setGear_down ( (*i)->getGear_down() );
wpt->setFlaps_down ( (*i)->getFlaps_down() );

View file

@ -22,20 +22,17 @@
#include <simgear/compiler.h>
#include <vector>
#include <string>
#include <simgear/math/SGMath.hxx>
class FGTaxiRoute;
class FGRunway;
class FGAIAircraft;
class FGAirport;
class SGGeod;
class FGAIWaypoint {
private:
std::string name;
double latitude;
double longitude;
double altitude;
SGGeod pos;
double speed;
double crossat;
bool finished;
@ -51,9 +48,10 @@ public:
FGAIWaypoint();
~FGAIWaypoint() {};
void setName (std::string nam) { name = nam; };
void setLatitude (double lat) { latitude = lat; };
void setLongitude (double lon) { longitude = lon; };
void setAltitude (double alt) { altitude = alt; };
void setLatitude (double lat);
void setLongitude (double lon);
void setAltitude (double alt);
void setPos (const SGGeod& aPos) { pos = aPos; }
void setSpeed (double spd) { speed = spd; };
void setCrossat (double val) { crossat = val; };
void setFinished (bool fin) { finished = fin; };
@ -68,9 +66,10 @@ public:
bool contains(std::string name);
std::string getName () { return name; };
double getLatitude () { return latitude; };
double getLongitude () { return longitude; };
double getAltitude () { return altitude; };
const SGGeod& getPos () { return pos; };
double getLatitude ();
double getLongitude ();
double getAltitude ();
double getSpeed () { return speed; };
double getCrossat () { return crossat; };