From 9388692a4717f0ecccfb2e37aedddb779042dae2 Mon Sep 17 00:00:00 2001 From: Ralph Sennhauser Date: Mon, 25 May 2026 20:37:05 +0200 Subject: [PATCH] Add bird view to Atlas Fixes: #2657 Signed-off-by: Ralph Sennhauser --- .../AtlasUI/ScenarioEditor/ScenarioEditor.cpp | 6 +++ .../Handlers/CameraCtrlHandlers.cpp | 38 +++++++++++++++++++ source/tools/atlas/GameInterface/Messages.h | 4 +- 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp b/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp index 02133d5df3..ee63902d98 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/ScenarioEditor.cpp @@ -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(); diff --git a/source/tools/atlas/GameInterface/Handlers/CameraCtrlHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/CameraCtrlHandlers.cpp index 4028483a00..31293a4d76 100644 --- a/source/tools/atlas/GameInterface/Handlers/CameraCtrlHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/CameraCtrlHandlers.cpp @@ -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 / 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; +} + } diff --git a/source/tools/atlas/GameInterface/Messages.h b/source/tools/atlas/GameInterface/Messages.h index 27acf7d03c..32ea2d9ce3 100644 --- a/source/tools/atlas/GameInterface/Messages.h +++ b/source/tools/atlas/GameInterface/Messages.h @@ -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