Advertisement
LILCodeProgrammer

Untitled

Mar 11th, 2023
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. //test cpp:
  2.  
  3.     FBox SelectionBox(FVector(0.f, -4000.f, 0.f), FVector(3000, 5000, 600.f));
  4.     FVector BoxExtent = SelectionBox.GetExtent();
  5.     FVector BoxCenter = SelectionBox.GetCenter();
  6.     TArray<int32> InstancesDetected = George_GetInstancesOverlappingBox(ISM1, SelectionBox, ISM2->GetComponentTransform());
  7.     for (int32 i = 0; i < InstancesDetected.Num(); ++i) {
  8.     FTransform T3;
  9.     BenchEnemy->HISM2->GetInstanceTransform(InstancesDetected[i], T3, true);
  10.     DrawDebugSphere(GetWorld(), T3.GetLocation(), 100.f, 8, FColor::Yellow, false, 6.f, 0, 6.f);
  11.  
  12. }
  13.  
  14.  
  15. //.h
  16.  
  17.     TArray<int32> George_GetInstancesOverlappingBox(UInstancedStaticMeshComponent* MeshComponent, FBox& Box, FTransform BoxTransform);
  18.  
  19.  
  20.  
  21. //cpp
  22.  
  23. TArray<int32> ABenchmark::George_GetInstancesOverlappingBox(UInstancedStaticMeshComponent* MeshComponent, FBox& Box, FTransform BoxTransform)
  24. {
  25.     TArray<int32> Result;
  26.     if (const UStaticMesh* Mesh = MeshComponent->GetStaticMesh())
  27.     {
  28.         const FVector StaticMeshBoundsExtent = Mesh->GetBounds().BoxExtent;
  29.         for (int32 Index = 0; Index < MeshComponent->PerInstanceSMData.Num(); Index++)
  30.         {
  31.             const FMatrix& Matrix = MeshComponent->PerInstanceSMData[Index].Transform;
  32.             const FVector InstanceOrigin = Matrix.GetOrigin();
  33.             const FVector PositionInOrientedBoxSpace = BoxTransform.InverseTransformPosition(InstanceOrigin);
  34.             if (Box.IsInside(PositionInOrientedBoxSpace))
  35.             {
  36.                 Result.Add(Index);
  37.             }
  38.         }
  39.     }
  40.     return Result;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement