Game Development Community

TGE Bug and fix for scaled Item collision

by Thomas Huehn · in Torque Game Engine · 07/26/2008 (4:46 am) · 0 replies

When a Item is scaled the collision does not work correct, because it use the unscaled object box.

Fix:

In item.cc at void Item::updatePos:

replace:
Point3F startCast((mObjBox.min.x + mObjBox.max.x) * 0.5,
                     (mObjBox.min.y + mObjBox.max.y) * 0.5,
                     mObjBox.max.z);
   Point3F endCast((mObjBox.min.x + mObjBox.max.x) * 0.5,
                   (mObjBox.min.y + mObjBox.max.y) * 0.5,
                   mObjBox.min.z);

with:
//XXTH fix for scaled objects!
   Box3F ColBox = mObjBox;
   ColBox.min.convolve(mObjScale);
   ColBox.max.convolve(mObjScale);

   Point3F startCast((ColBox.min.x + ColBox.max.x) * 0.5,
                     (ColBox.min.y + ColBox.max.y) * 0.5,
                     ColBox.max.z);
   Point3F endCast((ColBox.min.x + ColBox.max.x) * 0.5,
                   (ColBox.min.y + ColBox.max.y) * 0.5,
                   ColBox.min.z);
   /* Orig:
   Point3F startCast((mObjBox.min.x + mObjBox.max.x) * 0.5,
                     (mObjBox.min.y + mObjBox.max.y) * 0.5,
                     mObjBox.max.z);
   Point3F endCast((mObjBox.min.x + mObjBox.max.x) * 0.5,
                   (mObjBox.min.y + mObjBox.max.y) * 0.5,
                   mObjBox.min.z);
   */

I'am not sure about this but should also be changed (bold = new lines):
if (doToughCollision)
   {
      U32 count;
      for (count = 0; count < 3; count++)
      {
         // Build list from convex states here...
         end = pos + mVelocity * time;

         collisionMatrix.setColumn(3, end);
         Box3F wBox = getObjBox();
[b]
	 //XXTH scaled collision fix
	 wBox.min.convolve(mObjScale);
         wBox.max.convolve(mObjScale);
[/b]
         collisionMatrix.mul(wBox);
         Box3F testBox = wBox;
         Point3F oldMin = testBox.min;
         Point3F oldMax = testBox.max;
         testBox.min.setMin(oldMin + (mVelocity * time));
         testBox.max.setMin(oldMax + (mVelocity * time));