So it dawned on me this morning how to avoid making redundant collision checks (i.e. checking whether one object intersects another and then checking the converse).
Basically it goes something like this:
obj1=gameObjects->getRootObject(gameObjects);
while(!traverse1)
{
obj2=gameObjects->getRootObject(gameObjects):
while(!traverse2)
{
// check for collision between obj1 and obj2
// until the entire tree of objects is covered
// and traverse2=true
}
//traverse tree until traverse1=true
}
Now, that will perform lots of unnecessary checks between the same objects. A painfully blatant way to prevent this is to set obj2 to the next object in the tree traverse (thereby not testing it against objects against which it has already been tested, namely all the obj1's prior).
That leaves us with this:
obj1=gameObjects->getRootObject(gameObjects);
while(!traverse1)
{
obj2=obj1->traverseTree(obj1,&traverse1);
while(!traverse2)
{
// check for collision between obj1 and obj2
// until the entire tree of objects is covered
// and traverse2=true
}
//traverse tree until traverse1=true
}
And voila! I'll implement this tonight. That should hopefully take care of the "sluggish with more than three objects on screen" bug to some degree.
I also need to take care of the checks against spheres and cylinders. On top of that, I need to add the bit for checking points along the edges formed by two vertices, thus rendering the collision detection complete.
That will be awesome.
No comments:
Post a Comment