A place to discuss everything related to Newton Dynamics.
Moderators: Sascha Willems, walaber
by sinisa » Tue Nov 10, 2009 1:29 pm
Hi All,
I've been using Newton 2.x and I can see several functions are different than what Newton Wiki describes. One in particular:
Newton Wiki (I guess this was for 1.5x version):
NewtonMaterialSetCollisionCallback (const NewtonWorld* newtonWorld, int id0, int id1, void* userData, GenericContactBegin, GenericContactProcess, GenericContactEnd);
Newton.h:
NewtonMaterialSetCollisionCallback (const NewtonWorld* newtonWorld, int id0, int id1, void* userData, NewtonOnAABBOverlap aabbOverlap, NewtonContactsProcess process);
So now there are 2 callbacks instead of 3. I'd like to play sound on impact of one body into another, but not to constantly play sound while AABB of bodies overlap neither while contacts are being processed (which in both cases results in bunch of sounds played in every frame).
Is there an example how to determine when is appropriate to play impact sound, for newton 2.x? In 1.5 it was quite simple, since callback ContactBegin was called only once. Now in 2.x is different. I've been trying to use velocity of both bodies as parameter if sound should be played, but that doesn't work well if for example ball is rolling fast on the flat surface, velocity is always high and AABB and ContactsProcess are constantly being called.
Anyone has an idea?
-
sinisa
-
- Posts: 12
- Joined: Mon Nov 09, 2009 11:26 am
by sinisa » Tue Nov 10, 2009 2:14 pm
Ok, I should have looked more on Wiki, apparently there are mixed examples, some for 1.5x and some for 2.x.
For all who had same question as I did, here is what Wiki says:
- Code: Select all
// play sound on impact using only "Contacts Process" material callback:
ContactsProcess (const NewtonJoint* contactJoint, dFloat timestep, int threadIndex)
{
xfloat contactBestSpeed = 0.5f; // min required contact normal speed (body speed in direction normal to collision face)
// since bodies can have multiple contacts, loop through them all
for (void* contact = NewtonContactJointGetFirstContact (contactJoint); contact; contact = NewtonContactJointGetNextContact (contactJoint, contact))
{
NewtonMaterial *material = NewtonContactGetMaterial (contact);
xfloat contactNormalSpeed = NewtonMaterialGetContactNormalSpeed (material);
if (contactNormalSpeed > contactBestSpeed)
{
// play sound here
}
}
}
-
sinisa
-
- Posts: 12
- Joined: Mon Nov 09, 2009 11:26 am
by JernejL » Tue Nov 10, 2009 6:20 pm
in 1.53 you have GenericContactBegin, GenericContactProcess, GenericContactEnd
You would get the begin call when aabb of bodies would overlap, contactsprocess for each contact and then contactend (just for a bonus.. to tell you all callbacks for all contacts have ended).
In 2.0 you simply get a aabboverlap, and a contactsprocess, contactsprocess is used to process all contacts (with NewtonContactJointGetFirstContact & NewtonContactJointGetNextContact iterators), the contactsprocess in 2.0 also serves as contactsend callback as it was used in 1.5.
The reason for the change is mostly to do with multicore architecture of newton2.0 where many contacts are solved out of order for many bodies.
This topic could help you with the material callback use in 2.0:
viewtopic.php?f=9&t=5456&p=39299&#p39299
-

JernejL
-
- Posts: 1587
- Joined: Mon Dec 06, 2004 2:00 pm
- Location: Slovenia
-
by sinisa » Wed Nov 11, 2009 4:35 am
Delfi wrote:The reason for the change is mostly to do with multicore architecture of newton2.0 where many contacts are solved out of order for many bodies.
This topic could help you with the material callback use in 2.0:
http://newtondynamics.com/forum/viewtop ... 99&#p39299
Thanx for clarification. I've made it work with source above.
-
sinisa
-
- Posts: 12
- Joined: Mon Nov 09, 2009 11:26 am
Return to General Discussion
Who is online
Users browsing this forum: No registered users and 2 guests