[ODE] box/trimesh possible bug ?

Olivier Bantiche Olivier.Bantiche at sophia.inria.fr
Mon Aug 4 07:48:02 2003


Hello everyone,

I'v been going though the collision_trimesh_box.cpp code, and there are 
a few things I don't quite understand ...
I usually blame it on my ignorance, but since I have serious doubts 
about this one, I thought I might as well share it with you,
hoping it will either help everyone, or at least someone would help me 
understand.
In the dCollideBTL, at one point contacts that are close to one another 
are merged.
Contact->g1 is used as a counter to keep trace of how many contacts have 
been merged together.
But it seems to me that the way it is done, that counter doesn't 
actually work and in the end the sum of contacts is used instead of the 
mean.
I've put "simplified" code hereafter from the cvs (I think it's the same 
as in 0.039) to show what troubles me.
Can someone please confirm, or explain to me why I am a fool ?

Olivier


                 int OutTriCount = 0;
                 for (int j = 0; j < InContacts.Count; j++){
                    dContactGeom* Contact = SAFECONTACT(Flags, Contacts, 
OutTriCount, Stride);

                    ... "unrelevant" stuff ...
                   
                    Contact->g1 = (dxGeom*)1;

                    int Index;
                    for (Index = 0; Index < OutTriCount; Index++){
                        dContactGeom* TempContact = SAFECONTACT(Flags, 
Contacts, Index, Stride);
                        ... computing DistSq : square distance between 
contact and tempcontact ...
                       
                        if (DistSq < 0.001){//BoxRadius * REAL(0.1)){
                            break;
                        }
                    }
                    if (Index != OutTriCount){
                        dContactGeom* TempContact = SAFECONTACT(Flags, 
Contacts, Index, Stride);
                        ..... TempContact->normal += Contact->normal ...
                        TempContact->depth += Contact->depth;
                        Contact->g1 = (dxGeom*)(((char*)Contact->g1) + 
1);  // ???????????shouldn't it be TempContact->g1 = 
(dxGeom*)(((char*)TempContact->g1) + 1); ?
                    }
                    else OutTriCount++;
                }
              
          
        for (int i = 0; i < OutTriCount; i++){    // Now normalize normals
            dContactGeom* Contact = SAFECONTACT(Flags, Contacts, i, Stride);
            dNormalize3(Contact->normal);

            Contact->depth /= (int&)Contact->g1;    // Hacking again.

            Contact->g1 = TriMesh;
            Contact->g2 = BoxGeom;
        }