Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

enter image description here

I'm using Box2D. As you can see, there are three dynamic bodies connected to each other (think of it as a table from front view). LEG1 and LEG2 are connected to the static body (it's the ground body). Another dynamic body is falling onto the table.

I need to get the compression in the LEG1 and LEG2 separately.

Joints have a GetReactionForce() function which returns a b2Vec, which in turn has Length() and LengthSqd() functions. This will give the total sum of the forces in any taken joint. But what I need is forces in individual bodies that are connected with joints. Once you connect several bodies with a single joint it again will show the sum of forces which is not useful. Here's the case I'm talking about:

enter image description here

share|improve this question

migrated from gaming.stackexchange.com Feb 26 '13 at 20:55

This question came from our site for passionate videogamers on all platforms.

1  
>> Once you connect several bodies One joint can connect only two bodies. Connect each leg to table plate, and you will get again first case. Am I wrong? –  Pavel Feb 28 '13 at 5:27
    
Sorry, I just forgot that a joint joins only two bodies. –  Mike JM Mar 1 '13 at 19:11
add comment

1 Answer 1

Both the distance joint and weld joints have local anchors within them. Each anchor is relative to one of the bodies connected by the joint. You can find your compression of an individual joint by finding the distance between the two anchor points in world space.

You can use these functions to retrieve them:

joint->GetLocalAnchorA( );
joint->GetLocalAnchorB( );

To transform these points to world space you can use the function on each body called:

body->GetWorldPoint( v ); // Get the world coordinates of a vector given the local coordinates.

The weld joints (or distance joints) should be using soft constraints, otherwise the error will mostly be negligible anyway.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.