Skip to content

Commit 25a5783

Browse files
committed
Avoid fixed camera mode on no-op setCameraMatrix calls
1 parent 3964410 commit 25a5783

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5079,6 +5079,27 @@ bool CStaticFunctionDefinitions::SetCameraMatrix(const CVector& vecPosition, CVe
50795079

50805080
if (!m_pCamera->IsInFixedMode())
50815081
{
5082+
// Some scripts call setCameraMatrix(getCameraMatrix()) while dead to preserve the current frame.
5083+
// Treat this as a no-op so we don't switch into fixed mode and block later spectate target updates.
5084+
CMatrix currentMatrix;
5085+
if (m_pCamera->GetMatrix(currentMatrix))
5086+
{
5087+
const CVector currentLookAt = currentMatrix.vPos + currentMatrix.vFront;
5088+
const CVector requestedLookAt = pvecLookAt ? *pvecLookAt : currentLookAt;
5089+
5090+
constexpr float kCameraNoOpEpsilon = 0.01f;
5091+
const float posDeltaSq = (currentMatrix.vPos - vecPosition).LengthSquared();
5092+
const float lookDeltaSq = (currentLookAt - requestedLookAt).LengthSquared();
5093+
const float epsilonSq = kCameraNoOpEpsilon * kCameraNoOpEpsilon;
5094+
5095+
if (posDeltaSq <= epsilonSq && lookDeltaSq <= epsilonSq)
5096+
{
5097+
if (std::isfinite(fFOV) && fFOV > 0.0f && fFOV < 180.0f)
5098+
m_pCamera->SetFOV(fFOV);
5099+
return true;
5100+
}
5101+
}
5102+
50825103
m_pCamera->ToggleCameraFixedMode(true);
50835104
}
50845105

0 commit comments

Comments
 (0)