Simple body hanging in two ropes

Official forum for the Chipmunk2D Physics Library.
Post Reply
ganesha
Posts: 71
Joined: Mon Sep 06, 2010 1:29 pm
Contact:

Simple body hanging in two ropes

Post by ganesha »

I am trying to create a simple body hanging in two ropes. I have tried both ChipmunkPivotJoint, ChipmunkPinJoint and ChipmunkDampedSpring but it doesn´t work. I would really appreciate some input about what I am doing wrong.

Pseudo code

Code: Select all


	ChipmunkBody *newBody = [ChipmunkBody bodyWithMass:10.0f andMoment:cpMomentForBox(10.0f, width, height)];
	newBody.position =  startPointArg;

        // Create the joints (assumes default center of mass in the middle)
	CGPoint jointPos1 = CGPointMake(newBody.position.x - width*0.45f, newBody.position.y + ropeLength);
	CGPoint jointPos1_2 = CGPointMake(newBody.position.x - width*0.45f, newBody.position.y);

	CGPoint jointPos2 = CGPointMake(newBody.position.x + width*0.45f, newBody.position.y + ropeLength);
	CGPoint jointPos2_2 = CGPointMake(newBody.position.x + width*0.45f, newBody.position.y);
	

	self.joint1 = [ChipmunkPinJoint pinJointWithBodyA:[ChipmunkBody staticBody] bodyB:newBody anchorA:jointPos1 anchorB: jointPos1_2];
	self.joint1.maxForce = INFINITY; self.joint1.maxBias = INFINITY;
	
	self.joint2 = [ChipmunkPinJoint pinJointWithBodyA:[ChipmunkBody staticBody] bodyB:newBody anchorA:jointPos2 anchorB: jointPos2_2];
	self.joint2.maxForce = INFINITY; self.joint2.maxBias = INFINITY;

   // Add joints and body to space etc.
Attachments
Rectangle with 4 joints and two "ropes". The joints can rotate 360 degrees.
Rectangle with 4 joints and two "ropes". The joints can rotate 360 degrees.
joints.jpg (6.79 KiB) Viewed 4645 times
ganesha
Posts: 71
Joined: Mon Sep 06, 2010 1:29 pm
Contact:

Re: Simple body hanging in two ropes

Post by ganesha »

Looks like a bug calculating the distance between the points for the joints.

I calculate the distance to double check with this formula:
float distance = abs(ccpDistance(jointPos1, jointPos1_2));

distance = ropeLength OK!

When I check the calculated distance:
joint1.dist = 518.0f which is outside the screen!

If I use the set method it doesn´t effect the distance between the joints.
Post Reply

Who is online

Users browsing this forum: No registered users and 24 guests