void AHUD::GetActorsInSelectionRectangle(TSubclassOf<class AActor> ClassFilter, const FVector2D& FirstPoint, const FVector2D& SecondPoint, TArray<AActor*>& OutActors, bool bIncludeNonCollidingComponents, bool bActorMustBeFullyEnclosed)
{
// Because this is a HUD function it is likely to get called each tick,
// so make sure any previous contents of the out actor array have been cleared!
OutActors.Empty(); //Create Selection Rectangle from Points
FBox2D SelectionRectangle(); //This method ensures that an appropriate rectangle is generated,
// no matter what the coordinates of first and second point actually are.
SelectionRectangle += FirstPoint;
SelectionRectangle += SecondPoint; //The Actor Bounds Point Mapping
const FVector BoundsPointMapping[] =
{
FVector(, , ),
FVector(, , -),
FVector(, -, ),
FVector(, -, -),
FVector(-, , ),
FVector(-, , -),
FVector(-, -, ),
FVector(-, -, -)
}; //~~~ //For Each Actor of the Class Filter Type
for (TActorIterator<AActor> Itr(GetWorld(), ClassFilter); Itr; ++Itr)
{
AActor* EachActor = *Itr; //Get Actor Bounds //casting to base class, checked by template in the .h
const FBox EachActorBounds = Cast<AActor>(EachActor)->GetComponentsBoundingBox(bIncludeNonCollidingComponents); /* All Components? */ //Center
const FVector BoxCenter = EachActorBounds.GetCenter(); //Extents
const FVector BoxExtents = EachActorBounds.GetExtent(); // Build 2D bounding box of actor in screen space
FBox2D ActorBox2D();
for (uint8 BoundsPointItr = ; BoundsPointItr < ; BoundsPointItr++)
{
// Project vert into screen space.
const FVector ProjectedWorldLocation = Project(BoxCenter + (BoundsPointMapping[BoundsPointItr] * BoxExtents));
// Add to 2D bounding box
ActorBox2D += FVector2D(ProjectedWorldLocation.X, ProjectedWorldLocation.Y);
} //Selection Box must fully enclose the Projected Actor Bounds
if (bActorMustBeFullyEnclosed)
{
if(SelectionRectangle.IsInside(ActorBox2D))
{
OutActors.Add(Cast<AActor>(EachActor));
}
}
//Partial Intersection with Projected Actor Bounds
else
{
if (SelectionRectangle.Intersect(ActorBox2D))
{
OutActors.Add(Cast<AActor>(EachActor));
}
}
}
}