From 89fe5dab825a62a0e3fd8d248cbc91c65eb2a426 Mon Sep 17 00:00:00 2001 From: Jacek Antonelli Date: Fri, 15 Aug 2008 23:44:50 -0500 Subject: Second Life viewer sources 1.14.0.0 --- linden/indra/newview/llmaniptranslate.cpp | 240 ++++++++++++++++++++++-------- 1 file changed, 177 insertions(+), 63 deletions(-) (limited to 'linden/indra/newview/llmaniptranslate.cpp') diff --git a/linden/indra/newview/llmaniptranslate.cpp b/linden/indra/newview/llmaniptranslate.cpp index fea6092..bb58a9c 100644 --- a/linden/indra/newview/llmaniptranslate.cpp +++ b/linden/indra/newview/llmaniptranslate.cpp @@ -59,6 +59,7 @@ #include "llworld.h" #include "viewer.h" #include "llui.h" +#include "pipeline.h" const S32 NUM_AXES = 3; const S32 MOUSE_DRAG_SLOP = 2; // pixels @@ -257,6 +258,7 @@ void LLManipTranslate::handleSelect() { gSelectMgr->saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK); gFloaterTools->setStatusText("Drag to move, shift-drag to copy"); + LLManip::handleSelect(); } void LLManipTranslate::handleDeselect() @@ -264,6 +266,7 @@ void LLManipTranslate::handleDeselect() mHighlightedPart = LL_NO_PART; mManipPart = LL_NO_PART; gFloaterTools->setStatusText(""); + LLManip::handleDeselect(); } BOOL LLManipTranslate::handleMouseDown(S32 x, S32 y, MASK mask) @@ -289,10 +292,10 @@ BOOL LLManipTranslate::handleMouseDown(S32 x, S32 y, MASK mask) // Assumes that one of the arrows on an object was hit. BOOL LLManipTranslate::handleMouseDownOnPart( S32 x, S32 y, MASK mask ) { - BOOL can_move = gSelectMgr->getObjectCount() != 0; - for (LLViewerObject* objectp = gSelectMgr->getFirstObject(); + BOOL can_move = mObjectSelection->getObjectCount() != 0; + for (LLViewerObject* objectp = mObjectSelection->getFirstObject(); objectp; - objectp = gSelectMgr->getNextObject()) + objectp = mObjectSelection->getNextObject()) { can_move = can_move && objectp->permMove() && (objectp->permModify() || gSavedSettings.getBOOL("SelectLinkedSet")); } @@ -332,7 +335,7 @@ BOOL LLManipTranslate::handleMouseDownOnPart( S32 x, S32 y, MASK mask ) LLVector3 axis; - LLSelectNode *selectNode = gSelectMgr->getFirstMoveableNode(TRUE); + LLSelectNode *selectNode = mObjectSelection->getFirstMoveableNode(TRUE); if (!selectNode) { @@ -407,7 +410,7 @@ BOOL LLManipTranslate::handleHover(S32 x, S32 y, MASK mask) BOOL rotated = FALSE; // ...build mode moves camera about focus point - if (gSelectMgr->getSelectType() != SELECT_TYPE_HUD) + if (mObjectSelection->getSelectType() != SELECT_TYPE_HUD) { if (x < ROTATE_H_MARGIN) { @@ -421,6 +424,8 @@ BOOL LLManipTranslate::handleHover(S32 x, S32 y, MASK mask) } } + LLViewerObject *object; + // Suppress processing if mouse hasn't actually moved. // This may cause problems if the camera moves outside of the // rotation above. @@ -467,11 +472,10 @@ BOOL LLManipTranslate::handleHover(S32 x, S32 y, MASK mask) LLVector3 axis_f; LLVector3d axis_d; - LLViewerObject *object; // pick the first object to constrain to grid w/ common origin // this is so we don't screw up groups - LLSelectNode* selectNode = gSelectMgr->getFirstMoveableNode(TRUE); + LLSelectNode* selectNode = mObjectSelection->getFirstMoveableNode(TRUE); if (!selectNode) { // somehow we lost the object! @@ -643,12 +647,12 @@ BOOL LLManipTranslate::handleHover(S32 x, S32 y, MASK mask) LLVector3d clamped_relative_move = axis_magnitude * axis_d; // scalar multiply LLVector3 clamped_relative_move_f = (F32)axis_magnitude * axis_f; // scalar multiply - for(selectNode = gSelectMgr->getFirstNode(); + for(selectNode = mObjectSelection->getFirstNode(); selectNode; - selectNode = gSelectMgr->getNextNode() ) + selectNode = mObjectSelection->getNextNode() ) { object = selectNode->getObject(); - + // Only apply motion to root objects and objects selected // as "individual". if (!object->isRootEdit() && !selectNode->mIndividualSelection) @@ -779,27 +783,12 @@ BOOL LLManipTranslate::handleHover(S32 x, S32 y, MASK mask) send_update = TRUE; } } + selectNode->mLastPositionLocal = object->getPosition(); } } - // Handle throttling to 10 updates per second. - F32 elapsed_time = mUpdateTimer.getElapsedTimeF32(); - const F32 UPDATE_DELAY = 0.1f; // min time between transmitted updates - if (send_update && (elapsed_time > UPDATE_DELAY)) - { - gSelectMgr->sendMultipleUpdate(UPD_POSITION); - mUpdateTimer.reset(); - mSendUpdateOnMouseUp = FALSE; - } - else - { - // ...suppressed update - mSendUpdateOnMouseUp = TRUE; - } - gSelectMgr->updateSelectionCenter(); gAgent.clearFocusObject(); - //gAgent.setObjectTracking(FALSE); dialog_refresh_all(); // ??? is this necessary? lldebugst(LLERR_USER_INPUT) << "hover handled by LLManipTranslate (active)" << llendl; @@ -811,7 +800,7 @@ void LLManipTranslate::highlightManipulators(S32 x, S32 y) { mHighlightedPart = LL_NO_PART; - if (!gSelectMgr->getObjectCount()) + if (!mObjectSelection->getObjectCount()) { return; } @@ -832,7 +821,7 @@ void LLManipTranslate::highlightManipulators(S32 x, S32 y) LLMatrix4 transform; - if (gSelectMgr->getSelectType() == SELECT_TYPE_HUD) + if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD) { relative_camera_dir = LLVector3(1.f, 0.f, 0.f) * ~grid_rotation; LLVector4 translation(object_position); @@ -1056,17 +1045,8 @@ BOOL LLManipTranslate::handleMouseUp(S32 x, S32 y, MASK mask) gSelectMgr->enableSilhouette(TRUE); // Might have missed last update due to UPDATE_DELAY timing. - if (mSendUpdateOnMouseUp) - { - gSelectMgr->sendMultipleUpdate( UPD_POSITION ); - mSendUpdateOnMouseUp = FALSE; - } - -// if (mCopyMadeThisDrag) -// { -// gSelectMgr->clearGridObjects(); -// } - + gSelectMgr->sendMultipleUpdate( UPD_POSITION ); + mInSnapRegime = FALSE; gSelectMgr->saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK); //gAgent.setObjectTracking(gSavedSettings.getBOOL("TrackFocusObject")); @@ -1079,7 +1059,7 @@ void LLManipTranslate::render() { glMatrixMode(GL_MODELVIEW); glPushMatrix(); - if (gSelectMgr->getSelectType() == SELECT_TYPE_HUD) + if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD) { F32 zoom = gAgent.getAvatarObject()->mHUDCurZoom; glScalef(zoom, zoom, zoom); @@ -1117,7 +1097,7 @@ void LLManipTranslate::renderSnapGuides() return; } - LLSelectNode *first_node = gSelectMgr->getFirstMoveableNode(TRUE); + LLSelectNode *first_node = mObjectSelection->getFirstMoveableNode(TRUE); if (!first_node) { return; @@ -1139,10 +1119,36 @@ void LLManipTranslate::renderSnapGuides() //pick appropriate projection plane for snap rulers according to relative camera position if (mManipPart >= LL_X_ARROW && mManipPart <= LL_Z_ARROW) { + LLVector3 normal; + LLColor4 inner_color; + LLManip::EManipPart temp_manip = mManipPart; + switch (mManipPart) + { + case LL_X_ARROW: + normal.setVec(1,0,0); + inner_color.setVec(0,1,1,line_alpha); + mManipPart = LL_YZ_PLANE; + break; + case LL_Y_ARROW: + normal.setVec(0,1,0); + inner_color.setVec(1,0,1,line_alpha); + mManipPart = LL_XZ_PLANE; + break; + case LL_Z_ARROW: + normal.setVec(0,0,1); + inner_color.setVec(1,1,0,line_alpha); + mManipPart = LL_XY_PLANE; + break; + default: + break; + } + + highlightIntersection(normal, selection_center, grid_rotation, inner_color); + mManipPart = temp_manip; getManipAxis(first_object, mManipPart, translate_axis); LLVector3 at_axis_abs; - if (gSelectMgr->getSelectType() == SELECT_TYPE_HUD) + if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD) { at_axis_abs = LLVector3::x_axis * ~grid_rotation; } @@ -1217,7 +1223,7 @@ void LLManipTranslate::renderSnapGuides() F32 guide_size_meters; - if (gSelectMgr->getSelectType() == SELECT_TYPE_HUD) + if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD) { guide_size_meters = 1.f / gAgent.getAvatarObject()->mHUDCurZoom; mSnapOffsetMeters = mArrowLengthMeters * 1.5f; @@ -1419,7 +1425,7 @@ void LLManipTranslate::renderSnapGuides() } } } - if (gSelectMgr->getSelectType() != SELECT_TYPE_HUD) + if (mObjectSelection->getSelectType() != SELECT_TYPE_HUD) { // render helpful text if (mHelpTextTimer.getElapsedTimeF32() < sHelpTextVisibleTime + sHelpTextFadeTime && sNumTimesHelpTextShown < sMaxTimesShowHelpText) @@ -1443,10 +1449,10 @@ void LLManipTranslate::renderSnapGuides() std::string help_text = "Move mouse cursor over ruler to snap"; LLColor4 help_text_color = LLColor4::white; help_text_color.mV[VALPHA] = clamp_rescale(mHelpTextTimer.getElapsedTimeF32(), sHelpTextVisibleTime, sHelpTextVisibleTime + sHelpTextFadeTime, line_alpha, 0.f); - hud_render_utf8text(help_text, help_text_pos, *big_fontp, LLFontGL::NORMAL, -0.5f * big_fontp->getWidthF32(help_text), 3.f, help_text_color, gSelectMgr->getSelectType() == SELECT_TYPE_HUD); + hud_render_utf8text(help_text, help_text_pos, *big_fontp, LLFontGL::NORMAL, -0.5f * big_fontp->getWidthF32(help_text), 3.f, help_text_color, mObjectSelection->getSelectType() == SELECT_TYPE_HUD); help_text = "to snap to grid"; help_text_pos -= gCamera->getUpAxis() * mSnapOffsetMeters * 0.2f; - hud_render_utf8text(help_text, help_text_pos, *big_fontp, LLFontGL::NORMAL, -0.5f * big_fontp->getWidthF32(help_text), 3.f, help_text_color, gSelectMgr->getSelectType() == SELECT_TYPE_HUD); + hud_render_utf8text(help_text, help_text_pos, *big_fontp, LLFontGL::NORMAL, -0.5f * big_fontp->getWidthF32(help_text), 3.f, help_text_color, mObjectSelection->getSelectType() == SELECT_TYPE_HUD); } } } @@ -1455,18 +1461,13 @@ void LLManipTranslate::renderSnapGuides() // render gridlines for planar snapping F32 u = 0, v = 0; - glPushMatrix(); - - F32 x,y,z,angle_radians; - grid_rotation.getAngleAxis(&angle_radians, &x, &y, &z); - glTranslatef(selection_center.mV[VX], selection_center.mV[VY], selection_center.mV[VZ]); - glRotatef(angle_radians * RAD_TO_DEG, x, y, z); - + LLColor4 inner_color; + LLVector3 normal; LLVector3 grid_center = selection_center - grid_origin; - grid_center *= ~grid_rotation; - F32 usc = 1; F32 vsc = 1; + + grid_center *= ~grid_rotation; switch (mManipPart) { @@ -1475,23 +1476,38 @@ void LLManipTranslate::renderSnapGuides() v = grid_center.mV[VZ]; usc = grid_scale.mV[VY]; vsc = grid_scale.mV[VZ]; + inner_color.setVec(0,1,1,line_alpha); + normal.setVec(1,0,0); break; case LL_XZ_PLANE: u = grid_center.mV[VX]; v = grid_center.mV[VZ]; usc = grid_scale.mV[VX]; vsc = grid_scale.mV[VZ]; + inner_color.setVec(1,0,1,line_alpha); + normal.setVec(0,1,0); break; case LL_XY_PLANE: u = grid_center.mV[VX]; v = grid_center.mV[VY]; usc = grid_scale.mV[VX]; vsc = grid_scale.mV[VY]; + inner_color.setVec(1,1,0,line_alpha); + normal.setVec(0,0,1); break; default: break; } + highlightIntersection(normal, selection_center, grid_rotation, inner_color); + + glPushMatrix(); + + F32 x,y,z,angle_radians; + grid_rotation.getAngleAxis(&angle_radians, &x, &y, &z); + glTranslatef(selection_center.mV[VX], selection_center.mV[VY], selection_center.mV[VZ]); + glRotatef(angle_radians * RAD_TO_DEG, x, y, z); + F32 sz = mGridSizeMeters; F32 tiles = sz; glMatrixMode(GL_TEXTURE); @@ -1608,20 +1624,118 @@ void LLManipTranslate::renderGrid(F32 x, F32 y, F32 size, F32 r, F32 g, F32 b, F } +void LLManipTranslate::highlightIntersection(LLVector3 normal, + LLVector3 selection_center, + LLQuaternion grid_rotation, + LLColor4 inner_color) +{ + if (!gSavedSettings.getBOOL("GridCrossSections")) + { + return; + } + + U32 types[] = { LLRenderPass::PASS_SIMPLE, LLRenderPass::PASS_ALPHA, LLRenderPass::PASS_FULLBRIGHT }; + + GLuint stencil_mask = 0xFFFFFFFF; + //stencil in volumes + { + glStencilMask(stencil_mask); + glClearStencil(1); + glClear(GL_STENCIL_BUFFER_BIT); + LLGLEnable cull_face(GL_CULL_FACE); + LLGLEnable stencil(GL_STENCIL_TEST); + LLGLDepthTest depth (GL_TRUE, GL_FALSE, GL_ALWAYS); + glStencilFunc(GL_ALWAYS, 0, stencil_mask); + glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); + LLGLDisable tex(GL_TEXTURE_2D); + glColor4f(1,1,1,1); + + //setup clip plane + normal = normal * grid_rotation; + if (normal * (gCamera->getOrigin()-selection_center) < 0) + { + normal = -normal; + } + F32 d = -(selection_center * normal); + F64 plane[] = { normal.mV[0], normal.mV[1], normal.mV[2], d }; + LLGLEnable clip(GL_CLIP_PLANE0); + glClipPlane(GL_CLIP_PLANE0, plane); + + BOOL particles = gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_PARTICLES); + BOOL clouds = gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_CLOUDS); + + if (particles) + { + LLPipeline::toggleRenderType(LLPipeline::RENDER_TYPE_PARTICLES); + } + if (clouds) + { + LLPipeline::toggleRenderType(LLPipeline::RENDER_TYPE_CLOUDS); + } + + //stencil in volumes + glStencilOp(GL_INCR, GL_INCR, GL_INCR); + glCullFace(GL_FRONT); + for (U32 i = 0; i < 3; i++) + { + gPipeline.renderObjects(types[i], LLVertexBuffer::MAP_VERTEX, FALSE); + } + + glStencilOp(GL_DECR, GL_DECR, GL_DECR); + glCullFace(GL_BACK); + for (U32 i = 0; i < 3; i++) + { + gPipeline.renderObjects(types[i], LLVertexBuffer::MAP_VERTEX, FALSE); + } + + if (particles) + { + LLPipeline::toggleRenderType(LLPipeline::RENDER_TYPE_PARTICLES); + } + if (clouds) + { + LLPipeline::toggleRenderType(LLPipeline::RENDER_TYPE_CLOUDS); + } + + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + } + + glPushMatrix(); + + F32 x,y,z,angle_radians; + grid_rotation.getAngleAxis(&angle_radians, &x, &y, &z); + glTranslatef(selection_center.mV[VX], selection_center.mV[VY], selection_center.mV[VZ]); + glRotatef(angle_radians * RAD_TO_DEG, x, y, z); + + F32 sz = mGridSizeMeters; + F32 tiles = sz; + + //draw volume/plane intersections + { + LLGLDisable tex(GL_TEXTURE_2D); + LLGLDepthTest depth(GL_FALSE); + LLGLEnable stencil(GL_STENCIL_TEST); + glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); + glStencilFunc(GL_EQUAL, 0, stencil_mask); + renderGrid(0,0,tiles,inner_color.mV[0], inner_color.mV[1], inner_color.mV[2], 0.25f); + } + + glPopMatrix(); +} void LLManipTranslate::renderText() { - if (gSelectMgr->getRootObjectCount() && !gSelectMgr->selectionIsAttachment()) + if (mObjectSelection->getRootObjectCount() && !mObjectSelection->isAttachment()) { LLVector3 pos = getPivotPoint(); renderXYZ(pos); } else { - LLViewerObject* objectp = gSelectMgr->getFirstRootObject(); + LLViewerObject* objectp = mObjectSelection->getFirstRootObject(); if(!objectp) { - objectp = gSelectMgr->getFirstObject(); + objectp = mObjectSelection->getFirstObject(); } if (objectp) @@ -1640,7 +1754,7 @@ void LLManipTranslate::renderTranslationHandles() gSelectMgr->getGrid(grid_origin, grid_rotation, grid_scale); LLVector3 at_axis; - if (gSelectMgr->getSelectType() == SELECT_TYPE_HUD) + if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD) { at_axis = LLVector3::x_axis * ~grid_rotation; } @@ -1676,13 +1790,13 @@ void LLManipTranslate::renderTranslationHandles() mPlaneManipPositions.mV[VZ] = -1.f; } - LLViewerObject *first_object = gSelectMgr->getFirstMoveableObject(TRUE); + LLViewerObject *first_object = mObjectSelection->getFirstMoveableObject(TRUE); if (!first_object) return; LLVector3 selection_center = getPivotPoint(); // Drag handles - if (gSelectMgr->getSelectType() == SELECT_TYPE_HUD) + if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD) { mArrowLengthMeters = mAxisArrowLength / gViewerWindow->getWindowHeight(); mArrowLengthMeters /= gAgent.getAvatarObject()->mHUDCurZoom; @@ -1735,7 +1849,7 @@ void LLManipTranslate::renderTranslationHandles() LLVector3 relative_camera_dir; - if (gSelectMgr->getSelectType() == SELECT_TYPE_HUD) + if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD) { relative_camera_dir = LLVector3::x_axis * invRotation; } @@ -2007,7 +2121,7 @@ void LLManipTranslate::renderTranslationHandles() // draw arrows for deeper faces first, closer faces last LLVector3 camera_axis; - if (gSelectMgr->getSelectType() == SELECT_TYPE_HUD) + if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD) { camera_axis = LLVector3::x_axis; } -- cgit v1.1