Skip to content

Instantly share code, notes, and snippets.

@Shaptic
Last active December 15, 2015 12:09
Show Gist options
  • Save Shaptic/5258722 to your computer and use it in GitHub Desktop.
Save Shaptic/5258722 to your computer and use it in GitHub Desktop.
CQuadTree::RCollides()
CEntity* CQuadTree::RCollides(const CEnity* pBody,
const QTNode* pStart) const
{
// Is leaf?
if(pStart->pChildren == nullptr)
{
// Iterate over each object in the node and check for
// collision. We also compare the objects to make sure
// we don't count a collision of an object with itself,
// which would obviously make no sense.
for(auto i = pStart->nodeObjects.cbegin();
i != pStart->nodeObjects.cend(); ++i)
{
if((*i)->CheckCollision(pBody) && (*i) != pBody)
return *i;
}
}
else
{
// Iterate over children
for(size_t i = 0; i < 4; ++i)
{
CEntity* pResult = this->RCollides(pBody, pStart->pChildren[i]);
if(pResult != nullptr) return pResult;
}
}
return nullptr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment