Game Development Reference
In-Depth Information
//Get first vertex
pt = obj->pts;
//Initialise the bounding box
obj->bbmin.x = pt.x;
obj->bbmin.y = pt.y;
obj->bbmin.z = pt.z;
obj->bbmax.x = pt.x;
obj->bbmax.y = pt.y;
obj->bbmax.z = pt.z;
for (i=0; i<obj->numpoints; i++){
//Transformation code
//Update bounding box min and max
if (pt.x<obj->bbmin.x) obj->bbmin.x = pt.x;
if (pt.y<obj->bbmin.y) obj->bbmin.y = pt.y;
if (pt.z<obj->bbmin.z) obj->bbmin.z = pt.z;
if (pt.x>obj->bbmax.x) obj->bbmax.x = pt.x;
if (pt.y>obj->bbmax.y) obj->bbmax.y = pt.y;
if (pt.z>obj->bbmax.z) obj->bbmax.z = pt.z;
Once you have your bounding boxes you can check if one bounding
box is inside another. Since the bounding boxes are aligned along their
axes this is very simply done. If the character's bounding box, defined by
bbmin , bbmax , is inside the test bounding box, defined by testbbmin ,
testbbmax , then the following conditional evaluates to true:
if (bbmin.x<testbbmax.x && bbmax.x>testbbmin.x &&
bbmin.y<testbbmax.y && bbmax.y>testbbmin.y &&
bbmin.z<testbbmax.z && bbmax.z>testbbmin.z)
An alternative to testing for intersections is to force a bounding box to
remain totally inside another. If a contained bounding box goes outside
another, then the following conditional evaluates to true:
if (bbmin.x>testbbmin.x || bbmax.x>testbbmax.x ||
bbmin.y>testbbmin.y || bbmax.y>testbbmax.y ||
bbmin.z>testbbmin.z || bbmax.z>testbbmax.z)
Search Nedrilad ::

Custom Search