Game Development Community

Test if a given bounding volume intersects stuff ?

by Orion Elenzil · in Torque Game Engine · 07/15/2008 (6:01 pm) · 6 replies

Howdy -

is there a way to test if a given bounding volume (any volume would do - sphere, box, whatever) intersects either DTS objects or solid portions of DIF objects ?

i want to validate the placement of spawnspheres.

tia!

ooo

#1
07/15/2008 (9:50 pm)
Orion,

One option is to do a radius search. If you are doing your test from script, then this is your only real option anyway. You set it up server-side with a call to initContainerRadiusSearch(pos, radius, mask). And then run a while loop over containerSearchNext until you get back an id of 0.

Example:

//Note: mask is the type mask, so you could put $TypeMasks::StaticObjectType | $TypeMasks::TerrainObjectType | $TypeMasks::PlayerObjectType for starters
function testClearRadius(pos, radius, mask)
{
      initContainerRadiusSearch(pos, radius, mask);

      %test = containerSearchNext();

      //Only need to test whether there is at least one object in the way.
      return %test == 0;
}
#2
07/15/2008 (11:07 pm)
Hey Alex, thanks for replying.

i'm not 100% sure, but i think containerRadiusSearch() will return "collision" on DIF objects even if the specified sphere does not in fact intersect any of the solid geometry of the DIF.

ie, if i have a DIF which is a big hollow room, i'd like to be able to test a volume (spherical or otherwise) in the center of it and have that test return "no intersection".
#3
07/15/2008 (11:42 pm)
Hi Orion.

There is a command object.contains or object.overlaps etc I can't remember which. Look in the box.h header or trigger.cc for clues.
#4
07/16/2008 (2:23 am)
Thanks Duncan, I was looking for the same thing..
I found the following functions in math/mBox.h (TGEA 1.7.1) for checking overlapping and contained boxes:

bool Box3F::isOverlapped(const Box3F& in_rOverlap)

bool Box3F::isContained(const Box3F& in_rContained)
#5
07/16/2008 (9:42 am)
There are several methods in the Container class for spacial queries.

void Container::findObjects(const Box3F& box, U32 mask, FindCallback callback, void *key)

void Container::polyhedronFindObjects(const Polyhedron& polyhedron, U32 mask, FindCallback callback, void *key)

bool Container::buildPolyList(const Box3F& box, U32 mask, AbstractPolyList* polyList,FindCallback callback,void *key)

Assuming this query is originating from another object, ( the spawn sphere?) you can do object->getContainer for the container pointer to call this on.
#6
07/16/2008 (11:02 am)
Thanks James!

so i used Container::buildPolyList() to write a consoleFunction "containerIntersectBox",
and as was just testing it out and tab-completing "container..", i discovered "containerBoxEmpty",
which does exactly the same thing.

in any event,
containerBoxEmpty() seems to behave quite nicely.
if the box is inside an interior, it only reports collision if the box actually overlaps geometry.