test collision between two body

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

test collision between two body

Postby izissise » Sat Jul 24, 2010 8:43 am

Hello,
I need a function returned if there is collision between two body something like that :

Code: Select all
bool newton_test_collision(newtonbody* body1,newtonbody* body2)


Does there is anything like that in newton ?

thank you !
izissise
 
Posts: 23
Joined: Sat Jul 24, 2010 8:20 am

Re: test collision between two body

Postby Julio Jerez » Sat Jul 24, 2010 10:41 am

Yes

Code: Select all
// return the collision joint, if the body collide
NewtonJoint*  newton_test_collision (NewtonBody* body0, NewtonBody* body1)
{
   for (NewtonJoint* joint = NewtonBodyGetFirstContactJoint (body0); joint; joint = NewtonBodyGetNextContactJoint (body0, joint)) {
      if ((NewtonJointGetBody0(joint) == body1) || (NewtonJointGetBody1(joint) == body1)) {
         return joint;
      }
   }
   return NULL;
}


Code: Select all
//to get the collision points
void HandlecollisionPoints (NewtonJoint* contactjoint)
{
   NewtonBody* body0 = NewtonJointGetBody0(contactjoint);
   NewtonBody* body1 = NewtonJointGetBody1(contactjoint);
   for (void* contact = NewtonContactJointGetFirstContact (contactjoint); contact; contact = NewtonContactJointGetNextContact (contactjoint, contact)) {

      float forceMag;
      dVector point;
      dVector normal;   
      NewtonMaterial* material = NewtonContactGetMaterial (contact);

      // do whatever you want here

      //NewtonMaterialGetContactForce (material, &forceMag);
//      NewtonMaterialGetContactPositionAndNormal (material, &point.m_x, &normal.m_x);
      // do whatever you want with the force
   }
}
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: test collision between two body

Postby izissise » Sat Jul 24, 2010 2:34 pm

Thank you !!! :D
izissise
 
Posts: 23
Joined: Sat Jul 24, 2010 8:20 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron