I'm looking at this code from Game Physics Engine Development for a BVH traversal algorithm, specifically getPotentialContacts
and getPotentialContactsWith
at the end of the file.
By the looks of this algorithm, it'll compare an initial pair of siblings, but it won't look for collisions within each descendant.
I can't see how this would work on a graph like this one, where dotted lines represent branches, solids are leaf nodes, and the tree depths are represented by spectrum colors (red, orange, yellow, green):
What is it that I'm not understanding here? Do I need another algorithm to find all the contacts within a tree?
I also tried traversing down each of the leafs, but then I end up detecting the collisions twice in many cases -- so that's not it either.
I was having the same problem with this function... so I tried a few approaches and I ended up with this:
//// About the code: Well, its in java but I guess its easy to translate or understand what it is doing. I created the function "alreadyInside" to check if I already added the potential contact and I was increasing the variable errors if I did, so far this code is not adding any repeated potential contact (errors=0), so I will problably drop this function to optimize the code. Also, I added the "descend" parameter, which is a flag which tells when to go further down in the structure.