PivotJoint problem

Official forum for the Chipmunk2D Physics Library.
Post Reply
WhyteDawg
Posts: 2
Joined: Tue Jan 29, 2008 9:29 pm
Contact:

PivotJoint problem

Post by WhyteDawg »

Hi, I've just started playing with the chipmunk physics engine (best 2d physics engine i have ever played with btw, great job :D ) and I think I may have found a little problem with the pivot joint.

I have a body that doesn't move (infinite mass and inertia, and doesn't belong to a space) connected to a body which represents a crate. The crate is directly below the body, which is positioned at 0,0. I disabled gravity so that forces wont affect anything in this test. Now, I find as long as the angle of the crate is 0, no matter where the crate connects, the engine will handle it correctly. But, if I make the angle of the crate the radian equiv of 180 degrees, the crate springs up to the top. Here is a screenshot:

Image

Is this normal, has anyone else had this happen or am I doing something fundamentally wrong ?
WhyteDawg
Posts: 2
Joined: Tue Jan 29, 2008 9:29 pm
Contact:

Re: PivotJoint problem

Post by WhyteDawg »

Ah solved it.

I read over the source code and discovered a member called rot, which i think holds calculated values for sin(a) and cos(a). Since I was just settings body.a, the rot value wasn't updated. Instead, I should have used cpBodySetAngle

So my bad! Should have known it would be my fault :(
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: PivotJoint problem

Post by slembcke »

Yeah, that is one problem with a C based API. I can't really properly encapsulate everything. The options are to make getters and setters for everything, or just the ones that need them and hope that people read the documentation. ;) I chose the latter as it makes things significantly less verbose, and there isn't really a good reason to ever change the internal representation of cpBody.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
supertommy
Posts: 56
Joined: Tue Sep 11, 2007 2:30 pm
Contact:

Re: PivotJoint problem

Post by supertommy »

Another option would be to ditch either 'body->a' or 'body->rot'. The 'rot' member seems to be necessary, but the 'a' member does not seem to be used a lot. Is this code in cpBodyUpdatePosition the only place?

Code: Select all

cpBodySetAngle(body, body->a + (body->w + body->w_bias)*dt);
Could this be done using direction vectors instead?
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: PivotJoint problem

Post by slembcke »

I've considered it, but body->rot is harder to work with in many cases. You'd end up having to convert it to an angle all the time for drawing and such. It also has the downside of being relative. While I currently wrap the angle to lie within 0-360 degrees, not doing so might be useful in the future for some fancy constraints.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests