3083: Make menu background camera impl more robust r=def- a=Jupeyy

The vanilla code isnt really robust against short distances, hope this fixes almost all edge cases

Co-authored-by: Jupeyy <jupjopjap@gmail.com>
This commit is contained in:
bors[bot] 2020-10-13 16:00:42 +00:00 committed by GitHub
commit 6ee362fa0e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 4 deletions

View file

@ -21,6 +21,8 @@ CMenuBackground::CMenuBackground() :
m_Camera.m_PrevCenter = vec2(0.0f, 0.0f); m_Camera.m_PrevCenter = vec2(0.0f, 0.0f);
m_MenuCenter = vec2(0.0f, 0.0f); m_MenuCenter = vec2(0.0f, 0.0f);
m_ChangedPosition = false;
ResetPositions(); ResetPositions();
m_CurrentPosition = -1; m_CurrentPosition = -1;
@ -70,7 +72,7 @@ void CMenuBackground::ResetPositions()
m_Positions[POS_SETTINGS_DDNET] = vec2(1200.0f, 200.0f); m_Positions[POS_SETTINGS_DDNET] = vec2(1200.0f, 200.0f);
m_Positions[POS_SETTINGS_ASSETS] = vec2(500.0f, 500.0f); m_Positions[POS_SETTINGS_ASSETS] = vec2(500.0f, 500.0f);
for(int i = 0; i < POS_BROWSER_CUSTOM_NUM; ++i) 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) for(int i = 0; i < POS_SETTINGS_RESERVED_NUM; ++i)
m_Positions[POS_SETTINGS_RESERVED0 + i] = vec2(0, 0); m_Positions[POS_SETTINGS_RESERVED0 + i] = vec2(0, 0);
for(int i = 0; i < POS_RESERVED_NUM; ++i) for(int i = 0; i < POS_RESERVED_NUM; ++i)
@ -308,7 +310,8 @@ bool CMenuBackground::Render()
m_Camera.m_Zoom = 0.7f; m_Camera.m_Zoom = 0.7f;
static vec2 Dir = vec2(1.0f, 0.0f); 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 // do little rotation
float RotPerTick = 360.0f / (float)g_Config.m_ClRotationSpeed * clamp(Client()->RenderFrameTime(), 0.0f, 0.1f); float RotPerTick = 360.0f / (float)g_Config.m_ClRotationSpeed * clamp(Client()->RenderFrameTime(), 0.0f, 0.1f);
@ -318,9 +321,17 @@ bool CMenuBackground::Render()
else else
{ {
// positions for the animation // positions for the animation
Dir = normalize(m_AnimationStartPos - m_RotationCenter); vec2 DirToCenter;
vec2 TargetPos = m_RotationCenter + Dir * (float)g_Config.m_ClRotationRadius; 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); float Distance = distance(m_AnimationStartPos, TargetPos);
if(Distance > 0.001f)
Dir = normalize(m_AnimationStartPos - TargetPos);
else
Dir = vec2(1, 0);
// move time // move time
m_MoveTime += clamp(Client()->RenderFrameTime(), 0.0f, 0.1f) * g_Config.m_ClCameraSpeed / 10.0f; 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); XVal = pow(XVal, 7.0f);
m_Camera.m_Center = TargetPos + Dir * (XVal * Distance); m_Camera.m_Center = TargetPos + Dir * (XVal * Distance);
m_ChangedPosition = false;
} }
CMapLayers::OnRender(); CMapLayers::OnRender();
@ -352,6 +365,8 @@ void CMenuBackground::ChangePosition(int PositionNumber)
{ {
m_CurrentPosition = POS_START; m_CurrentPosition = POS_START;
} }
m_ChangedPosition = true;
} }
m_AnimationStartPos = m_Camera.m_Center; m_AnimationStartPos = m_Camera.m_Center;
m_RotationCenter = m_Positions[m_CurrentPosition]; m_RotationCenter = m_Positions[m_CurrentPosition];

View file

@ -79,6 +79,7 @@ public:
vec2 m_Positions[NUM_POS]; vec2 m_Positions[NUM_POS];
int m_CurrentPosition; int m_CurrentPosition;
vec2 m_AnimationStartPos; vec2 m_AnimationStartPos;
bool m_ChangedPosition;
float m_MoveTime; float m_MoveTime;
bool m_IsInit; bool m_IsInit;