I created a patch to do convex casts: ray-casts that cast a convex shape over a path instead of a ray. There's lots of room for optimization, but it seems to perform reasonably well. I'm posting here for suggestions on API improvements and for help with a bug.
The ConvexCast function is added to b2World.h:
And the callback is in b2WorldCallbacks.h:
I've run into a bug that may be related to the use of b2TimeOfImpact. I get a lot of false positives for collisions. When a fixture should be detected by the cast, it reports the intersection correctly, but it will also report a hit way off on the sides (much larger than radii). I only report a hit when I see e_touching, so I find this behavior odd.
Should b2TimeOfImpact show lots of error over larger distances? Perhaps it assumes overlap at t=1?
The ConvexCast function is added to b2World.h:
Code:
void ConvexCast(b2ConvexCastCallback* callback,
const b2Shape* shape,
const b2Transform& xf1,
const b2Transform& xf2) const;
const b2Shape* shape,
const b2Transform& xf1,
const b2Transform& xf2) const;
And the callback is in b2WorldCallbacks.h:
Code:
virtual float32 ReportFixture(
b2Fixture* fixture, const b2Shape* shape,
const b2Transform& xf, const b2Vec2& point,
const b2Vec2& normal, float32 fraction) = 0;
b2Fixture* fixture, const b2Shape* shape,
const b2Transform& xf, const b2Vec2& point,
const b2Vec2& normal, float32 fraction) = 0;
I've run into a bug that may be related to the use of b2TimeOfImpact. I get a lot of false positives for collisions. When a fixture should be detected by the cast, it reports the intersection correctly, but it will also report a hit way off on the sides (much larger than radii). I only report a hit when I see e_touching, so I find this behavior odd.
Should b2TimeOfImpact show lots of error over larger distances? Perhaps it assumes overlap at t=1?