diff options
author | Rick Pasetto <rick@lindenlab.com> | 2009-10-15 16:30:48 -0700 |
---|---|---|
committer | Rick Pasetto <rick@lindenlab.com> | 2009-10-15 16:30:48 -0700 |
commit | 2cb043a6262e61809c26496a6ec197179806e0d4 (patch) | |
tree | db621da086e3848698eb4cbc16ddf0217cd26c13 | |
parent | 47e02d13f7e6307d9eb507177b88bbf0ab496894 (diff) |
FIX DEV-39513: Tweak target camera position to avoid a flip when target normal is vertical
Review #21
This attempts to tweak the target camera position slightly towards where the camera started from, so as to avoid the flip noted in this JIRA.
-rw-r--r-- | indra/newview/llviewermediafocus.cpp | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/indra/newview/llviewermediafocus.cpp b/indra/newview/llviewermediafocus.cpp index db31714f16..74ed6eea7b 100644 --- a/indra/newview/llviewermediafocus.cpp +++ b/indra/newview/llviewermediafocus.cpp @@ -227,8 +227,27 @@ void LLViewerMediaFocus::setCameraZoom(F32 padding_factor) distance += depth * 0.5; // Finally animate the camera to this new position and focal point - gAgent.setCameraPosAndFocusGlobal(LLSelectMgr::getInstance()->getSelectionCenterGlobal() + LLVector3d(pick.mNormal * distance), - LLSelectMgr::getInstance()->getSelectionCenterGlobal(), LLSelectMgr::getInstance()->getSelection()->getFirstObject()->mID ); + LLVector3d camera_pos, target_pos; + // Target lookat position is the center of the selection (in global coords) + target_pos = LLSelectMgr::getInstance()->getSelectionCenterGlobal(); + // Target look-from (camera) position is "distance" away from the target along the normal + LLVector3d pickNormal = LLVector3d(pick.mNormal); + pickNormal.normalize(); + camera_pos = target_pos + pickNormal * distance; + if (pickNormal == LLVector3d::z_axis || pickNormal == LLVector3d::z_axis_neg) + { + // If the normal points directly up, the camera will "flip" around. + // We try to avoid this by adjusting the target camera position a + // smidge towards current camera position + LLVector3d cur_camera_pos = LLVector3d(gAgent.getCameraPositionGlobal()); + LLVector3d delta = (cur_camera_pos - camera_pos); + F64 len = delta.length(); + delta.normalize(); + // Move 1% of the distance towards original camera location + camera_pos += 0.01 * len * delta; + } + + gAgent.setCameraPosAndFocusGlobal(camera_pos, target_pos, LLSelectMgr::getInstance()->getSelection()->getFirstObject()->mID ); } } void LLViewerMediaFocus::onFocusReceived() |