[ODE] Contacts and materials
Nate W
coding at natew.com
Fri Nov 29 00:33:01 2002
On Thu, 28 Nov 2002, Anselm Hook wrote:
> What about finding a way to generalize material properties such that
> contacts could be generated automatically? I'd sure enjoy finding a way
> to remove the collision callback.
As would I - probably because I've been having fun with C# and I'm eager
to put your wrappers to work. :-)
Here's how I was thinking the problem might be approached:
The wrapper (your C# wrapper, or probably any wrapper) would define a
material data structure, something like:
typedef struct
{
void *pUserData;
dReal Mu;
dReal Bounce;
dReal SoftERP;
dReal SoftCFM;
// etc
} Material;
All geom objects would have Material pointers in their dGeomGetData /
dGeomSetData members, and the wrapper would implement those methods as
follows:
// GetData implementation
return ((Material*) dGeomGetData())->m_Data;
// SetData implementation
((Material*) dGeomGetData())->m_Data = p;
Then, a wrapper-defined collision callback would work something like this:
void Callback (void *, dGeomID o1, dGeomID o2)
{
int iCount = dCollide (o1, o2, iContacts, &contact[0].geom, sizeof (dContact));
if (iCount)
{
int iMax = min (iCount, iContacts);
for (int iContact = 0; iContact < iMax; iContact++)
{
Material *pMaterial1 = null;
Material *pMaterial2 = null;
if (o1)
pMaterial1 = dGeomGetData (o1);
if (o2)
pMaterial2 = dGeomGetData (o2);
SetContactParameters (&contact[iContact], pMaterial1, pMaterial2);
dJointID ContactJoint = dJointCreateContact (WorldID,
CollisionJointGroupID, &contact[iContact]);
dJointAttach (ContactJoint, Body1, Body2);
}
}
}
The implementation of SetContactParameters is left as an exercise for the
reader. :-) But, as Anselm suggested, I think it would make a nice
contrib. It would make the C# wrapper considerably more useful, and would
probably be helpful for most non-C/C++ applications that want to use ODE,
since there would no longer be a need for a callback into the application
language. Instead, applications would just set material properties for
all of the Geoms, and the SetContactParameters method would take care of
material interactions.
Comments?
--
Nate Waddoups
Redmond WA USA
http://www.natew.com