During my work on the Quadtree Project, I developed a C++ implementation of the quadtree algorithm to simulate query behavior using Unreal Engine. Below are some of the key achievements:
Below is a key code snippet demonstrating the core quadtree algorithm implementation from the project:
#include "Quadtree.h"
// Initialize the quadtree with a center and size
void AQuadtree::Initialize(FVector InCenter, float InSize)
{
Center = InCenter;
Size = InSize;
Clear();
}
// Insert a point into the quadtree
bool AQuadtree::Insert(FVector Point)
{
if (!ContainsPoint(Point)) return false;
if (Points.Num() < Capacity)
{
Points.Add(Point);
return true;
}
if (!bDivided) Subdivide();
if (NW->Insert(Point)) return true;
if (NE->Insert(Point)) return true;
if (SW->Insert(Point)) return true;
if (SE->Insert(Point)) return true;
return false;
}
// Query points within a specified range
TArray AQuadtree::Query(FVector RangeCenter, float RangeSize)
{
TArray FoundPoints;
if (!Intersect(RangeCenter, RangeSize)) return FoundPoints;
for (FVector Point : Points)
{
if (FVector::Dist(Point, RangeCenter) <= RangeSize)
{
FoundPoints.Add(Point);
}
}
if (bDivided)
{
FoundPoints.Append(NW->Query(RangeCenter, RangeSize));
FoundPoints.Append(NE->Query(RangeCenter, RangeSize));
FoundPoints.Append(SW->Query(RangeCenter, RangeSize));
FoundPoints.Append(SE->Query(RangeCenter, RangeSize));
}
return FoundPoints;
}
QuadTree Project showcases the implementation of a 2D quadtree data structure using Unreal Engine, focusing on efficient spatial data management and querying. The project demonstrates the use of quadtrees for optimizing performance in operations like collision detection in particle systems.