- Code: Select all
//Function to create a NewtonCollision from irrlicht mesh
NewtonCollision *CreateCollisionFromMesh(NewtonWorld *nWorld,IMesh *mesh)
{
//Get number of vertices
u32 nVertices = 0, nMeshBuffer;
for( nMeshBuffer = 0 ; nMeshBuffer < mesh->getMeshBufferCount(); ++nMeshBuffer)
{
IMeshBuffer *buffer = mesh->getMeshBuffer(nMeshBuffer);
nVertices += buffer->getVertexCount();
}
// allocate block for positions of every vertex in mesh, no need to delete
// anything, the array cleans up for us.
core::array<f32> vertices;
vertices.reallocate(nVertices * 3);
//Get mesh buffers and copy face vertices
for( nMeshBuffer = 0 ; nMeshBuffer < mesh->getMeshBufferCount(); ++nMeshBuffer)
{
scene::IMeshBuffer *buffer = mesh->getMeshBuffer(nMeshBuffer);
// handle the irrlicht supported vertex types
switch(buffer->getVertexType())
{
case video::EVT_STANDARD:
{
video::S3DVertex* verts = (video::S3DVertex*)buffer->getVertices();
for(u32 v = 0; v < buffer->getVertexCount(); ++v)
{
vertices.push_back(verts[v].Pos.X);
vertices.push_back(verts[v].Pos.Y);
vertices.push_back(verts[v].Pos.Z);
}
}
break;
case video::EVT_2TCOORDS:
{
video::S3DVertex2TCoords* verts = (video::S3DVertex2TCoords*)buffer->getVertices();
for(u32 v = 0; v < buffer->getVertexCount(); ++v)
{
vertices.push_back(verts[v].Pos.X);
vertices.push_back(verts[v].Pos.Y);
vertices.push_back(verts[v].Pos.Z);
}
}
break;
case video::EVT_TANGENTS:
{
video::S3DVertexTangents* verts = (video::S3DVertexTangents*)buffer->getVertices();
for(u32 v = 0; v < buffer->getVertexCount(); ++v)
{
vertices.push_back(verts[v].Pos.X);
vertices.push_back(verts[v].Pos.Y);
vertices.push_back(verts[v].Pos.Z);
}
}
break;
default:
return 0; // don't know vertex type! bail.
}
}
//Create Newton collision object
return NewtonCreateConvexHull(nWorld, nVertices, &vertices[0], sizeof(f32)*3, NULL);
}
There are some changes to the function in Newton 3.0, it requires two additional variables to be passed (an offset matrix and a shape ID i think, although I'm unsure because I can't find the documentation for the old function?). What should I add to my code for the function to work? Perhaps this isn't the best way to create a convex hull? I need it for a basic collision detection program.
EDIT: This Problem is solved