Game Development Community

Collision convex scaling issue

by Conrad "Lynx" Wong · in Torque Game Engine · 03/02/2003 (11:39 am) · 7 replies

Okay, in the great struggle to get objects to be scaled correctly, I've scaled a Vehicle to 5x normal and am trying to collide it with a TSStatic object. This appears to run through the following code.

bool Convex::getCollisionInfo(const MatrixF& mat, const Point3F& scale, CollisionList* cList,F32 tol)
{
   for (CollisionStateList* itr = mList.mNext; itr != &mList; itr = itr->mNext) {
      CollisionState* state = itr->mState;
      if (state->mLista != itr)
         state->swap();
      if (state->dist <= tol) {
         ConvexFeature fa,fb;
         VectorF v;

         MatrixF imat = mat;
         imat.scale(scale);
         imat.inverse();
         imat.mulV(-state->v,&v);
         getFeatures(mat,v,&fa);

         imat = state->b->getTransform();
         imat.scale(state->b->getScale());
         MatrixF bxform = imat;
         imat.inverse();
         imat.mulV(state->v,&v);
         state->b->getFeatures(bxform,v,&fb);

         fa.collide(fb,cList,tol);
      }
   }
   return (cList->count != 0);
}

I've verified that this function gets called when the scaled vehicle model comes close to the TSStatic object. At that point, this function should be telling us what collisions have occurred.

Unfortunately, it appears that even though we do seem to be applying some kind of scale, as noted by the scale being passed in, the effect is that the vehicle only really collides (and collisions are generated) when the TSStatic has passed through much of the vehicle.

Unfortunately, these matrix calculations are beyond me. Can anyone explain what's going on here?

Mucho gracias in advance!

#1
03/02/2003 (12:05 pm)
Did you make sure to also scale the bounding box. I believe this is found in the scripts for the vehicles, it is for the player :/
#2
03/02/2003 (12:10 pm)
Vehicles don't have bounding boxes. (only the player does) ShapeBase calculates a bounding box and that gets scaled correctly, at least as shown in the world editor, so it's a matter of working out the collision issues.
#3
03/02/2003 (2:17 pm)
I think I got it... The problem is that we need to pass a scaled mat to GetFeature, not the original (unscaled) mat. See the 'mutant' code part below:

bool Convex::getCollisionInfo(const MatrixF& mat, const Point3F& scale, CollisionList* cList,F32 tol)
{
   for (CollisionStateList* itr = mList.mNext; itr != &mList; itr = itr->mNext) {
      CollisionState* state = itr->mState;
      if (state->mLista != itr)
         state->swap();
      if (state->dist <= tol) {
         ConvexFeature fa,fb;
         VectorF v;

#if 0 // this is the original code
         MatrixF imat = mat;
         imat.scale(scale);
         imat.inverse();
         imat.mulV(-state->v,&v);
         getFeatures(mat,v,&fa);
#else // This is the horrible mutant code
         MatrixF omat = mat;
         omat.scale(scale);
         MatrixF imat = omat;
         imat.inverse();
         imat.mulV(-state->v,&v);
         getFeatures(omat,v,&fa);
#endif // end of mutated code

         imat = state->b->getTransform();
         imat.scale(state->b->getScale());
         MatrixF bxform = imat;
         imat.inverse();
         imat.mulV(state->v,&v);
         state->b->getFeatures(bxform,v,&fb);

         fa.collide(fb,cList,tol);
      }
   }
   return (cList->count != 0);
}

When tested, the vehicle now correctly bounces off of the TSStatic at the expected distance.

A second opinion is always welcome, of course.
#4
04/24/2003 (8:36 pm)
There still seems to be a problem with this. I have a static object with 5 collision meshes. It works fine at a scale of 1 1 1. But when scaled down, the collision detection does not work correctly. I need to do some more debugging, but I was wondering if other people are having the same problem?
#5
04/26/2003 (4:44 pm)
My changes got merged into head a while back, and may be more comprehensive than what appears here, give that a try. If they still don't work, well, I can't suggest anything, I'm afraid, I don't have anything with an especially complex mesh.
#6
04/28/2003 (12:01 pm)
I was using the head. It looks like they took exactly what you did.
#7
04/28/2003 (10:01 pm)
Ah, well, good luck tracking it down, please do submit a patch if you figure out what it is. :)