From bfd24d7dd8e7e488132099514bd837e0f5651aaa Mon Sep 17 00:00:00 2001 From: Jupeyy Date: Mon, 7 Sep 2020 00:19:38 +0200 Subject: [PATCH] Clamp camera zoom --- src/game/client/components/camera.cpp | 13 ++++++++++++- src/game/client/components/camera.h | 2 ++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/game/client/components/camera.cpp b/src/game/client/components/camera.cpp index 55e075fbd..2cab23422 100644 --- a/src/game/client/components/camera.cpp +++ b/src/game/client/components/camera.cpp @@ -36,9 +36,19 @@ void CCamera::ScaleZoom(float Factor) ChangeZoom(CurrentTarget * Factor); } +float CCamera::MaxZoomLevel() +{ + return (Graphics()->IsTileBufferingEnabled()? 60 : 30); +} + +float CCamera::MinZoomLevel() +{ + return 0.01f; +} + void CCamera::ChangeZoom(float Target) { - if(Target >= (Graphics()->IsTileBufferingEnabled()? 60 : 30)) + if(Target > MaxZoomLevel() || Target < MinZoomLevel()) { return; } @@ -75,6 +85,7 @@ void CCamera::OnRender() { m_Zoom = m_ZoomSmoothing.Evaluate(ZoomProgress(Time)); } + m_Zoom = clamp(m_Zoom, MinZoomLevel(), MaxZoomLevel()); } if(!(m_pClient->m_Snap.m_SpecInfo.m_Active || GameClient()->m_GameInfo.m_AllowZoom || Client()->State() == IClient::STATE_DEMOPLAYBACK)) diff --git a/src/game/client/components/camera.h b/src/game/client/components/camera.h index cfb69ae4c..4968f5301 100644 --- a/src/game/client/components/camera.h +++ b/src/game/client/components/camera.h @@ -28,6 +28,8 @@ class CCamera : public CComponent void ChangeZoom(float Target); float ZoomProgress(float CurrentTime) const; + float MinZoomLevel(); + float MaxZoomLevel(); public: vec2 m_Center; bool m_ZoomSet;