I think I figured out, it is not the solver, it has to do with the fact that I seprated the collsion funtion tha calculate conc for roudn shape and contact for poygoinal faces.
in teh case of boxes, conve hull and cylinders, they use the same collsion funtion that was use in core 200,
however in teh prosses I commnet pout an very imprtnt funtion that filet the contact putput makin sure they are valid for physiocs simulation.
Basically contact in newton are calculate by usin closest mism diff threrom for conce objects. In most case thi made be that conave distance may no generta the best contact.
In this aparticaul example I see that teh contact calculatoir find 4 good contacts point in the direction (0, 0, 1)
but the it also find 3 more in direction (1, 0, 0) and tow in diretion (-1, 0, 0) it si teh last 5 contacts tha generete the bad bug
These last conat are diametrially opposed an dther form a sysme mass matrix with a very high condition numeber.
The solve solver blow up, the reason that it does is that it run out of iterations an exist with a bad solution that add energy to the system
This is a very very big problem I has alwy stroggle with.
In newton 1.0 teh way I solved was by srunn a mini single value decompasition on each contac joint and elimination teh contact that generar teh worse condition number.
This is elegant and very rubust, but is can be slow.
in newton 2.00 I remuve that and I adde a contact clipping function
- Code: Select all
dgInt32 dgWorld::CalculatePolySoupToHullContactsDescrete (dgCollisionParamProxy& proxy) const
{
dgCollisionBoundPlaneCache planeCache;
dgInt32 count = 0;
_ASSERTE (proxy.m_floatingCollision->IsType (dgCollision::dgCollisionMesh_RTTI));
_ASSERTE (proxy.m_referenceCollision->IsType (dgCollision::dgCollisionConvexShape_RTTI));
dgCollisionInstance* const polysoupInstance = proxy.m_floatingCollision;
const dgPolygonMeshDesc& data = *proxy.m_polyMeshData;
_ASSERTE (data.m_faceCount);
dgFloat32* const faceSize = data.m_faceMaxSize;
dgInt32* const idArray = (dgInt32*)data.m_userAttribute;
dgInt32* const indexArray = (dgInt32*)data.m_faceVertexIndex;
_ASSERTE (idArray);
dgCollisionConvexPolygon polygon (m_allocator);
dgCollisionInstance polyInstance (*polysoupInstance, &polygon);
polygon.m_vertex = data.m_vertex;
polygon.m_stride = dgInt32 (data.m_vertexStrideInBytes / sizeof (dgFloat32));
dgInt32 reduceContactCountLimit = 0;
dgInt32 countleft = proxy.m_maxContacts;
dgInt32 indexCount = 0;
proxy.m_floatingCollision = &polyInstance;
dgContactPoint* const contactOut = proxy.m_contacts;
for (dgInt32 j = 0; (j < data.m_faceCount) && (countleft > 0); j ++) {
polygon.m_count = data.m_faceIndexCount[j];
polygon.m_index = &indexArray[indexCount];
if (data.m_faceNormalIndex) {
polygon.m_normalIndex = data.m_faceNormalIndex[j];
polygon.m_adjacentNormalIndex = (dgInt32*) &data.m_faceAdjencentEdgeNormal[indexCount];
} else {
polygon.m_normalIndex = 0;
polygon.m_adjacentNormalIndex = NULL;
}
polygon.m_faceId = idArray[j];
polygon.m_faceClipSize = faceSize ? faceSize[j] : dgFloat32 (0.0f);
proxy.m_maxContacts = countleft;
proxy.m_contacts = &contactOut[count];
dgInt32 count1 = CalculateConvexPolygonToHullContactsDescrete (proxy);
if (count1) {
// this is want causes the high energy collsion bug
//count1 = polygon->ClipContacts (count1, &contactOut[count], soupMatrix);
count += count1;
countleft -= count1;
reduceContactCountLimit += count1;
if ((reduceContactCountLimit > 24) || (countleft <= 0)) {
count = ReduceContacts (count, contactOut, proxy.m_maxContacts >> 2, dgFloat32 (1.0e-2f));
countleft = proxy.m_maxContacts - count;
reduceContactCountLimit = 0;
}
}
indexCount += data.m_faceIndexCount[j];
}
Basically the funtion uses teh hewristic that all cotact sopdul pint in teh same hiemsphere direction, so it remove contact tah fall ouside, it is no as robust as a SVD analysis but is was relativally correct.
the problem is that is no loneg waor afte I intruduct Genral scale, so I commbete out and I forget to write the new function.
To test this I am going to re enable the function and since this test has unit scale, then the bug should go away.
I am also considerinhg addin teh SBD analisi fo contact, maybe as an option.