[ODE] Fix for Trimesh-Sphere with double-sided geometry

O'dell Hicks ohicks at austin.rr.com
Thu Apr 8 14:10:49 MST 2004


The problem is with double-sided trimeshes.  Contacts produced may cause the
sphere to get stuck or pushed through to the other side.  I haven't tested
it, but I guess the problem would also arise at certain velocities/updates
for close triangles with opposite winding orders that aren't necessarily
coplanar (eg, adjacent buildings with little space between them).

I was about to start looking at Tokamak due to this problem (this
funcitonality is important in my current project), but the fix turned out to
be easier than switching physics engines : )

This is probably pointless, as it sounds like Croteam's collider may be used
in the near future, but here it is for anyone interested:

In collision_trimesh_sphere.cpp, at the beginning of the function
GetContactData, add this code:

//calculate plane of triangle

 dVector4 Plane;
 dCROSS(Plane, =, Edge0, Edge1);
 Plane[3] = dDOT(Plane, Origin);

 //normalize
 float magnitude = 1.0f / dSqrt(dDOT(Plane, Plane));
 Plane[0] *= magnitude;
 Plane[1] *= magnitude;
 Plane[2] *= magnitude;
 Plane[3] *= magnitude;

/*If the center of the sphere is within the positive halfspace of the
triangle's plane, allow a contact to be generated.
If the center of the sphere made it into the positive halfspace of a
back-facing triangle, then the physics update and/or velocity needs
 to be adjusted (penetration has occured anyway).
*/

 float side = dDOT(Plane,Center) - Plane[3];

 if(side < 0.0f)
  return false;



More information about the ODE mailing list