Page 2 of 2

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

Posted: Mon Mar 07, 2016 10:45 am
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

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

Posted: Mon Mar 07, 2016 12:36 pm
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.

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

Posted: Tue Mar 08, 2016 8:18 am
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

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

Posted: Tue Mar 08, 2016 11:21 am
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.

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

Posted: Thu Mar 10, 2016 3:23 pm
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!

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

Posted: Thu Oct 04, 2018 1:54 pm
slembcke wrote:
This correction is more or less applied directly to the position and does not affect the regular velocity or forces.

How it works is that the solver uses bias velocities, an idea that came from Box2D. To make the position change a certain amount over a certain time step, that's a velocity, and there is already a powerful mechanism for solving velocity constraints. It basically just duplicates the regular velocity solver and then throws the bias velocities away after updating the position.

Solver:

Thanks for this bro