Game Development Reference
In-Depth Information
unsigned limit
) const
{
// Early-out if we don't overlap or if we have no room
// to report contacts.
if (!overlaps(other) || limit == 0) return 0;
// If we're both at leaf nodes, then we have a potential contact.
if (isLeaf() && other->isLeaf())
{
contacts->body[0] = body;
contacts->body[1] = other->body;
return 1;
}
// Determine which node to descend into. If either is
// a leaf, then we descend the other. If both are branches,
// then we use the one with the largest size.
if (other->isLeaf() ||
(!isLeaf() && volume->getSize() >= other->volume->getSize()))
{
// Recurse into ourself.
unsigned count = children[0]->getPotentialContactsWith(
other, contacts, limit
);
// Check whether we have enough slots to do the other side too.
if (limit > count) {
return count + children[1]->getPotentialContactsWith(
other, contacts+count, limit-count
);
} else {
return count;
}
}
else
{
// Recurse into the other node.
unsigned count = getPotentialContactsWith(
other->children[0], contacts, limit
);
// Check whether we have enough slots to do the other side too.
if (limit > count) {
Search Nedrilad ::




Custom Search