diff options
author | Ricky Curtice <kf6kjg+hg@gmail.com> | 2011-03-10 22:07:06 -0800 |
---|---|---|
committer | Ricky Curtice <kf6kjg+hg@gmail.com> | 2011-03-10 22:07:06 -0800 |
commit | d4d292258e31eee6d639106147758f39deae63e3 (patch) | |
tree | 577571cc2d4cdef5aa24706520b790f56b875c1c | |
parent | 1426765e82549ec9d17a0f90d902f25c0e785bbd (diff) |
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.
-rw-r--r-- | doc/contributions.txt | 1 | ||||
-rw-r--r-- | indra/llcharacter/llbvhloader.cpp | 6 | ||||
-rw-r--r-- | indra/llmath/tests/llbbox_test.cpp | 2 | ||||
-rw-r--r-- | indra/newview/llagent.cpp | 2 | ||||
-rw-r--r-- | indra/newview/llfloaterchat.cpp | 5 | ||||
-rw-r--r-- | indra/newview/llhudeffectlookat.cpp | 2 | ||||
-rw-r--r-- | indra/newview/llhudeffectpointat.cpp | 2 | ||||
-rw-r--r-- | indra/newview/llmaniprotate.cpp | 2 | ||||
-rw-r--r-- | indra/newview/llmanipscale.cpp | 12 | ||||
-rw-r--r-- | indra/newview/llnetmap.cpp | 14 | ||||
-rw-r--r-- | indra/newview/llpanelpeople.cpp | 4 | ||||
-rw-r--r-- | indra/newview/llselectmgr.cpp | 8 | ||||
-rw-r--r-- | indra/newview/llspeakers.cpp | 2 | ||||
-rw-r--r-- | indra/newview/llviewerchat.cpp | 10 | ||||
-rw-r--r-- | indra/newview/llvoicevivox.cpp | 4 | ||||
-rw-r--r-- | indra/newview/llworld.cpp | 6 |
16 files changed, 44 insertions, 38 deletions
diff --git a/doc/contributions.txt b/doc/contributions.txt index e94acb566a..9ba155eece 100644 --- a/doc/contributions.txt +++ b/doc/contributions.txt @@ -237,6 +237,7 @@ Coaldust Numbers VWR-1095 Cron Stardust VWR-10579 + VWR-25126 Cypren Christenson STORM-417 Dale Glass diff --git a/indra/llcharacter/llbvhloader.cpp b/indra/llcharacter/llbvhloader.cpp index 532a2c1b0d..a340bab6d3 100644 --- a/indra/llcharacter/llbvhloader.cpp +++ b/indra/llcharacter/llbvhloader.cpp @@ -1196,7 +1196,7 @@ void LLBVHLoader::optimize() if (ki_prev == ki_last_good_pos) { joint->mNumPosKeys++; - if (dist_vec(LLVector3(ki_prev->mPos), first_frame_pos) > POSITION_MOTION_THRESHOLD) + if (dist_vec_squared(LLVector3(ki_prev->mPos), first_frame_pos) > POSITION_MOTION_THRESHOLD * POSITION_MOTION_THRESHOLD) { pos_changed = TRUE; } @@ -1209,12 +1209,12 @@ void LLBVHLoader::optimize() LLVector3 current_pos(ki->mPos); LLVector3 interp_pos = lerp(current_pos, last_good_pos, 1.f / (F32)numPosFramesConsidered); - if (dist_vec(current_pos, first_frame_pos) > POSITION_MOTION_THRESHOLD) + if (dist_vec_squared(current_pos, first_frame_pos) > POSITION_MOTION_THRESHOLD * POSITION_MOTION_THRESHOLD) { pos_changed = TRUE; } - if (dist_vec(interp_pos, test_pos) < POSITION_KEYFRAME_THRESHOLD) + if (dist_vec_squared(interp_pos, test_pos) < POSITION_KEYFRAME_THRESHOLD * POSITION_KEYFRAME_THRESHOLD) { ki_prev->mIgnorePos = TRUE; numPosFramesConsidered++; diff --git a/indra/llmath/tests/llbbox_test.cpp b/indra/llmath/tests/llbbox_test.cpp index 8064ab217d..b9e1d29cd7 100644 --- a/indra/llmath/tests/llbbox_test.cpp +++ b/indra/llmath/tests/llbbox_test.cpp @@ -34,7 +34,7 @@ #define ANGLE (3.14159265f / 2.0f) -#define APPROX_EQUAL(a, b) dist_vec((a),(b)) < 1e-5 +#define APPROX_EQUAL(a, b) dist_vec_squared((a),(b)) < 1e-10 namespace tut { diff --git a/indra/newview/llagent.cpp b/indra/newview/llagent.cpp index 7d908df5ce..4628adee1f 100644 --- a/indra/newview/llagent.cpp +++ b/indra/newview/llagent.cpp @@ -1343,7 +1343,7 @@ void LLAgent::stopAutoPilot(BOOL user_cancel) //NB: auto pilot can terminate for a reason other than reaching the destination if (mAutoPilotFinishedCallback) { - mAutoPilotFinishedCallback(!user_cancel && dist_vec(gAgent.getPositionGlobal(), mAutoPilotTargetGlobal) < mAutoPilotStopDistance, mAutoPilotCallbackData); + mAutoPilotFinishedCallback(!user_cancel && dist_vec_squared(gAgent.getPositionGlobal(), mAutoPilotTargetGlobal) < mAutoPilotStopDistance * mAutoPilotStopDistance, mAutoPilotCallbackData); } mLeaderID = LLUUID::null; diff --git a/indra/newview/llfloaterchat.cpp b/indra/newview/llfloaterchat.cpp index c2c2e7fe22..2679dbb78b 100644 --- a/indra/newview/llfloaterchat.cpp +++ b/indra/newview/llfloaterchat.cpp @@ -413,8 +413,9 @@ LLColor4 get_text_color(const LLChat& chat) if (!chat.mPosAgent.isExactlyZero()) { LLVector3 pos_agent = gAgent.getPositionAgent(); - F32 distance = dist_vec(pos_agent, chat.mPosAgent); - if (distance > gAgent.getNearChatRadius()) + F32 distance_squared = dist_vec_squared(pos_agent, chat.mPosAgent); + F32 dist_near_chat = gAgent.getNearChatRadius(); + if (distance_squared > dist_near_chat * dist_near_chat) { // diminish far-off chat text_color.mV[VALPHA] = 0.8f; diff --git a/indra/newview/llhudeffectlookat.cpp b/indra/newview/llhudeffectlookat.cpp index 8cf7d23f88..10ee6f1d39 100644 --- a/indra/newview/llhudeffectlookat.cpp +++ b/indra/newview/llhudeffectlookat.cpp @@ -416,7 +416,7 @@ BOOL LLHUDEffectLookAt::setLookAt(ELookAtType target_type, LLViewerObject *objec BOOL lookAtChanged = (target_type != mTargetType) || (object != mTargetObject); // lookat position has moved a certain amount and we haven't just sent an update - lookAtChanged = lookAtChanged || ((dist_vec(position, mLastSentOffsetGlobal) > MIN_DELTAPOS_FOR_UPDATE) && + lookAtChanged = lookAtChanged || ((dist_vec_squared(position, mLastSentOffsetGlobal) > MIN_DELTAPOS_FOR_UPDATE * MIN_DELTAPOS_FOR_UPDATE) && ((current_time - mLastSendTime) > (1.f / MAX_SENDS_PER_SEC))); if (lookAtChanged) diff --git a/indra/newview/llhudeffectpointat.cpp b/indra/newview/llhudeffectpointat.cpp index bfb0f150b3..562d7cd4ed 100644 --- a/indra/newview/llhudeffectpointat.cpp +++ b/indra/newview/llhudeffectpointat.cpp @@ -244,7 +244,7 @@ BOOL LLHUDEffectPointAt::setPointAt(EPointAtType target_type, LLViewerObject *ob BOOL targetTypeChanged = (target_type != mTargetType) || (object != mTargetObject); - BOOL targetPosChanged = (dist_vec(position, mLastSentOffsetGlobal) > MIN_DELTAPOS_FOR_UPDATE) && + BOOL targetPosChanged = (dist_vec_squared(position, mLastSentOffsetGlobal) > MIN_DELTAPOS_FOR_UPDATE * MIN_DELTAPOS_FOR_UPDATE) && ((current_time - mLastSendTime) > (1.f / MAX_SENDS_PER_SEC)); if (targetTypeChanged || targetPosChanged) diff --git a/indra/newview/llmaniprotate.cpp b/indra/newview/llmaniprotate.cpp index f1c7e952d1..815b718f33 100644 --- a/indra/newview/llmaniprotate.cpp +++ b/indra/newview/llmaniprotate.cpp @@ -1127,7 +1127,7 @@ BOOL LLManipRotate::updateVisiblity() if (gSavedSettings.getBOOL("LimitSelectDistance")) { F32 max_select_distance = gSavedSettings.getF32("MaxSelectDistance"); - if (dist_vec(gAgent.getPositionAgent(), center) > max_select_distance) + if (dist_vec_squared(gAgent.getPositionAgent(), center) > max_select_distance * max_select_distance) { visible = FALSE; } diff --git a/indra/newview/llmanipscale.cpp b/indra/newview/llmanipscale.cpp index 060677f9f3..4f8e7e4792 100644 --- a/indra/newview/llmanipscale.cpp +++ b/indra/newview/llmanipscale.cpp @@ -217,8 +217,6 @@ void LLManipScale::render() LLVector3 center_agent = gAgent.getPosAgentFromGlobal(LLSelectMgr::getInstance()->getSelectionCenterGlobal()); - F32 range; - F32 range_from_agent; if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD) { mBoxHandleSize = BOX_HANDLE_BASE_SIZE * BOX_HANDLE_BASE_FACTOR / (F32) LLViewerCamera::getInstance()->getViewHeightInPixels(); @@ -226,25 +224,25 @@ void LLManipScale::render() } else { - range = dist_vec(gAgentCamera.getCameraPositionAgent(), center_agent); - range_from_agent = dist_vec(gAgent.getPositionAgent(), center_agent); + F32 range_squared = dist_vec_squared(gAgentCamera.getCameraPositionAgent(), center_agent); + F32 range_from_agent_squared = dist_vec_squared(gAgent.getPositionAgent(), center_agent); // Don't draw manip if object too far away if (gSavedSettings.getBOOL("LimitSelectDistance")) { F32 max_select_distance = gSavedSettings.getF32("MaxSelectDistance"); - if (range_from_agent > max_select_distance) + if (range_from_agent_squared > max_select_distance * max_select_distance) { return; } } - if (range > 0.001f) + if (range_squared > 0.00001f) { // range != zero F32 fraction_of_fov = BOX_HANDLE_BASE_SIZE / (F32) LLViewerCamera::getInstance()->getViewHeightInPixels(); F32 apparent_angle = fraction_of_fov * LLViewerCamera::getInstance()->getView(); // radians - mBoxHandleSize = range * tan(apparent_angle) * BOX_HANDLE_BASE_FACTOR; + mBoxHandleSize = fsqrtf(range_squared) * tan(apparent_angle) * BOX_HANDLE_BASE_FACTOR; } else { diff --git a/indra/newview/llnetmap.cpp b/indra/newview/llnetmap.cpp index 93039d935d..394e0bf1f1 100644 --- a/indra/newview/llnetmap.cpp +++ b/indra/newview/llnetmap.cpp @@ -334,8 +334,8 @@ void LLNetMap::draw() //localMouse(&local_mouse_x, &local_mouse_y); LLUI::getMousePositionLocal(this, &local_mouse_x, &local_mouse_y); mClosestAgentToCursor.setNull(); - F32 closest_dist = F32_MAX; - F32 min_pick_dist = mDotRadius * MIN_PICK_SCALE; + F32 closest_dist_squared = F32_MAX; + F32 min_pick_dist_squared = (mDotRadius * MIN_PICK_SCALE) * (mDotRadius * MIN_PICK_SCALE); // Draw avatars for (LLWorld::region_list_t::const_iterator iter = LLWorld::getInstance()->getRegionList().begin(); @@ -414,11 +414,11 @@ void LLNetMap::draw() } } - F32 dist_to_cursor = dist_vec(LLVector2(pos_map.mV[VX], pos_map.mV[VY]), + F32 dist_to_cursor_squared = dist_vec_squared(LLVector2(pos_map.mV[VX], pos_map.mV[VY]), LLVector2(local_mouse_x,local_mouse_y)); - if(dist_to_cursor < min_pick_dist && dist_to_cursor < closest_dist) + if(dist_to_cursor_squared < min_pick_dist_squared && dist_to_cursor_squared < closest_dist_squared) { - closest_dist = dist_to_cursor; + closest_dist_squared = dist_to_cursor_squared; mClosestAgentToCursor = regionp->mMapAvatarIDs.get(i); } } @@ -455,9 +455,9 @@ void LLNetMap::draw() dot_width, dot_width); - F32 dist_to_cursor = dist_vec(LLVector2(pos_map.mV[VX], pos_map.mV[VY]), + F32 dist_to_cursor_squared = dist_vec_squared(LLVector2(pos_map.mV[VX], pos_map.mV[VY]), LLVector2(local_mouse_x,local_mouse_y)); - if(dist_to_cursor < min_pick_dist && dist_to_cursor < closest_dist) + if(dist_to_cursor_squared < min_pick_dist_squared && dist_to_cursor_squared < closest_dist_squared) { mClosestAgentToCursor = gAgent.getID(); } diff --git a/indra/newview/llpanelpeople.cpp b/indra/newview/llpanelpeople.cpp index b52f33ec3b..dbfdf0bdf6 100644 --- a/indra/newview/llpanelpeople.cpp +++ b/indra/newview/llpanelpeople.cpp @@ -158,8 +158,8 @@ protected: const LLVector3d& me_pos = gAgent.getPositionGlobal(); const LLVector3d& item1_pos = mAvatarsPositions.find(item1->getAvatarId())->second; const LLVector3d& item2_pos = mAvatarsPositions.find(item2->getAvatarId())->second; - F32 dist1 = dist_vec(item1_pos, me_pos); - F32 dist2 = dist_vec(item2_pos, me_pos); + F32 dist1 = dist_vec_squared(item1_pos, me_pos); + F32 dist2 = dist_vec_squared(item2_pos, me_pos); return dist1 < dist2; } private: 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. diff --git a/indra/newview/llspeakers.cpp b/indra/newview/llspeakers.cpp index 40aea05839..31492e33d9 100644 --- a/indra/newview/llspeakers.cpp +++ b/indra/newview/llspeakers.cpp @@ -920,7 +920,7 @@ void LLLocalSpeakerMgr::updateSpeakerList() if (speakerp->mStatus == LLSpeaker::STATUS_TEXT_ONLY) { LLVOAvatar* avatarp = (LLVOAvatar*)gObjectList.findObject(speaker_id); - if (!avatarp || dist_vec(avatarp->getPositionAgent(), gAgent.getPositionAgent()) > CHAT_NORMAL_RADIUS) + if (!avatarp || dist_vec_squared(avatarp->getPositionAgent(), gAgent.getPositionAgent()) > CHAT_NORMAL_RADIUS * CHAT_NORMAL_RADIUS) { setSpeakerNotInChannel(speakerp); } diff --git a/indra/newview/llviewerchat.cpp b/indra/newview/llviewerchat.cpp index 0af850a46b..7cce2831c9 100644 --- a/indra/newview/llviewerchat.cpp +++ b/indra/newview/llviewerchat.cpp @@ -87,8 +87,9 @@ void LLViewerChat::getChatColor(const LLChat& chat, LLColor4& r_color) if (!chat.mPosAgent.isExactlyZero()) { LLVector3 pos_agent = gAgent.getPositionAgent(); - F32 distance = dist_vec(pos_agent, chat.mPosAgent); - if (distance > gAgent.getNearChatRadius()) + F32 distance_squared = dist_vec_squared(pos_agent, chat.mPosAgent); + F32 dist_near_chat = gAgent.getNearChatRadius(); + if (distance_squared > dist_near_chat * dist_near_chat) { // diminish far-off chat r_color.mV[VALPHA] = 0.8f; @@ -152,8 +153,9 @@ void LLViewerChat::getChatColor(const LLChat& chat, std::string& r_color_name, F if (!chat.mPosAgent.isExactlyZero()) { LLVector3 pos_agent = gAgent.getPositionAgent(); - F32 distance = dist_vec(pos_agent, chat.mPosAgent); - if (distance > gAgent.getNearChatRadius()) + F32 distance_squared = dist_vec_squared(pos_agent, chat.mPosAgent); + F32 dist_near_chat = gAgent.getNearChatRadius(); + if (distance_squared > dist_near_chat * dist_near_chat) { // diminish far-off chat r_color_alpha = 0.8f; diff --git a/indra/newview/llvoicevivox.cpp b/indra/newview/llvoicevivox.cpp index 08e242af8e..08581be38b 100644 --- a/indra/newview/llvoicevivox.cpp +++ b/indra/newview/llvoicevivox.cpp @@ -5088,7 +5088,7 @@ void LLVivoxVoiceClient::enforceTether(void) } } - if(dist_vec(mCameraPosition, tethered) > 0.1) + if(dist_vec_squared(mCameraPosition, tethered) > 0.01) { mCameraPosition = tethered; mSpatialCoordsDirty = true; @@ -5150,7 +5150,7 @@ void LLVivoxVoiceClient::setCameraPosition(const LLVector3d &position, const LLV void LLVivoxVoiceClient::setAvatarPosition(const LLVector3d &position, const LLVector3 &velocity, const LLMatrix3 &rot) { - if(dist_vec(mAvatarPosition, position) > 0.1) + if(dist_vec_squared(mAvatarPosition, position) > 0.01) { mAvatarPosition = position; mSpatialCoordsDirty = true; diff --git a/indra/newview/llworld.cpp b/indra/newview/llworld.cpp index 8f7197c607..a21a7eac9e 100644 --- a/indra/newview/llworld.cpp +++ b/indra/newview/llworld.cpp @@ -1446,6 +1446,8 @@ static LLVector3d unpackLocalToGlobalPosition(U32 compact_local, const LLVector3 void LLWorld::getAvatars(uuid_vec_t* avatar_ids, std::vector<LLVector3d>* positions, const LLVector3d& relative_to, F32 radius) const { + F32 radius_squared = radius * radius; + if(avatar_ids != NULL) { avatar_ids->clear(); @@ -1463,7 +1465,7 @@ void LLWorld::getAvatars(uuid_vec_t* avatar_ids, std::vector<LLVector3d>* positi for (S32 i = 0; i < count; i++) { LLVector3d pos_global = unpackLocalToGlobalPosition(regionp->mMapAvatars.get(i), origin_global); - if(dist_vec(pos_global, relative_to) <= radius) + if(dist_vec_squared(pos_global, relative_to) <= radius_squared) { if(positions != NULL) { @@ -1491,7 +1493,7 @@ void LLWorld::getAvatars(uuid_vec_t* avatar_ids, std::vector<LLVector3d>* positi if(uuid.isNull()) continue; LLVector3d pos_global = pVOAvatar->getPositionGlobal(); - if(dist_vec(pos_global, relative_to) <= radius) + if(dist_vec_squared(pos_global, relative_to) <= radius_squared) { bool found = false; uuid_vec_t::iterator sel_iter = avatar_ids->begin(); |