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

View file

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