Adding Networking to my Car game is proving to be a headache. So as break. Here is my code to Create a Newton Convex Hull (for collision) from a Vertex Buffer.
Its not very long, but it works very well

, but there are limitations, as this is the mesh buffer, it does not take into account scaling, rotation and position. But then, you can get the matrix data from the node, and pass that directly into newton, via NewtonBodySetMatrix(body, NodesMatrix.M);
Code: Select all
scene::IMeshBuffer *pBuffer = smgr->getMesh("models/cone.3DS")->getMesh(0)->getMeshBuffer(0);
int VertexCount = pBuffer->getVertexCount();
video::S3DVertex *vertices = (video::S3DVertex *)pBuffer->getVertices();
NewtonCollision *Collision = NewtonCreateConvexHull( nWorld, VertexCount, &vertices[0].Pos.X, 36, NULL );
NewtonBody *Body = NewtonCreateBody( nWorld, Collision);
The 36 as the 4th Parameter specifies the byte stride. NewtonCreateConvexHull reads in the first 12 bytes (3 floats) of the vertices struct and then skips the other 24 bytes (so normals, texture coordinates etc). It must be pointed to the Pos.X position within the structure, as it appeared that the Pos was offset by inside the structure.
My car deformation uses this convex hull at its core, but the best part of this, is to allow more interesting shapes to interact with. Instead of boring bound boxes, spheres and such.