Download

How can I visualize my quadtree in UE4 / c++

I’m making a Quadtree in UE4 with c++, I’m quite new to c++, so I need help on this.
My main concern is about visualizing the Quadtree.
Basically I have a native c++ class called Quadtree. Inside of this class I have all the functions like Insert Point, Subdivide, etc… And I have an AActor c++ class called C_Quadtree (dumb name, I know), that has a Blueprint callable function to insert points, and a visualization method.
Here’s how I try to visualize it :



void AC_Quadtree::show(Quadtree* Node)
{
    FVector BoxCenter = FVector(Node->GetBoundary().GetCenter(), 0);
    FVector BoxExtent = FVector(Node->GetBoundary().GetExtent(), 0);
    DrawDebugBox(GetWorld(), BoxCenter, BoxExtent, FColor::White, false, -1, 0, 3);
}

void AC_Quadtree::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);

    for (Quadtree *Node : TreeNodes) {
        show(Node);
    }

}

I have declared an Array in the Actor C_Quadtree to store the TreeNodes :


TArray<Quadtree*> TreeNodes;

However, I have no Idea how I could add the created Quadtrees from the native Quadtree class, into the array that is inside of the Actor C_Quadtree class.
Here’s the subdivide function declared in the Quadtree class :


void Quadtree::subdivide()
{   
    //Init local variables to make the Math clearer.
    FVector2D Center = Boundary.GetCenter();
    FVector2D HalfExtent = Boundary.GetExtent() / 2;

    NorthWest = new Quadtree( FVector2D(Center.X + HalfExtent.X, Center.Y - HalfExtent.Y), HalfExtent);
    NorthEast = new Quadtree( Center + HalfExtent, HalfExtent);
    SouthWest = new Quadtree( Center - HalfExtent, HalfExtent);
    SouthEast = new Quadtree( FVector2D(Center.X - HalfExtent.X, Center.Y + HalfExtent.Y), HalfExtent);
}

Any Ideas?

Hi, I’m trying to create a quadtree too, but I don’t understand how to start, if you can help me, I would appreciate it very much