Page 1 of 1

Crossed pin joints

Posted: Wed Aug 05, 2009 4:17 am
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?

Re: Crossed pin joints

Posted: Wed Aug 05, 2009 7:05 am
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.

Re: Crossed pin joints

Posted: Wed Aug 05, 2009 7:11 am
by vulh102
now its acting like a pivot joint

Re: Crossed pin joints

Posted: Wed Aug 05, 2009 8:07 am
by slembcke
I would also guess it's because your joint anchors are so close together.

Re: Crossed pin joints

Posted: Wed Aug 05, 2009 5:03 pm
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

Re: Crossed pin joints

Posted: Thu Aug 06, 2009 4:35 am
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] );