Collision Callbacks

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Collision Callbacks

Postby jamesm6162 » Mon Nov 23, 2015 7:59 am

Hi

I am running into a problem where it seems the collision callbacks are only called the first time that the collision happens between two bodies. If they are still colliding in the next update, then the callbacks are not called again.

I basically need to detect when two bodies "stop" colliding. So in my application I store the contacts in the callbacks and I clear them before every update. But right now this doesn't work as the callbacks are never called again after the first time for two bodies resting on each other for example.

Is there any other way how I can detect when the are colliding or not?

Thanks

James
jamesm6162
 
Posts: 49
Joined: Wed Aug 12, 2015 8:50 am

Re: Collision Callbacks

Postby JoeJ » Mon Nov 23, 2015 11:33 am

You can iterate over contacts from a body to find all other bodies touching it:

Code: Select all
for (NewtonJoint* joint = NewtonBodyGetFirstContactJoint(body); joint;
  joint = NewtonBodyGetNextContactJoint(body, joint))
{
 NewtonBody* b0 = NewtonJointGetBody0(joint);
 NewtonBody* c1 = NewtonJointGetBody1(joint);
 NewtonBody* otherBody = (b0==body ? b1 : b0);
}


But i don't know if there is a faster way.
User avatar
JoeJ
 
Posts: 1489
Joined: Tue Dec 21, 2010 6:18 pm

Re: Collision Callbacks

Postby Julio Jerez » Mon Nov 23, 2015 2:25 pm

you can look at class CustomTriggerManager and implement one of your own or use that one as an example of how to do what you described.

If a pair is sleeping the call back is no called. this is how the engine manage to get performance.
if you are using version 3.13 and up, you can look at function
void CustomTriggerManager::UpdateTrigger (CustomTriggerController* const controller)

as Joe say you can get the object, and iterate over the contact joints, the you can check if the joint is active, NewtonJointIsActive in order to see if the object are colliding.
is it common for tow objects to have a joint and not be colliding,
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest