I suffered with a code here, and I think that is very useful for those who is using Irrlicht together with Newton Dynamics physics engine. This code allows you to pass a ConvexHull object to Irrlicht and see it without need to initialize any graphics interface by Newton. This way we keep Irrlicht for all graphics.
Code: Select all
ISceneNode* renderConvexHull(NewtonCollision* convexHull, video::SColor color, ISceneManager* smgr)
{
NewtonMesh* mesh;
SMesh* irrMesh;
SMeshBuffer* buffer;
dInt32 m_vertexCount;
dInt32 m_indexCount;
GLfloat *m_uv;
GLfloat *m_vertex;
GLfloat *m_normal;
GLushort* m_indexes;
int i = 0;
int x = 0;
int handle;
mesh = NewtonMeshCreateFromCollision(convexHull);
// getting vertexes position
m_vertexCount = NewtonMeshGetVertexCount (mesh);
m_vertex = (GLfloat*) malloc (3 * m_vertexCount * sizeof (GLfloat));
m_normal = (GLfloat*) malloc (3 * m_vertexCount * sizeof (GLfloat));
m_uv = (GLfloat*) malloc (2 * m_vertexCount * sizeof (GLfloat));
memset (m_uv, 0, 2 * m_vertexCount * sizeof (GLfloat));
NewtonMeshGetVertexStreams (mesh,
3 * sizeof (GLfloat), (dFloat*) m_vertex,
3 * sizeof (GLfloat), (dFloat*) m_normal,
2 * sizeof (GLfloat), (dFloat*) m_uv);
// Getting face indexes.
handle = NewtonMeshFirstMaterial(mesh);
m_indexes = (GLushort *) malloc (m_indexCount * sizeof (GLushort ));
m_indexCount = NewtonMeshMaterialGetIndexCount (mesh, handle);
NewtonMeshMaterialGetIndexStreamShort (mesh, handle, (short int*)m_indexes);
// Creating SMesh
buffer = new SMeshBuffer();
buffer->Indices.set_used(m_indexCount);
for (i=0; i<m_indexCount; ++i)
buffer->Indices[i] = m_indexes[i];
buffer->Vertices.set_used(m_vertexCount);
for (i=0; i < m_vertexCount * 3; i+=3)
{
buffer->Vertices[x] = video::S3DVertex(m_vertex[i], m_vertex[i+1], m_vertex[i+2],1,1,1,color, 1, 1);
x++;
}
irrMesh = new SMesh();
irrMesh->addMeshBuffer(buffer);
ISceneNode * collmesh = smgr->addMeshSceneNode(irrMesh);
collmesh -> setMaterialFlag(EMF_LIGHTING,false);
collmesh -> setMaterialFlag(EMF_WIREFRAME, true);
NewtonMeshDestroy(mesh);
return (collmesh);
}