From 6006c9d85b5d486aeee9e10595626d701f9ea8a4 Mon Sep 17 00:00:00 2001 From: TsFreddie Date: Wed, 14 Oct 2020 08:43:30 +0800 Subject: [PATCH] smooth camera --- src/game/client/components/camera.cpp | 39 ++++++++++++++++--- src/game/client/components/menus_settings.cpp | 16 ++++++++ src/game/variables.h | 3 ++ 3 files changed, 52 insertions(+), 6 deletions(-) diff --git a/src/game/client/components/camera.cpp b/src/game/client/components/camera.cpp index 45e23a83b..2f83da6e2 100644 --- a/src/game/client/components/camera.cpp +++ b/src/game/client/components/camera.cpp @@ -124,22 +124,49 @@ void CCamera::OnRender() m_CamType = CAMTYPE_PLAYER; } - vec2 CameraOffset(0, 0); + float DeltaTime = Client()->RenderFrameTime(); + static vec2 s_LastMousePos(0, 0); + static vec2 s_CurrentCameraOffset[2] = {vec2(0, 0), vec2(0, 0)}; + static float s_SpeedBias = 0.5f; - float l = length(m_pClient->m_pControls->m_MousePos[g_Config.m_ClDummy]); + if(g_Config.m_ClCameraSmoothness > 0) + { + float CameraSpeed = (1.0f - (g_Config.m_ClCameraSmoothness / 100.0f)) * 9.5f + 0.5f; + float CameraStabilizingFactor = 1 + g_Config.m_ClCameraStabilizing / 100.0f; + + s_SpeedBias += CameraSpeed * DeltaTime; + if(g_Config.m_ClDyncam) + { + s_SpeedBias -= length(m_pClient->m_pControls->m_MousePos[g_Config.m_ClDummy] - s_LastMousePos) * log10f(CameraStabilizingFactor) * 0.02f; + s_SpeedBias = clamp(s_SpeedBias, 0.5f, CameraSpeed); + } + else + { + s_SpeedBias = maximum(5.0f, CameraSpeed); // make sure toggle back is fast + } + } + + vec2 TargetCameraOffset(0, 0); + s_LastMousePos = m_pClient->m_pControls->m_MousePos[g_Config.m_ClDummy]; + float l = length(s_LastMousePos); if(l > 0.0001f) // make sure that this isn't 0 { float DeadZone = g_Config.m_ClDyncam ? g_Config.m_ClDyncamDeadzone : g_Config.m_ClMouseDeadzone; float FollowFactor = (g_Config.m_ClDyncam ? g_Config.m_ClDyncamFollowFactor : g_Config.m_ClMouseFollowfactor) / 100.0f; float OffsetAmount = maximum(l - DeadZone, 0.0f) * FollowFactor; - CameraOffset = normalize(m_pClient->m_pControls->m_MousePos[g_Config.m_ClDummy]) * OffsetAmount; + TargetCameraOffset = normalize(m_pClient->m_pControls->m_MousePos[g_Config.m_ClDummy]) * OffsetAmount; } - if(m_pClient->m_Snap.m_SpecInfo.m_Active) - m_Center = m_pClient->m_Snap.m_SpecInfo.m_Position + CameraOffset; + if(g_Config.m_ClCameraSmoothness > 0) + s_CurrentCameraOffset[g_Config.m_ClDummy] += (TargetCameraOffset - s_CurrentCameraOffset[g_Config.m_ClDummy]) * minimum(DeltaTime * s_SpeedBias, 1.0f); else - m_Center = m_pClient->m_LocalCharacterPos + CameraOffset; + s_CurrentCameraOffset[g_Config.m_ClDummy] = TargetCameraOffset; + + if(m_pClient->m_Snap.m_SpecInfo.m_Active) + m_Center = m_pClient->m_Snap.m_SpecInfo.m_Position + s_CurrentCameraOffset[g_Config.m_ClDummy]; + else + m_Center = m_pClient->m_LocalCharacterPos + s_CurrentCameraOffset[g_Config.m_ClDummy]; } m_PrevCenter = m_Center; diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp index cd5a8e438..0fc07be8c 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -106,6 +106,22 @@ void CMenus::RenderSettingsGeneral(CUIRect MainView) } } + // smooth camera + Left.HSplitTop(5.0f, 0, &Left); + Left.HSplitTop(20.0f, &Button, &Left); + if(DoButton_CheckBox(&g_Config.m_ClCameraSmoothness, Localize("Smooth Camera"), g_Config.m_ClCameraSmoothness, &Button)) + { + if(g_Config.m_ClCameraSmoothness) + { + g_Config.m_ClCameraSmoothness = 0; + } + else + { + g_Config.m_ClCameraSmoothness = 50; + g_Config.m_ClCameraStabilizing = 50; + } + } + // weapon pickup Left.HSplitTop(5.0f, 0, &Left); Left.HSplitTop(20.0f, &Button, &Left); diff --git a/src/game/variables.h b/src/game/variables.h index 6e3e3b089..5414526f0 100644 --- a/src/game/variables.h +++ b/src/game/variables.h @@ -71,6 +71,9 @@ MACRO_CONFIG_INT(ClDyncamMousesens, cl_dyncam_mousesens, 0, 0, 100000, CFGFLAG_C MACRO_CONFIG_INT(ClDyncamDeadzone, cl_dyncam_deadzone, 300, 1, 1300, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Dynamic camera dead zone") MACRO_CONFIG_INT(ClDyncamFollowFactor, cl_dyncam_follow_factor, 60, 0, 200, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Dynamic camera follow factor") +MACRO_CONFIG_INT(ClCameraSmoothness, cl_camera_smoothness, 0, 0, 100, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Transition amount of the camera movement, 0=instant, 100=slow and smooth") +MACRO_CONFIG_INT(ClCameraStabilizing, cl_camera_stabilizing, 0, 0, 100, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Amount of camera slowdown during fast cursor movement. High value can cause delay in camera movement") + MACRO_CONFIG_INT(EdZoomTarget, ed_zoom_target, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Zoom to the current mouse target") MACRO_CONFIG_INT(EdShowkeys, ed_showkeys, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "")