From d4d292258e31eee6d639106147758f39deae63e3 Mon Sep 17 00:00:00 2001 From: Ricky Curtice Date: Thu, 10 Mar 2011 22:07:06 -0800 Subject: Squared all dist_vec() based comparisons and other dist_vec() operations where sensible. Not all instances of dist_vec() were squared, only those where it wouldn't (hopefully) change the functionality. --- indra/newview/llselectmgr.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'indra/newview/llselectmgr.cpp') diff --git a/indra/newview/llselectmgr.cpp b/indra/newview/llselectmgr.cpp index 50bc0b4a98..39f3cd4196 100644 --- a/indra/newview/llselectmgr.cpp +++ b/indra/newview/llselectmgr.cpp @@ -6577,12 +6577,14 @@ bool LLSelectMgr::selectionMove(const LLVector3& displ, { obj_pos = (*it)->getObject()->getPositionEdit(); - F32 obj_dist = dist_vec(obj_pos, LLViewerCamera::getInstance()->getOrigin()); - if (obj_dist < min_dist) + F32 obj_dist_squared = dist_vec_squared(obj_pos, LLViewerCamera::getInstance()->getOrigin()); + if (obj_dist_squared < min_dist) { - min_dist = obj_dist; + min_dist = obj_dist_squared; } } + // since the above uses squared values, take the square root. + min_dist = sqrt(min_dist); // factor the distance inside the displacement vector. This will get us // equally visible movements for both close and far away selections. -- cgit v1.2.3 From 9bac314ba0d8b6bd35c8d2e27ce99a28b924dea6 Mon Sep 17 00:00:00 2001 From: Ricky Curtice Date: Sat, 12 Mar 2011 23:39:10 -0800 Subject: Switched to using *_SQUARED constants instead of multiplied constants, and cleaned up a few other minor issues noted during review. --- indra/newview/llselectmgr.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'indra/newview/llselectmgr.cpp') diff --git a/indra/newview/llselectmgr.cpp b/indra/newview/llselectmgr.cpp index 39f3cd4196..262c9a4515 100644 --- a/indra/newview/llselectmgr.cpp +++ b/indra/newview/llselectmgr.cpp @@ -6570,7 +6570,8 @@ bool LLSelectMgr::selectionMove(const LLVector3& displ, if (update_position) { // calculate the distance of the object closest to the camera origin - F32 min_dist = 1e+30f; + F32 min_dist_squared = F32_MAX; // value will be overridden in the loop + LLVector3 obj_pos; for (LLObjectSelection::root_iterator it = getSelection()->root_begin(); it != getSelection()->root_end(); ++it) @@ -6578,20 +6579,22 @@ bool LLSelectMgr::selectionMove(const LLVector3& displ, obj_pos = (*it)->getObject()->getPositionEdit(); F32 obj_dist_squared = dist_vec_squared(obj_pos, LLViewerCamera::getInstance()->getOrigin()); - if (obj_dist_squared < min_dist) + if (obj_dist_squared < min_dist_squared) { - min_dist = obj_dist_squared; + min_dist_squared = obj_dist_squared; } } - // since the above uses squared values, take the square root. - min_dist = sqrt(min_dist); + + // get the non-squared edition for use below + // note the use of fsqrtf, this was used in the definition of dist_vec() and is therefore re-used here + F32 min_dist = fsqrtf(min_dist_squared); // factor the distance inside the displacement vector. This will get us // equally visible movements for both close and far away selections. - min_dist = sqrt(min_dist) / 2; - displ_global.setVec(displ.mV[0]*min_dist, - displ.mV[1]*min_dist, - displ.mV[2]*min_dist); + F32 min_dist_factored = sqrt(min_dist) / 2; + displ_global.setVec(displ.mV[0]*min_dist_factored, + displ.mV[1]*min_dist_factored, + displ.mV[2]*min_dist_factored); // equates to: Displ_global = Displ * M_cam_axes_in_global_frame displ_global = LLViewerCamera::getInstance()->rotateToAbsolute(displ_global); -- cgit v1.2.3 From ca186a64014942540baaf280bb3967d2582336bd Mon Sep 17 00:00:00 2001 From: Ricky Curtice Date: Mon, 4 Apr 2011 10:24:43 -0700 Subject: Parenthisized a #define to make it safer, adjusted some notes (and added a TODO) around some extremely obscure code that needs further attention but which is outside this scope. --- indra/newview/llselectmgr.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'indra/newview/llselectmgr.cpp') diff --git a/indra/newview/llselectmgr.cpp b/indra/newview/llselectmgr.cpp index 262c9a4515..2c5073d027 100644 --- a/indra/newview/llselectmgr.cpp +++ b/indra/newview/llselectmgr.cpp @@ -6589,11 +6589,11 @@ bool LLSelectMgr::selectionMove(const LLVector3& displ, // note the use of fsqrtf, this was used in the definition of dist_vec() and is therefore re-used here F32 min_dist = fsqrtf(min_dist_squared); - // factor the distance inside the displacement vector. This will get us + // factor the distance into the displacement vector. This will get us // equally visible movements for both close and far away selections. - F32 min_dist_factored = sqrt(min_dist) / 2; - displ_global.setVec(displ.mV[0]*min_dist_factored, - displ.mV[1]*min_dist_factored, + F32 min_dist_factored = sqrt(min_dist) / 2; // FIXME: this variable name doesn't state its true meaning. + displ_global.setVec(displ.mV[0]*min_dist_factored, + displ.mV[1]*min_dist_factored, displ.mV[2]*min_dist_factored); // equates to: Displ_global = Displ * M_cam_axes_in_global_frame -- cgit v1.2.3 From 26f2762b89705a69e831016ea67af9500907721d Mon Sep 17 00:00:00 2001 From: Ricky Curtice Date: Mon, 25 Apr 2011 16:24:16 -0700 Subject: Removed an extra variable I'd added. Also cleaned up some whitespace-around-operator issues. While removing the extra variable seems to make the code more ugly, all it does is reveal the pre-existing ugliness that had been masked in the past. Trying to find a fix, or even try to come to a real understanding of why this section of code is the way it is, is out of my scope for this task. --- indra/newview/llselectmgr.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'indra/newview/llselectmgr.cpp') diff --git a/indra/newview/llselectmgr.cpp b/indra/newview/llselectmgr.cpp index 2c5073d027..96468c0b21 100644 --- a/indra/newview/llselectmgr.cpp +++ b/indra/newview/llselectmgr.cpp @@ -6585,16 +6585,12 @@ bool LLSelectMgr::selectionMove(const LLVector3& displ, } } - // get the non-squared edition for use below - // note the use of fsqrtf, this was used in the definition of dist_vec() and is therefore re-used here - F32 min_dist = fsqrtf(min_dist_squared); - // factor the distance into the displacement vector. This will get us // equally visible movements for both close and far away selections. - F32 min_dist_factored = sqrt(min_dist) / 2; // FIXME: this variable name doesn't state its true meaning. - displ_global.setVec(displ.mV[0]*min_dist_factored, - displ.mV[1]*min_dist_factored, - displ.mV[2]*min_dist_factored); + F32 min_dist = sqrt(fsqrtf(min_dist_squared)) / 2; + displ_global.setVec(displ.mV[0] * min_dist, + displ.mV[1] * min_dist, + displ.mV[2] * min_dist); // equates to: Displ_global = Displ * M_cam_axes_in_global_frame displ_global = LLViewerCamera::getInstance()->rotateToAbsolute(displ_global); -- cgit v1.2.3