aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/lltoolgrab.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-09-06 18:24:57 -0500
committerJacek Antonelli2008-09-06 18:25:07 -0500
commit798d367d54a6c6379ad355bd8345fa40e31e7fe9 (patch)
tree1921f1708cd0240648c97bc02df2c2ab5f2fc41e /linden/indra/newview/lltoolgrab.cpp
parentSecond Life viewer sources 1.20.15 (diff)
downloadmeta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.zip
meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.gz
meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.bz2
meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.xz
Second Life viewer sources 1.21.0-RC
Diffstat (limited to '')
-rw-r--r--linden/indra/newview/lltoolgrab.cpp345
1 files changed, 264 insertions, 81 deletions
diff --git a/linden/indra/newview/lltoolgrab.cpp b/linden/indra/newview/lltoolgrab.cpp
index a8e789d..74810d1 100644
--- a/linden/indra/newview/lltoolgrab.cpp
+++ b/linden/indra/newview/lltoolgrab.cpp
@@ -75,15 +75,12 @@ extern BOOL gDebugClicks;
75// Methods 75// Methods
76// 76//
77LLToolGrab::LLToolGrab( LLToolComposite* composite ) 77LLToolGrab::LLToolGrab( LLToolComposite* composite )
78: LLTool( "Grab", composite ), 78: LLTool( std::string("Grab"), composite ),
79 mMode( GRAB_INACTIVE ), 79 mMode( GRAB_INACTIVE ),
80 mVerticalDragging( FALSE ), 80 mVerticalDragging( FALSE ),
81 mHitLand(FALSE),
82 mHitObjectID(),
83 mGrabObject( NULL ),
84 mMouseDownX( -1 ),
85 mMouseDownY( -1 ),
86 mHasMoved( FALSE ), 81 mHasMoved( FALSE ),
82 mOutsideSlop(FALSE),
83 mDeselectedThisClick(FALSE),
87 mSpinGrabbing( FALSE ), 84 mSpinGrabbing( FALSE ),
88 mSpinRotation(), 85 mSpinRotation(),
89 mHideBuildHighlight(FALSE) 86 mHideBuildHighlight(FALSE)
@@ -131,24 +128,23 @@ BOOL LLToolGrab::handleMouseDown(S32 x, S32 y, MASK mask)
131 llinfos << "LLToolGrab handleMouseDown" << llendl; 128 llinfos << "LLToolGrab handleMouseDown" << llendl;
132 } 129 }
133 130
134 mHitLand = FALSE;
135
136 // call the base class to propogate info to sim 131 // call the base class to propogate info to sim
137 LLTool::handleMouseDown(x, y, mask); 132 LLTool::handleMouseDown(x, y, mask);
138 133
139 if (!gAgent.leftButtonGrabbed()) 134 if (!gAgent.leftButtonGrabbed())
140 { 135 {
141 // can grab transparent objects (how touch event propagates, scripters rely on this) 136 // can grab transparent objects (how touch event propagates, scripters rely on this)
142 gViewerWindow->hitObjectOrLandGlobalAsync(x, y, mask, pickCallback, TRUE); 137 gViewerWindow->pickAsync(x, y, mask, pickCallback, TRUE, TRUE);
143 } 138 }
144 return TRUE; 139 return TRUE;
145} 140}
146 141
147void LLToolGrab::pickCallback(S32 x, S32 y, MASK mask) 142void LLToolGrab::pickCallback(const LLPickInfo& pick_info)
148{ 143{
149 LLViewerObject *objectp = gObjectList.findObject( gLastHitObjectID ); 144 LLToolGrab::getInstance()->mGrabPick = pick_info;
145 LLViewerObject *objectp = pick_info.getObject();
150 146
151 BOOL extend_select = (mask & MASK_SHIFT); 147 BOOL extend_select = (pick_info.mKeyMask & MASK_SHIFT);
152 148
153 if (!extend_select && !LLSelectMgr::getInstance()->getSelection()->isEmpty()) 149 if (!extend_select && !LLSelectMgr::getInstance()->getSelection()->isEmpty())
154 { 150 {
@@ -165,23 +161,22 @@ void LLToolGrab::pickCallback(S32 x, S32 y, MASK mask)
165 { 161 {
166 LLToolGrab::getInstance()->setMouseCapture(TRUE); 162 LLToolGrab::getInstance()->setMouseCapture(TRUE);
167 LLToolGrab::getInstance()->mMode = GRAB_NOOBJECT; 163 LLToolGrab::getInstance()->mMode = GRAB_NOOBJECT;
168 LLToolGrab::getInstance()->mHitObjectID.setNull(); 164 LLToolGrab::getInstance()->mGrabPick.mObjectID.setNull();
169 } 165 }
170 else 166 else
171 { 167 {
172 LLToolGrab::getInstance()->handleObjectHit(objectp, x, y, mask); 168 LLToolGrab::getInstance()->handleObjectHit(LLToolGrab::getInstance()->mGrabPick);
173 } 169 }
174} 170}
175 171
176BOOL LLToolGrab::handleObjectHit(LLViewerObject *objectp, S32 x, S32 y, MASK mask) 172BOOL LLToolGrab::handleObjectHit(const LLPickInfo& info)
177{ 173{
178 mMouseDownX = x; 174 mGrabPick = info;
179 mMouseDownY = y; 175 LLViewerObject* objectp = mGrabPick.getObject();
180 mMouseMask = mask;
181 176
182 if (gDebugClicks) 177 if (gDebugClicks)
183 { 178 {
184 llinfos << "LLToolGrab handleObjectHit " << mMouseDownX << "," << mMouseDownY << llendl; 179 llinfos << "LLToolGrab handleObjectHit " << info.mMousePt.mX << "," << info.mMousePt.mY << llendl;
185 } 180 }
186 181
187 if (NULL == objectp) // unexpected 182 if (NULL == objectp) // unexpected
@@ -202,8 +197,6 @@ BOOL LLToolGrab::handleObjectHit(LLViewerObject *objectp, S32 x, S32 y, MASK mas
202 197
203 setMouseCapture( TRUE ); 198 setMouseCapture( TRUE );
204 199
205 mHitObjectID = objectp->getID();
206
207 // Grabs always start from the root 200 // Grabs always start from the root
208 // objectp = (LLViewerObject *)objectp->getRoot(); 201 // objectp = (LLViewerObject *)objectp->getRoot();
209 202
@@ -223,13 +216,13 @@ BOOL LLToolGrab::handleObjectHit(LLViewerObject *objectp, S32 x, S32 y, MASK mas
223 if (gAgent.cameraMouselook() && !script_touch) 216 if (gAgent.cameraMouselook() && !script_touch)
224 { 217 {
225 mMode = GRAB_LOCKED; 218 mMode = GRAB_LOCKED;
219 gViewerWindow->hideCursor();
220 gViewerWindow->moveCursorToCenter();
226 } 221 }
227 else 222 else
228 { 223 {
229 mMode = GRAB_NONPHYSICAL; 224 mMode = GRAB_NONPHYSICAL;
230 } 225 }
231 gViewerWindow->hideCursor();
232 gViewerWindow->moveCursorToCenter();
233 // Don't bail out here, go on and grab so buttons can get 226 // Don't bail out here, go on and grab so buttons can get
234 // their "touched" event. 227 // their "touched" event.
235 } 228 }
@@ -254,20 +247,18 @@ BOOL LLToolGrab::handleObjectHit(LLViewerObject *objectp, S32 x, S32 y, MASK mas
254 247
255 // Always send "touched" message 248 // Always send "touched" message
256 249
250 mLastMouseX = gViewerWindow->getCurrentMouseX();
251 mLastMouseY = gViewerWindow->getCurrentMouseY();
257 mAccumDeltaX = 0; 252 mAccumDeltaX = 0;
258 mAccumDeltaY = 0; 253 mAccumDeltaY = 0;
259 mHasMoved = FALSE; 254 mHasMoved = FALSE;
260 mOutsideSlop = FALSE; 255 mOutsideSlop = FALSE;
261 256
262 mGrabObject = objectp; 257 mVerticalDragging = (info.mKeyMask == MASK_VERTICAL) || gGrabBtnVertical;
263 258
264 mGrabOffset.clearVec(); 259 startGrab();
265 260
266 mVerticalDragging = (mask == MASK_VERTICAL) || gGrabBtnVertical; 261 if ((info.mKeyMask == MASK_SPIN) || gGrabBtnSpin)
267
268 startGrab(x, y);
269
270 if ((mask == MASK_SPIN) || gGrabBtnSpin)
271 { 262 {
272 startSpin(); 263 startSpin();
273 } 264 }
@@ -275,10 +266,10 @@ BOOL LLToolGrab::handleObjectHit(LLViewerObject *objectp, S32 x, S32 y, MASK mas
275 LLSelectMgr::getInstance()->updateSelectionCenter(); // update selection beam 266 LLSelectMgr::getInstance()->updateSelectionCenter(); // update selection beam
276 267
277 // update point at 268 // update point at
278 LLViewerObject *edit_object = gObjectList.findObject(mHitObjectID); 269 LLViewerObject *edit_object = info.getObject();
279 if (edit_object) 270 if (edit_object && info.mPickType != LLPickInfo::PICK_FLORA)
280 { 271 {
281 LLVector3 local_edit_point = gAgent.getPosAgentFromGlobal(gLastHitNonFloraPosGlobal); 272 LLVector3 local_edit_point = gAgent.getPosAgentFromGlobal(info.mPosGlobal);
282 local_edit_point -= edit_object->getPositionAgent(); 273 local_edit_point -= edit_object->getPositionAgent();
283 local_edit_point = local_edit_point * ~edit_object->getRenderRotation(); 274 local_edit_point = local_edit_point * ~edit_object->getRenderRotation();
284 gAgent.setPointAt(POINTAT_TARGET_GRAB, edit_object, local_edit_point ); 275 gAgent.setPointAt(POINTAT_TARGET_GRAB, edit_object, local_edit_point );
@@ -300,10 +291,15 @@ BOOL LLToolGrab::handleObjectHit(LLViewerObject *objectp, S32 x, S32 y, MASK mas
300 291
301void LLToolGrab::startSpin() 292void LLToolGrab::startSpin()
302{ 293{
294 LLViewerObject* objectp = mGrabPick.getObject();
295 if (!objectp)
296 {
297 return;
298 }
303 mSpinGrabbing = TRUE; 299 mSpinGrabbing = TRUE;
304 300
305 // Was saveSelectedObjectTransform() 301 // Was saveSelectedObjectTransform()
306 LLViewerObject *root = (LLViewerObject *)mGrabObject->getRoot(); 302 LLViewerObject *root = (LLViewerObject *)objectp->getRoot();
307 mSpinRotation = root->getRotation(); 303 mSpinRotation = root->getRotation();
308 304
309 LLMessageSystem *msg = gMessageSystem; 305 LLMessageSystem *msg = gMessageSystem;
@@ -312,8 +308,8 @@ void LLToolGrab::startSpin()
312 msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID() ); 308 msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
313 msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID()); 309 msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
314 msg->nextBlockFast(_PREHASH_ObjectData); 310 msg->nextBlockFast(_PREHASH_ObjectData);
315 msg->addUUIDFast(_PREHASH_ObjectID, mGrabObject->getID() ); 311 msg->addUUIDFast(_PREHASH_ObjectID, mGrabPick.mObjectID );
316 msg->sendMessage( mGrabObject->getRegion()->getHost() ); 312 msg->sendMessage( objectp->getRegion()->getHost() );
317} 313}
318 314
319 315
@@ -321,6 +317,12 @@ void LLToolGrab::stopSpin()
321{ 317{
322 mSpinGrabbing = FALSE; 318 mSpinGrabbing = FALSE;
323 319
320 LLViewerObject* objectp = mGrabPick.getObject();
321 if (!objectp)
322 {
323 return;
324 }
325
324 LLMessageSystem *msg = gMessageSystem; 326 LLMessageSystem *msg = gMessageSystem;
325 switch(mMode) 327 switch(mMode)
326 { 328 {
@@ -332,8 +334,8 @@ void LLToolGrab::stopSpin()
332 msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID() ); 334 msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
333 msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID()); 335 msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
334 msg->nextBlockFast(_PREHASH_ObjectData); 336 msg->nextBlockFast(_PREHASH_ObjectData);
335 msg->addUUIDFast(_PREHASH_ObjectID, mGrabObject->getID() ); 337 msg->addUUIDFast(_PREHASH_ObjectID, objectp->getID() );
336 msg->sendMessage( mGrabObject->getRegion()->getHost() ); 338 msg->sendMessage( objectp->getRegion()->getHost() );
337 break; 339 break;
338 340
339 case GRAB_NOOBJECT: 341 case GRAB_NOOBJECT:
@@ -345,11 +347,17 @@ void LLToolGrab::stopSpin()
345} 347}
346 348
347 349
348void LLToolGrab::startGrab(S32 x, S32 y) 350void LLToolGrab::startGrab()
349{ 351{
350 // Compute grab_offset in the OBJECT's root's coordinate frame 352 // Compute grab_offset in the OBJECT's root's coordinate frame
351 // (sometimes root == object) 353 // (sometimes root == object)
352 LLViewerObject *root = (LLViewerObject *)mGrabObject->getRoot(); 354 LLViewerObject* objectp = mGrabPick.getObject();
355 if (!objectp)
356 {
357 return;
358 }
359
360 LLViewerObject *root = (LLViewerObject *)objectp->getRoot();
353 361
354 // drag from center 362 // drag from center
355 LLVector3d grab_start_global = root->getPositionGlobal(); 363 LLVector3d grab_start_global = root->getPositionGlobal();
@@ -358,7 +366,7 @@ void LLToolGrab::startGrab(S32 x, S32 y)
358 // JC - This code looks wonky, but I believe it does the right thing. 366 // JC - This code looks wonky, but I believe it does the right thing.
359 // Otherwise, when you grab a linked object set, it "pops" on the start 367 // Otherwise, when you grab a linked object set, it "pops" on the start
360 // of the drag. 368 // of the drag.
361 LLVector3d grab_offsetd = root->getPositionGlobal() - mGrabObject->getPositionGlobal(); 369 LLVector3d grab_offsetd = root->getPositionGlobal() - objectp->getPositionGlobal();
362 370
363 LLVector3 grab_offset; 371 LLVector3 grab_offset;
364 grab_offset.setVec(grab_offsetd); 372 grab_offset.setVec(grab_offsetd);
@@ -377,9 +385,16 @@ void LLToolGrab::startGrab(S32 x, S32 y)
377 msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); 385 msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
378 msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID()); 386 msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
379 msg->nextBlockFast(_PREHASH_ObjectData); 387 msg->nextBlockFast(_PREHASH_ObjectData);
380 msg->addU32Fast(_PREHASH_LocalID, mGrabObject->mLocalID); 388 msg->addU32Fast(_PREHASH_LocalID, objectp->mLocalID);
381 msg->addVector3Fast(_PREHASH_GrabOffset, grab_offset ); 389 msg->addVector3Fast(_PREHASH_GrabOffset, grab_offset );
382 msg->sendMessage( mGrabObject->getRegion()->getHost()); 390 msg->nextBlock("SurfaceInfo");
391 msg->addVector3("UVCoord", LLVector3(mGrabPick.mUVCoords));
392 msg->addVector3("STCoord", LLVector3(mGrabPick.mSTCoords));
393 msg->addS32Fast(_PREHASH_FaceIndex, mGrabPick.mObjectFace);
394 msg->addVector3("Position", mGrabPick.mIntersection);
395 msg->addVector3("Normal", mGrabPick.mNormal);
396 msg->addVector3("Binormal", mGrabPick.mBinormal);
397 msg->sendMessage( objectp->getRegion()->getHost());
383 398
384 mGrabOffsetFromCenterInitial = grab_offset; 399 mGrabOffsetFromCenterInitial = grab_offset;
385 mGrabHiddenOffsetFromCamera = mDragStartFromCamera; 400 mGrabHiddenOffsetFromCamera = mDragStartFromCamera;
@@ -390,9 +405,6 @@ void LLToolGrab::startGrab(S32 x, S32 y)
390 405
391BOOL LLToolGrab::handleHover(S32 x, S32 y, MASK mask) 406BOOL LLToolGrab::handleHover(S32 x, S32 y, MASK mask)
392{ 407{
393 mLastMouseX = x;
394 mLastMouseY = y;
395
396 if (!gViewerWindow->getLeftMouseDown()) 408 if (!gViewerWindow->getLeftMouseDown())
397 { 409 {
398 gViewerWindow->setCursor(UI_CURSOR_TOOLGRAB); 410 gViewerWindow->setCursor(UI_CURSOR_TOOLGRAB);
@@ -404,9 +416,12 @@ BOOL LLToolGrab::handleHover(S32 x, S32 y, MASK mask)
404 switch( mMode ) 416 switch( mMode )
405 { 417 {
406 case GRAB_ACTIVE_CENTER: 418 case GRAB_ACTIVE_CENTER:
407 case GRAB_NONPHYSICAL:
408 handleHoverActive( x, y, mask ); // cursor hidden 419 handleHoverActive( x, y, mask ); // cursor hidden
409 break; 420 break;
421
422 case GRAB_NONPHYSICAL:
423 handleHoverNonPhysical(x, y, mask);
424 break;
410 425
411 case GRAB_INACTIVE: 426 case GRAB_INACTIVE:
412 handleHoverInactive( x, y, mask ); // cursor set here 427 handleHoverInactive( x, y, mask ); // cursor set here
@@ -419,18 +434,24 @@ BOOL LLToolGrab::handleHover(S32 x, S32 y, MASK mask)
419 434
420 } 435 }
421 436
437 mLastMouseX = x;
438 mLastMouseY = y;
439
422 return TRUE; 440 return TRUE;
423} 441}
424 442
443const F32 GRAB_SENSITIVITY_X = 0.0075f;
444const F32 GRAB_SENSITIVITY_Y = 0.0075f;
445
425 446
426 447
427 448
428// Dragging. 449// Dragging.
429void LLToolGrab::handleHoverActive(S32 x, S32 y, MASK mask) 450void LLToolGrab::handleHoverActive(S32 x, S32 y, MASK mask)
430{ 451{
431 llassert( hasMouseCapture() ); 452 LLViewerObject* objectp = mGrabPick.getObject();
432 llassert( mGrabObject ); 453 if (!objectp || !hasMouseCapture() ) return;
433 if (mGrabObject->isDead()) 454 if (objectp->isDead())
434 { 455 {
435 // Bail out of drag because object has been killed 456 // Bail out of drag because object has been killed
436 setMouseCapture(FALSE); 457 setMouseCapture(FALSE);
@@ -459,7 +480,7 @@ void LLToolGrab::handleHoverActive(S32 x, S32 y, MASK mask)
459 // ...switch to horizontal dragging 480 // ...switch to horizontal dragging
460 mVerticalDragging = FALSE; 481 mVerticalDragging = FALSE;
461 482
462 mDragStartPointGlobal = gViewerWindow->clickPointInWorldGlobal(x, y, mGrabObject); 483 mDragStartPointGlobal = gViewerWindow->clickPointInWorldGlobal(x, y, objectp);
463 mDragStartFromCamera = mDragStartPointGlobal - gAgent.getCameraPositionGlobal(); 484 mDragStartFromCamera = mDragStartPointGlobal - gAgent.getCameraPositionGlobal();
464 } 485 }
465 else if (!mVerticalDragging && (mask == MASK_VERTICAL) ) 486 else if (!mVerticalDragging && (mask == MASK_VERTICAL) )
@@ -467,16 +488,13 @@ void LLToolGrab::handleHoverActive(S32 x, S32 y, MASK mask)
467 // ...switch to vertical dragging 488 // ...switch to vertical dragging
468 mVerticalDragging = TRUE; 489 mVerticalDragging = TRUE;
469 490
470 mDragStartPointGlobal = gViewerWindow->clickPointInWorldGlobal(x, y, mGrabObject); 491 mDragStartPointGlobal = gViewerWindow->clickPointInWorldGlobal(x, y, objectp);
471 mDragStartFromCamera = mDragStartPointGlobal - gAgent.getCameraPositionGlobal(); 492 mDragStartFromCamera = mDragStartPointGlobal - gAgent.getCameraPositionGlobal();
472 } 493 }
473 494
474 const F32 RADIANS_PER_PIXEL_X = 0.01f; 495 const F32 RADIANS_PER_PIXEL_X = 0.01f;
475 const F32 RADIANS_PER_PIXEL_Y = 0.01f; 496 const F32 RADIANS_PER_PIXEL_Y = 0.01f;
476 497
477 const F32 SENSITIVITY_X = 0.0075f;
478 const F32 SENSITIVITY_Y = 0.0075f;
479
480 S32 dx = x - (gViewerWindow->getWindowWidth() / 2); 498 S32 dx = x - (gViewerWindow->getWindowWidth() / 2);
481 S32 dy = y - (gViewerWindow->getWindowHeight() / 2); 499 S32 dy = y - (gViewerWindow->getWindowHeight() / 2);
482 500
@@ -518,9 +536,9 @@ void LLToolGrab::handleHoverActive(S32 x, S32 y, MASK mask)
518 msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID() ); 536 msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
519 msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID()); 537 msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
520 msg->nextBlockFast(_PREHASH_ObjectData); 538 msg->nextBlockFast(_PREHASH_ObjectData);
521 msg->addUUIDFast(_PREHASH_ObjectID, mGrabObject->getID() ); 539 msg->addUUIDFast(_PREHASH_ObjectID, objectp->getID() );
522 msg->addQuatFast(_PREHASH_Rotation, mSpinRotation ); 540 msg->addQuatFast(_PREHASH_Rotation, mSpinRotation );
523 msg->sendMessage( mGrabObject->getRegion()->getHost() ); 541 msg->sendMessage( objectp->getRegion()->getHost() );
524 } 542 }
525 else 543 else
526 { 544 {
@@ -548,8 +566,8 @@ void LLToolGrab::handleHoverActive(S32 x, S32 y, MASK mask)
548 } 566 }
549 567
550 mGrabHiddenOffsetFromCamera = mGrabHiddenOffsetFromCamera 568 mGrabHiddenOffsetFromCamera = mGrabHiddenOffsetFromCamera
551 + (x_part * (-dx * SENSITIVITY_X)) 569 + (x_part * (-dx * GRAB_SENSITIVITY_X))
552 + (y_part * ( dy * SENSITIVITY_Y)); 570 + (y_part * ( dy * GRAB_SENSITIVITY_Y));
553 571
554 572
555 // Send the message to the viewer. 573 // Send the message to the viewer.
@@ -633,7 +651,7 @@ void LLToolGrab::handleHoverActive(S32 x, S32 y, MASK mask)
633 && (grab_center_gl.mY > 24)) 651 && (grab_center_gl.mY > 24))
634 { 652 {
635 // Transmit update to simulator 653 // Transmit update to simulator
636 LLVector3 grab_pos_region = mGrabObject->getRegion()->getPosRegionFromGlobal( grab_point_global ); 654 LLVector3 grab_pos_region = objectp->getRegion()->getPosRegionFromGlobal( grab_point_global );
637 655
638 LLMessageSystem *msg = gMessageSystem; 656 LLMessageSystem *msg = gMessageSystem;
639 msg->newMessageFast(_PREHASH_ObjectGrabUpdate); 657 msg->newMessageFast(_PREHASH_ObjectGrabUpdate);
@@ -641,11 +659,19 @@ void LLToolGrab::handleHoverActive(S32 x, S32 y, MASK mask)
641 msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); 659 msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
642 msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID()); 660 msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
643 msg->nextBlockFast(_PREHASH_ObjectData); 661 msg->nextBlockFast(_PREHASH_ObjectData);
644 msg->addUUIDFast(_PREHASH_ObjectID, mGrabObject->getID() ); 662 msg->addUUIDFast(_PREHASH_ObjectID, objectp->getID() );
645 msg->addVector3Fast(_PREHASH_GrabOffsetInitial, mGrabOffsetFromCenterInitial ); 663 msg->addVector3Fast(_PREHASH_GrabOffsetInitial, mGrabOffsetFromCenterInitial );
646 msg->addVector3Fast(_PREHASH_GrabPosition, grab_pos_region ); 664 msg->addVector3Fast(_PREHASH_GrabPosition, grab_pos_region );
647 msg->addU32Fast(_PREHASH_TimeSinceLast, dt_milliseconds ); 665 msg->addU32Fast(_PREHASH_TimeSinceLast, dt_milliseconds );
648 msg->sendMessage( mGrabObject->getRegion()->getHost() ); 666 msg->nextBlock("SurfaceInfo");
667 msg->addVector3("UVCoord", LLVector3(mGrabPick.mUVCoords));
668 msg->addVector3("STCoord", LLVector3(mGrabPick.mSTCoords));
669 msg->addS32Fast(_PREHASH_FaceIndex, mGrabPick.mObjectFace);
670 msg->addVector3("Position", mGrabPick.mIntersection);
671 msg->addVector3("Normal", mGrabPick.mNormal);
672 msg->addVector3("Binormal", mGrabPick.mBinormal);
673
674 msg->sendMessage( objectp->getRegion()->getHost() );
649 } 675 }
650 } 676 }
651 677
@@ -659,8 +685,8 @@ void LLToolGrab::handleHoverActive(S32 x, S32 y, MASK mask)
659 if (mHasMoved) 685 if (mHasMoved)
660 { 686 {
661 if (!gAgent.cameraMouselook() && 687 if (!gAgent.cameraMouselook() &&
662 !mGrabObject->isHUDAttachment() && 688 !objectp->isHUDAttachment() &&
663 mGrabObject->getRoot() == gAgent.getAvatarObject()->getRoot()) 689 objectp->getRoot() == gAgent.getAvatarObject()->getRoot())
664 { 690 {
665 // force focus to point in space where we were looking previously 691 // force focus to point in space where we were looking previously
666 gAgent.setFocusGlobal(gAgent.calcFocusPositionTargetGlobal(), LLUUID::null); 692 gAgent.setFocusGlobal(gAgent.calcFocusPositionTargetGlobal(), LLUUID::null);
@@ -679,6 +705,134 @@ void LLToolGrab::handleHoverActive(S32 x, S32 y, MASK mask)
679} 705}
680 706
681 707
708void LLToolGrab::handleHoverNonPhysical(S32 x, S32 y, MASK mask)
709{
710 LLViewerObject* objectp = mGrabPick.getObject();
711 if (!objectp || !hasMouseCapture() ) return;
712 if (objectp->isDead())
713 {
714 // Bail out of drag because object has been killed
715 setMouseCapture(FALSE);
716 return;
717 }
718
719 LLPickInfo pick = mGrabPick;
720 pick.mMousePt = LLCoordGL(x, y);
721 pick.getSurfaceInfo();
722
723 // compute elapsed time
724 F32 dt = mGrabTimer.getElapsedTimeAndResetF32();
725 U32 dt_milliseconds = (U32) (1000.f * dt);
726
727 // i'm not a big fan of the following code - it's been culled from the physical grab case.
728 // ideally these two would be nicely integrated - but the code in that method is a serious
729 // mess of spaghetti. so here we go:
730
731 LLVector3 grab_pos_region(0,0,0);
732
733 const BOOL SUPPORT_LLDETECTED_GRAB = TRUE;
734 if (SUPPORT_LLDETECTED_GRAB)
735 {
736 //--------------------------------------------------
737 // Toggle vertical dragging
738 //--------------------------------------------------
739 if (mVerticalDragging && !(mask == MASK_VERTICAL) && !gGrabBtnVertical)
740 {
741 mVerticalDragging = FALSE;
742 }
743
744 else if (!mVerticalDragging && (mask == MASK_VERTICAL) )
745 {
746 mVerticalDragging = TRUE;
747 }
748
749 S32 dx = x - mLastMouseX;
750 S32 dy = y - mLastMouseY;
751
752 if (dx != 0 || dy != 0)
753 {
754 mAccumDeltaX += dx;
755 mAccumDeltaY += dy;
756
757 S32 dist_sq = mAccumDeltaX * mAccumDeltaX + mAccumDeltaY * mAccumDeltaY;
758 if (dist_sq > SLOP_DIST_SQ)
759 {
760 mOutsideSlop = TRUE;
761 }
762
763 // mouse has moved
764 mHasMoved = TRUE;
765
766 //------------------------------------------------------
767 // Handle grabbing
768 //------------------------------------------------------
769
770 LLVector3d x_part;
771 x_part.setVec(LLViewerCamera::getInstance()->getLeftAxis());
772 x_part.mdV[VZ] = 0.0;
773 x_part.normVec();
774
775 LLVector3d y_part;
776 if( mVerticalDragging )
777 {
778 y_part.setVec(LLViewerCamera::getInstance()->getUpAxis());
779 // y_part.setVec(0.f, 0.f, 1.f);
780 }
781 else
782 {
783 // drag toward camera
784 y_part = x_part % LLVector3d::z_axis;
785 y_part.mdV[VZ] = 0.0;
786 y_part.normVec();
787 }
788
789 mGrabHiddenOffsetFromCamera = mGrabHiddenOffsetFromCamera
790 + (x_part * (-dx * GRAB_SENSITIVITY_X))
791 + (y_part * ( dy * GRAB_SENSITIVITY_Y));
792
793 }
794
795 // need to return offset from mGrabStartPoint
796 LLVector3d grab_point_global = gAgent.getCameraPositionGlobal() + mGrabHiddenOffsetFromCamera;
797 grab_pos_region = objectp->getRegion()->getPosRegionFromGlobal( grab_point_global );
798 }
799
800 LLMessageSystem *msg = gMessageSystem;
801 msg->newMessageFast(_PREHASH_ObjectGrabUpdate);
802 msg->nextBlockFast(_PREHASH_AgentData);
803 msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
804 msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
805 msg->nextBlockFast(_PREHASH_ObjectData);
806 msg->addUUIDFast(_PREHASH_ObjectID, objectp->getID() );
807 msg->addVector3Fast(_PREHASH_GrabOffsetInitial, mGrabOffsetFromCenterInitial );
808 msg->addVector3Fast(_PREHASH_GrabPosition, grab_pos_region );
809 msg->addU32Fast(_PREHASH_TimeSinceLast, dt_milliseconds );
810 msg->nextBlock("SurfaceInfo");
811 msg->addVector3("UVCoord", LLVector3(pick.mUVCoords));
812 msg->addVector3("STCoord", LLVector3(pick.mSTCoords));
813 msg->addS32Fast(_PREHASH_FaceIndex, pick.mObjectFace);
814 msg->addVector3("Position", pick.mIntersection);
815 msg->addVector3("Normal", pick.mNormal);
816 msg->addVector3("Binormal", pick.mBinormal);
817
818 msg->sendMessage( objectp->getRegion()->getHost() );
819
820 // update point-at / look-at
821 if (pick.mObjectFace != -1) // if the intersection was on the surface of the obejct
822 {
823 LLVector3 local_edit_point = pick.mIntersection;
824 local_edit_point -= objectp->getPositionAgent();
825 local_edit_point = local_edit_point * ~objectp->getRenderRotation();
826 gAgent.setPointAt(POINTAT_TARGET_GRAB, objectp, local_edit_point );
827 gAgent.setLookAt(LOOKAT_TARGET_SELECT, objectp, local_edit_point );
828 }
829
830
831
832 gViewerWindow->setCursor(UI_CURSOR_HAND);
833}
834
835
682// Not dragging. Just showing affordances 836// Not dragging. Just showing affordances
683void LLToolGrab::handleHoverInactive(S32 x, S32 y, MASK mask) 837void LLToolGrab::handleHoverInactive(S32 x, S32 y, MASK mask)
684{ 838{
@@ -719,7 +873,7 @@ void LLToolGrab::handleHoverFailed(S32 x, S32 y, MASK mask)
719 } 873 }
720 else 874 else
721 { 875 {
722 S32 dist_sq = (x-mMouseDownX) * (x-mMouseDownX) + (y-mMouseDownY) * (y-mMouseDownY); 876 S32 dist_sq = (x-mGrabPick.mMousePt.mX) * (x-mGrabPick.mMousePt.mX) + (y-mGrabPick.mMousePt.mY) * (y-mGrabPick.mMousePt.mY);
723 if( mOutsideSlop || dist_sq > SLOP_DIST_SQ ) 877 if( mOutsideSlop || dist_sq > SLOP_DIST_SQ )
724 { 878 {
725 mOutsideSlop = TRUE; 879 mOutsideSlop = TRUE;
@@ -784,23 +938,27 @@ void LLToolGrab::stopEditing()
784 938
785void LLToolGrab::onMouseCaptureLost() 939void LLToolGrab::onMouseCaptureLost()
786{ 940{
941 LLViewerObject* objectp = mGrabPick.getObject();
942 if (!objectp)
943 {
944 gViewerWindow->showCursor();
945 return;
946 }
787 // First, fix cursor placement 947 // First, fix cursor placement
788 if( !gAgent.cameraMouselook() 948 if( !gAgent.cameraMouselook()
789 && (GRAB_ACTIVE_CENTER == mMode || GRAB_NONPHYSICAL == mMode)) 949 && (GRAB_ACTIVE_CENTER == mMode))
790 { 950 {
791 llassert( mGrabObject ); 951 if (objectp->isHUDAttachment())
792
793 if (mGrabObject->isHUDAttachment())
794 { 952 {
795 // ...move cursor "naturally", as if it had moved when hidden 953 // ...move cursor "naturally", as if it had moved when hidden
796 S32 x = mMouseDownX + mAccumDeltaX; 954 S32 x = mGrabPick.mMousePt.mX + mAccumDeltaX;
797 S32 y = mMouseDownY + mAccumDeltaY; 955 S32 y = mGrabPick.mMousePt.mY + mAccumDeltaY;
798 LLUI::setCursorPositionScreen(x, y); 956 LLUI::setCursorPositionScreen(x, y);
799 } 957 }
800 else if (mHasMoved) 958 else if (mHasMoved)
801 { 959 {
802 // ...move cursor back to the center of the object 960 // ...move cursor back to the center of the object
803 LLVector3 grab_point_agent = mGrabObject->getRenderPosition(); 961 LLVector3 grab_point_agent = objectp->getRenderPosition();
804 962
805 LLCoordGL gl_point; 963 LLCoordGL gl_point;
806 if (LLViewerCamera::getInstance()->projectPosAgentToScreen(grab_point_agent, gl_point)) 964 if (LLViewerCamera::getInstance()->projectPosAgentToScreen(grab_point_agent, gl_point))
@@ -811,19 +969,21 @@ void LLToolGrab::onMouseCaptureLost()
811 else 969 else
812 { 970 {
813 // ...move cursor back to click position 971 // ...move cursor back to click position
814 LLUI::setCursorPositionScreen(mMouseDownX, mMouseDownY); 972 LLUI::setCursorPositionScreen(mGrabPick.mMousePt.mX, mGrabPick.mMousePt.mY);
815 } 973 }
816 974
817 gViewerWindow->showCursor(); 975 gViewerWindow->showCursor();
818 } 976 }
819 977
820 stopGrab(); 978 stopGrab();
979 if (mSpinGrabbing)
821 stopSpin(); 980 stopSpin();
981
822 mMode = GRAB_INACTIVE; 982 mMode = GRAB_INACTIVE;
823 983
824 mHideBuildHighlight = FALSE; 984 mHideBuildHighlight = FALSE;
825 985
826 mGrabObject = NULL; 986 mGrabPick.mObjectID.setNull();
827 987
828 LLSelectMgr::getInstance()->updateSelectionCenter(); 988 LLSelectMgr::getInstance()->updateSelectionCenter();
829 gAgent.setPointAt(POINTAT_TARGET_CLEAR); 989 gAgent.setPointAt(POINTAT_TARGET_CLEAR);
@@ -835,6 +995,24 @@ void LLToolGrab::onMouseCaptureLost()
835 995
836void LLToolGrab::stopGrab() 996void LLToolGrab::stopGrab()
837{ 997{
998 LLViewerObject* objectp = mGrabPick.getObject();
999 if (!objectp)
1000 {
1001 return;
1002 }
1003
1004 LLPickInfo pick = mGrabPick;
1005
1006 if (mMode == GRAB_NONPHYSICAL)
1007 {
1008 // for non-physical (touch) grabs,
1009 // gather surface info for this degrab (mouse-up)
1010 S32 x = gViewerWindow->getCurrentMouseX();
1011 S32 y = gViewerWindow->getCurrentMouseY();
1012 pick.mMousePt = LLCoordGL(x, y);
1013 pick.getSurfaceInfo();
1014 }
1015
838 // Next, send messages to simulator 1016 // Next, send messages to simulator
839 LLMessageSystem *msg = gMessageSystem; 1017 LLMessageSystem *msg = gMessageSystem;
840 switch(mMode) 1018 switch(mMode)
@@ -847,11 +1025,18 @@ void LLToolGrab::stopGrab()
847 msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID()); 1025 msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
848 msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID()); 1026 msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
849 msg->nextBlockFast(_PREHASH_ObjectData); 1027 msg->nextBlockFast(_PREHASH_ObjectData);
850 msg->addU32Fast(_PREHASH_LocalID, mGrabObject->mLocalID); 1028 msg->addU32Fast(_PREHASH_LocalID, objectp->mLocalID);
851 msg->sendMessage(mGrabObject->getRegion()->getHost()); 1029 msg->nextBlock("SurfaceInfo");
1030 msg->addVector3("UVCoord", LLVector3(pick.mUVCoords));
1031 msg->addVector3("STCoord", LLVector3(pick.mSTCoords));
1032 msg->addS32Fast(_PREHASH_FaceIndex, pick.mObjectFace);
1033 msg->addVector3("Position", pick.mIntersection);
1034 msg->addVector3("Normal", pick.mNormal);
1035 msg->addVector3("Binormal", pick.mBinormal);
1036
1037 msg->sendMessage(objectp->getRegion()->getHost());
852 1038
853 mVerticalDragging = FALSE; 1039 mVerticalDragging = FALSE;
854 mGrabOffset.clearVec();
855 break; 1040 break;
856 1041
857 case GRAB_NOOBJECT: 1042 case GRAB_NOOBJECT:
@@ -873,14 +1058,12 @@ void LLToolGrab::render()
873 1058
874BOOL LLToolGrab::isEditing() 1059BOOL LLToolGrab::isEditing()
875{ 1060{
876 // Can't just compare to null directly due to "smart" pointer. 1061 return (mGrabPick.getObject().notNull());
877 LLViewerObject *obj = mGrabObject;
878 return (obj != NULL);
879} 1062}
880 1063
881LLViewerObject* LLToolGrab::getEditingObject() 1064LLViewerObject* LLToolGrab::getEditingObject()
882{ 1065{
883 return mGrabObject; 1066 return mGrabPick.getObject();
884} 1067}
885 1068
886 1069