Collision detection is a way of determining if two objects have (duh) collided in
3d (or, if you're insane enough to bother,
2d) space. Some
3D libraries don't support this out of the box, while many do. It's used almost solely in
game development, though some
mathematical applications utilize
vector math like this.
For this writeup,
camera =
player.
Basically, to do
collision detection, you need to do a few things. First, trace in the direction the
camera is heading. That will give you the plane you'll be testing on. You need two
vectors: the normal of the
plane in the direction you're going and a
vector from the
camera to the
radius of
collision in the
direction of the
plane. Get the
dot product of these
vectors:
float DotProduct( Vector v1, Vector v2 )
{
float dot = (v1.x * v2.x) + (v1.y * v2.y) + (v1.z * v2.z);
return dot;
}
If the
dot product is greater than
zero, a
collision has occurred. If the
dot product is less than
zero, the
camera has penetrated the plane. If the
dot product is
zero, you're safe. That simple, eh? =-)
And by the way, its a safe bet that your game won't end up like
Rainbow Six with bodies falling through walls and other crappy effects if you test for
collision a few loops before you move the
camera. Otherwise... well, ugh. I'm not buying your
game.
One last thing,
OpenGL 0wnz j00. *ahem* *adjusts his lapel*