From 4c87b0cf054695a5b5a21d7be6dd9b5174c1f7f5 Mon Sep 17 00:00:00 2001 From: Jupeyy Date: Tue, 13 Oct 2020 13:15:44 +0200 Subject: [PATCH] Make menu background camera impl more robust --- .../client/components/menu_background.cpp | 23 +++++++++++++++---- src/game/client/components/menu_background.h | 1 + 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/game/client/components/menu_background.cpp b/src/game/client/components/menu_background.cpp index 9ecbed995..b154967d5 100644 --- a/src/game/client/components/menu_background.cpp +++ b/src/game/client/components/menu_background.cpp @@ -21,6 +21,8 @@ CMenuBackground::CMenuBackground() : m_Camera.m_PrevCenter = vec2(0.0f, 0.0f); m_MenuCenter = vec2(0.0f, 0.0f); + m_ChangedPosition = false; + ResetPositions(); m_CurrentPosition = -1; @@ -70,7 +72,7 @@ void CMenuBackground::ResetPositions() m_Positions[POS_SETTINGS_DDNET] = vec2(1200.0f, 200.0f); m_Positions[POS_SETTINGS_ASSETS] = vec2(500.0f, 500.0f); for(int i = 0; i < POS_BROWSER_CUSTOM_NUM; ++i) - m_Positions[POS_BROWSER_CUSTOM0 + i] = vec2(500.0f + (75.0f * (float)i), 1250.0f - (75.0f * (float)i)); + m_Positions[POS_BROWSER_CUSTOM0 + i] = vec2(500.0f + (75.0f * (float)i), 650.0f - (75.0f * (float)i)); for(int i = 0; i < POS_SETTINGS_RESERVED_NUM; ++i) m_Positions[POS_SETTINGS_RESERVED0 + i] = vec2(0, 0); for(int i = 0; i < POS_RESERVED_NUM; ++i) @@ -308,7 +310,8 @@ bool CMenuBackground::Render() m_Camera.m_Zoom = 0.7f; static vec2 Dir = vec2(1.0f, 0.0f); - if(distance(m_Camera.m_Center, m_RotationCenter) <= (float)g_Config.m_ClRotationRadius + 0.5f) + float DistToCenter = distance(m_Camera.m_Center, m_RotationCenter); + if(!m_ChangedPosition && absolute(DistToCenter - (float)g_Config.m_ClRotationRadius) <= 0.5f) { // do little rotation float RotPerTick = 360.0f / (float)g_Config.m_ClRotationSpeed * clamp(Client()->RenderFrameTime(), 0.0f, 0.1f); @@ -318,9 +321,17 @@ bool CMenuBackground::Render() else { // positions for the animation - Dir = normalize(m_AnimationStartPos - m_RotationCenter); - vec2 TargetPos = m_RotationCenter + Dir * (float)g_Config.m_ClRotationRadius; + vec2 DirToCenter; + if(DistToCenter > 0.5f) + DirToCenter = normalize(m_AnimationStartPos - m_RotationCenter); + else + DirToCenter = vec2(1, 0); + vec2 TargetPos = m_RotationCenter + DirToCenter * (float)g_Config.m_ClRotationRadius; float Distance = distance(m_AnimationStartPos, TargetPos); + if(Distance > 0.001f) + Dir = normalize(m_AnimationStartPos - TargetPos); + else + Dir = vec2(1, 0); // move time m_MoveTime += clamp(Client()->RenderFrameTime(), 0.0f, 0.1f) * g_Config.m_ClCameraSpeed / 10.0f; @@ -328,6 +339,8 @@ bool CMenuBackground::Render() XVal = pow(XVal, 7.0f); m_Camera.m_Center = TargetPos + Dir * (XVal * Distance); + + m_ChangedPosition = false; } CMapLayers::OnRender(); @@ -352,6 +365,8 @@ void CMenuBackground::ChangePosition(int PositionNumber) { m_CurrentPosition = POS_START; } + + m_ChangedPosition = true; } m_AnimationStartPos = m_Camera.m_Center; m_RotationCenter = m_Positions[m_CurrentPosition]; diff --git a/src/game/client/components/menu_background.h b/src/game/client/components/menu_background.h index 15c982ce7..36a298e23 100644 --- a/src/game/client/components/menu_background.h +++ b/src/game/client/components/menu_background.h @@ -79,6 +79,7 @@ public: vec2 m_Positions[NUM_POS]; int m_CurrentPosition; vec2 m_AnimationStartPos; + bool m_ChangedPosition; float m_MoveTime; bool m_IsInit;