From b815dc9aa4dc60bf405c10e426579950570d5436 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Thu, 10 Mar 2011 20:20:17 -0800 Subject: SOCIAL-530 WIP When double clicking a nearby location I want my avatar to walk to that spot Initial mouse-based steering and single click to walk --- indra/newview/lltoolpie.cpp | 221 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 183 insertions(+), 38 deletions(-) (limited to 'indra/newview/lltoolpie.cpp') diff --git a/indra/newview/lltoolpie.cpp b/indra/newview/lltoolpie.cpp index 19d7b70101..e539174a4b 100644 --- a/indra/newview/lltoolpie.cpp +++ b/indra/newview/lltoolpie.cpp @@ -79,7 +79,7 @@ static ECursorType cursor_from_parcel_media(U8 click_action); LLToolPie::LLToolPie() : LLTool(std::string("Pie")), - mGrabMouseButtonDown( FALSE ), + mMouseButtonDown( FALSE ), mMouseOutsideSlop( FALSE ), mClickAction(0), mClickActionBuyEnabled( gSavedSettings.getBOOL("ClickActionBuyEnabled") ), @@ -99,12 +99,18 @@ BOOL LLToolPie::handleAnyMouseClick(S32 x, S32 y, MASK mask, EClickType clicktyp BOOL LLToolPie::handleMouseDown(S32 x, S32 y, MASK mask) { + mMouseOutsideSlop = FALSE; + mMouseDownX = x; + mMouseDownY = y; + mLastYaw = 0.f; //left mouse down always picks transparent mPick = gViewerWindow->pickImmediate(x, y, TRUE); mPick.mKeyMask = mask; - mGrabMouseButtonDown = TRUE; + + mDragPick = mPick; + mMouseButtonDown = TRUE; - pickLeftMouseDownCallback(); + handleLeftClickPick(); return TRUE; } @@ -119,7 +125,7 @@ BOOL LLToolPie::handleRightMouseDown(S32 x, S32 y, MASK mask) // claim not handled so UI focus stays same - pickRightMouseDownCallback(); + handleRightClickPick(); return FALSE; } @@ -136,7 +142,7 @@ BOOL LLToolPie::handleScrollWheel(S32 x, S32 y, S32 clicks) } // True if you selected an object. -BOOL LLToolPie::pickLeftMouseDownCallback() +BOOL LLToolPie::handleLeftClickPick() { S32 x = mPick.mMousePt.mX; S32 y = mPick.mMousePt.mY; @@ -319,7 +325,7 @@ BOOL LLToolPie::pickLeftMouseDownCallback() if (!gSavedSettings.getBOOL("LeftClickShowMenu")) { // mouse already released - if (!mGrabMouseButtonDown) + if (!mMouseButtonDown) { return TRUE; } @@ -513,7 +519,27 @@ void LLToolPie::selectionPropertiesReceived() BOOL LLToolPie::handleHover(S32 x, S32 y, MASK mask) { + if (!mMouseOutsideSlop && mMouseButtonDown) + { + S32 delta_x = x - mMouseDownX; + S32 delta_y = y - mMouseDownY; + S32 threshold = gSavedSettings.getS32("DragAndDropDistanceThreshold"); + if (delta_x * delta_x + delta_y * delta_y > threshold * threshold) + { + startCameraSteering(); + mMouseOutsideSlop = TRUE; + setMouseCapture(TRUE); + } + } + mHoverPick = gViewerWindow->pickImmediate(x, y, FALSE); + + if (mMouseOutsideSlop) + { + steerCameraWithMouse(x, y); + return TRUE; + } + // perform a separate pick that detects transparent objects since they respond to 1-click actions LLPickInfo click_action_pick = gViewerWindow->pickImmediate(x, y, TRUE); @@ -584,37 +610,31 @@ BOOL LLToolPie::handleHover(S32 x, S32 y, MASK mask) BOOL LLToolPie::handleMouseUp(S32 x, S32 y, MASK mask) { LLViewerObject* obj = mPick.getObject(); + U8 click_action = final_click_action(obj); - handleMediaMouseUp(); + if (hasMouseCapture()) + { + setMouseCapture(FALSE); + } - U8 click_action = final_click_action(obj); - if (click_action != CLICK_ACTION_NONE) + bool media_handled_click = handleMediaMouseUp() || LLViewerMediaFocus::getInstance()->getFocus(); + bool mouse_moved = mMouseOutsideSlop; + mMouseOutsideSlop = FALSE; + mMouseButtonDown = FALSE; + + if (!media_handled_click && click_action == CLICK_ACTION_NONE && !mouse_moved) { - switch(click_action) + if (gSavedSettings.getBOOL("ClickToWalk") // click to walk enabled + && !mPick.mPosGlobal.isExactlyZero() // valid coordinates for pick + && (mPick.mPickType == LLPickInfo::PICK_LAND // we clicked on land + || mPick.mObjectID.notNull())) // or on an object { - // NOTE: mClickActionBuyEnabled flag enables/disables BUY action but setting cursor to default is okay - case CLICK_ACTION_BUY: - // NOTE: mClickActionPayEnabled flag enables/disables PAY action but setting cursor to default is okay - case CLICK_ACTION_PAY: - case CLICK_ACTION_OPEN: - case CLICK_ACTION_ZOOM: - case CLICK_ACTION_PLAY: - case CLICK_ACTION_OPEN_MEDIA: - // Because these actions open UI dialogs, we won't change - // the cursor again until the next hover and GL pick over - // the world. Keep the cursor an arrow, assuming that - // after the user moves off the UI, they won't be on the - // same object anymore. - gViewerWindow->setCursor(UI_CURSOR_ARROW); - // Make sure the hover-picked object is ignored. - //gToolTipView->resetLastHoverObject(); - break; - default: - break; + handle_go_to(); + return TRUE; } } + gViewerWindow->setCursor(UI_CURSOR_ARROW); - mGrabMouseButtonDown = FALSE; LLToolMgr::getInstance()->clearTransientTool(); gAgentCamera.setLookAt(LOOKAT_TARGET_CONVERSATION, obj); // maybe look at object/person clicked on return LLTool::handleMouseUp(x, y, mask); @@ -1276,6 +1296,7 @@ void LLToolPie::stopEditing() void LLToolPie::onMouseCaptureLost() { mMouseOutsideSlop = FALSE; + mMouseButtonDown = FALSE; handleMediaMouseUp(); } @@ -1444,8 +1465,6 @@ bool LLToolPie::handleMediaMouseUp() mMediaMouseCaptureID.setNull(); - setMouseCapture(FALSE); - result = true; } @@ -1508,7 +1527,7 @@ static ECursorType cursor_from_parcel_media(U8 click_action) // True if we handled the event. -BOOL LLToolPie::pickRightMouseDownCallback() +BOOL LLToolPie::handleRightClickPick() { S32 x = mPick.mMousePt.mX; S32 y = mPick.mMousePt.mY; @@ -1630,10 +1649,136 @@ BOOL LLToolPie::pickRightMouseDownCallback() void LLToolPie::showVisualContextMenuEffect() { - // VEFFECT: ShowPie - LLHUDEffectSpiral *effectp = (LLHUDEffectSpiral *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_SPHERE, TRUE); - effectp->setPositionGlobal(mPick.mPosGlobal); - effectp->setColor(LLColor4U(gAgent.getEffectColor())); - effectp->setDuration(0.25f); + // VEFFECT: ShowPie + LLHUDEffectSpiral *effectp = (LLHUDEffectSpiral *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_SPHERE, TRUE); + effectp->setPositionGlobal(mPick.mPosGlobal); + effectp->setColor(LLColor4U(gAgent.getEffectColor())); + effectp->setDuration(0.25f); +} + + +LLVector3 intersect_ray_with_sphere( const LLVector3& ray_pt, const LLVector3& ray_dir, const LLVector3& sphere_center, F32 sphere_radius) +{ + // from http://www.siggraph.org/education/materials/HyperGraph/raytrace/rtinter1.htm + LLVector3 sphere_to_ray_start_vec = ray_pt - sphere_center; + F32 B = 2.f * ray_dir * sphere_to_ray_start_vec; + F32 C = sphere_to_ray_start_vec.lengthSquared() - (sphere_radius * sphere_radius); + + LLVector3 intersection_pt; + + F32 discriminant = B*B - 4.f*C; + if (discriminant < 0.f) + { + // no intersection, compute closest intersection point + LLVector3 ray_to_sphere(sphere_to_ray_start_vec * -1.f); + + LLVector3 ray_orthogonal_dir = ray_pt + projected_vec(ray_to_sphere, ray_dir) - sphere_center; + ray_orthogonal_dir.normalize(); + intersection_pt = sphere_center + ray_orthogonal_dir * sphere_radius; + } + else + { + F32 t0 = (-B - sqrtf(discriminant)) / 2.f; + if (t0 > 0.f) + { + intersection_pt = ray_pt + ray_dir * t0; + } + else + { + F32 t1 = (-B + sqrtf(discriminant)) / 2.f; + intersection_pt = ray_pt + ray_dir * t1; + } + } + + return intersection_pt; + //LLVector3 ray_pt_to_center = sphere_center - ray_pt; + //F32 center_distance = ray_pt_to_center.normVec(); + + //F32 dot = ray_dir * ray_pt_to_center; + + //if (dot == 0.f) + //{ + // return LLVector3::zero; + //} + + //// point which ray hits plane centered on sphere origin, facing ray origin + //LLVector3 intersection_sphere_plane = ray_pt + (ray_dir * center_distance / dot); + //// vector from sphere origin to the point, normalized to sphere radius + //LLVector3 sphere_center_to_intersection = (intersection_sphere_plane - sphere_center) / sphere_radius; + + //F32 dist_squared = sphere_center_to_intersection.magVecSquared(); + //LLVector3 result; + + //if (dist_squared > 1.f) + //{ + // result = sphere_center_to_intersection; + // result.normVec(); + //} + //else + //{ + // result = sphere_center_to_intersection - ray_dir * sqrtf(1.f - dist_squared); + //} + + //return sphere_center + (result * sphere_radius); } + +void LLToolPie::startCameraSteering() +{ + mMouseSteerX = mMouseDownX; + mMouseSteerY = mMouseDownY; +} + +void LLToolPie::steerCameraWithMouse(S32 x, S32 y) +{ + const F32 MIN_ROTATION_RADIUS = 1.f; + + const LLVector3 pick_pos = gAgent.getPosAgentFromGlobal(mDragPick.mPosGlobal); + const LLVector3 rotation_center = gAgent.getFrameAgent().getOrigin(); + const LLVector3 rotation_up_axis(gAgent.getReferenceUpVector()); + + LLVector3 pick_offset = pick_pos - rotation_center; + F32 up_distance = pick_offset * rotation_up_axis; + LLVector3 object_rotation_center = rotation_center + rotation_up_axis * up_distance; + F32 pick_distance_from_rotation_center = llclamp(dist_vec(pick_pos, object_rotation_center), MIN_ROTATION_RADIUS, F32_MAX); + + LLVector3 screen_rotation_up_axis = rotation_up_axis - projected_vec(rotation_up_axis, LLViewerCamera::instance().getAtAxis()); + screen_rotation_up_axis.normalize(); + LLVector3 screen_rotation_left_axis = screen_rotation_up_axis % LLViewerCamera::instance().getAtAxis(); + + LLVector3 mouse_ray = gViewerWindow->mouseDirectionGlobal(x, y); + mouse_ray = mouse_ray - projected_vec(mouse_ray, rotation_up_axis); + mouse_ray.normalize(); + + LLVector3 old_mouse_ray = gViewerWindow->mouseDirectionGlobal(mMouseSteerX, mMouseSteerY); + old_mouse_ray = old_mouse_ray - projected_vec(old_mouse_ray, rotation_up_axis); + old_mouse_ray.normalize(); + + LLVector3 camera_pos = gAgentCamera.getCameraPositionAgent(); + LLVector3 camera_to_rotation_center = object_rotation_center - camera_pos; + LLVector3 adjusted_camera_pos = camera_pos + projected_vec(camera_to_rotation_center, rotation_up_axis); + LLVector3 rotation_fwd_axis = LLViewerCamera::instance().getAtAxis() - projected_vec(LLViewerCamera::instance().getAtAxis(), rotation_up_axis); + rotation_fwd_axis.normalize(); + F64 pick_dist = dist_vec(pick_pos, adjusted_camera_pos); + LLVector3 mouse_on_sphere = intersect_ray_with_sphere(adjusted_camera_pos + (mouse_ray * pick_dist * 1.1f), + -1.f * mouse_ray, + object_rotation_center, + pick_distance_from_rotation_center); + LLVector3 old_mouse_on_sphere = intersect_ray_with_sphere(adjusted_camera_pos + (old_mouse_ray * pick_dist * 1.1f), + -1.f * old_mouse_ray, + object_rotation_center, + pick_distance_from_rotation_center); + + + LLVector3 rotation_furthest_pt = object_rotation_center + pick_distance_from_rotation_center * rotation_fwd_axis; + F32 mouse_lateral_distance = llclamp(((mouse_on_sphere - rotation_furthest_pt) * screen_rotation_left_axis) / pick_distance_from_rotation_center, -1.f, 1.f); + F32 old_mouse_lateral_distance = llclamp(((old_mouse_on_sphere - rotation_furthest_pt) * screen_rotation_left_axis) / pick_distance_from_rotation_center, -1.f, 1.f); + + F32 yaw_angle = -1.f * asinf(mouse_lateral_distance); + F32 old_yaw_angle = -1.f * asinf(old_mouse_lateral_distance); + + // apply delta + gAgent.yaw(yaw_angle - old_yaw_angle); + mMouseSteerX = x; + mMouseSteerY = y; +} \ No newline at end of file -- cgit v1.2.3 From 1c5d2516e0d926c8bd0bc2faad0f8ccaa2725339 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 11 Mar 2011 00:21:22 -0800 Subject: SOCIAL-530 WIP When double clicking a nearby location I want my avatar to walk to that spot can drag objects in front of avatar in opposite direction now reliably release mouse capture min rotation radius is now scaled by camera distance from rotation center --- indra/newview/lltoolpie.cpp | 125 ++++++++++++++++++-------------------------- 1 file changed, 50 insertions(+), 75 deletions(-) (limited to 'indra/newview/lltoolpie.cpp') diff --git a/indra/newview/lltoolpie.cpp b/indra/newview/lltoolpie.cpp index e539174a4b..c52111ab54 100644 --- a/indra/newview/lltoolpie.cpp +++ b/indra/newview/lltoolpie.cpp @@ -102,7 +102,7 @@ BOOL LLToolPie::handleMouseDown(S32 x, S32 y, MASK mask) mMouseOutsideSlop = FALSE; mMouseDownX = x; mMouseDownY = y; - mLastYaw = 0.f; + //left mouse down always picks transparent mPick = gViewerWindow->pickImmediate(x, y, TRUE); mPick.mKeyMask = mask; @@ -612,11 +612,6 @@ BOOL LLToolPie::handleMouseUp(S32 x, S32 y, MASK mask) LLViewerObject* obj = mPick.getObject(); U8 click_action = final_click_action(obj); - if (hasMouseCapture()) - { - setMouseCapture(FALSE); - } - bool media_handled_click = handleMediaMouseUp() || LLViewerMediaFocus::getInstance()->getFocus(); bool mouse_moved = mMouseOutsideSlop; mMouseOutsideSlop = FALSE; @@ -634,6 +629,10 @@ BOOL LLToolPie::handleMouseUp(S32 x, S32 y, MASK mask) } } gViewerWindow->setCursor(UI_CURSOR_ARROW); + if (hasMouseCapture()) + { + setMouseCapture(FALSE); + } LLToolMgr::getInstance()->clearTransientTool(); gAgentCamera.setLookAt(LOOKAT_TARGET_CONVERSATION, obj); // maybe look at object/person clicked on @@ -1657,28 +1656,16 @@ void LLToolPie::showVisualContextMenuEffect() } -LLVector3 intersect_ray_with_sphere( const LLVector3& ray_pt, const LLVector3& ray_dir, const LLVector3& sphere_center, F32 sphere_radius) +bool intersect_ray_with_sphere( const LLVector3& ray_pt, const LLVector3& ray_dir, const LLVector3& sphere_center, F32 sphere_radius, LLVector3& intersection_pt) { - // from http://www.siggraph.org/education/materials/HyperGraph/raytrace/rtinter1.htm + // do ray/sphere intersection by solving quadratic equation LLVector3 sphere_to_ray_start_vec = ray_pt - sphere_center; F32 B = 2.f * ray_dir * sphere_to_ray_start_vec; F32 C = sphere_to_ray_start_vec.lengthSquared() - (sphere_radius * sphere_radius); - LLVector3 intersection_pt; - F32 discriminant = B*B - 4.f*C; - if (discriminant < 0.f) - { - // no intersection, compute closest intersection point - LLVector3 ray_to_sphere(sphere_to_ray_start_vec * -1.f); - - LLVector3 ray_orthogonal_dir = ray_pt + projected_vec(ray_to_sphere, ray_dir) - sphere_center; - ray_orthogonal_dir.normalize(); - - intersection_pt = sphere_center + ray_orthogonal_dir * sphere_radius; - } - else - { + if (discriminant > 0.f) + { // intersection detected, now find closest one F32 t0 = (-B - sqrtf(discriminant)) / 2.f; if (t0 > 0.f) { @@ -1689,49 +1676,25 @@ LLVector3 intersect_ray_with_sphere( const LLVector3& ray_pt, const LLVector3& r F32 t1 = (-B + sqrtf(discriminant)) / 2.f; intersection_pt = ray_pt + ray_dir * t1; } + return true; } - return intersection_pt; - //LLVector3 ray_pt_to_center = sphere_center - ray_pt; - //F32 center_distance = ray_pt_to_center.normVec(); - - //F32 dot = ray_dir * ray_pt_to_center; - - //if (dot == 0.f) - //{ - // return LLVector3::zero; - //} - - //// point which ray hits plane centered on sphere origin, facing ray origin - //LLVector3 intersection_sphere_plane = ray_pt + (ray_dir * center_distance / dot); - //// vector from sphere origin to the point, normalized to sphere radius - //LLVector3 sphere_center_to_intersection = (intersection_sphere_plane - sphere_center) / sphere_radius; - - //F32 dist_squared = sphere_center_to_intersection.magVecSquared(); - //LLVector3 result; - - //if (dist_squared > 1.f) - //{ - // result = sphere_center_to_intersection; - // result.normVec(); - //} - //else - //{ - // result = sphere_center_to_intersection - ray_dir * sqrtf(1.f - dist_squared); - //} - - //return sphere_center + (result * sphere_radius); + return false; } void LLToolPie::startCameraSteering() { mMouseSteerX = mMouseDownX; mMouseSteerY = mMouseDownY; + const LLVector3 camera_to_rotation_center = gAgent.getFrameAgent().getOrigin() - LLViewerCamera::instance().getOrigin(); + const LLVector3 rotation_center_to_pick = gAgent.getPosAgentFromGlobal(mDragPick.mPosGlobal) - gAgent.getFrameAgent().getOrigin(); + + mClockwise = camera_to_rotation_center * rotation_center_to_pick < 0.f; } void LLToolPie::steerCameraWithMouse(S32 x, S32 y) { - const F32 MIN_ROTATION_RADIUS = 1.f; + const F32 MIN_ROTATION_RADIUS_FRACTION = 0.2f; const LLVector3 pick_pos = gAgent.getPosAgentFromGlobal(mDragPick.mPosGlobal); const LLVector3 rotation_center = gAgent.getFrameAgent().getOrigin(); @@ -1740,7 +1703,8 @@ void LLToolPie::steerCameraWithMouse(S32 x, S32 y) LLVector3 pick_offset = pick_pos - rotation_center; F32 up_distance = pick_offset * rotation_up_axis; LLVector3 object_rotation_center = rotation_center + rotation_up_axis * up_distance; - F32 pick_distance_from_rotation_center = llclamp(dist_vec(pick_pos, object_rotation_center), MIN_ROTATION_RADIUS, F32_MAX); + F32 min_rotation_radius = MIN_ROTATION_RADIUS_FRACTION * dist_vec(rotation_center, LLViewerCamera::instance().getOrigin());; + F32 pick_distance_from_rotation_center = llclamp(dist_vec(pick_pos, object_rotation_center), min_rotation_radius, F32_MAX); LLVector3 screen_rotation_up_axis = rotation_up_axis - projected_vec(rotation_up_axis, LLViewerCamera::instance().getAtAxis()); screen_rotation_up_axis.normalize(); @@ -1760,25 +1724,36 @@ void LLToolPie::steerCameraWithMouse(S32 x, S32 y) LLVector3 rotation_fwd_axis = LLViewerCamera::instance().getAtAxis() - projected_vec(LLViewerCamera::instance().getAtAxis(), rotation_up_axis); rotation_fwd_axis.normalize(); F64 pick_dist = dist_vec(pick_pos, adjusted_camera_pos); - LLVector3 mouse_on_sphere = intersect_ray_with_sphere(adjusted_camera_pos + (mouse_ray * pick_dist * 1.1f), - -1.f * mouse_ray, - object_rotation_center, - pick_distance_from_rotation_center); - LLVector3 old_mouse_on_sphere = intersect_ray_with_sphere(adjusted_camera_pos + (old_mouse_ray * pick_dist * 1.1f), - -1.f * old_mouse_ray, - object_rotation_center, - pick_distance_from_rotation_center); - - - LLVector3 rotation_furthest_pt = object_rotation_center + pick_distance_from_rotation_center * rotation_fwd_axis; - F32 mouse_lateral_distance = llclamp(((mouse_on_sphere - rotation_furthest_pt) * screen_rotation_left_axis) / pick_distance_from_rotation_center, -1.f, 1.f); - F32 old_mouse_lateral_distance = llclamp(((old_mouse_on_sphere - rotation_furthest_pt) * screen_rotation_left_axis) / pick_distance_from_rotation_center, -1.f, 1.f); - - F32 yaw_angle = -1.f * asinf(mouse_lateral_distance); - F32 old_yaw_angle = -1.f * asinf(old_mouse_lateral_distance); - - // apply delta - gAgent.yaw(yaw_angle - old_yaw_angle); - mMouseSteerX = x; - mMouseSteerY = y; + + LLVector3 mouse_on_sphere; + bool mouse_hit_sphere = intersect_ray_with_sphere(adjusted_camera_pos + (mouse_ray * pick_dist * 1.1f), + -1.f * mouse_ray, + object_rotation_center, + pick_distance_from_rotation_center, + mouse_on_sphere); + + LLVector3 old_mouse_on_sphere; + intersect_ray_with_sphere(adjusted_camera_pos + (old_mouse_ray * pick_dist * 1.1f), + -1.f * old_mouse_ray, + object_rotation_center, + pick_distance_from_rotation_center, + old_mouse_on_sphere); + + if (mouse_hit_sphere) + { + + LLVector3 rotation_furthest_pt = object_rotation_center + pick_distance_from_rotation_center * rotation_fwd_axis; + F32 mouse_lateral_distance = llclamp(((mouse_on_sphere - rotation_furthest_pt) * screen_rotation_left_axis) / pick_distance_from_rotation_center, -1.f, 1.f); + F32 old_mouse_lateral_distance = llclamp(((old_mouse_on_sphere - rotation_furthest_pt) * screen_rotation_left_axis) / pick_distance_from_rotation_center, -1.f, 1.f); + + F32 yaw_angle = -1.f * asinf(mouse_lateral_distance); + F32 old_yaw_angle = -1.f * asinf(old_mouse_lateral_distance); + + F32 delta_angle = yaw_angle - old_yaw_angle; + if (mClockwise) delta_angle *= -1.f; + + gAgent.yaw(delta_angle); + mMouseSteerX = x; + mMouseSteerY = y; + } } \ No newline at end of file -- cgit v1.2.3 From 34807845ab6c6440d17624e1cbf042472d25ce9e Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 11 Mar 2011 11:20:20 -0800 Subject: fixed avatar picker url fixed linux build --- indra/newview/lltoolpie.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/newview/lltoolpie.cpp') diff --git a/indra/newview/lltoolpie.cpp b/indra/newview/lltoolpie.cpp index c52111ab54..c98feca91c 100644 --- a/indra/newview/lltoolpie.cpp +++ b/indra/newview/lltoolpie.cpp @@ -1756,4 +1756,4 @@ void LLToolPie::steerCameraWithMouse(S32 x, S32 y) mMouseSteerX = x; mMouseSteerY = y; } -} \ No newline at end of file +} -- cgit v1.2.3 From 426ff3fbbbd5b274c7258adabfea2802d93d27fd Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 11 Mar 2011 16:46:13 -0800 Subject: SOCIAL-690 FIX Mouse captured by camera after clicking on scripted object --- indra/newview/lltoolpie.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'indra/newview/lltoolpie.cpp') diff --git a/indra/newview/lltoolpie.cpp b/indra/newview/lltoolpie.cpp index c98feca91c..b6e99ac09f 100644 --- a/indra/newview/lltoolpie.cpp +++ b/indra/newview/lltoolpie.cpp @@ -79,8 +79,8 @@ static ECursorType cursor_from_parcel_media(U8 click_action); LLToolPie::LLToolPie() : LLTool(std::string("Pie")), - mMouseButtonDown( FALSE ), - mMouseOutsideSlop( FALSE ), + mMouseButtonDown( false ), + mMouseOutsideSlop( false ), mClickAction(0), mClickActionBuyEnabled( gSavedSettings.getBOOL("ClickActionBuyEnabled") ), mClickActionPayEnabled( gSavedSettings.getBOOL("ClickActionPayEnabled") ) @@ -108,7 +108,7 @@ BOOL LLToolPie::handleMouseDown(S32 x, S32 y, MASK mask) mPick.mKeyMask = mask; mDragPick = mPick; - mMouseButtonDown = TRUE; + mMouseButtonDown = true; handleLeftClickPick(); @@ -310,6 +310,7 @@ BOOL LLToolPie::handleLeftClickPick() ) { gGrabTransientTool = this; + mMouseButtonDown = false; LLToolMgr::getInstance()->getCurrentToolset()->selectTool( LLToolGrab::getInstance() ); return LLToolGrab::getInstance()->handleObjectHit( mPick ); } @@ -327,7 +328,7 @@ BOOL LLToolPie::handleLeftClickPick() // mouse already released if (!mMouseButtonDown) { - return TRUE; + return true; } while( object && object->isAttachment() && !object->flagHandleTouch()) @@ -339,9 +340,10 @@ BOOL LLToolPie::handleLeftClickPick() } object = (LLViewerObject*)object->getParent(); } - if (object && object == gAgentAvatarp) + if (object && object == gAgentAvatarp && !gSavedSettings.getBOOL("ClickToWalk")) { // we left clicked on avatar, switch to focus mode + mMouseButtonDown = false; LLToolMgr::getInstance()->setTransientTool(LLToolCamera::getInstance()); gViewerWindow->hideCursor(); LLToolCamera::getInstance()->setMouseCapture(TRUE); @@ -537,6 +539,7 @@ BOOL LLToolPie::handleHover(S32 x, S32 y, MASK mask) if (mMouseOutsideSlop) { steerCameraWithMouse(x, y); + gViewerWindow->setCursor(UI_CURSOR_TOOLGRAB); return TRUE; } @@ -614,8 +617,8 @@ BOOL LLToolPie::handleMouseUp(S32 x, S32 y, MASK mask) bool media_handled_click = handleMediaMouseUp() || LLViewerMediaFocus::getInstance()->getFocus(); bool mouse_moved = mMouseOutsideSlop; - mMouseOutsideSlop = FALSE; - mMouseButtonDown = FALSE; + mMouseOutsideSlop = false; + mMouseButtonDown = false; if (!media_handled_click && click_action == CLICK_ACTION_NONE && !mouse_moved) { @@ -1294,8 +1297,8 @@ void LLToolPie::stopEditing() void LLToolPie::onMouseCaptureLost() { - mMouseOutsideSlop = FALSE; - mMouseButtonDown = FALSE; + mMouseOutsideSlop = false; + mMouseButtonDown = false; handleMediaMouseUp(); } @@ -1698,7 +1701,8 @@ void LLToolPie::steerCameraWithMouse(S32 x, S32 y) const LLVector3 pick_pos = gAgent.getPosAgentFromGlobal(mDragPick.mPosGlobal); const LLVector3 rotation_center = gAgent.getFrameAgent().getOrigin(); - const LLVector3 rotation_up_axis(gAgent.getReferenceUpVector()); + // FIXME: get this to work with camera tilt (i.e. sitting on a rotating object) + const LLVector3 rotation_up_axis(LLVector3::z_axis); LLVector3 pick_offset = pick_pos - rotation_center; F32 up_distance = pick_offset * rotation_up_axis; -- cgit v1.2.3 From 184c454222ff509629de8abc49a72122c75f0487 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 11 Mar 2011 20:44:57 -0800 Subject: visual feedback for click to walk --- indra/newview/lltoolpie.cpp | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) (limited to 'indra/newview/lltoolpie.cpp') diff --git a/indra/newview/lltoolpie.cpp b/indra/newview/lltoolpie.cpp index b6e99ac09f..5bfc69016b 100644 --- a/indra/newview/lltoolpie.cpp +++ b/indra/newview/lltoolpie.cpp @@ -42,6 +42,7 @@ #include "llfloaterreg.h" #include "llfloaterscriptdebug.h" #include "lltooltip.h" +#include "llhudeffectblob.h" #include "llhudeffecttrail.h" #include "llhudmanager.h" #include "llkeyboard.h" @@ -81,6 +82,8 @@ LLToolPie::LLToolPie() : LLTool(std::string("Pie")), mMouseButtonDown( false ), mMouseOutsideSlop( false ), + mMouseSteerX(-1), + mMouseSteerY(-1), mClickAction(0), mClickActionBuyEnabled( gSavedSettings.getBOOL("ClickActionBuyEnabled") ), mClickActionPayEnabled( gSavedSettings.getBOOL("ClickActionPayEnabled") ) @@ -529,14 +532,12 @@ BOOL LLToolPie::handleHover(S32 x, S32 y, MASK mask) if (delta_x * delta_x + delta_y * delta_y > threshold * threshold) { startCameraSteering(); - mMouseOutsideSlop = TRUE; - setMouseCapture(TRUE); } } mHoverPick = gViewerWindow->pickImmediate(x, y, FALSE); - if (mMouseOutsideSlop) + if (inCameraSteerMode()) { steerCameraWithMouse(x, y); gViewerWindow->setCursor(UI_CURSOR_TOOLGRAB); @@ -617,16 +618,23 @@ BOOL LLToolPie::handleMouseUp(S32 x, S32 y, MASK mask) bool media_handled_click = handleMediaMouseUp() || LLViewerMediaFocus::getInstance()->getFocus(); bool mouse_moved = mMouseOutsideSlop; - mMouseOutsideSlop = false; + stopCameraSteering(); mMouseButtonDown = false; if (!media_handled_click && click_action == CLICK_ACTION_NONE && !mouse_moved) { if (gSavedSettings.getBOOL("ClickToWalk") // click to walk enabled + && !gFocusMgr.getKeyboardFocus() // focus is on world && !mPick.mPosGlobal.isExactlyZero() // valid coordinates for pick && (mPick.mPickType == LLPickInfo::PICK_LAND // we clicked on land || mPick.mObjectID.notNull())) // or on an object { + gAgentCamera.setFocusOnAvatar(TRUE, TRUE); + mAutoPilotDestination = (LLHUDEffectBlob *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_BLOB, FALSE); + mAutoPilotDestination->setPositionGlobal(mPick.mPosGlobal); + mAutoPilotDestination->setColor(LLColor4U::white); + mAutoPilotDestination->setDuration(5.f); + handle_go_to(); return TRUE; } @@ -1297,11 +1305,21 @@ void LLToolPie::stopEditing() void LLToolPie::onMouseCaptureLost() { - mMouseOutsideSlop = false; + stopCameraSteering(); mMouseButtonDown = false; handleMediaMouseUp(); } +void LLToolPie::stopCameraSteering() +{ + mMouseOutsideSlop = false; + mMouseSteerGrabPoint = NULL; +} + +bool LLToolPie::inCameraSteerMode() +{ + return mMouseButtonDown && mMouseOutsideSlop; +} // true if x,y outside small box around start_x,start_y BOOL LLToolPie::outsideSlop(S32 x, S32 y, S32 start_x, S32 start_y) @@ -1687,12 +1705,19 @@ bool intersect_ray_with_sphere( const LLVector3& ray_pt, const LLVector3& ray_di void LLToolPie::startCameraSteering() { + mMouseOutsideSlop = true; + setMouseCapture(TRUE); + mMouseSteerX = mMouseDownX; mMouseSteerY = mMouseDownY; - const LLVector3 camera_to_rotation_center = gAgent.getFrameAgent().getOrigin() - LLViewerCamera::instance().getOrigin(); - const LLVector3 rotation_center_to_pick = gAgent.getPosAgentFromGlobal(mDragPick.mPosGlobal) - gAgent.getFrameAgent().getOrigin(); + const LLVector3 camera_to_rotation_center = gAgent.getFrameAgent().getOrigin() - LLViewerCamera::instance().getOrigin(); + const LLVector3 rotation_center_to_pick = gAgent.getPosAgentFromGlobal(mDragPick.mPosGlobal) - gAgent.getFrameAgent().getOrigin(); mClockwise = camera_to_rotation_center * rotation_center_to_pick < 0.f; + mMouseSteerGrabPoint= (LLHUDEffectBlob *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_BLOB, FALSE); + mMouseSteerGrabPoint->setPositionGlobal(mPick.mPosGlobal); + mMouseSteerGrabPoint->setColor(LLColor4U::white); + mMouseSteerGrabPoint->setDuration(1000.f); } void LLToolPie::steerCameraWithMouse(S32 x, S32 y) -- cgit v1.2.3 From 5dc467b4f7940f31b0e98798eb6aa2d82a2d4919 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Sun, 13 Mar 2011 11:51:44 -0700 Subject: only enable click to steer with "ClickToWalk" is turned on --- indra/newview/lltoolpie.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/newview/lltoolpie.cpp') diff --git a/indra/newview/lltoolpie.cpp b/indra/newview/lltoolpie.cpp index 5bfc69016b..698d55836c 100644 --- a/indra/newview/lltoolpie.cpp +++ b/indra/newview/lltoolpie.cpp @@ -524,7 +524,7 @@ void LLToolPie::selectionPropertiesReceived() BOOL LLToolPie::handleHover(S32 x, S32 y, MASK mask) { - if (!mMouseOutsideSlop && mMouseButtonDown) + if (!mMouseOutsideSlop && mMouseButtonDown && gSavedSettings.getBOOL("ClickToWalk")) { S32 delta_x = x - mMouseDownX; S32 delta_y = y - mMouseDownY; @@ -1318,7 +1318,7 @@ void LLToolPie::stopCameraSteering() bool LLToolPie::inCameraSteerMode() { - return mMouseButtonDown && mMouseOutsideSlop; + return mMouseButtonDown && mMouseOutsideSlop && gSavedSettings.getBOOL("ClickToWalk"); } // true if x,y outside small box around start_x,start_y -- cgit v1.2.3 From 5038c068eac20425c702fd1dff06ccdacdec9e6f Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Mon, 14 Mar 2011 12:39:50 -0700 Subject: SOCIAL-695 FIX clicking on world to give it focus will make your avatar walk --- indra/newview/lltoolpie.cpp | 71 ++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 33 deletions(-) (limited to 'indra/newview/lltoolpie.cpp') diff --git a/indra/newview/lltoolpie.cpp b/indra/newview/lltoolpie.cpp index 698d55836c..23290e5cc6 100644 --- a/indra/newview/lltoolpie.cpp +++ b/indra/newview/lltoolpie.cpp @@ -84,6 +84,7 @@ LLToolPie::LLToolPie() mMouseOutsideSlop( false ), mMouseSteerX(-1), mMouseSteerY(-1), + mAbortClickToWalk(false), mClickAction(0), mClickActionBuyEnabled( gSavedSettings.getBOOL("ClickActionBuyEnabled") ), mClickActionPayEnabled( gSavedSettings.getBOOL("ClickActionPayEnabled") ) @@ -112,6 +113,7 @@ BOOL LLToolPie::handleMouseDown(S32 x, S32 y, MASK mask) mDragPick = mPick; mMouseButtonDown = true; + mAbortClickToWalk = false; handleLeftClickPick(); @@ -301,7 +303,12 @@ BOOL LLToolPie::handleLeftClickPick() } // put focus back "in world" - gFocusMgr.setKeyboardFocus(NULL); + if (gFocusMgr.getKeyboardFocus()) + { + // don't click to walk on attempt to give focus to world + mAbortClickToWalk = true; + gFocusMgr.setKeyboardFocus(NULL); + } BOOL touchable = (object && object->flagHandleTouch()) || (parent && parent->flagHandleTouch()); @@ -616,28 +623,28 @@ BOOL LLToolPie::handleMouseUp(S32 x, S32 y, MASK mask) LLViewerObject* obj = mPick.getObject(); U8 click_action = final_click_action(obj); - bool media_handled_click = handleMediaMouseUp() || LLViewerMediaFocus::getInstance()->getFocus(); - bool mouse_moved = mMouseOutsideSlop; + if (handleMediaMouseUp() || LLViewerMediaFocus::getInstance()->getFocus()) + { + mAbortClickToWalk = true; + } stopCameraSteering(); mMouseButtonDown = false; - if (!media_handled_click && click_action == CLICK_ACTION_NONE && !mouse_moved) + if (click_action == CLICK_ACTION_NONE // not doing 1-click action + && gSavedSettings.getBOOL("ClickToWalk") // click to walk enabled + && !mAbortClickToWalk // another behavior hasn't cancelled click to walk + && !mPick.mPosGlobal.isExactlyZero() // valid coordinates for pick + && (mPick.mPickType == LLPickInfo::PICK_LAND // we clicked on land + || mPick.mObjectID.notNull())) // or on an object { - if (gSavedSettings.getBOOL("ClickToWalk") // click to walk enabled - && !gFocusMgr.getKeyboardFocus() // focus is on world - && !mPick.mPosGlobal.isExactlyZero() // valid coordinates for pick - && (mPick.mPickType == LLPickInfo::PICK_LAND // we clicked on land - || mPick.mObjectID.notNull())) // or on an object - { - gAgentCamera.setFocusOnAvatar(TRUE, TRUE); - mAutoPilotDestination = (LLHUDEffectBlob *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_BLOB, FALSE); - mAutoPilotDestination->setPositionGlobal(mPick.mPosGlobal); - mAutoPilotDestination->setColor(LLColor4U::white); - mAutoPilotDestination->setDuration(5.f); + gAgentCamera.setFocusOnAvatar(TRUE, TRUE); + mAutoPilotDestination = (LLHUDEffectBlob *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_BLOB, FALSE); + mAutoPilotDestination->setPositionGlobal(mPick.mPosGlobal); + mAutoPilotDestination->setColor(LLColor4U::white); + mAutoPilotDestination->setDuration(5.f); - handle_go_to(); - return TRUE; - } + handle_go_to(); + return TRUE; } gViewerWindow->setCursor(UI_CURSOR_ARROW); if (hasMouseCapture()) @@ -1706,6 +1713,7 @@ bool intersect_ray_with_sphere( const LLVector3& ray_pt, const LLVector3& ray_di void LLToolPie::startCameraSteering() { mMouseOutsideSlop = true; + mAbortClickToWalk = true; setMouseCapture(TRUE); mMouseSteerX = mMouseDownX; @@ -1729,22 +1737,14 @@ void LLToolPie::steerCameraWithMouse(S32 x, S32 y) // FIXME: get this to work with camera tilt (i.e. sitting on a rotating object) const LLVector3 rotation_up_axis(LLVector3::z_axis); - LLVector3 pick_offset = pick_pos - rotation_center; - F32 up_distance = pick_offset * rotation_up_axis; - LLVector3 object_rotation_center = rotation_center + rotation_up_axis * up_distance; + LLVector3 object_rotation_center = rotation_center + parallel_component(pick_pos - rotation_center, rotation_up_axis); F32 min_rotation_radius = MIN_ROTATION_RADIUS_FRACTION * dist_vec(rotation_center, LLViewerCamera::instance().getOrigin());; F32 pick_distance_from_rotation_center = llclamp(dist_vec(pick_pos, object_rotation_center), min_rotation_radius, F32_MAX); - LLVector3 screen_rotation_up_axis = rotation_up_axis - projected_vec(rotation_up_axis, LLViewerCamera::instance().getAtAxis()); - screen_rotation_up_axis.normalize(); - LLVector3 screen_rotation_left_axis = screen_rotation_up_axis % LLViewerCamera::instance().getAtAxis(); - - LLVector3 mouse_ray = gViewerWindow->mouseDirectionGlobal(x, y); - mouse_ray = mouse_ray - projected_vec(mouse_ray, rotation_up_axis); + LLVector3 mouse_ray = orthogonal_component(gViewerWindow->mouseDirectionGlobal(x, y), rotation_up_axis); mouse_ray.normalize(); - LLVector3 old_mouse_ray = gViewerWindow->mouseDirectionGlobal(mMouseSteerX, mMouseSteerY); - old_mouse_ray = old_mouse_ray - projected_vec(old_mouse_ray, rotation_up_axis); + LLVector3 old_mouse_ray = orthogonal_component(gViewerWindow->mouseDirectionGlobal(mMouseSteerX, mMouseSteerY), rotation_up_axis); old_mouse_ray.normalize(); LLVector3 camera_pos = gAgentCamera.getCameraPositionAgent(); @@ -1752,7 +1752,7 @@ void LLToolPie::steerCameraWithMouse(S32 x, S32 y) LLVector3 adjusted_camera_pos = camera_pos + projected_vec(camera_to_rotation_center, rotation_up_axis); LLVector3 rotation_fwd_axis = LLViewerCamera::instance().getAtAxis() - projected_vec(LLViewerCamera::instance().getAtAxis(), rotation_up_axis); rotation_fwd_axis.normalize(); - F64 pick_dist = dist_vec(pick_pos, adjusted_camera_pos); + F32 pick_dist = dist_vec(pick_pos, adjusted_camera_pos); LLVector3 mouse_on_sphere; bool mouse_hit_sphere = intersect_ray_with_sphere(adjusted_camera_pos + (mouse_ray * pick_dist * 1.1f), @@ -1770,16 +1770,21 @@ void LLToolPie::steerCameraWithMouse(S32 x, S32 y) if (mouse_hit_sphere) { + // calculate rotation frame in screen space + LLVector3 screen_rotation_up_axis = orthogonal_component(rotation_up_axis, LLViewerCamera::instance().getAtAxis()); + screen_rotation_up_axis.normalize(); + + LLVector3 screen_rotation_left_axis = screen_rotation_up_axis % LLViewerCamera::instance().getAtAxis(); LLVector3 rotation_furthest_pt = object_rotation_center + pick_distance_from_rotation_center * rotation_fwd_axis; F32 mouse_lateral_distance = llclamp(((mouse_on_sphere - rotation_furthest_pt) * screen_rotation_left_axis) / pick_distance_from_rotation_center, -1.f, 1.f); F32 old_mouse_lateral_distance = llclamp(((old_mouse_on_sphere - rotation_furthest_pt) * screen_rotation_left_axis) / pick_distance_from_rotation_center, -1.f, 1.f); - F32 yaw_angle = -1.f * asinf(mouse_lateral_distance); - F32 old_yaw_angle = -1.f * asinf(old_mouse_lateral_distance); + F32 yaw_angle = asinf(mouse_lateral_distance); + F32 old_yaw_angle = asinf(old_mouse_lateral_distance); F32 delta_angle = yaw_angle - old_yaw_angle; - if (mClockwise) delta_angle *= -1.f; + if (!mClockwise) delta_angle *= -1.f; gAgent.yaw(delta_angle); mMouseSteerX = x; -- cgit v1.2.3 From a3edf75015508f6b518d6f49387a5d180554b71c Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Mon, 14 Mar 2011 12:43:46 -0700 Subject: SOCIAL-701 FIX Clicking on world while flying moves avatar to location and avatar and camera shake... --- indra/newview/lltoolpie.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'indra/newview/lltoolpie.cpp') diff --git a/indra/newview/lltoolpie.cpp b/indra/newview/lltoolpie.cpp index 23290e5cc6..65c9f2b8f6 100644 --- a/indra/newview/lltoolpie.cpp +++ b/indra/newview/lltoolpie.cpp @@ -623,6 +623,7 @@ BOOL LLToolPie::handleMouseUp(S32 x, S32 y, MASK mask) LLViewerObject* obj = mPick.getObject(); U8 click_action = final_click_action(obj); + // let media have first pass at click if (handleMediaMouseUp() || LLViewerMediaFocus::getInstance()->getFocus()) { mAbortClickToWalk = true; @@ -632,6 +633,7 @@ BOOL LLToolPie::handleMouseUp(S32 x, S32 y, MASK mask) if (click_action == CLICK_ACTION_NONE // not doing 1-click action && gSavedSettings.getBOOL("ClickToWalk") // click to walk enabled + && !gAgent.getFlying() // don't auto-navigate while flying until that works && !mAbortClickToWalk // another behavior hasn't cancelled click to walk && !mPick.mPosGlobal.isExactlyZero() // valid coordinates for pick && (mPick.mPickType == LLPickInfo::PICK_LAND // we clicked on land -- cgit v1.2.3