Game Development Community

Bounding box - box intersection

by Ivan Mandzhukov · in Torque 3D Professional · 11/26/2010 (3:06 pm) · 1 replies

Hey guys,
I am working on a movable object ( let's say it is a staticShape).
I am trying to implement a simple collision detection for it - when it moves and when a player (respectively AIplayer) is detected,then I'll throw a callback.
I have a problem with the detection.
This is what I have:

...
   const Point3F& scale = getScale();
   Box3F mScaledBox = mObjBox;
   mScaledBox.minExtents.convolve( scale );
   mScaledBox.maxExtents.convolve( scale );

   Box3F plistBox = mScaledBox;
   
   Point3F oldMin = plistBox.minExtents;
   Point3F oldMax = plistBox.maxExtents;
   plistBox.minExtents.setMin(oldMin + (mVelocity * 0.032f) - Point3F(0.1f, 0.1f, 0.1f));
   plistBox.maxExtents.setMax(oldMax + (mVelocity * 0.032f) + Point3F(0.1f, 0.1f, 0.1f));
   plistBox.setCenter(this->getPosition());

   SimpleQueryList list;
   U32 mask = PlayerObjectType | AIObjectType;
   Container* pContainer = isServerObject() ? &gServerContainer : &gClientContainer;
   pContainer->findObjects(plistBox,mask, SimpleQueryList::insertionCallback, &list);

   for (S32 i = 0; i < list.mList.size(); i++) {
            SceneObject* foundObj = list.mList[i];

            // we have found something
            return true;

   }
   // nothing is found
   return false;
...

OK,this code actually works if I put it in the player class.But it doesn't work for my shape.
I obviosly don't want to setup a movable box and to update the working list.I just want a simple box intersection.
Do I miss something ?

#1
11/26/2010 (4:10 pm)
huh!
I have a wrong sized box.
This is the full code:

Point3F box;

// the size of our box is 5 X 5 X 5 (world units!)
box.set(5.0f,5.0f,5.0f);
Point3F lastPos;
lastPos.set(this->getPosition());

Box3F plistBox = 
Box3F(lastPos.x-box.x*0.5f,lastPos.y-box.y*0.5f,lastPos.z-box.z*0.5f,   lastPos.x+box.x*0.5f,lastPos.y+box.y*0.5f,lastPos.z+box.z*0.5f);             
plistBox.setCenter(lastPos);
   
Point3F oldMin = plistBox.minExtents;
Point3F oldMax = plistBox.maxExtents;
   
plistBox.minExtents.setMin(oldMin + (mVelocity * 0.032f) - Point3F(0.1f, 0.1f, 0.1f));
plistBox.maxExtents.setMax(oldMax + (mVelocity * 0.032f) + Point3F(0.1f, 0.1f, 0.1f));
   

SimpleQueryList list;
U32 mask = PlayerObjectType | AIObjectType;
Container* pContainer = isServerObject() ? &gServerContainer : &gClientContainer;
pContainer->findObjects(plistBox,mask, SimpleQueryList::insertionCallback, &list);

for (S32 i = 0; i < list.mList.size(); i++) {
            SceneObject* foundObj = list.mList[i];
			Con::warnf("found!");
			return true;


   }
return false;

Moved to useful threads.