I'am trying to generate Newton Map Cillision for Newton World. I tried to use code from one of examples from Irrilicht tutorial site:
Code: Select all
terrainMesh = terrain->getMesh();
nMapCollision = NewtonCreateTreeCollision(nWorld, NULL);
NewtonTreeCollisionBeginBuild(nMapCollision);
u32 cMeshBuffer, j;
int v1i, v2i, v3i;
IMeshBuffer *mb;
float vArray[9]; // vertex array (3*3 floats)
int tmpCount = 0;
scene::IMesh *mesh = terrainMesh;
for (cMeshBuffer=0; cMeshBuffer<mesh->getMeshBufferCount(); cMeshBuffer++)
{
mb = mesh->getMeshBuffer(cMeshBuffer);
S3DVertex2TCoords*/*video::S3DVertex*/ mb_vertices = (S3DVertex2TCoords*/*video::S3DVertex**/)mb->getVertices();
u16* mb_indices = mb->getIndices();
// add each triangle from the mesh
for (j=0; j<mb->getIndexCount(); j+=3)
{
v1i = mb_indices[j];
v2i = mb_indices[j+1];
v3i = mb_indices[j+2];
vArray[0] = mb_vertices[v1i].Pos.X;
vArray[1] = mb_vertices[v1i].Pos.Y;
vArray[2] = mb_vertices[v1i].Pos.Z;
vArray[3] = mb_vertices[v2i].Pos.X;
vArray[4] = mb_vertices[v2i].Pos.Y;
vArray[5] = mb_vertices[v2i].Pos.Z;
vArray[6] = mb_vertices[v3i].Pos.X;
vArray[7] = mb_vertices[v3i].Pos.Y;
vArray[8] = mb_vertices[v3i].Pos.Z;
box.addInternalPoint(mb_vertices[v1i].Pos.X, mb_vertices[v1i].Pos.Y, mb_vertices[v1i].Pos.Z);
box.addInternalPoint(mb_vertices[v2i].Pos.X, mb_vertices[v2i].Pos.Y, mb_vertices[v2i].Pos.Z);
box.addInternalPoint(mb_vertices[v3i].Pos.X, mb_vertices[v3i].Pos.Y, mb_vertices[v3i].Pos.Z);
NewtonTreeCollisionAddFace(nMapCollision, 3, &vArray[0], 12, 1);
}
}
NewtonTreeCollisionEndBuild(nMapCollision, 0);
NewtonBody* nmapbody = NewtonCreateBody(nWorld, nMapCollision);
When i debug program I get, that there is ony one MeshBuffer and
Code: Select all
mb->getIndices();
Is there another way to do this, or maybe I have to list Vertices??
Please help.
P.s. sorry for my english but i'am beginner...