I am trying to implement marching cubes in C#, but I’ve come to a part where I don’t understand the algorithm and I don’t how to implement it.
int Polygonise(GRIDCELL grid, double isolevel, TRIANGLE *triangles)
The third argument I don’t really understand. I know it’s a pointer, but later on in the algo, when you set the triangles it appears as though the triangles variable is an array of the TRIANGLE struct:
int ntriang = 0;
for (int i=0; triTable[cubeindex,i]!=-1; i+=3) {
triangles[ntriang].p[i ] = vertlist[triTable[cubeindex,i ]];
triangles[ntriang].p[i+1] = vertlist[triTable[cubeindex,i+1]];
triangles[ntriang].p[i+2] = vertlist[triTable[cubeindex,i+2]];
ntriang++;
}
Notice the triangles[ntriang]. That doesn’t make sense because before we set triangles to TRIANGLE *triangles. I also don’t understand why It’s a pointer.
The caller of
Polygonizeexpects*trianglespoint to an allocated array long enough to contain all the triangles. The equivalent in c# can be aTRIANGLE[]or aList<TRIANGLE>()