Game Development Community

new consoleMethod: SceneObject::objBoxesOverlap()

by Orion Elenzil · 06/07/2007 (11:10 am) · 0 comments

DO NOT USE THIS YET
it has some problems. namely it's not symmetric with two DIFs i've tried it on. ie A.objBoxesOverlap(B) != B.objBoxesOverlap(A). - probably something to do w/ the origin of the boxes.




this is similar to SceneObject::objBoxContainsPoint().
returns true or false depending on whether the object boxes of the two objects overlap.

example:
echo(%DIFObject1.objBoxesOverlap(%SomeDTSObject));

SceneObject.cc
insert the following lines after the ConsoleMethod for objBoxContainsPoint.
bool SceneObject::objBoxesOverlap(SceneObject* otherObject)
{
   Box3F   otherBox = otherObject->mObjBoxScaled;
   Point3F radii    = otherBox.max - otherBox.min;

   MatrixF m1       = otherObject->getTransform();
   MatrixF m2       = getWorldTransform();

   m2.mul(m1);

   return mObjBoxScaled.collideOrientedBox(radii, m2);
}

ConsoleMethod( SceneObject, objBoxesOverlap, bool , 3, 3, "(object)")
{
   SceneObject* otherObject = dynamic_cast<SceneObject*>(Sim::findObject(argv[2]));
   if (otherObject == NULL)
   {
      Con::errorf("%s - unable to find object %s", "objBoxesOverlap()", argv[2]);
      return false;
   }

   return object->objBoxesOverlap(otherObject);
}