aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llhudeffectlookat.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/newview/llhudeffectlookat.cpp')
-rw-r--r--linden/indra/newview/llhudeffectlookat.cpp63
1 files changed, 36 insertions, 27 deletions
diff --git a/linden/indra/newview/llhudeffectlookat.cpp b/linden/indra/newview/llhudeffectlookat.cpp
index 813f924..da0ec60 100644
--- a/linden/indra/newview/llhudeffectlookat.cpp
+++ b/linden/indra/newview/llhudeffectlookat.cpp
@@ -442,12 +442,25 @@ void LLHUDEffectLookAt::update()
442 } 442 }
443} 443}
444 444
445/**
446 * Initializes the mTargetPos member from the current mSourceObjec and mTargetObject
447 * (and possibly mTargetOffsetGlobal).
448 * When mTargetObject is another avatar, it sets mTargetPos to be their eyes.
449 *
450 * Has the side-effect of also calling setAnimationData("LookAtPoint") with the new
451 * mTargetPos on the source object which is assumed to be an avatar.
452 */
445void LLHUDEffectLookAt::calcTargetPosition() 453void LLHUDEffectLookAt::calcTargetPosition()
446{ 454{
447 LLViewerObject *targetObject = (LLViewerObject *)mTargetObject; 455 if (gNoRender)
456 {
457 return;
458 }
459
460 LLViewerObject *target_obj = (LLViewerObject *)mTargetObject;
448 LLVector3 local_offset; 461 LLVector3 local_offset;
449 462
450 if (targetObject) 463 if (target_obj)
451 { 464 {
452 local_offset.setVec(mTargetOffsetGlobal); 465 local_offset.setVec(mTargetOffsetGlobal);
453 } 466 }
@@ -456,20 +469,16 @@ void LLHUDEffectLookAt::calcTargetPosition()
456 local_offset = gAgent.getPosAgentFromGlobal(mTargetOffsetGlobal); 469 local_offset = gAgent.getPosAgentFromGlobal(mTargetOffsetGlobal);
457 } 470 }
458 471
459 if (gNoRender) 472 LLVOAvatar* source_avatar = (LLVOAvatar*)(LLViewerObject*)mSourceObject;
460 {
461 return;
462 }
463 LLVector3 head_position = ((LLVOAvatar*)(LLViewerObject*)mSourceObject)->mHeadp->getWorldPosition();
464 473
465 if (targetObject && targetObject->mDrawable.notNull()) 474 if (target_obj && target_obj->mDrawable.notNull())
466 { 475 {
467 LLQuaternion objRot; 476 LLQuaternion target_rot;
468 if (targetObject->isAvatar()) 477 if (target_obj->isAvatar())
469 { 478 {
470 LLVOAvatar *avatarp = (LLVOAvatar *)targetObject; 479 LLVOAvatar *target_av = (LLVOAvatar *)target_obj;
471 480
472 BOOL looking_at_self = ((LLVOAvatar*)(LLViewerObject*)mSourceObject)->isSelf() && avatarp->isSelf(); 481 BOOL looking_at_self = source_avatar->isSelf() && target_av->isSelf();
473 482
474 // if selecting self, stare forward 483 // if selecting self, stare forward
475 if (looking_at_self && mTargetOffsetGlobal.magVecSquared() < MIN_TARGET_OFFSET_SQUARED) 484 if (looking_at_self && mTargetOffsetGlobal.magVecSquared() < MIN_TARGET_OFFSET_SQUARED)
@@ -479,46 +488,46 @@ void LLHUDEffectLookAt::calcTargetPosition()
479 local_offset.setVec(mTargetOffsetGlobal); 488 local_offset.setVec(mTargetOffsetGlobal);
480 } 489 }
481 490
482 mTargetPos = avatarp->mHeadp->getWorldPosition(); 491 // look the other avatar in the eye. note: what happens if target is self? -MG
492 mTargetPos = target_av->mHeadp->getWorldPosition();
483 if (mTargetType == LOOKAT_TARGET_MOUSELOOK || mTargetType == LOOKAT_TARGET_FREELOOK) 493 if (mTargetType == LOOKAT_TARGET_MOUSELOOK || mTargetType == LOOKAT_TARGET_FREELOOK)
484 { 494 {
485 // mouselook and freelook target offsets are absolute 495 // mouselook and freelook target offsets are absolute
486 objRot = LLQuaternion::DEFAULT; 496 target_rot = LLQuaternion::DEFAULT;
487 } 497 }
488 else if (looking_at_self && gAgent.cameraCustomizeAvatar()) 498 else if (looking_at_self && gAgent.cameraCustomizeAvatar())
489 { 499 {
490 // *NOTE: We have to do this because animation 500 // *NOTE: We have to do this because animation
491 // overrides do not set lookat behavior. 501 // overrides do not set lookat behavior.
492 // *TODO: animation overrides for lookat behavior. 502 // *TODO: animation overrides for lookat behavior.
493 objRot = avatarp->mPelvisp->getWorldRotation(); 503 target_rot = target_av->mPelvisp->getWorldRotation();
494 } 504 }
495 else 505 else
496 { 506 {
497 objRot = avatarp->mRoot.getWorldRotation(); 507 target_rot = target_av->mRoot.getWorldRotation();
498 } 508 }
499 } 509 }
500 else 510 else // target obj is not an avatar
501 { 511 {
502 if (targetObject->mDrawable->getGeneration() == -1) 512 if (target_obj->mDrawable->getGeneration() == -1)
503 { 513 {
504 mTargetPos = targetObject->getPositionAgent(); 514 mTargetPos = target_obj->getPositionAgent();
505 objRot = targetObject->getWorldRotation(); 515 target_rot = target_obj->getWorldRotation();
506 } 516 }
507 else 517 else
508 { 518 {
509 mTargetPos = targetObject->getRenderPosition(); 519 mTargetPos = target_obj->getRenderPosition();
510 objRot = targetObject->getRenderRotation(); 520 target_rot = target_obj->getRenderRotation();
511 } 521 }
512 } 522 }
513 523
514 mTargetPos += (local_offset * objRot); 524 mTargetPos += (local_offset * target_rot);
515 } 525 }
516 else 526 else // no target obj or it's not drawable
517 { 527 {
518 mTargetPos = local_offset; 528 mTargetPos = local_offset;
519 } 529 }
520 530
521 mTargetPos -= head_position; 531 mTargetPos -= source_avatar->mHeadp->getWorldPosition();
522 532 source_avatar->setAnimationData("LookAtPoint", (void *)&mTargetPos);
523 ((LLVOAvatar*)(LLViewerObject*)mSourceObject)->setAnimationData("LookAtPoint", (void *)&mTargetPos);
524} 533}