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.