From 4c6584d1ecc57e8a34e078935b03851b59d4f9eb Mon Sep 17 00:00:00 2001 From: Hadet Date: Thu, 28 May 2026 21:27:52 -0500 Subject: add Over-The-Shoulder mouse look alternative --- indra/newview/llagentcamera.cpp | 76 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 3 deletions(-) (limited to 'indra/newview/llagentcamera.cpp') diff --git a/indra/newview/llagentcamera.cpp b/indra/newview/llagentcamera.cpp index 369a6d3697..80dfeac2d2 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() + @@ -1598,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 ots_focus_dist(gSavedSettings, "OTSFocusDistance", 10.0f); + static LLCachedControl ots_height(gSavedSettings, "OTSCameraHeight", 0.5f); + static LLCachedControl 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); @@ -1776,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 ots_dist(gSavedSettings, "OTSCameraDistance", 3.0f); + static LLCachedControl ots_side(gSavedSettings, "OTSCameraSide", -0.5f); + static LLCachedControl 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()) @@ -2243,6 +2269,50 @@ 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); + } + } +} + +//----------------------------------------------------------------------------- +// 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() //----------------------------------------------------------------------------- -- cgit v1.3