A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by Ivan Mandić » Sat Nov 28, 2009 3:30 pm
Hello.
I'm using NewtonGD as physics engine,what function can I use to check collision?
p.s.
I did found NewtonCollisionCollide function,but if I'm right it's made for those who aren't fully using NewtonGD.
Thanks.
-

Ivan Mandić
-
- Posts: 15
- Joined: Sun Jun 28, 2009 1:42 pm
- Location: Croatia, Slavonski Brod, Slobodnica
-
by JernejL » Sat Nov 28, 2009 3:49 pm
Use newtonupdate() it'll do collision detection and response automaticly, just use the forcetorque callback to add forces to bodies so the simulation will move.
-

JernejL
-
- Posts: 1587
- Joined: Mon Dec 06, 2004 2:00 pm
- Location: Slovenia
-
by Ivan Mandić » Sat Nov 28, 2009 4:06 pm
I know all that,that isn't the problem. I want to check collision for specific body after calling NewtonUpdate.?
(There is no point in using NewtonCollisionCollide if NewtonUpdate already calculated all that. )
-

Ivan Mandić
-
- Posts: 15
- Joined: Sun Jun 28, 2009 1:42 pm
- Location: Croatia, Slavonski Brod, Slobodnica
-
by Julio Jerez » Sat Nov 28, 2009 4:25 pm
In older version of Newton you can use queues to place bodies from a callback,
with newer version you can iterates over the contacts, materials, or joint from almost any objects
to find the contcat joint on a body you can use NewtonBodyGetFirstContactJoint(body)
here is an example tha will show the contact points (from the SDK)
- Code: Select all
void ShowContacts (const NewtonJoint* contactJoint)
{
// the application can implement some kind of contact debug here
if (showContacts) {
NewtonWorld* world;
world = NewtonBodyGetWorld(NewtonJointGetBody0(contactJoint));
NewtonWorldCriticalSectionLock(world);
for (void* contact = NewtonContactJointGetFirstContact (contactJoint); contact; contact = NewtonContactJointGetNextContact (contactJoint, contact)) {
dVector point;
dVector normal;
NewtonMaterial* material;
material = NewtonContactGetMaterial (contact);
NewtonMaterialGetContactPositionAndNormal (material, &point.m_x, &normal.m_x);
// if we are display debug info we need to block other threads from writing the data at the same time
DebugDrawContact (point, normal);
}
NewtonWorldCriticalSectionUnlock(world);
}
}
void ShowBodyContacts (const NewtonBody* body)
{
// iterate over all of the contact joint for this body
for (NewtonJoint* contactJoint = NewtonBodyGetFirstContactJoint (body); contactJoint; contactJoint = NewtonBodyGetNextContactJoint (body, contactJoint)) {
// for debug purpose show the contact
ShowContacts (contactJoint);
}
}
for find when the body collide for the first time you can use struture to keep track when the body adquired contact joints and when the body loses its contact joints.
-
Julio Jerez
- Moderator

-
- Posts: 12426
- Joined: Sun Sep 14, 2003 2:18 pm
- Location: Los Angeles
-
by Ivan Mandić » Sat Nov 28, 2009 4:45 pm
Thanks man.

-

Ivan Mandić
-
- Posts: 15
- Joined: Sun Jun 28, 2009 1:42 pm
- Location: Croatia, Slavonski Brod, Slobodnica
-
by JernejL » Sat Nov 28, 2009 5:58 pm
Ah, the question wasn't clear, in that case you can use the material callback as Julio described
Just remember to assign it to bodies first using NewtonMaterialSetCollisionCallback.
-

JernejL
-
- Posts: 1587
- Joined: Mon Dec 06, 2004 2:00 pm
- Location: Slovenia
-
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 2 guests