getContactSpeed [solved]

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

getContactSpeed [solved]

Postby nathanf534 » Sun Jul 18, 2010 10:15 pm

I want a callback to be called each time something collides, so I can get the collision speed.

I used

Code: Select all
defaultGroupID = NewtonMaterialGetDefaultGroupID(nWorld);
NewtonMaterialSetCollisionCallback (nWorld,defaultGroupID,defaultGroupID,NULL,NULL,contactProcess);


to set the callback, and my callback is...
Code: Select all
static void contactProcess(const NewtonJoint* contact, dFloat timestep, int threadIndex){
   dFloat contactSpeed= NewtonMaterialGetContactNormalSpeed (NewtonContactGetMaterial(contact));
   cout<<contactSpeed<<endl;
}


The callback is called everytime a collision occurs, so that works fine, but I can't figure out how to get the contactSpeed from what the callback function provides (I can't figure out how to get the material for the contact)

What I currently have in the callback function crashes on contact.

Thanks in advance.

EDIT: I figured out I needed to convert the NewtonJoint contact into an actual contact, and then it works perfectly. Sorry for bothering :)
Code: Select all
static void contactProcess(const NewtonJoint* contact, dFloat timestep, int threadIndex){
   dFloat contactSpeed= NewtonMaterialGetContactNormalSpeed (NewtonContactGetMaterial(NewtonContactJointGetFirstContact (contact)));
   cout<<contactSpeed<<endl;
}
nathanf534
 
Posts: 19
Joined: Sun Jul 11, 2010 9:01 am

Return to General Discussion

Who is online

Users browsing this forum: No registered users and 3 guests

cron