Game Development Community

Custom Convex Problems

by Eric Roberts · in Torque Game Engine · 04/22/2006 (9:13 am) · 2 replies

Hello all,

I seem to be having a problems with creating a custom Convex class that I've been creating. Simply put, the player (or any shapebase) doesn't collide with it properly (the Convex::getPolyList method). If you move really slowly you can manage to climb/sink through the convex, and as far as I can tell some sides don't collide at all.

Here is what the convex looks like:
Front:
i72.photobucket.com/albums/i199/EricR86/customconv1.gif
Side:
i72.photobucket.com/albums/i199/EricR86/customconv2.gif

I've drawn out the edges of the convex with blue lines so I could see what my convex actually looked like. Click to see a larger image if you can't make out the lines.

My overloaded Convex::getPolyList method returns all the polys clockwise oriented. I even copied the order of the polys added by BoxConvex - but still to no avail. Does what order I add in the polys to the list really matter?

A snippet of getPolyList:
void ForceFieldConvex::getPolyList(AbstractPolyList* list)
{
   static const unsigned int OFFSET = 1;
   //Set our object
   list->setObject(mObject);

   //Build a small enclosing convex

      //Copy the vertices twice into mConvexVert
      for(int j = 0; j < 8; ++j)
         mConvexVert[j] = pOwner->mVertices[j%4];

      //Next add an offset to the first 4 vertices
      for(int j = 0; j < 4; ++j)
         mConvexVert[j].y -= OFFSET;

      //Next subtract an offset to the next 4 vertices
      for(int j = 4; j < 8; ++j)
         mConvexVert[j].y += OFFSET;

      //Now make setup the list
      U32 base = list->addPoint(mConvexVert[0]);

      for(int j = 1; j < 8; ++j)
         list->addPoint(mConvexVert[j]);
      
      //Front face
      list->begin(0,0);
      list->vertex(base + 3);
      list->vertex(base);
      list->vertex(base + 1);
      list->vertex(base + 2);
      list->plane(base + 3, base, base + 1);
      list->end();

      //...

      //Top face
      list->begin(0,5);
      list->vertex(base);
      list->vertex(base + 1);
      list->vertex(base + 5);
      list->vertex(base + 4);
      list->plane(base, base + 1, base + 5);
      list->end();

It doesn't use the same indexing as Box Convex, but the same positioning of vertices are added in the same order.

The object stores all of its coordinates (for itself and it's convex vertices) in world coordinates. As far as I can tell this seems safe. Considering how collision already seems to sort of register, I don't think this is a problem.

Thanks for your time in advance,

- Eric

EDIT: Geez - I thought those pics would show up as thumbnails. I apologize to the 56kers.

#1
04/22/2006 (6:43 pm)
I've fought with the convexes and collisions for quite a while, but all I can say is that you'll need to add a buttload debug rendering code in there to find exactly what the problem is.

From my experience, wandering aimlessly at the code trying to figure out what's wrong on trial and error yelds results totally at random. And often when you think you fixed it, it comes back to bite you later when you least expect.

Try to find a way (even if hackish) to render the polygons it's returning, or at least to change the bounding box color if a player or vehicle actually requested it's polygons. I say that since there are chances the problem is not with your buildPolyList function, it could easily be something else, like your convex bounding box calculation (the player and vehicles will check if their boxes overlap the other convex' box before grabbing polygons).
#2
04/23/2006 (3:30 pm)
@Manoel: I've already done plenty of checks, and yes the getPolyList function is being called when it should. I made sure the object bounding box (the box returned by Convex::getBoundingBox) was larger than the convex itself. 'll try to see if I can render/take a look at the faces being returned and after they've been processed (since ALL of the faces of the convex get added to the list anyway.) Thanks for your input.

From experimenting around - it seems the order in which verticies are added matters - but I could be mistaken. Anyone know why?

I was kind of hoping someone could give insight to this problem that was dramatically over-evident. Say, the convex is too big (even I don't really think it is, but you get the idea).

Thanks,

- Eric