Game Development Reference
empty, if so, there's nothing to do and we return nullptr . The next checks are for fit, if the
rectangle we are inserting is larger than the area available to us, we cannot continue, but if
the space is precisely the size that we are trying to insert, then we have found our node, we
will mark it as no longer empty and return it.
If none of the first conditions were met, it means we are in a larger area than can fit the
will create the partition. If the rectangle is wider than it is tall, we will partition the space
horizontally, if the rectangle is taller than it is wide, we will partition the space vertically.
Once partitioned, we will recursively call Insert again using the first child we just created.
After each insertion into the binary space partition tree, we get a pointer to the node in
which our texture was stored, only we haven't stored anything, and the best part is that we
really don't need to. Once we insert a node into the bsp tree, we can query the tree for the
texture coordinates of this node.
const math::vector4 TextureCoordinates(const std::shared_ptr<node>& node) const
auto width = m_root->Rectangle().Width();
auto height = m_root->Rectangle().Height();
const auto& rectangle = node->Rectangle();
return math::vector4(rectangle.Left() / width, rectangle.Top() / height, rectangle.Right() / width, rectangle.Bottom() / height );
Thesewillbethenormalized UVcoordinates wewillneedtousetorenderthetextintothe
time a world space text is added (it will not be rendered right away).
auto rtWidth = m_renderTarget->Width();
auto rtHeight = m_renderTarget->Height();
// Insert the root node into the BSP tree
target's size. The next part would be to set the render target active on the graphics device
and proceed to add all the world space text that we wish to draw in this frame.