From FAQ "Can I use the collision system separate from the "

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

From FAQ "Can I use the collision system separate from the "

Postby koirat » Wed Jun 30, 2010 10:50 am

It would be great to just

Body[] GetCollisions(World* world,Position,Orientation,Collision* col)

And get all the bodies colliding with col in the world :).
Making use of Newton internal spatial structure, and not with some brute force iterations over all bodies.
koirat
 
Posts: 4
Joined: Sat Feb 21, 2009 5:16 am

Re: From FAQ "Can I use the collision system separate from the "

Postby Julio Jerez » Wed Jun 30, 2010 11:28 am

I beleive that is a feature of 2.0 since the begining
here is a sample code to do that

Code: Select all
void GetContactOnBody (NewtonBody* body)
{
   for (NewtonJoint* joint = NewtonBodyGetFirstContactJoint (body); joint; joint = NewtonBodyGetNextContactJoint (body, joint)) {
      for (void* contact = NewtonContactJointGetFirstContact (joint); contact; contact = NewtonContactJointGetNextContact (joint, contact)) {

         float forceMag;
         dVector point;
         dVector normal;   
         NewtonBody* body0 = NewtonJointGetBody0(joint);
         NewtonBody* body1 = NewtonJointGetBody1(joint);
         NewtonMaterial* material = NewtonContactGetMaterial (contact);

         //NewtonMaterialGetContactForce (material, &forceMag);
         NewtonMaterialGetContactPositionAndNormal (material, &point.m_x, &normal.m_x);
         // do whatever you want with the force
      }
   }
}



Basically you cna get all teh bodies and all teh contact a body is in touch at any time.
Is that what you look for?
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: From FAQ "Can I use the collision system separate from the "

Postby koirat » Thu Jul 01, 2010 11:39 am

But the Body have to be already in a newton world. So I can use this feature only after updating physics.
Also you have to create Body even if you don't need it for what you want to do.

What I'm doing is a simple explosion. I just want to gather all the bodies inside a sphere collision object placed at a specified position. I don't want to create body object, I don't want to wait until physics is updated, and I don't want to update physics manually.
It's just like get Bodies intersecting with a sphere and add impulses to them.
koirat
 
Posts: 4
Joined: Sat Feb 21, 2009 5:16 am

Re: From FAQ "Can I use the collision system separate from the "

Postby Julio Jerez » Thu Jul 01, 2010 11:56 am

but there are simpler ways to do that, can't you use ForAll Bodies in AABB, it is very efficient,

in the callback you pass the sphere shape, and as you get the bodies, you call Collision test to see if the Body is hitting the sphere
For AllBodies in AABB will only repist teh bodies in the AABB, so it iwll be effiecent, the the collison tess will have to check against the sphere radio,
and you can do that with using Netwon collison (sevaral of eth few flavor) or you cna just do a simple radio test.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: From FAQ "Can I use the collision system separate from the "

Postby koirat » Thu Jul 01, 2010 12:07 pm

Yes this is something I was looking for.
Thank you.
[edit] We are talking about -- > NewtonWorldForEachBodyInAABBDo ?[/edit]

You can still add some helper function to your engine so users will just pass collision shape and it's position/orientation.
So we got automatic AABB and collsion tests.
koirat
 
Posts: 4
Joined: Sat Feb 21, 2009 5:16 am

Re: From FAQ "Can I use the collision system separate from the "

Postby Julio Jerez » Thu Jul 01, 2010 1:35 pm

but
void NewtonWorldForEachBodyInAABBDo (const NewtonWorld* newtonWorld, const dFloat* p0, const dFloat* p1, NewtonBodyIterator callback, void* userData);

has a user data pointer, you can pass a pointer to a class or an object that contain all the information you need.
the collision shape, tha matrix, and an empty array to teh object that the function. or you cna just appli the ipulse as teh object are found.
It is all well defined. I think.

Remember you goal is to do the saerch as cheaply as possible, once you get body in NewtonWorldForEachBodyInAABBDo
why doing a expensive collision test? when all you need to kknow is the body is intesescting radius of teh explosion.
A sphere collison call will cost more than just a radiuos interstion test, because the collison test will calculate exact contacts

better so either save the radio of the body or call GetAABB on the body and do a BOX-sphere or get the radio of the AABB and do a Spheer-Sphere test
so you only need to pass the cneter of the explosion and the radius.
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

cron