Trying to implement simple marching cubes using Paul Bourke's code example (http://paulbourke.net/geometry/polygonise/)
I first set up a test voxel field like so:
void setup_voxels()
{
int x=0;
int y=0;
int z=0;
for(x=0;x<voxel_num;x++)
{
for(y=0;y<voxel_num;y++)
{
for(z=0;z<voxel_num;z++)
{
if (z<4)
{
voxel[x][y][z]=1;
}
else
{
voxel[x][y][z]=0;
}
}
}
}
This would be a 16*16*16 cube, with only the the first four levels actually set as "on" .
I then loop through each cell and try to set up the grid cells and call the polygonise function
for(x=0;x<voxel_num;x++)
{
for(y=0;y<voxel_num;y++)
{
for(z=0;z<voxel_num;z++)
{
GRIDCELL CELL;
TRIANGLE TRI[5];
XYZ tempvec;
tempvec.x=x*16;tempvec.y=y*16;tempvec.z=z*16;
vec_set(CELL.p[0],tempvec);
tempvec.x=x*16+16;tempvec.y=y*16;tempvec.z=z*16;
vec_set(CELL.p[1],tempvec);
tempvec.x=x*16+16;tempvec.y=y*16+16;tempvec.z=z*16;
vec_set(CELL.p[2],tempvec);
tempvec.x=x*16;tempvec.y=y*16+16;tempvec.z=z*16;
vec_set(CELL.p[3],tempvec);
tempvec.x=x*16;tempvec.y=y*16;tempvec.z=z*16+16;
vec_set(CELL.p[4],tempvec);
tempvec.x=x*16+16;tempvec.y=y*16;tempvec.z=z*16+16;
vec_set(CELL.p[5],tempvec);
tempvec.x=x*16+16;tempvec.y=y*16+16;tempvec.z=z*16+16;
vec_set(CELL.p[6],tempvec);
tempvec.x=x*16;tempvec.y=y*16+16;tempvec.z=z*16+16;
vec_set(CELL.p[7],tempvec);
CELL.val[0]=voxel[x][y][z];
CELL.val[1]=voxel[x+1][y][z];
CELL.val[2]=voxel[x+1][y+1][z];
CELL.val[3]=voxel[x][y+1][z];
CELL.val[4]=voxel[x][y][z+1];
CELL.val[5]=voxel[x+1][y][z+1];
CELL.val[6]=voxel[x+1][y+1][z+1];
CELL.val[7]=voxel[x][y+1][z+1];
int i=0;
int p=0;
p= Polygonise(CELL,0.5,TRI);
This is written in something called "lite-c" so it might seem a bit weird. Compiles fine and does return triangles, but they all seem messed up as far as positions and so on. I'm assuming I'm not getting something about the CELL.val and what the values are actually supposed to be , I just made it one or zero depending on if a voxel cell is filled or not.
I hope this makes at least some sense...maybe I am totally misunderstanding how this method works..?? If anyone has any idea what's going on I'd be happy to get some help.