Allow user data to be attached to any callback?

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

Allow user data to be attached to any callback?

Postby richard » Wed Mar 30, 2011 11:47 pm

[this refers to the 200 API, not 300 which I can't currently build]

I'm helping implement the Python bindings to Newton and one of the nastier problems we have to deal with is callbacks that call from Newton back into Python objects. The problem is how the callback knows what Python object is being manipulated in order to translate the C callback to a Python callback.

In some cases we can attach a Python object to eg. a NewtonBody and then in the callback we can retrieve the object. This isn't possible for NewtonJoints though as there is no user data (as far as I can tell). Also for some other callbacks the code required to get the Python callback can be quite complex (eg. NewtonMaterial contacts_process callback where the callbacks are stored as user data on the NewtonMaterial, but getting to the NewtonMaterial inside the C callback requires several other calls).

What would make it significantly simpler would be to be able to have the Python callback be passed directly to the C level callback as a user data argument.


On a somewhat similar note, is there any reason why the contacts_process callback from NewtonMaterialSetCollisionCallback isn't passed a pointed to the NewtonMaterial as the first argument (like the aabb_overlap callback is)?
richard
 
Posts: 4
Joined: Wed Mar 30, 2011 10:37 pm

Re: Allow user data to be attached to any callback?

Postby Julio Jerez » Thu Mar 31, 2011 12:35 am

Th ejoint do have user data, in fact all callback have user data. See how the joint library is implemented.
I was able to conver the complete library to Objective C without problems, you should be able to do the same for Phyton

as for the void NewtonMaterialSetCollisionCallback (const NewtonWorld* newtonWorld, int id0, int id1, void* userData, NewtonOnAABBOverlap aabbOverlap, NewtonContactsProcess process);
you have to realize that there are two set of material functions, the set that takes ido, and id1 as argument are for when you are making your Materail Matrix,
the one that take Material as argument are for when you call material functions from a call back or from an iterator.

The material you get in a callback is not a Material, it is a copy that is created on the Stack.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Allow user data to be attached to any callback?

Postby JernejL » Thu Mar 31, 2011 3:04 am

Inside NewtonContactsProcess you can retrieve pointers to both bodies & their userdata from the "contact joint".

See example here: http://newtondynamics.com/wiki/index.ph ... 53_and_2.0
Help improving the Newton Game Dynamics WIKI
User avatar
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 1 guest

cron