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