Joints Again

Official forum for the Chipmunk2D Physics Library.
Post Reply
maximile
Posts: 157
Joined: Mon Aug 20, 2007 12:53 pm
Location: London, UK
Contact:

Joints Again

Post by maximile »

I know joints have been addressed before on the forum, but I'm still confused.

I'm adding joints to Chipmunk Playground. They behave perfectly, but I'm having trouble drawing them properly.

On a pivot joint, I want to draw a line to the pivot from each body. I can get the body position from joint->a and joint->b, but I can't work out how to get the pivot position. cpPivotJointNew() returns a cpJoint, which has no info about the pivot. And the cpPivotJoint struct seems to have two anchors and no pivot (though I can't access them anyway).

I'll be adding the other joint types, but I suspect that they'll be easy enough once I get my head round this one. So, can anyone help?

Here's what I have done so far. But in this video, I'm drawing the pivot as the average of the two bodies' centres, which is obviously wrong.

http://www.youtube.com/watch?v=I5N10c37Yb8
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Joints Again

Post by slembcke »

You could pull the information about the anchor points from Chipmunk, but I wouldn't recommend it at all. First of all, it's meant to be somewhat opaque, and all of the joint types work slightly differently anyway so you wouldn't really be saving yourself any trouble.

What you want to do is to store the graphics information somewhere else. When creating a pivot joint, convert the pivot point to each bodies local coordinates. For slide or pin joints, store the anchor points (they are already body local coords). When drawing the joint, just convert those local points to world coords and use them for drawing lines and such.

FYI: All the joint types have to work off of body local anchor point coords. A pivot joint works by keeping the two anchor points together, the "pivot point" is not stored, only used initially to calculate the anchor points.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
maximile
Posts: 157
Joined: Mon Aug 20, 2007 12:53 pm
Location: London, UK
Contact:

Re: Joints Again

Post by maximile »

Ahhh! That makes perfect sense now! I should have realised that the pivot always stays still relative to the bodies.

Thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests