SpringJoint vs SlideJoint

Official forum for the Chipmunk2D Physics Library.
Post Reply
chickenhouse
Posts: 2
Joined: Fri Apr 16, 2010 1:36 am
Contact:

SpringJoint vs SlideJoint

Post by chickenhouse »

Hi,

I've had chipmunk and SpaceManger running with cocos2d in my iPhone App.

I've just upgraded to the latest version of cocos, chipmunk v5.0 and spacemanager and I'm trying to get the same effect as I had in my original game.

The game uses a stretchy rope made up of a series of springJoints for eg.

Code: Select all

for(i=1; i<p4Count; i++) {
		origin = cpvadd(origin, p4Offset);
		shape4 = [smgr addCircleAt:origin mass:5.0f radius:1.0f];

		springJoint = [smgr addSpringToBody:shape3->body fromBody:shape4->body 
							   toBodyAnchor:cpvzero fromBodyAnchor:cpvzero restLength:2.0f stiffness:6000.0f * 4 damping:40.0f * 4 * ropeFlex];
			springJN = [cpConstraintNode nodeWithConstraint:springJoint];
			springJN.color = ccBLACK;
			springJN.lineWidth = 1.5f;
			[cameraNode addChild:springJN z:3];
			
		shape3 = shape4;
	}
Now with the new version of Chipmunk the springJoints visually have a zigzag pattern. Is there some way to show a springJoint as a straight line or do I now need to use slideJoints.

If I need slideJoints can they be made to react the same way as the springJoints? How do I work out based on the above stiffness and damping what min and max lengths I should use.

Any help would be greatly appreciated.

Thanks,
Travis
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: SpringJoint vs SlideJoint

Post by slembcke »

You are using the Chipmunk debug drawing code in your game? You can just edit drawSpace.c I suppose.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
chickenhouse
Posts: 2
Joined: Fri Apr 16, 2010 1:36 am
Contact:

Re: SpringJoint vs SlideJoint

Post by chickenhouse »

Thanks you've put me on the right track.
It's not a chipmunk v5.0 issue the spring always had a zigzag pattern.

I had someone else work on the original code and I discovered that what they did was change the code in cpConstraintNode.m in SpaceManager.

To make the spring a straight line you delete everything in the drawSpringJoint method and change it to;

Code: Select all

- (void) drawSpringJoint:(cpDampedSpring*)joint bodyA:(cpBody*)body_a bodyB:(cpBody*)body_b
{
	[self drawPinJoint:(cpPinJoint*)joint bodyA:body_a bodyB:body_b];
}
mobilebros
Posts: 90
Joined: Tue Aug 04, 2009 9:53 am
Contact:

Re: SpringJoint vs SlideJoint

Post by mobilebros »

Ha! Thats one way of doing it! I think maybe you could subclass cpConstraintNode and just have a method "drawSpringJoint" with the same signature, it should override the base method and you could just have it draw a line (ccDrawLine would work).... you'd avoid corrupting cpConstraintNode if you ever did want a zigzaggy line, but then again perhaps you dont care :)
Post Reply

Who is online

Users browsing this forum: Heise IT-Markt [Crawler] and 9 guests