Game Development Community

SetCollisionPolyCustom with 2 vertices

by Adam Larson · in Torque Game Builder · 08/16/2005 (6:41 pm) · 3 replies

There seems to be an issue when generating a custom collision line (polygon of two points). I traced it back to the calculateMassInertia function of fxPhysics2D.cc. With certain vertex values for the endpoints, iNumer (and iDenom) are 0.0 when this is called:
// Line 774
setInertialMoment( (mMass/6.0f) * (iDenom/iNumer) ); // Possible divide by zero!
This only happens when c1 is set to 0.0 as a result of line 765. That would happen when the endpoints of the line fulfill this equation:
(point1.x * point2.y) = (point1.y * point2.x)
Which would happen if point1.x = -point2.x AND point1.y = -point2.y (point2 = point1 rotated 180 degrees).

A quick fix I guess would be to change it to this:
if (iNumer == 0.0f)
   setInertialMoment(0.0f);
else
   setInertialMoment (mMass/6.0f) * (iDenom/iNumer) );

#1
08/16/2005 (8:43 pm)
T2D probably doesn't handle a polygon with only 1 edge. Such an object has no mass, and therefore behaves kinda wierdly under physics. Plus, the collision detection may well expect a collision polygon that has an area.

Perhaps T2D should throw some kind of error when you try to use a 2-point polygon.

Additionally, while Melv is implementing swept circle collisions, perhaps he should also consider dropping in a line collision type.
#2
08/16/2005 (9:12 pm)
T2D's collision code works with both lines and points. There are special cases for points and lines in the mass calculations and for points in the inertia calculations.

I haven't looked into how the collision system works, but I did test it with both points and lines. It seemed to work just fine.
#3
08/24/2005 (5:31 am)
Thanks for the info. I'll look into this.

- Melv.