Compound collision and collision ID.

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Compound collision and collision ID.

Postby Crashy » Thu Sep 06, 2012 5:53 am

Hi,

I'm looking for a way to retrieve the collision id of a sub-part of a compound collision when the collision occurs. I've only found ways to retrieve the compound collision's id, but not the id of the sub-part involved in the contact. Is there a way to do it?

Thanks.
Crashy
 
Posts: 101
Joined: Fri Dec 03, 2010 6:30 am

Re: Compound collision and collision ID.

Postby Julio Jerez » Thu Sep 06, 2012 8:46 am

In a contact callback or when iteration over the contact joints that link two bodies, you can get the contact material that was use to generate teh contact, teh conta contaion teh subshape and the body for both bodies
NewtonCollision* NewtonMaterialGetBodyCollidingShape (const NewtonMaterial* const material, const NewtonBody* const body);
something like this

Code: Select all
                NewtonBody* const body = NewtonJointGetBody0(contactJoint);
   for (void* contact = NewtonContactJointGetFirstContact (contactJoint); contact; contact = NewtonContactJointGetNextContact (contactJoint, contact)) {
      dFloat speed;
      dVector point;
      dVector normal;   
      dVector dir0;   
      dVector dir1;   
      dVector force;
      NewtonMaterial* material;

      material = NewtonContactGetMaterial (contact);

      NewtonMaterialGetContactForce (material, body, &force.m_x);

                               NewtonCollision* collidingSubShape = NewtonMaterialGetBodyCollidingShape (material, body);


      NewtonMaterialGetContactPositionAndNormal (material, body, &point.m_x, &normal.m_x);
      NewtonMaterialGetContactTangentDirections (material, body, &dir0.m_x, &dir1.m_x);
      speed = NewtonMaterialGetContactNormalSpeed(material);


      //speed = NewtonMaterialGetContactNormalSpeed(material);
      // play sound base of the contact speed.
      //
   }
}
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Compound collision and collision ID.

Postby Crashy » Thu Sep 06, 2012 9:42 am

Thank you, it's working like a charm :)
Crashy
 
Posts: 101
Joined: Fri Dec 03, 2010 6:30 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest