From e3c2859e5549e1fb4e47cf2477241a5ba8cea595 Mon Sep 17 00:00:00 2001
From: Andrey Kleshchev <andreykproductengine@lindenlab.com>
Date: Mon, 14 Dec 2020 19:20:22 +0200
Subject: SL-11300 Camera distance to avatar in neighbouring region incorrect

---
 doc/contributions.txt        |  1 +
 indra/newview/lldrawable.cpp | 10 +++-------
 2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/doc/contributions.txt b/doc/contributions.txt
index eabb051361..9522ea8a6c 100755
--- a/doc/contributions.txt
+++ b/doc/contributions.txt
@@ -267,6 +267,7 @@ Beth Walcher
 Beq Janus
 	SL-10288
 	SL-13583
+	SL-11300
 Bezilon Kasei
 Biancaluce Robbiani
 	CT-225
diff --git a/indra/newview/lldrawable.cpp b/indra/newview/lldrawable.cpp
index 2219f20272..1da94f4698 100644
--- a/indra/newview/lldrawable.cpp
+++ b/indra/newview/lldrawable.cpp
@@ -912,22 +912,18 @@ void LLDrawable::updateDistance(LLCamera& camera, bool force_update)
             if (volume->getAvatar())
             {
                 const LLVector3* av_box = volume->getAvatar()->getLastAnimExtents();
-                LLVector3d cam_pos = gAgent.getPosGlobalFromAgent(LLViewerCamera::getInstance()->getOrigin());
-                LLVector3 cam_region_pos = LLVector3(cam_pos - volume->getRegion()->getOriginGlobal());
-                
-                LLVector3 cam_to_box_offset = point_to_box_offset(cam_region_pos, av_box);
+                LLVector3 cam_pos_from_agent = LLViewerCamera::getInstance()->getOrigin();
+                LLVector3 cam_to_box_offset = point_to_box_offset(cam_pos_from_agent, av_box);
                 mDistanceWRTCamera = llmax(0.01f, ll_round(cam_to_box_offset.magVec(), 0.01f));
                 LL_DEBUGS("DynamicBox") << volume->getAvatar()->getFullname() 
                                         << " pos (ignored) " << pos
-                                        << " cam pos " << cam_pos
-                                        << " cam region pos " << cam_region_pos
+                                        << " cam pos " << cam_pos_from_agent
                                         << " box " << av_box[0] << "," << av_box[1] 
                                         << " -> dist " << mDistanceWRTCamera
                                         << LL_ENDL;
                 mVObjp->updateLOD();
                 return;
             }
-            
 		}
 		else
 		{
-- 
cgit v1.2.3