I've been working on a fast-paced game for iPhone, using Newton for physics. Everything works great (very easy to use, works without any problems, congrats to developers on this one), except part when I want to use NewtonMesh to create collision, instead of Newton's box/sphere body. I need it because one model needs to have precise collision detection, and has some curved surface part.
Problem:
When I generate NewtonMesh, create a Convex Hull Collision based on that mesh, and then NewtonBody, bounding box of that body is significantly bigger than mesh's bounding box should be. I've read supporting vertices from newton's body (up/down/left/right/front/back) and rendered it in wireframe over actual 3d mesh to see what's going on, and wire box is huge. I've initially used code sample found somewhere on this forum. That sample was including vertex (smoothing) normals and texture coordinates (I have no idea why it was required for collision calculation).
I've changed code to what looked logical to me, and apparently it worked (now bounding box received back from NewtonBody is the same as the one loaded with real mesh, and body reacts on hits in a way I would expect it).
However, I'd like to check with Newton crew if this is how newton mesh was supposed to be generated, and also I have few more questions (below source code):
- Code: Select all
vec3f *data_verts = ddata->vertices; // ptr to array of vertices (vertices are glDrawElement ready, so 3 vertices in a row are 1 face)
NewtonMesh *nwMesh = NewtonMeshCreate(); // allocate new newton mesh
NewtonMeshBeginFace(nwMesh); // start adding faces
xfloat verts[3*3];
for( xint t = 0; t < trinum; t++) // for each triangle fill coordinates of 3 vertices (9 float values) ...
{
for( xint v = 0; v<3; v++)
{
verts[v*3+0] = data_verts[ t*3+v ].x;
verts[v*3+1] = data_verts[ t*3+v ].y;
verts[v*3+2] = data_verts[ t*3+v ].z;
}
NewtonMeshAddFace( nwMesh,3,verts,sizeof(xfloat)*3,0); // ...and add them to newton's mesh.
}
NewtonMeshEndFace(nwMesh);
col = NewtonCreateConvexHullFromMesh(nwWorld, nwMesh, 0.1f, 0);
body = NewtonCreateBody(nwWorld, col);
..... etc .....
- Code: Select all
NewtonMeshBeginFace(nwMesh);
QUESTION: is this really needed? I've tried without begin/end function pair and it worked too. what is the purpose of begin/end functions?
- Code: Select all
NewtonMeshAddFace( nwMesh,3,verts,sizeof(xfloat)*3,0);
QUESTION: why function 'add face' requires number of vertices? triangle has 3 vertices. is newton mesh able to load triangle fan instead? or multiple triangles with 1 function call? if so, is it better to pass to newton all triangles at once, or one-by-one? also, stride size is distance between vertex data (size of 1 vertex data), and in the case number of vertices is not 3, is this also affected?
- Code: Select all
col = NewtonCreateConvexHullFromMesh(nwWorld, nwMesh, 0.1f, 0);
QUESTION: if mesh is already defined with triangles, how will 'tolerance' parameter in this function affect collision calculation?
Thanks in advance!
Cheers,