Clamp Zoom

This commit is contained in:
Kevin Poretti 2023-01-16 12:13:11 -05:00
parent d07a08793b
commit 10a672dc8f
3 changed files with 19 additions and 2 deletions

Binary file not shown.

View File

@ -10,6 +10,8 @@ AGSCameraActor::AGSCameraActor()
{ {
PanSpeed = 100.0f; PanSpeed = 100.0f;
ZoomSpeed = 100.0f; ZoomSpeed = 100.0f;
MinZoom = 2666;
MaxZoom = 5000;
} }
@ -36,11 +38,13 @@ void AGSCameraActor::Tick(float DeltaSeconds)
FVector CurrLocation = GetActorLocation(); FVector CurrLocation = GetActorLocation();
float ZoomMove = ZoomDirection * ZoomSpeed * DeltaSeconds; float ZoomMove = ZoomDirection * ZoomSpeed * DeltaSeconds;
float NewZoom = CurrLocation.X + ZoomMove;
NewZoom = ClampZoom(NewZoom);
FVector2D PanMove = PanDirection * PanSpeed * DeltaSeconds; FVector2D PanMove = PanDirection * PanSpeed * DeltaSeconds;
FVector2D NewPan = FVector2D(CurrLocation.Y + PanMove.X, CurrLocation.Z + PanMove.Y); FVector2D NewPan = FVector2D(CurrLocation.Y + PanMove.X, CurrLocation.Z + PanMove.Y);
NewPan = ClampCameraLocationToStageBounds(NewPan, ScreenBoundingBox); NewPan = ClampCameraLocationToStageBounds(NewPan, ScreenBoundingBox);
FVector NewLocation = FVector(CurrLocation.X + ZoomMove, NewPan.X, NewPan.Y); FVector NewLocation = FVector(NewZoom, NewPan.X, NewPan.Y);
SetActorLocation(NewLocation); SetActorLocation(NewLocation);
} }
@ -113,3 +117,8 @@ FVector2D AGSCameraActor::ClampCameraLocationToStageBounds(FVector2D CameraLocat
float FinalY = FMath::Clamp(CameraLocation.Y, MinStageY, MaxStageY); float FinalY = FMath::Clamp(CameraLocation.Y, MinStageY, MaxStageY);
return FVector2D(FinalX, FinalY); return FVector2D(FinalX, FinalY);
} }
float AGSCameraActor::ClampZoom(float Zoom) const
{
return FMath::Clamp(Zoom, -MaxZoom, -MinZoom);
}

View File

@ -21,6 +21,12 @@ public:
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Camera Settings") UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Camera Settings")
float ZoomSpeed; float ZoomSpeed;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Camera Settings")
float MinZoom;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Camera Settings")
float MaxZoom;
UPROPERTY(BlueprintReadWrite) UPROPERTY(BlueprintReadWrite)
FVector2D PanDirection; FVector2D PanDirection;
@ -42,4 +48,6 @@ private:
FVector GetWorldLocationFromScreenCoords(float InX, float InY) const; FVector GetWorldLocationFromScreenCoords(float InX, float InY) const;
FVector2D ClampCameraLocationToStageBounds(FVector2D CameraLocation, FBox2D ScreenBox) const; FVector2D ClampCameraLocationToStageBounds(FVector2D CameraLocation, FBox2D ScreenBox) const;
float ClampZoom(float Zoom) const;
}; };