From 10a672dc8f217b25e22b592479eaed4d23bc97dc Mon Sep 17 00:00:00 2001 From: Kevin Poretti Date: Mon, 16 Jan 2023 12:13:11 -0500 Subject: [PATCH] Clamp Zoom --- GravityStomp/Content/Debug/Camera/TestCamera.umap | 2 +- .../Source/GravityStompGame/Camera/GSCameraActor.cpp | 11 ++++++++++- .../Source/GravityStompGame/Camera/GSCameraActor.h | 8 ++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/GravityStomp/Content/Debug/Camera/TestCamera.umap b/GravityStomp/Content/Debug/Camera/TestCamera.umap index 173f853..f1448bc 100644 --- a/GravityStomp/Content/Debug/Camera/TestCamera.umap +++ b/GravityStomp/Content/Debug/Camera/TestCamera.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:58012414f80549405aff7e9e70751c98fef38532e6b1275f3e412db28726d3b5 +oid sha256:15b2a2303f59190eb01d33b45ebf8a6a4c9976f2cd847fe2f17fc6f5055a0396 size 43400 diff --git a/GravityStomp/Source/GravityStompGame/Camera/GSCameraActor.cpp b/GravityStomp/Source/GravityStompGame/Camera/GSCameraActor.cpp index ff600b4..c249301 100644 --- a/GravityStomp/Source/GravityStompGame/Camera/GSCameraActor.cpp +++ b/GravityStomp/Source/GravityStompGame/Camera/GSCameraActor.cpp @@ -10,6 +10,8 @@ AGSCameraActor::AGSCameraActor() { PanSpeed = 100.0f; ZoomSpeed = 100.0f; + MinZoom = 2666; + MaxZoom = 5000; } @@ -36,11 +38,13 @@ void AGSCameraActor::Tick(float DeltaSeconds) FVector CurrLocation = GetActorLocation(); float ZoomMove = ZoomDirection * ZoomSpeed * DeltaSeconds; + float NewZoom = CurrLocation.X + ZoomMove; + NewZoom = ClampZoom(NewZoom); FVector2D PanMove = PanDirection * PanSpeed * DeltaSeconds; FVector2D NewPan = FVector2D(CurrLocation.Y + PanMove.X, CurrLocation.Z + PanMove.Y); NewPan = ClampCameraLocationToStageBounds(NewPan, ScreenBoundingBox); - FVector NewLocation = FVector(CurrLocation.X + ZoomMove, NewPan.X, NewPan.Y); + FVector NewLocation = FVector(NewZoom, NewPan.X, NewPan.Y); SetActorLocation(NewLocation); } @@ -113,3 +117,8 @@ FVector2D AGSCameraActor::ClampCameraLocationToStageBounds(FVector2D CameraLocat float FinalY = FMath::Clamp(CameraLocation.Y, MinStageY, MaxStageY); return FVector2D(FinalX, FinalY); } + +float AGSCameraActor::ClampZoom(float Zoom) const +{ + return FMath::Clamp(Zoom, -MaxZoom, -MinZoom); +} diff --git a/GravityStomp/Source/GravityStompGame/Camera/GSCameraActor.h b/GravityStomp/Source/GravityStompGame/Camera/GSCameraActor.h index 6d40f00..7605c8b 100644 --- a/GravityStomp/Source/GravityStompGame/Camera/GSCameraActor.h +++ b/GravityStomp/Source/GravityStompGame/Camera/GSCameraActor.h @@ -21,6 +21,12 @@ public: UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Camera Settings") float ZoomSpeed; + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Camera Settings") + float MinZoom; + + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Camera Settings") + float MaxZoom; + UPROPERTY(BlueprintReadWrite) FVector2D PanDirection; @@ -42,4 +48,6 @@ private: FVector GetWorldLocationFromScreenCoords(float InX, float InY) const; FVector2D ClampCameraLocationToStageBounds(FVector2D CameraLocation, FBox2D ScreenBox) const; + + float ClampZoom(float Zoom) const; };