diff options
Diffstat (limited to 'indra/newview/llagentcamera.cpp')
| -rw-r--r-- | indra/newview/llagentcamera.cpp | 92 |
1 files changed, 86 insertions, 6 deletions
diff --git a/indra/newview/llagentcamera.cpp b/indra/newview/llagentcamera.cpp index d884b32ac0..6f9f8bfa2a 100644 --- a/indra/newview/llagentcamera.cpp +++ b/indra/newview/llagentcamera.cpp @@ -1176,7 +1176,7 @@ void LLAgentCamera::updateLookAt(const S32 mouse_x, const S32 mouse_y) LLVector3 headLookAxis; LLCoordFrame frameCamera = *((LLCoordFrame*)LLViewerCamera::getInstance()); - if (cameraMouselook()) + if (cameraMouselook() || cameraOTS()) { lookAtType = LOOKAT_TARGET_MOUSELOOK; } @@ -1409,7 +1409,7 @@ void LLAgentCamera::updateCamera() gAgent.setShowAvatar(true); } - if (isAgentAvatarValid() && (mCameraMode != CAMERA_MODE_MOUSELOOK)) + if (isAgentAvatarValid() && mCameraMode != CAMERA_MODE_MOUSELOOK) { gAgentAvatarp->updateAttachmentVisibility(mCameraMode); } @@ -1497,7 +1497,8 @@ void LLAgentCamera::updateCamera() } gAgent.setLastPositionGlobal(global_pos); - if (LLVOAvatar::sVisibleInFirstPerson && isAgentAvatarValid() && !gAgentAvatarp->isSitting() && cameraMouselook()) + // Exclude OTS — shoulder camera position must not be overridden by head-tracking. + if (LLVOAvatar::sVisibleInFirstPerson && isAgentAvatarValid() && !gAgentAvatarp->isSitting() && cameraMouselook() && !cameraOTS()) { LLVector3 head_pos = gAgentAvatarp->mHeadp->getWorldPosition() + LLVector3(0.08f, 0.f, 0.05f) * gAgentAvatarp->mHeadp->getWorldRotation() + @@ -1511,6 +1512,7 @@ void LLAgentCamera::updateCamera() LLVector3 chest_scale = chest_joint->getScale(); // shorten avatar skeleton to avoid foot interpenetration +#if 0 // This offsets mouselook attachments, is disabled in other TPVs if (!gAgentAvatarp->mInAir) { LLVector3 chest_offset = LLVector3(0.f, 0.f, chest_joint->getPosition().mV[VZ]) * torso_joint->getWorldRotation(); @@ -1524,6 +1526,7 @@ void LLAgentCamera::updateCamera() chest_joint->setScale(LLVector3(1.f, 1.f, scale_factor)); diff.mV[VZ] = 0.f; } +#endif // SL-315 gAgentAvatarp->mPelvisp->setPosition(gAgentAvatarp->mPelvisp->getPosition() + diff); @@ -1596,6 +1599,19 @@ LLVector3d LLAgentCamera::calcFocusPositionTargetGlobal() mFocusTargetGlobal = gAgent.getPosGlobalFromAgent(mFollowCam.getSimulatedFocus()); return mFocusTargetGlobal; } + else if (mCameraMode == CAMERA_MODE_OTS) + { + // Focus in front of avatar at aim height + static LLCachedControl<F32> ots_focus_dist(gSavedSettings, "OTSFocusDistance", 10.0f); + static LLCachedControl<F32> ots_height(gSavedSettings, "OTSCameraHeight", 0.5f); + static LLCachedControl<F32> ots_side(gSavedSettings, "OTSCameraSide", -0.5f); + LLVector3 focus_local((F32)ots_focus_dist, (F32)ots_side * 0.3f, (F32)ots_height * 0.5f); + LLQuaternion agent_rot = gAgent.getFrameAgent().getQuaternion(); + LLVector3 focus_world = focus_local * agent_rot; + LLVector3d avatar_pos = gAgent.getPosGlobalFromAgent(getAvatarRootPosition()); + mFocusTargetGlobal = avatar_pos + LLVector3d(focus_world); + return mFocusTargetGlobal; + } else if (mCameraMode == CAMERA_MODE_MOUSELOOK) { LLVector3d at_axis(1.0, 0.0, 0.0); @@ -1774,6 +1790,18 @@ LLVector3d LLAgentCamera::calcCameraPositionTargetGlobal(bool *hit_limit) { camera_position_global = gAgent.getPosGlobalFromAgent(mFollowCam.getSimulatedPosition()); } + else if (mCameraMode == CAMERA_MODE_OTS) + { + // Shoulder offset camera — avatar-local space: X=forward, Y=left, Z=up + static LLCachedControl<F32> ots_dist(gSavedSettings, "OTSCameraDistance", 3.0f); + static LLCachedControl<F32> ots_side(gSavedSettings, "OTSCameraSide", -0.5f); + static LLCachedControl<F32> ots_height(gSavedSettings, "OTSCameraHeight", 0.5f); + LLVector3 local_offset(-(F32)ots_dist, (F32)ots_side, (F32)ots_height); + LLQuaternion agent_rot = gAgent.getFrameAgent().getQuaternion(); + LLVector3 world_offset = local_offset * agent_rot; + LLVector3d avatar_pos = gAgent.getPosGlobalFromAgent(getAvatarRootPosition()); + camera_position_global = avatar_pos + LLVector3d(world_offset); + } else if (mCameraMode == CAMERA_MODE_MOUSELOOK) { if (!isAgentAvatarValid() || gAgentAvatarp->mDrawable.isNull()) @@ -2242,6 +2270,58 @@ void LLAgentCamera::changeCameraToDefault() //----------------------------------------------------------------------------- +// changeCameraToOTS() +// Over-the-shoulder aim mode. +// Calls changeCameraToMouselook() to inherit ALL of its input setup +// (cursor hiding, mouse capture, control flags, focus management), +// then immediately overrides mCameraMode to CAMERA_MODE_OTS so that +// calcCameraPositionTargetGlobal places the camera at the shoulder offset +// instead of the avatar's eye position. +// Avatar rendering is handled explicitly in needsRenderAvatar() and needsRenderHead(). +//----------------------------------------------------------------------------- +void LLAgentCamera::changeCameraToOTS() +{ + if (mCameraMode != CAMERA_MODE_OTS) + { + // Inherit everything from mouselook: cursor lock, mouse capture, + // AGENT_CONTROL_MOUSELOOK flag, keyboard focus clear, etc. + changeCameraToMouselook(false); + + // Override mCameraMode to OTS so position/focus calculations + // use the shoulder offset instead of the eye position. + mCameraMode = CAMERA_MODE_OTS; + + // changeCameraToMouselook hid attachments via updateAttachmentVisibility + // with CAMERA_MODE_MOUSELOOK. Restore full visibility for OTS mode. + if (isAgentAvatarValid()) + { + gAgentAvatarp->updateAttachmentVisibility(CAMERA_MODE_THIRD_PERSON); + } + + // Start the camera animation LAST, after mCameraMode is OTS and after + // changeCameraToMouselook(false) has cleared mCameraAnimating via its + // animate=false branch. The rendered camera is still at the old + // (third-person) position this frame, so startCameraAnimation snapshots + // that as the start point and updateCamera lerps to the OTS shoulder + // target over ZoomTime seconds — matching the mouselook transition feel. + startCameraAnimation(); + } +} + +//----------------------------------------------------------------------------- +// changeCameraFromOTS() +//----------------------------------------------------------------------------- +void LLAgentCamera::changeCameraFromOTS() +{ + if (mCameraMode == CAMERA_MODE_OTS) + { + // changeCameraToDefault handles clearing AGENT_CONTROL_MOUSELOOK, + // showing the cursor, and restoring the normal camera mode. + changeCameraToDefault(); + } +} + +//----------------------------------------------------------------------------- // changeCameraToFollow() //----------------------------------------------------------------------------- void LLAgentCamera::changeCameraToFollow(bool animate) @@ -2334,7 +2414,7 @@ void LLAgentCamera::changeCameraToThirdPerson(bool animate) } mCameraLag.clearVec(); - if (mCameraMode == CAMERA_MODE_MOUSELOOK) + if (mCameraMode == CAMERA_MODE_MOUSELOOK || mCameraMode == CAMERA_MODE_OTS) { mCurrentCameraDistance = MIN_CAMERA_DISTANCE; mTargetCameraDistance = MIN_CAMERA_DISTANCE; @@ -2656,9 +2736,9 @@ void LLAgentCamera::setCameraPosAndFocusGlobal(const LLVector3d& camera_pos, con if (mCameraAnimating) { - const F64 ANIM_METERS_PER_SECOND = 10.0; + const F64 ANIM_METERS_PER_SECOND = 20.0; const F64 MIN_ANIM_SECONDS = 0.5; - const F64 MAX_ANIM_SECONDS = 10.0; + const F64 MAX_ANIM_SECONDS = 3.0; F64 anim_duration = llmax( MIN_ANIM_SECONDS, sqrt(focus_delta_squared) / ANIM_METERS_PER_SECOND ); anim_duration = llmin( anim_duration, MAX_ANIM_SECONDS ); setAnimationDuration( (F32)anim_duration ); |
