Bounding Boxes?

Started by
2 comments, last by TipTup 23 years, 7 months ago
Anyone know how to program Bounding Boxes? All 3d renderers have them and I think they would be great for collision testing... -TipTup TipTup.Com
Advertisement
Well a bounding box is just an invisible structure that fits around your object (irregaurdless of if the object is 2d or 3d).

If we were doing 2d collision detection on a 32x32 sprite then you'd do this:

// The rect structure takes in 4 points which creates a
// rectangle. The point order is LEFT(x1),TOP(y1), RIGHT(x2),
// BOTTOM(y2)
RECT BoundingBox = { 0, 0, 32, 32 };

then you'd check for collisions by doing this:

if (BoundingBox.bottom < Source.top || BoundingBox.top > Source.bottom || BoundingBox.right < Source.left || BoundingBox.left > Source.right)
// A collision occurrd and it's time to do something else.
return true;

Now in 3d we have to deal with the z coordinate. So this changes our bounding box into a bounding cube. Though most people still refer to it as a bounding box.

Now figure out how High, wide, and long your model is at it's highest and lowest points. Now what you do is build a invisible cube around your model using the high & low points. Now that your cube is created you need to check for collisions. The collision detection is nothing more than testing the points and seeing if anything falls in between those points. It's quite a large if statement in 3d but once it's done you can re-use it. I'd suggest making a function to test for collisions that way you only have to write it once. Anyway good luck.



Edited by - evaclear on September 1, 2000 11:41:28 PM
Joseph FernaldSoftware EngineerRed Storm Entertainment.------------------------The opinions expressed are that of the person postingand not that of Red Storm Entertainment.
hi,
bounding boxes can be very powerful and acurate. As i explain in an another thread few days ago, you can build a hierarchical tree of bounding boxes. look at here for a very general idea.


ECLIPSE DE SOLEIL PAR NOTRE LUNE...lunasol
I meant bounding boxes which aren''t gigantic and say you have a stick figure instead of having one big box, you have individual ones rotated so they cover the whole figure. (3d)

-TipTup
TipTup.Com

This topic is closed to new replies.

Advertisement