newton polygon to triangles
BlitzMax Forums/BlitzMax Programming/newton polygon to triangles
| ||
Hi, I'm totally confused here. I try to render the newton game dynamics collision meshes. But unfortunately newton does not save this data in as triangles. I have a callback ( based on code from http://irrlicht.sourceforge.net/forum/viewtopic.php?t=37024 ) that is run for every polygon of the mesh: which gives me this data: obviously I try to render a cube here. What I need now are tris. The function should transform the arrays to vertices to render a line between each pair of p0,p1. Problem is that this doesn't work in Bmax. faceArray[i * 3 + 0] is out of the array size sometimes and the value is 0.0 then (but it doesn't crash). I don't know why this should work in c++. Anyway the information of the tris is there (6 faces with 4 corners sounds promising). But how can I transform it to the form i need? |
| ||
EDIT: If you saw what I wrote before you can ignore it. I misunderstood the objective. I will try again soon. Okay, I think it's just a matter of the p1 index being "off by 1". For i = 0 To vertexCount - 1 p1 = _VECTOR3DF(faceArray[i * 3 + 0], .. faceArray[i * 3 + 1], .. faceArray[i * 3 + 2]) driver.draw3DLine(p0, p1, color) p0= p1 Next That should get rid of the "out of bounds" problem. But this looks like it is just drawing the polygon defined by the vertices, in this case a square. To triangulate each face you probably need something like this, in pseudocode. p0 = vertex at position vertexCount-1, as before. For i = 0 To vertexCount - 2 p1 = vertex at position i in the list p2 = vertex at position i+1 Add triangle p0,p1,p2 to the triangle list NextI have no experience with Newton and don't know how to actually deal with triangles. |
| ||
I got it! The code that works: What is the difference here? It is in the parameters. I declared faceArray as float ptr instead of float array (I thought that would be equivalent ?!). Anyway, now the values make much more sense and aren't 0.0 anymore. And the shapes are quads of course not tris. My bad. bye |