1
0
Fork 0

Change a hot-spot in the AI code, to use cartesian instead of geodetic math.

This commit is contained in:
James Turner 2011-10-26 17:26:11 +01:00
parent 34f86cd317
commit 16a54a4409
3 changed files with 13 additions and 5 deletions

View file

@ -838,11 +838,12 @@ bool FGAIAircraft::leadPointReached(FGAIWaypoint* curr) {
}
bool FGAIAircraft::aiTrafficVisible() {
SGGeod userPos(SGGeod::fromDeg(fgGetDouble("/position/longitude-deg"),
fgGetDouble("/position/latitude-deg")));
return (SGGeodesy::distanceNm(userPos, pos) <= TRAFFICTOAIDISTTODIE);
bool FGAIAircraft::aiTrafficVisible()
{
SGVec3d cartPos = SGVec3d::fromGeod(pos);
const double d2 = (TRAFFICTOAIDISTTODIE * SG_NM_TO_METER) *
(TRAFFICTOAIDISTTODIE * SG_NM_TO_METER);
return (distSqr(cartPos, globals->get_aircraft_positon_cart()) < d2);
}

View file

@ -380,6 +380,11 @@ FGGlobals::get_aircraft_position() const
throw sg_exception("Can't get aircraft position", "FGGlobals::get_aircraft_position()" );
}
const SGVec3d&
FGGlobals::get_aircraft_positon_cart() const
{
return SGVec3d::fromGeod(get_aircraft_position());
}
// Save the current state as the initial state.

View file

@ -267,6 +267,8 @@ public:
const SGGeod & get_aircraft_position() const;
const SGVec3d& get_aircraft_positon_cart() const;
inline FGModelMgr *get_model_mgr () { return model_mgr; }
inline void set_model_mgr (FGModelMgr * mgr)