Collision Detection – Signs of Improvement
Patrick Lam | 11 March, 2009 | 22:29
Finally see some signs of improvement to the collision detection (CD) function! The whole time, I’ve been testing with just basic objects (cube) and there didn’t seem to be much lag. But when I started using spheres (which has a lot more vertices than cube), I notice the CD test takes a lot longer, especially when I’m testing between spheres.
To decrease this lag time, I’ve implemented the idea of eliminating unnecessary triangle/triangle tests between objects. To do so, I had to calculate a bunch of info before starting the triangle/triangle test. First, I called the getBoundingSphere() for both object, so I could get their positions and their radius. Then I calculated the distance between the two objects, and the distance to be consider the back of the object.

So before I start testing the vertices in object A to object B, I check to see they’re not on the back side, and then I check to see vertices on object B is not on the back side. Once these two conditions pass, that’s when I perform the triangle/triangle test (which takes up a lot of process).
At first, I was afraid this would slow down the process instead of speed it up because I have to do so many calculations and also call the getBoundingSphere(). After testing it out, I notice that wasn’t the case. Before, when I was testing with sphere-cube and sphere-sphere, the program seemed to have stopped, but now, I can see it move, even though it’s still slow. The time it takes to finish the CD for each update is timed at about:
Cube-Cube: 4ms
Cube-Sphere: 2000ms
Sphere-Sphere:16000ms
Although this might not seem like a big improvement, but it is still significant enough to see changes happening. There are still many improvements I need to read up and implement to increase the efficiency of CD, hope to post about it soon.
To decrease this lag time, I’ve implemented the idea of eliminating unnecessary triangle/triangle tests between objects. To do so, I had to calculate a bunch of info before starting the triangle/triangle test. First, I called the getBoundingSphere() for both object, so I could get their positions and their radius. Then I calculated the distance between the two objects, and the distance to be consider the back of the object.

So before I start testing the vertices in object A to object B, I check to see they’re not on the back side, and then I check to see vertices on object B is not on the back side. Once these two conditions pass, that’s when I perform the triangle/triangle test (which takes up a lot of process).
At first, I was afraid this would slow down the process instead of speed it up because I have to do so many calculations and also call the getBoundingSphere(). After testing it out, I notice that wasn’t the case. Before, when I was testing with sphere-cube and sphere-sphere, the program seemed to have stopped, but now, I can see it move, even though it’s still slow. The time it takes to finish the CD for each update is timed at about:
Cube-Cube: 4ms
Cube-Sphere: 2000ms
Sphere-Sphere:16000ms
Although this might not seem like a big improvement, but it is still significant enough to see changes happening. There are still many improvements I need to read up and implement to increase the efficiency of CD, hope to post about it soon.
