mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-16 05:13:58 -07:00
Add bird view to Atlas
Fixes: #2657 Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
This commit is contained in:
parent
fa9584fdc0
commit
9388692a47
3 changed files with 47 additions and 1 deletions
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue