Mail Archives: djgpp/1999/05/11/09:41:05
Carlos Giani_AEN2003 (M2003) writes:
> How does collision detection in 3D work?
For object to object collisions, use bounding shapes. A sphere is the
simplest (just check the distance between the centre of your objects),
but for more complex shapes you might want to deal with ellipsoids
or box shapes. Checking these things for intersection is just a little
matter of mathematics (read: tricky to work out, but can be done:
see the comp.graphics.algorithms FAQ for some relevant formulas).
If you are talking about collision with an environment, you need to
check whether a vector (from where a point was to where it has moved)
has passed through any of the polygons in your mesh. Again, that is
just mathematics: calculate the intersection of the vector with the
plane defined by the polygon, then check whether this point actually
lies inside the region of the plane that is covered by the poly (you
can flatten the whole thing out into 2d for doing these tests,
discarding whichever axis has the smallest gradient).
In terms of doing it fast, the important thing is to cut out as many
polys as possible without having to test them at all. Sector
partitioning systems can work well, and a BSP tree format even better,
but it is really tricky to convert an arbitrary mesh into a well
balanced BSP.
Shawn Hargreaves.
- Raw text -