diff --git a/src/AIModel/AIAircraft.cxx b/src/AIModel/AIAircraft.cxx index a87a94fe6..2722886c6 100644 --- a/src/AIModel/AIAircraft.cxx +++ b/src/AIModel/AIAircraft.cxx @@ -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); } diff --git a/src/Main/globals.cxx b/src/Main/globals.cxx index 4d6d7bf57..c4bb125a7 100644 --- a/src/Main/globals.cxx +++ b/src/Main/globals.cxx @@ -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. diff --git a/src/Main/globals.hxx b/src/Main/globals.hxx index 54b777a71..365ce3988 100644 --- a/src/Main/globals.hxx +++ b/src/Main/globals.hxx @@ -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)