Simulating compression on a body

Official forum for the Chipmunk2D Physics Library.

Simulating compression on a body

Postby grassroot » Thu Jun 11, 2009 6:24 pm

Recently, I have been working on a project which requires 2 Bodies to come together and crush something in the middle.
What I wanted to do is that when the object in the middle experiences enough pressure (stress) from both objects. Then the object in the middle is destroyed.

I have there is a constant force being applied to each of the 2 compressing bodies. But force doesn't get transfered to the object in the middle when in contact.

Anyone has any idea on how I can simulate this stress, pressure on a shape or body?
grassroot
 
Posts: 1
Joined: Thu Jun 11, 2009 6:18 pm

Re: Simulating compression on a body

Postby slembcke » Wed Jun 17, 2009 11:49 am

A general solution would be to change the default collision function to save a list of arbiters onto the object attached to each body through it's data parameter. Then after the cpSpaceStep() call returns you would have to calculate the crush force on each object.

I wrote this a while back when pondering about such things, but it's not exactly usable as is. It computes the ratio of the sum of the magnitudes of all the impulses to the magnitude of the summed forces. In other words, a value telling you if the forces are all pushing in the same direction or not.
Code: Select all
cpFloat
cpContactsEstimateCrushingImpulse(cpContact *contacts, int numContacts)
{
        cpFloat fsum = 0.0f;
        cpVect vsum = cpvzero;
       
        for(int i=0; i<numContacts; i++){
                cpContact *con = &contacts[i];
                cpVect j = cpvrotate(con->n, cpv(con->jnAcc, con->jtAcc));
               
                fsum += cpvlength(j);
                vsum = cpvadd(vsum, j);
        }
       
        cpFloat vmag = cpvlength(vsum);
        return (1.0f - vmag/fsum);
}


You'd have to modify it to loop over all contact points for a body, not just a list from a single arbiter.

A simpler solution would be to just check if an object is between your two crushers and check that the crushing force they apply is above a certain point.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm


Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 1 guest

cron