Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions rts/Game/Camera/SpringController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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};
};

Expand All @@ -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));
Expand Down
2 changes: 2 additions & 0 deletions rts/Game/Camera/SpringController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down