diff options
Diffstat (limited to 'indra/newview/llmaniptranslate.cpp')
-rw-r--r-- | indra/newview/llmaniptranslate.cpp | 55 |
1 files changed, 33 insertions, 22 deletions
diff --git a/indra/newview/llmaniptranslate.cpp b/indra/newview/llmaniptranslate.cpp index 765b504afe..8d15ee936c 100644 --- a/indra/newview/llmaniptranslate.cpp +++ b/indra/newview/llmaniptranslate.cpp @@ -273,7 +273,6 @@ void LLManipTranslate::restoreGL() LLManipTranslate::~LLManipTranslate() { - for_each(mProjectedManipulators.begin(), mProjectedManipulators.end(), DeletePointer()); } @@ -888,8 +887,9 @@ void LLManipTranslate::highlightManipulators(S32 x, S32 y) planar_manip_xy_visible = TRUE; } - for_each(mProjectedManipulators.begin(), mProjectedManipulators.end(), DeletePointer()); - mProjectedManipulators.clear(); + // Project up to 9 manipulators to screen space 2*X, 2*Y, 2*Z, 3*planes + std::vector<ManipulatorHandle> projected_manipulators; + projected_manipulators.reserve(9); for (S32 i = 0; i < num_arrow_manips; i+= 2) { @@ -899,12 +899,12 @@ void LLManipTranslate::highlightManipulators(S32 x, S32 y) LLVector4 projected_end = mManipulatorVertices[i + 1] * transform; projected_end = projected_end * (1.f / projected_end.mV[VW]); - ManipulatorHandle* projManipulator = - new ManipulatorHandle(LLVector3(projected_start.mV[VX], projected_start.mV[VY], projected_start.mV[VZ]), + ManipulatorHandle projected_manip( + LLVector3(projected_start.mV[VX], projected_start.mV[VY], projected_start.mV[VZ]), LLVector3(projected_end.mV[VX], projected_end.mV[VY], projected_end.mV[VZ]), MANIPULATOR_IDS[i / 2], 10.f); // 10 pixel hotspot for arrows - mProjectedManipulators.insert(projManipulator); + projected_manipulators.push_back(projected_manip); } if (planar_manip_yz_visible) @@ -916,12 +916,12 @@ void LLManipTranslate::highlightManipulators(S32 x, S32 y) LLVector4 projected_end = mManipulatorVertices[i + 1] * transform; projected_end = projected_end * (1.f / projected_end.mV[VW]); - ManipulatorHandle* projManipulator = - new ManipulatorHandle(LLVector3(projected_start.mV[VX], projected_start.mV[VY], projected_start.mV[VZ]), + ManipulatorHandle projected_manip( + LLVector3(projected_start.mV[VX], projected_start.mV[VY], projected_start.mV[VZ]), LLVector3(projected_end.mV[VX], projected_end.mV[VY], projected_end.mV[VZ]), MANIPULATOR_IDS[i / 2], 20.f); // 20 pixels for planar manipulators - mProjectedManipulators.insert(projManipulator); + projected_manipulators.push_back(projected_manip); } if (planar_manip_xz_visible) @@ -933,12 +933,12 @@ void LLManipTranslate::highlightManipulators(S32 x, S32 y) LLVector4 projected_end = mManipulatorVertices[i + 1] * transform; projected_end = projected_end * (1.f / projected_end.mV[VW]); - ManipulatorHandle* projManipulator = - new ManipulatorHandle(LLVector3(projected_start.mV[VX], projected_start.mV[VY], projected_start.mV[VZ]), + ManipulatorHandle projected_manip( + LLVector3(projected_start.mV[VX], projected_start.mV[VY], projected_start.mV[VZ]), LLVector3(projected_end.mV[VX], projected_end.mV[VY], projected_end.mV[VZ]), MANIPULATOR_IDS[i / 2], 20.f); // 20 pixels for planar manipulators - mProjectedManipulators.insert(projManipulator); + projected_manipulators.push_back(projected_manip); } if (planar_manip_xy_visible) @@ -950,12 +950,12 @@ void LLManipTranslate::highlightManipulators(S32 x, S32 y) LLVector4 projected_end = mManipulatorVertices[i + 1] * transform; projected_end = projected_end * (1.f / projected_end.mV[VW]); - ManipulatorHandle* projManipulator = - new ManipulatorHandle(LLVector3(projected_start.mV[VX], projected_start.mV[VY], projected_start.mV[VZ]), + ManipulatorHandle projected_manip( + LLVector3(projected_start.mV[VX], projected_start.mV[VY], projected_start.mV[VZ]), LLVector3(projected_end.mV[VX], projected_end.mV[VY], projected_end.mV[VZ]), MANIPULATOR_IDS[i / 2], 20.f); // 20 pixels for planar manipulators - mProjectedManipulators.insert(projManipulator); + projected_manipulators.push_back(projected_manip); } LLVector2 manip_start_2d; @@ -967,13 +967,24 @@ void LLManipTranslate::highlightManipulators(S32 x, S32 y) LLVector2 mousePos((F32)x - half_width, (F32)y - half_height); LLVector2 mouse_delta; - for (minpulator_list_t::iterator iter = mProjectedManipulators.begin(); - iter != mProjectedManipulators.end(); ++iter) + struct { + bool operator()(const ManipulatorHandle& a, const ManipulatorHandle& b) const + { + return a.mEndPosition.mV[VZ] < b.mEndPosition.mV[VZ]; + } + } closest_to_camera; + // Keep order consistent with insertion via stable_sort + std::stable_sort( projected_manipulators.begin(), + projected_manipulators.end(), + closest_to_camera ); + + std::vector<ManipulatorHandle>::iterator it = projected_manipulators.begin(); + for ( ; it != projected_manipulators.end(); ++it) { - ManipulatorHandle* manipulator = *iter; + ManipulatorHandle& manipulator = *it; { - manip_start_2d.setVec(manipulator->mStartPosition.mV[VX] * half_width, manipulator->mStartPosition.mV[VY] * half_height); - manip_end_2d.setVec(manipulator->mEndPosition.mV[VX] * half_width, manipulator->mEndPosition.mV[VY] * half_height); + manip_start_2d.setVec(manipulator.mStartPosition.mV[VX] * half_width, manipulator.mStartPosition.mV[VY] * half_height); + manip_end_2d.setVec(manipulator.mEndPosition.mV[VX] * half_width, manipulator.mEndPosition.mV[VY] * half_height); manip_dir = manip_end_2d - manip_start_2d; mouse_delta = mousePos - manip_start_2d; @@ -985,9 +996,9 @@ void LLManipTranslate::highlightManipulators(S32 x, S32 y) if (mouse_pos_manip > 0.f && mouse_pos_manip < manip_length && - mouse_dist_manip_squared < manipulator->mHotSpotRadius * manipulator->mHotSpotRadius) + mouse_dist_manip_squared < manipulator.mHotSpotRadius * manipulator.mHotSpotRadius) { - mHighlightedPart = manipulator->mManipID; + mHighlightedPart = manipulator.mManipID; break; } } |