AbyssWolf

LibNebulaNodesBPLibrary.cpp

May 7th, 2024
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. // Copyright Epic Games, Inc. All Rights Reserved.
  2.  
  3. #include "LibNebulaNodesBPLibrary.h"
  4. #include "LibNebulaNodes.h"
  5.  
  6. ULibNebulaNodesBPLibrary::ULibNebulaNodesBPLibrary(const FObjectInitializer& ObjectInitializer)
  7. : Super(ObjectInitializer)
  8. {
  9.  
  10. }
  11.  
  12. FVector2f ULibNebulaNodesBPLibrary::RandomVector2(float fMin, float fMax, bool bPreventDuplicates, bool bRoundToInteger, float &x, float &y)
  13. {
  14.     float X, Y;
  15.     int iAttempts = 0;
  16.     int iMaxAttempts = 25;
  17.  
  18.     do
  19.     {
  20.         X = FMath::RandRange(fMin, fMax);
  21.         Y = FMath::RandRange(fMin, fMax);
  22.         iAttempts++;
  23.     } while (bPreventDuplicates && iAttempts < iMaxAttempts && FMath::IsNearlyEqual(X, Y));
  24.  
  25.     if (bRoundToInteger)
  26.     {
  27.         x = X;
  28.         y = Y;
  29.         return FVector2f(FMath::RoundToInt(X), FMath::RoundToInt(Y));
  30.     }
  31.     else
  32.     {
  33.         x = X;
  34.         y = Y;
  35.         return FVector2f(X, Y);
  36.     }
  37. }
  38.  
Add Comment
Please, Sign In to add comment