Graphics Reference
In-Depth Information
Then, by providing functionality to set and reset the alternative start node
// Specifies an alternative starting node, or none (if null)
Tree *gStartNode = NULL;
// Set a new alternative start node
void BeginGroupedQueryTestVolume(Sphere *s, Tree *root)
{
// Descend into the hierarchy as long as the given sphere
// overlaps either child bounding sphere (but not both)
while (root != NULL) {
bool OverlapsLeft = root- > left && SphereOverlapTest(s, root- > left.bvSphere);
bool OverlapsRight = root- > right && SphereOverlapTest(s, root- > right.bvSphere);
if (OverlapsLeft && !OverlapsRight) root = root- > left;
else if (!OverlapsLeft && OverlapsRight) root = root- > right;
else break;
}
// Set this as the new alternative starting node
gStartNode = root;
}
// Reset the alternative start node
void EndGroupedQueryTestVolume(void)
{
gStartNode = NULL;
}
the original code can now very easily be transformed into a grouped query, with
substantial savings in traversal time.
Sphere s[NUM_SPHERES];
...
// Compute a bounding sphere for the query spheres
Sphere bs = BoundingSphere(&s[0], NUM_SPHERES);
BeginGroupedQueryTestVolume(bs, worldHierarchy);
// Do the original queries just as before
for(inti=0;i<NUM_SPHERES; i++)
if (SphereTreeCollision(s[i], worldHierarchy))
...
// Reset everything back to not used a grouped query
EndGroupedQueryTestVolume();
...
 
Search WWH ::




Custom Search