Replace CourseAndDistance uses in traffic code with SGGeodesy calls.
This commit is contained in:
parent
6e42458a55
commit
52bac46535
1 changed files with 13 additions and 30 deletions
|
@ -194,9 +194,7 @@ bool FGAISchedule::update(time_t now)
|
||||||
|
|
||||||
FGAIManager *aimgr;
|
FGAIManager *aimgr;
|
||||||
string airport;
|
string airport;
|
||||||
|
|
||||||
double courseToUser;
|
|
||||||
double distanceToDest;
|
|
||||||
double speed;
|
double speed;
|
||||||
|
|
||||||
time_t
|
time_t
|
||||||
|
@ -351,38 +349,21 @@ bool FGAISchedule::update(time_t now)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SGGeod current;
|
||||||
if (now > (*i)->getDepartureTime())
|
if (now > (*i)->getDepartureTime())
|
||||||
{
|
{
|
||||||
SGGeoc geoc = SGGeoc::fromCart(newPos);
|
current = SGGeod::fromCart(newPos);
|
||||||
lat = geoc.getLatitudeDeg();
|
|
||||||
lon = geoc.getLongitudeDeg();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
lat = dep->getLatitude();
|
current = dep->geod();
|
||||||
lon = dep->getLongitude();
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
SGGeod user = SGGeod::fromDegM(userLongitude, userLatitude, (*i)->getCruiseAlt());
|
||||||
SGWayPoint current (lon,
|
speed = SGGeodesy::distanceNm(current, arr->geod()) /
|
||||||
lat,
|
|
||||||
(*i)->getCruiseAlt(),
|
|
||||||
SGWayPoint::SPHERICAL);
|
|
||||||
SGWayPoint user ( userLongitude,
|
|
||||||
userLatitude,
|
|
||||||
(*i)->getCruiseAlt(),
|
|
||||||
SGWayPoint::SPHERICAL);
|
|
||||||
SGWayPoint dest ( arr->getLongitude(),
|
|
||||||
arr->getLatitude(),
|
|
||||||
(*i)->getCruiseAlt(),
|
|
||||||
SGWayPoint::SPHERICAL);
|
|
||||||
// We really only need distance to user
|
|
||||||
// and course to destination
|
|
||||||
user.CourseAndDistance(current, &courseToUser, &distanceToUser);
|
|
||||||
dest.CourseAndDistance(current, &courseToDest, &distanceToDest);
|
|
||||||
speed = (distanceToDest*SG_METER_TO_NM) /
|
|
||||||
((double) remainingTimeEnroute/3600.0);
|
((double) remainingTimeEnroute/3600.0);
|
||||||
|
|
||||||
|
distanceToUser = SGGeodesy::distanceNm(current, user);
|
||||||
|
|
||||||
// If distance between user and simulated aircaft is less
|
// If distance between user and simulated aircaft is less
|
||||||
// then 500nm, create this flight. At jet speeds 500 nm is roughly
|
// then 500nm, create this flight. At jet speeds 500 nm is roughly
|
||||||
|
@ -390,8 +371,8 @@ bool FGAISchedule::update(time_t now)
|
||||||
// to start a more detailed simulation of this aircraft.
|
// to start a more detailed simulation of this aircraft.
|
||||||
SG_LOG (SG_GENERAL, SG_DEBUG, "Traffic manager: " << registration << " is scheduled for a flight from "
|
SG_LOG (SG_GENERAL, SG_DEBUG, "Traffic manager: " << registration << " is scheduled for a flight from "
|
||||||
<< dep->getId() << " to " << arr->getId() << ". Current distance to user: "
|
<< dep->getId() << " to " << arr->getId() << ". Current distance to user: "
|
||||||
<< distanceToUser*SG_METER_TO_NM);
|
<< distanceToUser);
|
||||||
if ((distanceToUser*SG_METER_TO_NM) < TRAFFICTOAIDISTTOSTART)
|
if (distanceToUser < TRAFFICTOAIDISTTOSTART)
|
||||||
{
|
{
|
||||||
string flightPlanName = dep->getId() + string("-") + arr->getId() +
|
string flightPlanName = dep->getId() + string("-") + arr->getId() +
|
||||||
string(".xml");
|
string(".xml");
|
||||||
|
@ -427,6 +408,8 @@ bool FGAISchedule::update(time_t now)
|
||||||
aircraft->setAltitude((*i)->getCruiseAlt()*100); // convert from FL to feet
|
aircraft->setAltitude((*i)->getCruiseAlt()*100); // convert from FL to feet
|
||||||
aircraft->setSpeed(speed);
|
aircraft->setSpeed(speed);
|
||||||
aircraft->setBank(0);
|
aircraft->setBank(0);
|
||||||
|
|
||||||
|
courseToDest = SGGeodesy::courseDeg(current, arr->geod());
|
||||||
aircraft->SetFlightPlan(new FGAIFlightPlan(aircraft, flightPlanName, courseToDest, deptime,
|
aircraft->SetFlightPlan(new FGAIFlightPlan(aircraft, flightPlanName, courseToDest, deptime,
|
||||||
dep, arr,true, radius,
|
dep, arr,true, radius,
|
||||||
(*i)->getCruiseAlt()*100,
|
(*i)->getCruiseAlt()*100,
|
||||||
|
|
Loading…
Add table
Reference in a new issue