diff --git a/binaries/data/config/default.cfg b/binaries/data/config/default.cfg index 74a88e151c..772258d7b6 100644 --- a/binaries/data/config/default.cfg +++ b/binaries/data/config/default.cfg @@ -248,6 +248,7 @@ reset = "R" ; Reset camera rotation to default follow = "" ; Follow the first unit in the selection rallypointfocus = "" ; Focus the camera on the rally point of the selected building lastattackfocus = "Space" ; Focus the camera on the last notified attack +togglebirdseyeview = "" ; Toggle bird's eye view zoom.in = Plus, NumPlus ; Zoom camera in (continuous control) zoom.out = Minus, NumMinus ; Zoom camera out (continuous control) zoom.wheel.in = WheelUp ; Zoom camera in (stepped control) diff --git a/binaries/data/mods/public/gui/credits/texts/programming.json b/binaries/data/mods/public/gui/credits/texts/programming.json index 51b45ae852..1118065735 100644 --- a/binaries/data/mods/public/gui/credits/texts/programming.json +++ b/binaries/data/mods/public/gui/credits/texts/programming.json @@ -194,6 +194,7 @@ { "nick": "mattlott", "name": "Matt Lott" }, { "nick": "maveric", "name": "Anton Protko" }, { "nick": "mbusy", "name": "Maxime Busy" }, + { "nick": "Mentula" }, { "nick": "Micnasty", "name": "Travis Gorkin" }, { "name": "MikoĊ‚aj \"Bajter\" Korcz" }, { "nick": "mimo" }, diff --git a/binaries/data/mods/public/gui/hotkeys/spec/camera.json b/binaries/data/mods/public/gui/hotkeys/spec/camera.json index 60db586c2a..ce8f838882 100644 --- a/binaries/data/mods/public/gui/hotkeys/spec/camera.json +++ b/binaries/data/mods/public/gui/hotkeys/spec/camera.json @@ -23,6 +23,10 @@ "name": "Focus on last attack notification", "desc": "Focus the camera on the position of the last attack notification." }, + "camera.togglebirdseyeview": { + "name": "Toggle bird's eye view", + "desc": "Toggle between regular and bird's eye (top-down) views." + }, "camera.zoom.in": { "name": "Zoom in", "desc": "Zoom camera in." diff --git a/source/graphics/CameraController.cpp b/source/graphics/CameraController.cpp index 0845ed4219..8ecc559602 100644 --- a/source/graphics/CameraController.cpp +++ b/source/graphics/CameraController.cpp @@ -54,6 +54,7 @@ CCameraController::CCameraController(CCamera& camera) m_ConstrainCamera(true), m_FollowEntity(INVALID_ENTITY), m_FollowFirstPerson(false), + m_BirdsEyeView(false), // Dummy values (these will be filled in by the config file) m_ViewScrollSpeed(0), @@ -179,9 +180,9 @@ void CCameraController::Update(const float deltaRealTime) m_RotateY.AddSmoothly(m_ViewRotateYSpeed * deltaRealTime); if (HotkeyIsPressed("camera.rotate.ccw")) m_RotateY.AddSmoothly(-m_ViewRotateYSpeed * deltaRealTime); - if (HotkeyIsPressed("camera.rotate.up")) + if (HotkeyIsPressed("camera.rotate.up") && !m_BirdsEyeView) m_RotateX.AddSmoothly(-m_ViewRotateXSpeed * deltaRealTime); - if (HotkeyIsPressed("camera.rotate.down")) + if (HotkeyIsPressed("camera.rotate.down") && !m_BirdsEyeView) m_RotateX.AddSmoothly(m_ViewRotateXSpeed * deltaRealTime); float moveRightward = 0.f; @@ -297,7 +298,12 @@ void CCameraController::Update(const float deltaRealTime) } if (m_ConstrainCamera) - m_RotateX.ClampSmoothly(DEGTORAD(m_ViewRotateXMin), DEGTORAD(m_ViewRotateXMax)); + { + if (m_BirdsEyeView) + m_RotateX.ClampSmoothly(M_PI / 2, M_PI / 2); + else + m_RotateX.ClampSmoothly(DEGTORAD(m_ViewRotateXMin), DEGTORAD(m_ViewRotateXMax)); + } FocusHeight(true); @@ -462,6 +468,9 @@ void CCameraController::SetCamera(const CVector3D& pos, float rotX, float rotY, // Break out of following mode so the camera really moves to the target m_FollowEntity = INVALID_ENTITY; + + // Leave bird's eye view + m_BirdsEyeView = false; } void CCameraController::MoveCameraTarget(const CVector3D& target) @@ -508,6 +517,9 @@ void CCameraController::ResetCameraTarget(const CVector3D& target) // Break out of following mode so the camera really moves to the target m_FollowEntity = INVALID_ENTITY; + + // Leave bird's eye view + m_BirdsEyeView = false; } void CCameraController::FollowEntity(entity_id_t entity, bool firstPerson) @@ -542,6 +554,16 @@ void CCameraController::ResetCameraAngleZoom() // Reset orientations to default m_RotateX.SetValueSmoothly(DEGTORAD(m_ViewRotateXDefault)); m_RotateY.SetValueSmoothly(DEGTORAD(m_ViewRotateYDefault)); + + // Leave bird's eye view + m_BirdsEyeView = false; +} + +void CCameraController::ToggleBirdsEyeView() +{ + m_BirdsEyeView = !m_BirdsEyeView; + float angle = m_BirdsEyeView ? M_PI / 2 : DEGTORAD(m_ViewRotateXDefault); + m_RotateX.SetValueSmoothly(angle); } void CCameraController::SetupCameraMatrixSmooth(CMatrix3D* orientation) @@ -640,6 +662,11 @@ InReaction CCameraController::HandleEvent(const SDL_Event_* ev) ResetCameraAngleZoom(); return IN_HANDLED; } + else if (hotkey == "camera.togglebirdseyeview") + { + ToggleBirdsEyeView(); + return IN_HANDLED; + } return IN_PASS; } diff --git a/source/graphics/CameraController.h b/source/graphics/CameraController.h index 370ac8fe38..1a60ead7ca 100644 --- a/source/graphics/CameraController.h +++ b/source/graphics/CameraController.h @@ -60,6 +60,7 @@ public: private: CVector3D GetSmoothPivot(CCamera &camera) const; void ResetCameraAngleZoom(); + void ToggleBirdsEyeView(); void SetupCameraMatrixSmooth(CMatrix3D* orientation); void SetupCameraMatrixSmoothRot(CMatrix3D* orientation); void SetupCameraMatrixNonSmooth(CMatrix3D* orientation); @@ -86,6 +87,11 @@ private: */ bool m_FollowFirstPerson; + /** + * Whether the camera is in bird's eye view mode. + */ + bool m_BirdsEyeView; + // Settings float m_ViewScrollSpeed; float m_ViewScrollSpeedModifier;