Problem with Pivotjoints

Official forum for the Chipmunk2D Physics Library.
Post Reply
Bob
Posts: 3
Joined: Mon Jul 14, 2008 8:12 am
Contact:

Problem with Pivotjoints

Post by Bob »

Hi guys,

first of all i like to thank you for this great library ;)

now to my problem: I'm using a DLL version of Chipmunk i've created of the last version, and it works fine so far. Now im trying to connect 2 'wheels' (circle shapes) by a segment shape with a Pivot joint on each side and i just can't get it to work properly. As soon as one of the body coolides with something, the connection starts ro rotate like crazy. The program is written in Delphi, so i don't know if you can read anything out of the code, but i'll post it anyway.

Code: Select all

function CreateCircle(P: TCPVect; rad, mass, friction, elasticity: Single) : PCPBody;
var
  body : PCPBody;
  shape : PCPShape;
begin
  body := cpBodyNew(mass, cpMomentForCircle(mass, rad, rad, cpvzero));
  body.p := P;
  cpSpaceAddBody(FSpace, body);
  shape := cpCircleShapeNew(body, rad, cpvzero);
  shape.e := elasticity;
  shape.u := friction;
  cpSpaceAddShape(FSpace, shape);
  Result := body;
end;

function CreateConn(P1, P2: TCPVect): PCPBody;
var
  shape : PCPShape;
begin
  Result := cpBodyNew(0.0002, 0.0002);
  Result.p := cpvMult(cpvadd(P1, P2), 0.5);
  cpSpaceAddBody(FSpace, Result);
  P1 := cpBodyWorld2Local(Result, P1);
  P2 := cpBodyWorld2Local(Result, P2);
  shape := cpSegmentShapeNew(Result, P1, P2, 0);
  shape^.e := 0;
  shape^.u := 0;
  shape^.layers := 0;
  cpSpaceAddShape(FSpace, shape);
end;

function Test;
var
  wheel1: PCPBody; {cpBody *wheel1 in c}
  wheel2: PCPBody;
  Conn: PCPBody;
  joint: PCPJoint;
begin
  wheel1 := CreateCircle(cpv(-20, 0), 10, 10, 1, 1);
  wheel2 := CreateCircle(cpv(20, 0), 10, 10, 1, 1);
  Conn := CreateConn(wheel1.p, wheel2.p);
  joint := cpPivotJointNew(wheel1, conn, wheel1.p);
  cpSpaceAddJoint(FSpace, joint);
  joint := cpPivotJointNew(wheel2, conn, wheel2.p);
  cpSpaceAddJoint(FSpace, joint);
end;

i really don't have a clue on what i am doing wrong, so any hint would be highly appreciated.

regards, Bob
Bob
Posts: 3
Joined: Mon Jul 14, 2008 8:12 am
Contact:

Re: Problem with Pivotjoints

Post by Bob »

Hi again,

i figured out, that i didn't nee a pivot, but a pinjoint. Using it, it seems to work, not quite the way i intended it, but thats hopefully gonna change too :)

im doing it like this

1. Create to wheels
2. Create a shape with layers set to 0 from wheel1.p to wheel2.p
3. Create to PinJoints. One at cpBodyWorld2Local(connector, wheel1.p) and one at cpBodyWorld2Local(connector, wheel2.p)

if this approach is terribly wrong, please say so ;)

bye
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests