Add bird view to Atlas

Fixes: #2657
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
This commit is contained in:
Ralph Sennhauser 2026-05-25 20:37:05 +02:00
parent fa9584fdc0
commit 9388692a47
No known key found for this signature in database
3 changed files with 47 additions and 1 deletions

View file

@ -173,6 +173,12 @@ private:
if (KeyScroll(evt, true))
return;
if (evt.GetKeyCode() == 'B')
{
POST_MESSAGE(ToggleBirdsEyeView, ());
return;
}
POST_MESSAGE(GuiKeyEvent, (GetSDLKeyFromWxKeyCode(evt.GetKeyCode()), evt.GetUnicodeKey(), true));
evt.Skip();

View file

@ -258,4 +258,42 @@ MESSAGEHANDLER(SetView)
// TODO: Rotation
}
MESSAGEHANDLER(ToggleBirdsEyeView)
{
if (!g_Game || g_Game->GetView()->GetCinema()->IsPlaying())
return;
static bool birdEyeView{false};
static float declination{0.f};
CCamera& camera = AtlasView::GetView_Game()->GetCamera();
CMatrix3D& orientation = camera.GetOrientation();
CVector3D focus = camera.GetFocus();
if (!birdEyeView)
{
CVector3D in = orientation.GetIn();
declination = atan2(sqrt(in.X*in.X + in.Z*in.Z), in.Y) - std::numbers::pi_v<float> / 2.f;
}
CQuaternion q;
// If really 90° then the camera movement bugs out as it has no clear
// forward anymore, so stick with 89°.
q.FromAxisAngle(orientation.GetLeft(), birdEyeView ?
DEGTORAD(89.f) - declination : DEGTORAD(-89.f) + declination);
CVector3D origin = orientation.GetTranslation();
CVector3D offset = q.Rotate(origin - focus);
q *= orientation.GetRotation();
q.Normalize();
q.ToMatrix(orientation);
orientation.Translate(focus + offset);
camera.UpdateFrustum();
birdEyeView = !birdEyeView;
}
}

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -469,6 +469,8 @@ MESSAGE(SetView,
((sCameraInfo, info))
);
MESSAGE(ToggleBirdsEyeView, );
//////////////////////////////////////////////////////////////////////////
#ifndef MESSAGES_SKIP_STRUCTS