Collision is not detected !!!!

Discuss any Chipmunk bugs here.
Post Reply
uhotspot
Posts: 4
Joined: Fri Jan 23, 2009 12:41 am
Contact:

Collision is not detected !!!!

Post by uhotspot »

Hi,
In the following piece of code the polygonal object passes the bottom stationary line !!! and chipmunk does not detect the collision.
Surprisingly if we change the second dimension of the last item in vertices array to 7 then it works fine !!!!
cpVect vt[4] = {cpv(-19,5), cpv(-15,-3), cpv(10, -5), cpv(10, 5)}; ==> cpVect vt[4] = {cpv(-19,5), cpv(-15,-3), cpv(10, -5), cpv(10, 7)};

I would appreciate if someone can tell me what is wrong with my code.

Thank you

uhs

Code: Select all

staticBody = cpBodyNew(INFINITY, INFINITY);

cpResetShapeIdCounter();

space = cpSpaceNew();
cpSpaceResizeStaticHash(space, 100.0, 999);
cpSpaceResizeActiveHash(space, 100.0, 999);
space->gravity = cpv(0, -100);

cpBody *body;
cpShape *shape;

shape = cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(-320,240), 0.0f);
shape->e = 1.0; shape->u = 1.0;
cpSpaceAddStaticShape(space, shape);

shape = cpSegmentShapeNew(staticBody, cpv(320,-240), cpv(320,240), 0.0f);
shape->e = 1.0; shape->u = 1.0;
cpSpaceAddStaticShape(space, shape);

shape = cpSegmentShapeNew(staticBody,cpv(-320,-240), cpv(320,-240), 0.0f);
shape->e = 1.0; shape->u = 1.0;
cpSpaceAddStaticShape(space, shape);

cpVect vt[4] = {cpv(-19,5), cpv(-15,-3), cpv(10, -5), cpv(10, 5)}; //if we change the last 5 to 7 then it works fine !!!
body = cpBodyNew(60, cpMomentForPoly(60, 4, vt, cpvzero));
body->p = cpv(140.0,40.8);
cpSpaceAddBody(space, body);
shape = cpPolyShapeNew(body, 4, vt, cpvzero);
cpSpaceAddShape(space, shape);

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

Re: Collision is not detected !!!!

Post by slembcke »

Without actually plotting it out to check, I'd assume that you have a concave polygon. If you want to do that, you'll need to split it into multiple convex polygons.

(Also, please refrain from double posting.)
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
uhotspot
Posts: 4
Joined: Fri Jan 23, 2009 12:41 am
Contact:

Re: Collision is not detected !!!!

Post by uhotspot »

No actually it is a convex polygon !!
And sorry about the double posting. I though I have posted the first one in a wrong section.

Thanks.
uhotspot
Posts: 4
Joined: Fri Jan 23, 2009 12:41 am
Contact:

Re: Collision is not detected !!!!

Post by uhotspot »

I think I found the answer myself. If you define the verts in a counter clock wise order starting from the third quarter.
I mean you have to define the points in the following order:

(-a, -b), (-c, d), (e, f), (g, -h)

and then it works. At least it did for mine !
uhotspot
Posts: 4
Joined: Fri Jan 23, 2009 12:41 am
Contact:

Re: Collision is not detected !!!!

Post by uhotspot »

Sorry let me correct myself. The ponts have to be define in a clock wise order and it is not important which vert you start at.
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests