Game Development Community

Rectangular model collision box doesn't rotate

by Steve Lamperti · in Torque Game Engine · 12/04/2006 (3:25 pm) · 6 replies

I have a model which is rectangular, (In fact it's quite a bit longer then it is wide, so the problem I am seeing is quite noticable,) and I have a type of object based on Item that moves around. When it turns, I don't believe that the collision box is rotating with the rest of the model. The model was exported from 3dsMax with a current exporter, and the collision bix is set up, I believe, correctly.

Is there something I need to do to attach the collision box to the model so it rotates with the object? Or is there some code missing in my C++ code?

If anyone has any suggestions, I would appreciate hearing them,

Thanks,

#1
12/05/2006 (7:09 am)
Im not sure what your doing with the item that makes it NEED a collision mesh, none of my item have collision mesh, and they have always worked fine as items.

If you are willing to rebuild the code, there is a way to make collision mesh render. Let me look it up and get back to you....
#2
12/05/2006 (7:22 am)
Sorry, all i found was ShowBoundingBox. I do recall something about getting the collision mesh visible, perhaps a bit of deep searching on the site here will turn it up, if you find you need it....
#3
12/06/2006 (9:13 am)
My Item object is overridden from the standard item, and includes a lot of changes. One aspect of my item is that it moves. (I've overridden a lot of the code, so it behaves quite a bit different then a regular item.)
I think I have a better idea what is happening. It looks like part of the collision code uses the mObjBox, and that box doesn't seem to be rotating with the object when it rotates. Perhaps it's not supposed to? I would like some code that shows the collsion box, so I will try that deep search that you are suggesting.
#4
12/06/2006 (9:37 am)
I did find a bit of code that displays the collision mesh very nice. It is from void RigidShape::renderImage (from rigidshape.cc the version for the resource not the 1.5/1.42- but the later may also have it), but im sure it can be tweaked to fit your needs.
if (gShowBoundingBox) {
      glDisable(GL_LIGHTING);
      glPushMatrix();
      dglMultMatrix(&getRenderTransform());

      // Box for the center of Mass
      glDisable(GL_DEPTH_TEST);
      glColor3f(1, 1, 1);
      wireCube(Point3F(0.1,0.1,0.1),mDataBlock->massCenter);
      glPopMatrix();

      // Collision points
      for (int i = 0; i < mCollisionList.count; i++) {
         glColor3f(0, 0, 1);
         Collision& collision = mCollisionList.collision[i];
         wireCube(Point3F(0.05,0.05,0.05),collision.point);
         glColor3f(1, 1, 1);
         glBegin(GL_LINES);
         glVertex3fv(collision.point);
         glVertex3fv(collision.point + collision.normal * 0.05);
         glEnd();
       }
#5
12/07/2006 (12:07 pm)
@Caylo

Thanks for your suggestions. After looking at this a bit more, I am quite sure that the problem is associated with my code in the object, and not with the engine in general.

The collision code in my object is based on the code from player, and it is creating a box to compare with the working collision list. The problem seems to be that the box the code is creating starts from mObjBox, and doesn't correctly taking the rotation into account. In fact, now that I think about it, the code is using a box object, and that only has two points that define it, so it can't be a rectangle at all. It is by defination a cube. I will probably have to figure out how to make the collision code custom, which means trying to understand it, which will probably make my head explode.
#6
12/07/2006 (12:28 pm)
After a little research, I realized that my last post (about the box always being a cube,) was wrong. What I need, is to create a box that is the same as the MObjBox, except it's rotated, and scaled. When I think about this, I think that this should just be the mWorldBox, but I think I already tried this and didn't get it to work correctly. I will try this again.