Capsule Shape

Ok, I've started looking at your patch. It's got some interesting changes quite aside from the extra capsule stuff, I hadn't realized.

Some notes:
  • There's quite a lot of AdjustDifference variations - 4 main ones, plus AdjustGJKDistance, and some in the supporters. Undocumented, I find it too hard to figure out what their different purposes are. Basically, I think a better name is needed.
  • Should there be a DistanceAdjust version using distanceSqr, seeing some of the original code you are replacing worked that way?
  • I don't see the purpose in the supporter system, it is just copying data for no reason. Except for XForms, but I don't see why those cannot be additional arguments like they are elsewhere in the system.

I cannot see what's wrong with your contact code with a quick look. In my experience most problems arise either from being inconsistent with separation for different modes that border each other, or doing warm starting incorrectly. I would disable the latter until you are confident the rest works well.
I wonder if it's possible to have a generic GJK algorithm for collision like bullet has. I doubt it would do any worse time-wise than my specialized capsule-polygon solver.


Yeah, the name of AdjustDistance should probably change. The purpose of it is that the original code stated that points worked better to approximate circles, and seeing as capsules are just circles swept across a segment, I figured they would work better as segments. AdjustDistance is the code that would add back the radius after the comparison took place.

Sure, we can use distanceSqr if it makes more sense.

The supporter classes were created because I needed a way to run GJK without slop for capsule-polygon collision. The transforms are included because the original circle code pretransformed the center point rather than doing it as needed, and I wanted a standard way to do this. I copied the data instead of using a reference to the shape because the copies seemed cheaper; the point/segment in circle/capsule are pretransformed, and the polygon uses a different set of vertices, the real ones or core, which is just a pointer copy.


I've kinda hit a dead end in terms of the code for now. It mostly works, but I doubt I'll get to it this week in case someone else wants to fiddle with it. (I do intend to finish it though.)
I've chopped your code a bit to not include the capsule stuff - it sounds unstablish at the moment, and (based on my own experience), I doubt you'll find the patience to fix it.
But the rest is stuff I would like to commit soonish, so I've kept that, with a few name modifications to suit my own tastes: s/TOI/Core/ s/Supporter/Support/ s/DistanceAdjust/ContractDistance/. (TOI is only really a Dynamics/ thing, all Collision/ knows of is core shapes).

One thing bothers me, I'm dubious of is the large amount of basic geometry functions that serve seemingly little purpose inside b2Collision.cpp.

Other changes:
b2Distance now returns actual distances, b2CoreDistance does the old b2Distance. I expect b2Distance will be useful to users for some use or other.
I use nested types. This is a bit of sugar so that inside a templated function I can do:
typename ShapeType::Support support = shape->GetSupport(xf);
instead of passing immediately to some subfunction.

Original thread: https://box2d.org/forum/viewtopic.php?t=2998