[ODE] Trimesh Collision Issues

Brian Uptagrafft instruo at hotmail.com
Sun Jul 17 14:46:25 MST 2005


Hi again all,

So, as appreciated as those suggestions are, they didn't end up solving my 
problem.  Since accuracy is more valuable to me for this application than 
performance, I find myself still in need of trimesh-trimesh collisions.  Per 
James's suggestion, I upped the number of collisions I'm requesting and 
manually created two cubes to use for testing instead of the single 
triangles.  Unfortunately, I still get the same result of 
System.NullReferenceException (object reference not set to an instance of an 
object) when I attempt dCollide on my trimeshes.  Here's a few things that I 
do know, however:

dCollide is working, at least in some capacity.  I created two spheres and 
threw them in there, and it returned as expected.

My vertex data seems to be okay, as I can use dGeomTriMeshGetTriangle and 
get back what I expect for any of my tris

I've attached my modified code (sorry about the length, laying out those 
cubes adds a bunch of lines).  If anyone would be willing to look over it 
and perhaps pick up on something I'm missing, I'd greatly appreciate it.  
Thanks a ton!

Brian


int data_id = ODE::dGeomTriMeshDataCreate();
int data_id2 = ODE::dGeomTriMeshDataCreate();

dVector3 verts[8];

verts[0][0] = 0.0;
verts[0][1] = 0.0;
verts[0][2] = 0.0;

verts[1][0] = 1.0;
verts[1][1] = 0.0;
verts[1][2] = 0.0;

verts[2][0] = 1.0;
verts[2][1] = 1.0;
verts[2][2] = 0.0;

verts[3][0] = 0.0;
verts[3][1] = 1.0;
verts[3][2] = 0.0;

verts[4][0] = 0.0;
verts[4][1] = 0.0;
verts[4][2] = -1.0;

verts[5][0] = 1.0;
verts[5][1] = 0.0;
verts[5][2] = -1.0;

verts[6][0] = 1.0;
verts[6][1] = 1.0;
verts[6][2] = -1.0;

verts[7][0] = 0.0;
verts[7][1] = 1.0;
verts[7][2] = -1.0;

int indices[36];
indices[0] = 0;
indices[1] = 1;
indices[2] = 2;

indices[3] = 0;
indices[4] = 2;
indices[5] = 3;

indices[6] = 1;
indices[7] = 5;
indices[8] = 6;

indices[9] = 1;
indices[10] = 6;
indices[11] = 2;

indices[12] = 5;
indices[13] = 4;
indices[14] = 7;

indices[15] = 5;
indices[16] = 7;
indices[17] = 6;

indices[18] = 4;
indices[19] = 0;
indices[20] = 3;

indices[21] = 4;
indices[22] = 3;
indices[23] = 7;

indices[24] = 3;
indices[25] = 2;
indices[26] = 6;

indices[27] = 3;
indices[28] = 6;
indices[29] = 7;

indices[30] = 5;
indices[31] = 4;
indices[32] = 0;

indices[33] = 5;
indices[34] = 0;
indices[35] = 1;

dVector3 verts2[8];

verts2[0][0] = 0.0;
verts2[0][1] = 0.0;
verts2[0][2] = 0.0;

verts2[1][0] = 1.0;
verts2[1][1] = 0.0;
verts2[1][2] = 0.0;

verts2[2][0] = 1.0;
verts2[2][1] = 1.0;
verts2[2][2] = 0.0;

verts2[3][0] = 0.0;
verts2[3][1] = 1.0;
verts2[3][2] = 0.0;

verts2[4][0] = 0.0;
verts2[4][1] = 0.0;
verts2[4][2] = -1.0;

verts2[5][0] = 1.0;
verts2[5][1] = 0.0;
verts2[5][2] = -1.0;

verts2[6][0] = 1.0;
verts2[6][1] = 1.0;
verts2[6][2] = -1.0;

verts2[7][0] = 0.0;
verts2[7][1] = 1.0;
verts2[7][2] = -1.0;

int indices2[36];
indices2[0] = 0;
indices2[1] = 1;
indices2[2] = 2;

indices2[3] = 0;
indices2[4] = 2;
indices2[5] = 3;

indices2[6] = 1;
indices2[7] = 5;
indices2[8] = 6;

indices2[9] = 1;
indices2[10] = 6;
indices2[11] = 2;

indices2[12] = 5;
indices2[13] = 4;
indices2[14] = 7;

indices2[15] = 5;
indices2[16] = 7;
indices2[17] = 6;

indices2[18] = 4;
indices2[19] = 0;
indices2[20] = 3;

indices2[21] = 4;
indices2[22] = 3;
indices2[23] = 7;

indices2[24] = 3;
indices2[25] = 2;
indices2[26] = 6;

indices2[27] = 3;
indices2[28] = 6;
indices2[29] = 7;

indices2[30] = 5;
indices2[31] = 4;
indices2[32] = 0;

indices2[33] = 5;
indices2[34] = 0;
indices2[35] = 1;

ODE::dGeomTriMeshDataBuildSimple(	data_id,
									verts,
									3,
									indices,
									3);

ODE::dGeomTriMeshDataBuildSimple(	data_id2,
									verts2,
									3,
									indices2,
									3);

int space_id = ODE::dSimpleSpaceCreate(0);

int geom_id = ODE::dCreateTriMesh(space_id, data_id);
int geom_id2 = ODE::dCreateTriMesh(space_id, data_id2);

dVector3 v0, v1, v2;

ODE::dGeomTriMeshGetTriangle(geom_id, 7, &v0, &v1, &v2);
cout << v0[0] << ", " << v0[1] << ", " << v0[2] << endl;
cout << v1[0] << ", " << v1[1] << ", " << v1[2] << endl;
cout << v2[0] << ", " << v2[1] << ", " << v2[2] << endl;

dContactGeom contacts[8];

cout << ODE::dCollide(geom_id, geom_id2, 8, contacts, sizeof(dContactGeom)) 
<< endl;




More information about the ODE mailing list