From 4d76fd88bad3bce1cdba50cb6d340f25e2fc7df4 Mon Sep 17 00:00:00 2001 From: PtaQQ Date: Sat, 13 Jun 2026 14:03:15 +0200 Subject: [PATCH] SpringController: name the camera focus point a "focus surface" Pure rename in preparation for the smooth mesh height tracking rework. The camera focus height and the zoom-distance-to-focus computation are about to stop being plain raw-ground lookups, so route them through GetFocusSurfaceHeight() and DistanceToFocusSurface() wrappers. Behavior is unchanged: both currently forward to the raw ground. Co-Authored-By: Claude Opus 4.8 (1M context) --- rts/Game/Camera/SpringController.cpp | 21 +++++++++++++++++---- rts/Game/Camera/SpringController.h | 2 ++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/rts/Game/Camera/SpringController.cpp b/rts/Game/Camera/SpringController.cpp index a4c1fdcbf46..8297bff4717 100644 --- a/rts/Game/Camera/SpringController.cpp +++ b/rts/Game/Camera/SpringController.cpp @@ -253,8 +253,8 @@ float CSpringController::ZoomIn(const float3& curCamPos, const float3& newDir, c const float zoomAmount = std::min(1.0f - scaledMode, (curDistPre - minDist) / curDistPre); const float3 wantedPos = curCamPos + cursorVec * zoomAmount; - // figure out how far we will end up from the ground at new wanted point - curDist = DistanceToGround(wantedPos, dir, pos.y); + // figure out how far we will end up from the focus surface at new wanted point + curDist = DistanceToFocusSurface(wantedPos); pos = wantedPos + dir * curDist; return 0.25f; @@ -293,7 +293,7 @@ float CSpringController::ZoomOut(const float3& curCamPos, const float3& newDir, auto extrapolate_position = [&] (float scale) { const float3 wantedCamPos = curCamPos + cursorVec * (1.0f - scaledMode) * scale; - const float newDist = DistanceToGround(wantedCamPos, dir, pos.y); + const float newDist = DistanceToFocusSurface(wantedCamPos); return std::pair{wantedCamPos, newDist}; }; @@ -318,13 +318,26 @@ float CSpringController::ZoomOut(const float3& curCamPos, const float3& newDir, +float CSpringController::GetFocusSurfaceHeight(float x, float z) const +{ + RECOIL_DETAILED_TRACY_ZONE; + return CGround::GetHeightReal(x, z, false); +} + +float CSpringController::DistanceToFocusSurface(const float3& from) const +{ + RECOIL_DETAILED_TRACY_ZONE; + return DistanceToGround(from, dir, pos.y); +} + + void CSpringController::Update() { RECOIL_DETAILED_TRACY_ZONE; pos.x = std::clamp(pos.x, 0.01f, mapDims.mapx * SQUARE_SIZE - 0.01f); pos.z = std::clamp(pos.z, 0.01f, mapDims.mapy * SQUARE_SIZE - 0.01f); - pos.y = CGround::GetHeightReal(pos.x, pos.z, false); // always focus on the ground + pos.y = GetFocusSurfaceHeight(pos.x, pos.z); // always focus on the ground rot.x = std::clamp(rot.x, math::PI * 0.51f, math::PI * 0.99f); // camera->SetRot(float3(rot.x, GetAzimuth(), rot.z)); diff --git a/rts/Game/Camera/SpringController.h b/rts/Game/Camera/SpringController.h index 177ab73ec54..a92b81ad3fe 100644 --- a/rts/Game/Camera/SpringController.h +++ b/rts/Game/Camera/SpringController.h @@ -44,6 +44,8 @@ class CSpringController : public CCameraController inline float ZoomOut(const float3& curCamPos, const float3& dir, const float& curDistPre, const float& scaledMode); void SmoothCamHeight(const float3& prevPos); + float GetFocusSurfaceHeight(float x, float z) const; + float DistanceToFocusSurface(const float3& from) const; private: float3 rot;