Last active
December 15, 2015 12:09
-
-
Save Shaptic/5258722 to your computer and use it in GitHub Desktop.
CQuadTree::RCollides()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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