Skip to content

Commit

Permalink
Make sure scope views are only smoothed once per frame
Browse files Browse the repository at this point in the history
  • Loading branch information
fholger committed Sep 8, 2023
1 parent 01735b7 commit 0394e4b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
34 changes: 25 additions & 9 deletions Sources/CryGame C++/Solution1/CryGame/XPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3104,16 +3104,8 @@ void CPlayer::GetFirePosAngles(Vec3d& firePos, Vec3d& fireAngles)

if (weapon->IsZoomActive())
{
// need to smooth the weapon orientation, or else zoom isn't really usable with motion controls
float factor = 0.03 * powf(DEFAULT_FOV / m_pEntity->GetCamera()->GetFov(), 1.5f);
Vec3 smoothedAngles = fireAngles;
float yawPitchDecay = powf(2.f, -m_pGame->GetSystem()->GetITimer()->GetFrameTime() / factor);
smoothedAngles.z = fireAngles.z + GetAngleDifference360(m_prevFireAngles.z, fireAngles.z) * yawPitchDecay;
smoothedAngles.x = fireAngles.x + GetAngleDifference360(m_prevFireAngles.x, fireAngles.x) * yawPitchDecay;
fireAngles = smoothedAngles;
fireAngles = m_smoothedFireAngles;
}

m_prevFireAngles = fireAngles;
}

if (m_pMountedWeapon)
Expand Down Expand Up @@ -3267,6 +3259,8 @@ void CPlayer::UpdateWeapon()

float frametime=m_pTimer->GetFrameTime();

CalcSmoothedFireAngles();

if(m_stats.firing_grenade)
{
FRAME_PROFILER( "UpdateWeapon::Grenade",GetISystem(),PROFILE_GAME );
Expand Down Expand Up @@ -7258,6 +7252,28 @@ void CPlayer::CheckMeleeWeaponSwing()
m_prevHandPos = handPos;
}

void CPlayer::CalcSmoothedFireAngles()
{
CWeaponClass* weapon = GetSelectedWeapon();
if (!weapon)
return;

Vec3 firePos, fireAngles;
weapon->GetMuzzlePosAngles(firePos, fireAngles);

if (weapon->IsZoomActive())
{
// need to smooth the weapon orientation, or else zoom isn't really usable with motion controls
float factor = 0.03 * powf(DEFAULT_FOV / m_pEntity->GetCamera()->GetFov(), 1.5f);
Vec3 smoothedAngles = fireAngles;
float yawPitchDecay = powf(2.f, -m_pGame->GetSystem()->GetITimer()->GetFrameTime() / factor);
smoothedAngles.z = fireAngles.z + GetAngleDifference360(m_smoothedFireAngles.z, fireAngles.z) * yawPitchDecay;
smoothedAngles.x = fireAngles.x + GetAngleDifference360(m_smoothedFireAngles.x, fireAngles.x) * yawPitchDecay;
fireAngles = smoothedAngles;
}
m_smoothedFireAngles = fireAngles;
}

void CPlayer::CheckLadderDismount()
{
Matrix34 cameraTransform = Matrix34::CreateRotationXYZ(Deg2Rad(m_pEntity->GetCamera()->GetAngles()), m_pEntity->GetCamera()->GetPos());
Expand Down
3 changes: 2 additions & 1 deletion Sources/CryGame C++/Solution1/CryGame/XPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,8 @@ enum eInVehiclestate
Vec3 m_prevMeleePos;
Vec3 m_swingDir;

Vec3 m_prevFireAngles;
void CalcSmoothedFireAngles();
Vec3 m_smoothedFireAngles;

// visible bare hands
CHand* m_handModel[2] = { nullptr };
Expand Down

0 comments on commit 0394e4b

Please sign in to comment.