Page 1 of 1

Collision bug in seg2poly

Posted: Sat Jan 26, 2013 12:49 pm
by josephg
I've created a couple shapes which should collide with each other, but don't seem to. I may well be doing something wrong - but I've tried poking my code in a few different ways and it seems to always mess up the same.

Two shapes:
* A segment from -50,-100 to 50,100
* A box which is 300 wide, 100 tall centered around the origin

Somehow, they don't collide with each other. I've tried putting them on bodies in an updating space and so on, and I get the same behaviour. If the box is 200 wide instead, they collide correctly. (??)

Code: Select all

  cpShape *seg = cpSegmentShapeNew(NULL, cpv(-50, -100), cpv(50, 100), 10);
  cpShapeUpdate(seg, cpvzero, cpvforangle(0));
  cpShape *poly = cpBoxShapeNew(NULL, 300, 100);
  cpShapeUpdate(poly, cpvzero, cpvforangle(0));

  cpContact c[100];
  int num = cpCollideShapes(seg, poly, c);
  printf("%d\n", num); // prints 0

Re: Collision bug in seg2poly

Posted: Mon Jan 28, 2013 6:15 pm
by slembcke
So without getting into it too much, it's definitely a bug. I've known that highly overlapping polygons and segments, it can report weird contact points. I didn't know there were bugs where it would report no collisions though. The collision detection code is the oldest in Chipmunk. (Actually older than Chipmunk itself).

The good news is that I have a branch where I've been rewriting the collision detection to fix the issues that I know about and add a few features that I've been wanting (beveled polygons, smoothed terrain collisions). The bad news is that I've been working on it for quite a while now. It works fine if I disable the GJK caching, but then it's prohibitively slow. When caching is enabled, it misses maybe 1/10,000 collisions depending on the previous position, but the performance is comparable to the SAT based version. I'm not quite sure when I'm going to get the caching to work right. :-\