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?
Simulating compression on a body
-
- Posts: 1
- Joined: Thu Jun 11, 2009 6:18 pm
- Contact:
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Simulating compression on a body
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.
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.
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);
}
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/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Who is online
Users browsing this forum: No registered users and 19 guests