NewtonContactEnd removed, soundsystem

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

NewtonContactEnd removed, soundsystem

Postby kallaspriit » Wed Mar 04, 2009 9:29 am

Hey,

I was wondering why has NewtonContactEnd callback been removed or am I misunderstanding something? My problem is that I'm implementing a sound system and having problems with playing sliding and rolling sounds.

My method is to start looping "scratch" sound when certain tangent speeds are exceeded and then adjust the volume based on the intensity of the slide until it falls below a certain level and then I stop the sliding sound.

Everything is good when the body starts and ends sliding on the ground, but when I pull the object so it slides and then pull it into the air, I have no way of knowing that I should stop the sliding sound because no more contact callbacks are called. It would be easy to stop the sound in NewtonContactEnd callback, but how should I handle it now?

Using the 2.0 beta to make clear, working great otherwise :)


Thanks,
Priit
kallaspriit
 
Posts: 216
Joined: Sun Aug 14, 2005 6:31 pm

Re: NewtonContactEnd removed, soundsystem

Postby Julio Jerez » Wed Mar 04, 2009 10:39 am

contact end was call after teh fact, when you codun do very lith about, now you can interate ove all contact in a single call
see the SDK there are varis sample of contact manipulation,

here is a funtion form teh SDK

Code: Select all
// this callback is called for every contact between the two bodies
//int GenericContactProcess (const NewtonMaterial* material, const NewtonBody* body0, const NewtonBody* body1, dFloat timestep, int threadIndex)
void GenericContactProcess (const NewtonJoint* contactJoint, dFloat timestep, int threadIndex)
{
   for (void* contact = NewtonContactJointGetFirstContact (contactJoint); contact; contact = NewtonContactJointGetNextContact (contactJoint, contact)) {
      dFloat speed;
      dVector point;
      dVector normal;   
      dVector dir0;   
      dVector dir1;   
      NewtonMaterial* material;

      material = NewtonContactGetMaterial (contact);
      NewtonMaterialGetContactPositionAndNormal (material, &point.m_x, &normal.m_x);
      NewtonMaterialGetContactTangentDirections (material, &dir0.m_x, &dir1.m_x);
      speed = NewtonMaterialGetContactNormalSpeed(material);
      speed = NewtonMaterialGetContactNormalSpeed(material);
      // play sound base of the contact speed.
      //
   }

}


basically you can iterate and select the best contacts to play teh spund of the effect.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonContactEnd removed, soundsystem

Postby kallaspriit » Wed Mar 04, 2009 11:00 am

I am doing exactly that and it works great for collision sounds, that have to be played just once, but I cant use the same method to play sliding-rolling sounds, because if I dont use looped sound and just start again if the previous one has finished, I get choppy results - the sound isnt stable, you can hear the replaying of the sound gap.

I need to stop a looping sound once body goes to rest (no problem with that) or when body is suddenly lifted from the other surface - how can I know whether that has happened?
kallaspriit
 
Posts: 216
Joined: Sun Aug 14, 2005 6:31 pm

Re: NewtonContactEnd removed, soundsystem

Postby Julio Jerez » Wed Mar 04, 2009 1:45 pm

yuo need a sound update function, which I asume you have.

this is what I would do.

when you decide to play a looping sound, you can save the contact contact joint and the contact with the by analizin the data in the contact
you can save ethe contact and the specific NewtonMaterial* material with sound handle

you also initilize a counter in teh sound handle.

the next tuiem arund you chek in the sound is in teh list of loppongd sound.
(To make this eassy I will add a function to save a user data with the contact, I though this was there but it is not
for now you can serach for th econtact in the sound list. Contact are persistent so if next time this is the same contact, then it will be in the list)
if you find the contact the you increase teh frame count in teh soudn handles, because tshi si teh same collision.

in you sound manager when you find teh soudn teh need to be played you ulny update teh one who's frame count is teh same a physics tick count.
bodies teh separted afte collision will have frame cound lower since they do no get contact callback.

I hope thes gives you the general idea.

The only part the is expensive is the search for the concact joint in the sound list, but since the number of sounds that can be play at one time is not too many this shuold be OK.
contacts are general joints is is possible to cast then to Custon joint and use set user data to save the sound handle but I will add and inteface for that.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
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 12 guests