Collision Callback has no userdata in V2B17?

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

Collision Callback has no userdata in V2B17?

Postby saxman » Sun Dec 14, 2008 2:08 pm

I'm setting the userdata field as so...

NewtonMaterialSetCollisionCallback( newtonWorld_, newtonMatId1_, newtonMatId2_, newtonData_, NULL, newtonContactsProcess );

But in my newtonContactsProcess function, the userdata is NULL...

newtonContactsProcess( const NewtonJoint *newtonJoint, dFloat newtonStep, int newtonThreadId )
{
void *newtonData = NewtonJointGetUserData( newtonJoint );

Is this a bug or is there another way to get the userdata set with NewtonMaterialSetCollisionCallback?
saxman
 
Posts: 12
Joined: Thu Oct 02, 2008 5:37 am

Re: Collision Callback has no userdata in V2B17?

Postby Gianluca » Mon Dec 15, 2008 11:56 am

It's your error !!

In fact, you setted the user data into the NewtonMaterialSetcollisionCallback... so, the userdata is regarding the material (NewtonMaterial).

But in your code after, you request the userdata to the joint (NewtonJointGetUserData) and you never setted it.
Instead, you have to use the NewtonMaterialGetUserData in the following way:
Code: Select all
void newtonContactsProcess( const NewtonJoint* contactJointList, dFloat timestep, int threadIndex ) {
   for( void* contact = NewtonContactJointGetFirstContact( contactJointList ); contact; contact = NewtonContactJointGetNextContact( contactJointList, contact ) ) {
      NewtonMaterial* material = NewtonContactGetMaterial( contact );
      YourData* data = (YourData*)( NewtonMaterialGetMaterialPairUserData( material ) );
}
Gianluca
 
Posts: 53
Joined: Fri Nov 11, 2005 4:37 am
Location: Rome - Italy

Re: Collision Callback has no userdata in V2B17?

Postby saxman » Mon Dec 15, 2008 3:47 pm

Since Newton is often wrapped in a C++ class, it would be much more helpful to get the userdata first thing, rather than having to iterate through a for loop to find it. In my case, I need access to the class before I start processing any collisions.

I ended up with...

const NewtonBody *newtonBody0 = NewtonJointGetBody0( newtonJoint );
NewtonWorld *newtonWorld = NewtonBodyGetWorld( newtonBody0 );
void *newtonData = NewtonWorldGetUserData( newtonWorld ;
saxman
 
Posts: 12
Joined: Thu Oct 02, 2008 5:37 am

Re: Collision Callback has no userdata in V2B17?

Postby JernejL » Tue Dec 16, 2008 4:34 am

If i'm not mistaken, NewtonContactJointGetFirstContact and NewtonContactJointGetNextContact actually iterate thru ALL contacts with all different materials in one callback, that's why you have to iterate them all to get all user data for all the unique material pairs.

Julio please correct me if i am wrong.
Help improving the Newton Game Dynamics WIKI
User avatar
JernejL
 
Posts: 1578
Joined: Mon Dec 06, 2004 2:00 pm
Location: Slovenia

Re: Collision Callback has no userdata in V2B17?

Postby saxman » Tue Dec 16, 2008 4:45 am

Hmm, a couple of the samples (BasicFriction/BasicRestitution) make reference to...

body0 = NewtonJointGetBody0(contactJoint);
body1 = NewtonJointGetBody1(contactJoint);

and even...

node = (RenderPrimitive*) NewtonBodyGetUserData (body);

but it would be good to know if I am understanding this incorrectly.
saxman
 
Posts: 12
Joined: Thu Oct 02, 2008 5:37 am

Re: Collision Callback has no userdata in V2B17?

Postby Julio Jerez » Wed Dec 17, 2008 11:01 am

look at teh demo that shwo teh track tanks they use the callback in many ways.
The callback now are much more flaxible thet they were in 1.53

plus you also can use the engine without using callback, after an update you can use the ietrator to collect the information you need.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to Bugs and Fixes

Who is online

Users browsing this forum: No registered users and 6 guests

cron