Add RandPointInBox2D method

This commit is contained in:
Steve Streeting 2023-11-20 16:20:51 +00:00
parent 54a94ea5b1
commit 244302781b

View File

@ -136,7 +136,7 @@ public:
return FRotator(PitchYaw.X, PitchYaw.Y, 0).RotateVector(FVector::UpVector);
}
/// Random point in a box
/// Random point in a 3D box
FORCEINLINE FVector RandPointInBox(const FBox& Box) const
{
const FVector R3 = Rand3D();
@ -145,6 +145,14 @@ public:
FMath::Lerp(Box.Min.Z, Box.Max.Z, R3.Z));
}
/// Random point in a 2D rectangle
FORCEINLINE FVector2D RandPointInBox2D(const FBox2D& Rect) const
{
const FVector2D R2 = Rand2D();
return FVector2D(FMath::Lerp(Rect.Min.X, Rect.Max.X, R2.X),
FMath::Lerp(Rect.Min.Y, Rect.Max.Y, R2.Y));
}
/// Random value in a range (inclusive)
float RandRange(float Min, float Max) const
{