Foundation Object Collision Tests

This class of objects is essentially orientation-less, which greatly simplifies the testing procedures. Nevertheless, these are among the most important types because of all collision detection, they are cheapest to compute and, therefore, the most used.

Point- or Sphere-to-Sphere

Point-to-sphere is one of the simplest collision tests. Using the standard distance formula

compute the distance between the point and the sphere center. If the distance is less than the sphere radius, there is a collision.

The main improvement to this test is to use the distance squared and the radius squared for the comparison to avoid computing the expensive square root operation. Because we are not really concerned with knowing the actual point-to-sphere distance and that the relative distance squared will generate the same collision profile as the more expensive square root distance, we can substitute the D < R test with D2 < R2. This is mathematically legal because both D and R are positive; therefore, after squaring them the inequality still holds true.

Testing two spheres is similarly done. All that needs to change is to compute the distance between the two sphere centers and compare the result to the sum of the two spheres’ radii. Again, alternatively computing the squared result is a valid optimization.

Point- or AABB-to-AABB

Point- or AABB-to-AABB determination is a simple set of inequalities based on the AABB’s extents and the point’s components. These are by far the cheapest collision object tests and, as a result, often the most used.

static public boolean isCollide( AABoundingBox bb1, Vector3f  position ) {     if ( bb1.min.x < position.x &&         bb1.min.y < position.y  &&         bb1.min.z < position.z  &&         bb1.max.x > position.x  &&         bb1.max.y > position.y  &&         bb1.max.z > position.z )         return true;     else         return false; }

These four techniques are summarized in Figure 16.8.

image from book
Figure 16.8: Point- to-AABB and -Sphere collisions.

Sphere-and-AABB

A fast approximation technique for sphere-and-AABB collision detection is to essentially replace the sphere with a temporary AABB and perform an AABB-to-AABB test where the new box is set to the size of the sphere.

Another way is to add the sphere radius to the AABB and perform the simple point-to-AABB test using the sphere center.

Both of these produce a false-positive collision in the case where the sphere is near the box’s corners. The error can be fairly small, depending on the relative size of the box and sphere, and because AABBs and spheres are usually approximations to other geometry that will be used in further testing anyway, this error is often considered acceptable (see figure 16.9).

image from book
Figure 16.9: Sphere-and-AABB collision.



Practical Java Game Programming
Practical Java Game Programming (Charles River Media Game Development)
ISBN: 1584503262
EAN: 2147483647
Year: 2003
Pages: 171

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net