Clamp Zoom
This commit is contained in:
parent
d07a08793b
commit
10a672dc8f
BIN
GravityStomp/Content/Debug/Camera/TestCamera.umap
(Stored with Git LFS)
BIN
GravityStomp/Content/Debug/Camera/TestCamera.umap
(Stored with Git LFS)
Binary file not shown.
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user