[ODE] Tri-collider with current ODE collision code
Nate W
coding at natew.com
Sat May 24 15:45:02 2003
I found and fixed the problem with tri-collider in the new ODE code.
The main problem is that tri-collider uses dCollideBoxPlane, and the geom
that it passes to dCollideBoxPlane must be laid out in memory in a way
that matches dxPlane. Far as I can tell, that's incompatible with the
dxUserGeom way of doing things - dxUserGeom seems to be putting a
user_data member right where dxPlane puts the first element of the plane's
normal.
So, in dxTriList.h, I put a structure that has a large section of unused
data, to match dxGeom, and has four dReals in the right place to match
dxPlane's normal vector and distance scalar.
struct dxTriangle
{
char unused [sizeof (dxGeom)];
dReal x,y,z,d;
};
(I would have simply derived dxTriangle from dxGeom to get the same
effect, but that would require implementing some abstract virtual
functions.)
In dcTriListCollider.cpp, I got rid of the code that used to copy triangle
data into dcTriListCollider::Geometry, and put in this instead:
for (int i = 0; i < CollisionTriangles.size(); i++) {
dxTriangle Triangle;
dcPlane &TriPlane = CollisionTriangles[i].Plane;
Triangle.x = TriPlane.Normal.x;
Triangle.y = TriPlane.Normal.y;
Triangle.z = TriPlane.Normal.z;
Triangle.d = TriPlane.Distance;
int ContactCount = dCollideBoxPlane(Box, (dxGeom*) &Triangle, ...
for (int j = 0; j < ContactCount; j++) {
BoxContacts[j].g2 = Geometry;
That last bit sets the contact's g2 member to the tri-list geom object
that the user will be expecting, because dCollideBoxPlane will just set it
to the "Triangle" pseudo-geom object.
It seems to work OK. Anyone want to try these changes and/or comment on
my form? :-)
Erwin, with your blessing and someone's confirmation (perhaps yours) that
this actually works, I'd like to check this into CVS.
--
Nate Waddoups
Redmond WA USA
http://www.natew.com