Skip to content

Commit 62486c0

Browse files
authored
#4393 Follow-Up (Roll value) (#4424)
* Calculate camera roll from matrix when not in fixed mode (Follow up #4393)
1 parent d0e210a commit 62486c0

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <game/TaskBasic.h>
3232
#include <enums/VehicleType.h>
3333
#include <enums/HandlingProperty.h>
34+
#include <numbers>
3435

3536
using std::list;
3637

@@ -5016,11 +5017,24 @@ bool CStaticFunctionDefinitions::GetCameraMatrix(CVector& vecPosition, CVector&
50165017

50175018
fFOV = m_pCamera->GetAccurateFOV();
50185019

5019-
if (!m_pCamera->IsInFixedMode() && fRoll == 0.0f)
5020+
if (fRoll == 0.0f)
50205021
{
5021-
CVector rotation;
5022-
m_pCamera->GetRotationDegrees(rotation);
5023-
fRoll = rotation.fZ;
5022+
// Calculate roll from camera matrix when not directly available
5023+
CMatrix matrix;
5024+
m_pCamera->GetMatrix(matrix);
5025+
5026+
CVector worldUp(0.0f, 0.0f, 1.0f);
5027+
CVector cameraUp = matrix.vUp;
5028+
CVector cameraRight = matrix.vRight;
5029+
5030+
// Project camera up vector onto plane perpendicular to camera front
5031+
CVector projectedUp = cameraUp - matrix.vFront * cameraUp.DotProduct(&matrix.vFront);
5032+
projectedUp.Normalize();
5033+
5034+
float cosRoll = worldUp.DotProduct(&projectedUp);
5035+
float sinRoll = cameraRight.DotProduct(&worldUp);
5036+
5037+
fRoll = std::atan2(sinRoll, cosRoll) * (180.0f / std::numbers::pi_v<float>);
50245038
}
50255039

50265040
return true;

0 commit comments

Comments
 (0)