Bug... Segments don't make collisions between them

Discuss any Chipmunk bugs here.
Post Reply
Haks
Posts: 2
Joined: Thu Jan 01, 2009 5:05 pm
Contact:

Bug... Segments don't make collisions between them

Post by Haks »

Hi, Happy new year :)

I'm working on a game for Academic work and I use the very nice physics library Chipmunk. (dowloaded here: http://files.slembcke.net/chipmunk/rele ... Latest.tgz)

But after all my work and after checking all my project, a bug still here: the Segments (Static or active) don't generate collisions between them...

just see this screen capture:

http://fr.youtube.com/watch?v=YLpxWxfYhxM

don't make matter about the grey Circle, and the force which is apply to the segment, it's normal...

but see the 2 active segments and the top part of the balance (which is made with active Segments):
- the 1st fall and don't hit the top part of the balance (which is made with active Segments)...
- the 2nd turn and don't hit the 2 static Segments near its, but it hit the balls...
- then, the top part of the balance hit the balls, and the triangle (which is made with static polygon) but it don't hit the 1st segment...

in my code, the Chipmunk step are like that:

Code: Select all

if (m == INFINITY)
{
	_isStatic = true;
	obj = cpBodyNew(INFINITY, INFINITY);
}
else
{
	_isStatic = false;
	obj = cpBodyNew(m, 500);
}
obj->p = cpv(xpos, ypos);

....

if (_isStatic == false)
	cpSpaceAddBody(space, obj);
shape = cpSegmentShapeNew(obj, pos1, pos2, radius);
shape->e = e; shape->u = u;
cpShapeCacheBB(shape);
if (_isStatic == true)
{
	shape->collision_type = 3;
	cpSpaceAddStaticShape(space, shape);
}
else
{
	shape->collision_type = 1;
	shape->data = this;
	cpSpaceAddShape(space, shape);
}
cpResetShapeIdCounter();
finally, this 3 active segment shape which each one is linked with differents bodies, with the default group ( 0 ) and default layers ( (int) 65535 ), don't generate collisions with all others static or active segments :(

Can I find a solution or a fix here ? or maybe It can be my code ?
Android_X
Posts: 18
Joined: Wed Oct 31, 2007 7:55 pm
Contact:

Re: Bug... Segments don't make collisions between them

Post by Android_X »

Lack of segment to segment collisions is a known limitation. It simply has not been implimented yet.
see: http://www.slembcke.net/forums/viewtopi ... p=812#p812

The only workaround I can think of is to use a thin polygon instead of a line segment.

Regards,
AX
Haks
Posts: 2
Joined: Thu Jan 01, 2009 5:05 pm
Contact:

Re: Bug... Segments don't make collisions between them

Post by Haks »

oh, ok...

but how you made a thin polygon or a polygon line?

cpPolyShapeNew don't work with a numVerts at 1...

then, I tried this code for a polygon with 2 lines:

Code: Select all

		tab = (cpVect*)malloc(2 * sizeof(cpVect));
		tab[0].x = pos1.x;
		tab[0].y = pos1.y;
		tab[1].x = pos2.x;
		tab[1].y = pos2.y;
		if (_isStatic == false)
		{
			cpBodySetMoment(obj, cpMomentForPoly(obj->m, 2, tab, cpvzero));
			cpSpaceAddBody(space, obj);
		}
		shape = cpPolyShapeNew(obj, 2, tab, cpvzero);
		shape->e = e; shape->u = u;
		cpShapeCacheBB(shape);
		if (_isStatic == true)
		{
			shape->collision_type = 3;
			cpSpaceAddStaticShape(space, shape);
		}
		else
			{
				shape->collision_type = 1;
				shape->data = this;
				cpSpaceAddShape(space, shape);
			}
		cpResetShapeIdCounter();
But it don't work too :(

So how you can make that ?
Android_X
Posts: 18
Joined: Wed Oct 31, 2007 7:55 pm
Contact:

Re: Bug... Segments don't make collisions between them

Post by Android_X »

I don't think a polygon shape would work with less than 3 vertices because the shape would have 0 area(nothing to collide with).

I was thinking of a thin rectangle when I said "thin polygon".

You could try replacing a line segment with: a rectangle with two parallel sides the length of the line, and the two remaining sides' length would be the "line segment" radius(must be greater than 0 in the case of a polygon though).
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests