/ #quadtree 


QuadTree is a tree data structure which internally has exactly four children. It can be used for different things, but here it’s used to more quicker find objects close to other objects.

This simplistic demo is using Pixel to render a bunch of small brown rectangles moving around and change to a random direction with a random speed every few seconds. The line grid is showing the quadtree in action. And, as you can see when running, when more than 1 object enters a rectangle, the rectangle is split up into 4 new smaller rectangles. This is to show that the objects are now in their own recangle. What this means is that finding brown rectangles that collide with other brown rectangles is only done by looking at the closest ones, and not comparing every brown rectangle with every other brown rectangle.

That means that finding out which brown rectangles are colliding is way quicker and requires less resoures, which means it is possible to have many more brown rectangles in the scene without dropping the FPS.

When the brown rectangles collide with another, they become red to indicate this.