Erwin, Since your webpages, explanations and demo code show how trivially easy all this actually is, i just had to try myself. (only the contact manifold part for now)
minor minor observation and idea...
one thing I noticed in how you are deciding which point to replace:
http://www.continuousphysics.com/Bullet/BulletFull/PersistentManifold_8cpp-source.html
Obviously it works, but i'm not sure i get the jist of the details. In particular when taking the cross product with an edge on the other side there would be two possible options, and you end up just hardcoding one of the choices.
I figure that the results could be sensitive to the choice of which edge we do the cross product with. Instead, I tried something that should be more "symmetrical" when searching for contact to replace. In the case when i've reached the maximum number of contacts and the next contact is at least epsilon away from any of the current ones we consider replacing. The pseudocode for that is:
Code:
for(j=0;j<count;j++)
{
float3& vp = contact[j-1]; // next point in contact manifold
float3& vn = contact[j+1]; // previous point
float3& vc = contact[j ]; // current point we consider replacing
float3& v = impact; // new point
float3& n = normal;
if(dot(n,cross(v-vp,vn-v))>dot(n,cross(vc-vp,vn-vc)))
{
replace old contact point vc with new impact v
break;
}
}
i.e. for each contact take the cross product of the previous and next edges. That's the actual area contribution added by that point. (technically you divide by 2 to get actual triangle area but i'm sure you get the idea.)
The points tend to always end up in a convex ccw order. Furthermore, the approach should let you scale up if you wanted to have more than just 4 contacts.
Anyways, just a suggestion. Perhaps i've over-analysed something that isn't all that important. Or, Perhaps you were already doing things in a particular way in your code for a reason and i simply didn't see what that was.
my 2c