Crossed pin joints

Official forum for the Chipmunk2D Physics Library.
Post Reply
vulh102
Posts: 13
Joined: Tue Sep 25, 2007 9:24 am
Contact:

Crossed pin joints

Post by vulh102 »

Hi!

Posted several weeks ago about how to fixate bodies together, the solution then where to either use crossed pin joints or merge the boides into one.
we went with merging, now though we hit a snag and everything would get emensly simpler for us if we used crossed pin joints instead.

the problem is that i cant get it to work.

This is how i do it:

Code: Select all

float l = 0.001f;
		m_Cross[0] = cpPinJointNew( m_Bodies[0]->GetBody() , m_Bodies[1]->GetBody() , cpBodyWorld2Local( m_Bodies[0]->GetBody() , cpv( m_Position.x+l , m_Position.y-l )) , cpBodyWorld2Local( m_Bodies[1]->GetBody() , cpv( m_Position.x-l , m_Position.y+l ) ));
		m_Cross[1] = cpPinJointNew( m_Bodies[0]->GetBody() , m_Bodies[1]->GetBody() , cpBodyWorld2Local( m_Bodies[0]->GetBody() , cpv( m_Position.x+l , m_Position.y+l )) , cpBodyWorld2Local( m_Bodies[1]->GetBody() , cpv( m_Position.x-l , m_Position.y-l ) ));

		cpSpaceAddJoint( World->GetSpace() , m_Cross[0] );
		cpSpaceAddJoint( World->GetSpace() , m_Cross[1] );

		m_Bodies[0]->DisableCollisions( m_Bodies[1] );
		m_Bodies[1]->DisableCollisions( m_Bodies[0] );

can someone with more expierience with chipmunk help me?
maximile
Posts: 157
Joined: Mon Aug 20, 2007 12:53 pm
Location: London, UK
Contact:

Re: Crossed pin joints

Post by maximile »

The anchors don't actually have to be inside the collision shapes, so you might as well use a much bigger value for l in your code.

If that's not the problem, can you describe what's going wrong? Are the bodies not attached at all, or do they just move around relative to each other? Don't forget that no matter what you do, it's not going to look quite as good as adding the shapes to the same body.
vulh102
Posts: 13
Joined: Tue Sep 25, 2007 9:24 am
Contact:

Re: Crossed pin joints

Post by vulh102 »

now its acting like a pivot joint
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Crossed pin joints

Post by slembcke »

I would also guess it's because your joint anchors are so close together.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
vulh102
Posts: 13
Joined: Tue Sep 25, 2007 9:24 am
Contact:

Re: Crossed pin joints

Post by vulh102 »

ive tried with different values for "l" ( the length of the pin )

wierdly it seems that only one joint is working, since when i have a larger value i get pin joint behavior
vulh102
Posts: 13
Joined: Tue Sep 25, 2007 9:24 am
Contact:

Re: Crossed pin joints

Post by vulh102 »

solved

i got better results using a box configuration instead of a cross...
so for the community i present this code for anyone to use

Code: Select all

float l = 0.1f;
		m_Cross[0] = cpPinJointNew( m_Bodies[0]->GetBody() , m_Bodies[1]->GetBody() , cpBodyWorld2Local( m_Bodies[0]->GetBody() , cpv( m_Position.x-l , m_Position.y+l )) , cpBodyWorld2Local( m_Bodies[1]->GetBody() , cpv( m_Position.x+l , m_Position.y+l ) ));
		m_Cross[1] = cpPinJointNew( m_Bodies[0]->GetBody() , m_Bodies[1]->GetBody() , cpBodyWorld2Local( m_Bodies[0]->GetBody() , cpv( m_Position.x+l , m_Position.y+l )) , cpBodyWorld2Local( m_Bodies[1]->GetBody() , cpv( m_Position.x+l , m_Position.y-l ) ));
		m_Cross[2] = cpPinJointNew( m_Bodies[0]->GetBody() , m_Bodies[1]->GetBody() , cpBodyWorld2Local( m_Bodies[0]->GetBody() , cpv( m_Position.x+l , m_Position.y-l )) , cpBodyWorld2Local( m_Bodies[1]->GetBody() , cpv( m_Position.x-l , m_Position.y-l ) ));
		m_Cross[3] = cpPinJointNew( m_Bodies[0]->GetBody() , m_Bodies[1]->GetBody() , cpBodyWorld2Local( m_Bodies[0]->GetBody() , cpv( m_Position.x-l , m_Position.y-l )) , cpBodyWorld2Local( m_Bodies[1]->GetBody() , cpv( m_Position.x-l , m_Position.y+l ) ));

		cpSpaceAddJoint( World->GetSpace() , m_Cross[0] );
		cpSpaceAddJoint( World->GetSpace() , m_Cross[1] );
		cpSpaceAddJoint( World->GetSpace() , m_Cross[2] );
		cpSpaceAddJoint( World->GetSpace() , m_Cross[3] );

		m_Bodies[0]->DisableCollisions( m_Bodies[1] );
		m_Bodies[1]->DisableCollisions( m_Bodies[0] );
Post Reply

Who is online

Users browsing this forum: No registered users and 21 guests