[ODE] Trimesh-Trimesh and Triangle Normals

Peter Kyme pk at dneg.com
Sun Jul 3 20:19:09 MST 2005


Peter Kyme wrote:
> After struggling to figure out why I was getting such poor results with 
> the trimesh-trimesh collider (despite the fact it seems to work quite 
> well in Softimage XSI), I've finally found what appears to be the 
> problem (for me anyway).
> 
> By adding one line that reverses the normals obtained for triangles on 
> the 2nd trimesh, almost all of the problems I was seeing went away. This 
> makes sense, since before this I would get contact normals facing in the 
> wrong direction whenever a triangle normal from the 2nd geometry was used.
> 
> Can somebody (Jeff Smith?) explain why I needed to do this? Is it a 
> symptom of another problem in the way I'm using the trimesh-trimesh 
> collider?
> 
> The above also fixed the problems with the test_moving_trimesh demo as 
> well for me (once the dGeomTriMeshDataSet call had been added).

Following on from the above, here are a couple of quick patches that 
make the test_moving_trimesh demo handle colliding trimesh correctly for 
me. I've decreased the timestep a fair bit to get decent collisions.

Any thoughts on the validity of this patch?
-------------- next part --------------
--- collision_trimesh_trimesh.cpp	(current cvs)
+++ collision_trimesh_trimesh.cpp	(working copy)
@@ -350,7 +350,7 @@
                                 dVector3 *pen_elt; // the elt_f of the penetrating face
                                 dVector3 *col_v;   // the "collision vertices" (the penetrated face)
                                 
-                                
+                                SMULT(n2, n2, -1.0);
                                 depth = 0.0;
                                 if ((total_dp1 > DISTANCE_EPSILON) || (total_dp2 > DISTANCE_EPSILON)) {
                                     ////////
-------------- next part --------------
--- test_moving_trimesh.cpp	(current cvs)
+++ test_moving_trimesh.cpp	(working copy)
@@ -1730,6 +1730,19 @@
   }
 }
 
+// set previous transformation matrix for trimesh
+void setCurrentTransform(dGeomID geom)
+{
+  const dTriMeshDataID TriMeshData = static_cast<dTriMeshDataID>(dGeomGetData(geom));
+  const dReal* Pos = dGeomGetPosition(geom);
+  const dReal* Rot = dGeomGetRotation(geom);
+  
+  const double Transform[16] = { Rot[0], Rot[4], Rot[8], 0,
+                                 Rot[1], Rot[5], Rot[9], 0,
+								 Rot[2], Rot[6], Rot[10], 0,
+								 Pos[0], Pos[1], Pos[2], 1.0 };
+  dGeomTriMeshDataSet(TriMeshData, TRIMESH_LAST_TRANSFORMATION, (void *)Transform);
+}
 
 // simulation loop
 
@@ -1737,8 +1750,20 @@
 {
   dsSetColor (0,0,2);
   dSpaceCollide (space,0,&nearCallback);
+  
+  if (!pause) {
+    for (int i=0; i<num; i++)
+      for (int j=0; j < GPB; j++)
+	    if (obj[i].geom[j])
+	      if (dGeomGetClass(obj[i].geom[j]) == dTriMeshClass)
+		    setCurrentTransform(obj[i].geom[j]);
+    
+    setCurrentTransform(TriMesh1);
+    setCurrentTransform(TriMesh2);
+  }
+  
   //if (!pause) dWorldStep (world,0.05);
-  if (!pause) dWorldStepFast1 (world,0.05, 5);
+  if (!pause) dWorldStepFast1 (world,0.01, 5);
 
   for (int j = 0; j < dSpaceGetNumGeoms(space); j++){
 	  dSpaceGetGeom(space, j);
@@ -1872,6 +1897,8 @@
   
   TriMesh1 = dCreateTriMesh(space, TriData1, 0, 0, 0);
   TriMesh2 = dCreateTriMesh(space, TriData2, 0, 0, 0);
+  dGeomSetData(TriMesh1, TriData1);
+  dGeomSetData(TriMesh2, TriData2);
   
   {dGeomSetPosition(TriMesh1, 0, 0, 0.9);
   dMatrix3 Rotation;


More information about the ODE mailing list