NewtonCreateConvexHull

A place to discuss everything related to Newton Dynamics.

Moderators: Sascha Willems, walaber

NewtonCreateConvexHull

Postby en51nm » Sat May 26, 2012 1:12 pm

I have a function created for Newton 1.53 code for creating a Convex Hull from an irrlicht mesh buffer:

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
Last edited by en51nm on Sun May 27, 2012 9:20 am, edited 1 time in total.
en51nm
 
Posts: 27
Joined: Thu May 17, 2012 3:20 pm

Re: NewtonCreateConvexHull

Postby Julio Jerez » Sat May 26, 2012 5:37 pm

a shape id is a user data, you can use to identify the mesh.
the offset matrix is a trasformation matrix you cna use to position the shape from this parametic construction values.
you can set and identity matrix and then changed if you want.
Julio Jerez
Moderator
Moderator
 
Posts: 12426
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests

cron