[pymunk] Retrieve force from Arbiter when no gravity

Official forum for the Chipmunk2D Physics Library.
Angel
Posts: 17
Joined: Thu Feb 09, 2012 6:21 am
Contact:

Re: [pymunk] Retrieve force from Arbiter when no gravity

Post by Angel »

OK, then. Thanks for all the answers.

However, it would be great to get a "pressure-like" value in those cases. When I have lots of body moving just because of overlap resolutions (no gravity, just new bodies that appeared on top of others) I need to be able to picture the pressure field of the world (i.e. impulses/forces applied to bodies). The overlap distance is not directly proportional. It keeps a proportionality somehow, but not direct.

If you could tell me a workaround, it would be very helpful.

Many thanks and congrats for all the job done!

A
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: [pymunk] Retrieve force from Arbiter when no gravity

Post by slembcke »

Well, like I said, the information you are looking for does exist inside of Chipmunk, but you are going to need to write a little C code to access it using the private APIs.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Angel
Posts: 17
Joined: Thu Feb 09, 2012 6:21 am
Contact:

Re: [pymunk] Retrieve force from Arbiter when no gravity

Post by Angel »

OK.

I know this may be a bit too much, but... could you tell me where to start from? Should I touch cpArbiter.h/.c to any extent? Maybe altering the value returned by totalImpulse to add non-impulsed bodies? If you could tell me where to look for the answer I'll do my best to recover that value.

Many thanks!
A
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: [pymunk] Retrieve force from Arbiter when no gravity

Post by slembcke »

This is the function that returns the impulse for a collision:
https://github.com/slembcke/Chipmunk2D/ ... ter.c#L142

A really easy solution that you might like is simply to add cpContact.jnAcc and cpContact.jBias together so the "sum" line looks like this:

Code: Select all

sum = cpvadd(sum, cpvrotate(n, cpv(con->jnAcc + con->jBias, con->jtAcc)));
Basically add the regular collision impulse to the bias impulse that pushes the objects apart. Then regular collision forces and "overlap pressure" is unified exactly the way it's actually calculated and applied. If you want them separately, you'll have to duplicate the function and make an extra pymunk wrapper for it.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Angel
Posts: 17
Joined: Thu Feb 09, 2012 6:21 am
Contact:

Re: [pymunk] Retrieve force from Arbiter when no gravity

Post by Angel »

Great! That does it very easily. Quite an obvious note: instead of "n", use "con->n".
Many thanks,
A!
PS. If I need something different I am quite confident now with the internal resolution of overlaps. Thanks for all the comments!
Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests