NewtonCollisionForEachPolygonDo() does not cap cylinder/cone

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

NewtonCollisionForEachPolygonDo() does not cap cylinder/cone

Postby agi_shi » Fri Apr 15, 2011 3:34 pm

Hey, I haven't been around in a while, I hope everything is going well :mrgreen:

I got back into some physics game coding and, of course, went straight to the Newton SVN :twisted:

Everything works great, except for one thing: when I use NewtonCollisionForEachPolygonDo() to generate geometry for a cylinder or a cone, the base(s) is/are not capped:
Image

Here's my code:
Code: Select all
            Mesh mesh = new Mesh(); // this is my own graphics Mesh which accepts vertices and indices
            uint currentIndex = 0;
            NewtonCollisionIterator func = (userData, vertexCount, faceArray, faceId) =>
            {
               uint[] indices = new uint[vertexCount];
               for (int i = 0; i < vertexCount; ++i)
               {
                  mesh.AddVertex(faceArray[i * 3], faceArray[i * 3 + 1], faceArray[i * 3 + 2], 0, 0, 0, 0, 0);
                  indices[i] = currentIndex + (uint)i;
               }
               mesh.AddFace(indices);
               currentIndex += (uint)vertexCount;
            };
            float* f = Util.IdentityFloat16();
            NewtonCollisionForEachPolygonDo(collision, f, func, 0);

(the language is C#, not C/C++, but it's close enough to understand)

Is this expected behavior, or is it a bug? All of the other primitives (spheres, capsules, boxes) work fine.

Any help is appreciated, thanks!
agi_shi
 
Posts: 263
Joined: Fri Aug 17, 2007 6:54 pm

Re: NewtonCollisionForEachPolygonDo() does not cap cylinder/

Postby Julio Jerez » Fri Apr 15, 2011 4:34 pm

long time,

There are not triangles they are polygons, if you modify you function like this

Code: Select all
NewtonCollisionIterator func = (userData, vertexCount, faceArray, faceId) =>
{
   for (int i = 0; i < vertexCount; ++i)
   {
      mesh.AddVertex(faceArray[i * 3], faceArray[i * 3 + 1], faceArray[i * 3 + 2], 0, 0, 0, 0, 0);
   }

   uint[] indices = new uint[(vertexCount - 2) * 3];
   for (int i = 2; i < vertexCount; ++i) {
      indices[i * 3 + 0] = currentIndex + 0;
      indices[i * 3 + 1] = currentIndex + i - 1;
      indices[i * 3 + 2] = currentIndex + i;
   }
   mesh.AddFace(indices);
   currentIndex += (vertexCount - 2) * 3;
}


I should work.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: NewtonCollisionForEachPolygonDo() does not cap cylinder/

Postby agi_shi » Fri Apr 15, 2011 4:56 pm

Wow awesome, thanks for the quick reply! Works great now :mrgreen:

(I went for a more general solution and fixed my AddFace() function so it works with non-triangles)
agi_shi
 
Posts: 263
Joined: Fri Aug 17, 2007 6:54 pm


Return to Bugs and Fixes

Who is online

Users browsing this forum: No registered users and 7 guests