Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (TipmyPip, AndrewAMD, Quad, aliswee, degenerate_762), 970 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Trouble implementing marching cubes #447240
11/28/14 02:44
11/28/14 02:44
Joined: Oct 2003
Posts: 4,131
M
Matt_Aufderheide Offline OP
Expert
Matt_Aufderheide  Offline OP
Expert
M

Joined: Oct 2003
Posts: 4,131
i'm trying to implement marching cubes using Paul Bourke's code example:http://paulbourke.net/geometry/polygonise/

I can get everything to compile and actually create a mesh using the TUST dynamic model functions...seems to sort of work except all the faces are connected wrong. Anyone have an idea?

I set up a voxel field like so:
for(x=0;x<voxel_num;x++)
{
for(y=0;y<voxel_num;y++)
{
for(z=0;z<voxel_num;z++)
{
if (y<4)
{
voxel[x][y][z]=1;
}

else
{
voxel[x][y][z]=0;


Here is my function to polygonize the voxel field:
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];

vec_set(CELL.p[0],vector(x,y,z));
vec_set(CELL.p[1],vector(x+1,y,z));
vec_set(CELL.p[2],vector(x,y+1,z));
vec_set(CELL.p[3],vector(x+1,y+1,z));

vec_set(CELL.p[4],vector(x,y,z+1));
vec_set(CELL.p[5],vector(x+1,y,z+1));
vec_set(CELL.p[6],vector(x,y+1,z+1));
vec_set(CELL.p[7],vector(x+1,y+1,z+1));

CELL.val[0]=voxel[x][y][z];
CELL.val[1]=voxel[x+1][y][z];
CELL.val[2]=voxel[x][y+1][z];
CELL.val[3]=voxel[x+1][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][y+1][z+1];
CELL.val[7]=voxel[x+1][y+1][z+1];

int i=0;
int p=0;
int q=0;

p= Polygonise(CELL,0.5,TRI);

for (i=0;i<p;i++)
{
for (q=0;q<3;q++)
{
DYNAMIC_FACE FACE;

FACE.v.x=TRI[i].p[q].x;
FACE.v.y=TRI[i].p[q].y;
FACE.v.z=TRI[i].p[q].z;

dmdl_add_face(myModel, FACE);

Last edited by Matt_Aufderheide; 11/28/14 02:46.
Re: Trouble implementing marching cubes [Re: Matt_Aufderheide] #447241
11/28/14 07:28
11/28/14 07:28
Joined: Mar 2012
Posts: 927
cyberspace
W
Wjbender Offline
User
Wjbender  Offline
User
W

Joined: Mar 2012
Posts: 927
cyberspace
a triangle has 3 vertices , a face has 3 vertices

v [0] , v [1] , v [2]

just saying...


Compulsive compiler
Re: Trouble implementing marching cubes [Re: Wjbender] #447247
11/28/14 11:02
11/28/14 11:02
Joined: Oct 2003
Posts: 4,131
M
Matt_Aufderheide Offline OP
Expert
Matt_Aufderheide  Offline OP
Expert
M

Joined: Oct 2003
Posts: 4,131
oops! yes that's a good one... works better now, but still not quite right yet..this is what I have now for the add face routine...see anything ese?

p=Polygonise(CELL,0.5,TRI);

for (i=0;i<p;i++)
{
DYNAMIC_FACE FACE;

for (q=0;q<3;q++)
{
FACE.v[q].x=TRI[i].p[q].x;
FACE.v[q].y=TRI[i].p[q].y;
FACE.v[q].z=TRI[i].p[q].z;
}

dmdl_add_face(myModel, FACE);
}

Re: Trouble implementing marching cubes [Re: Matt_Aufderheide] #447250
11/28/14 11:31
11/28/14 11:31
Joined: Oct 2003
Posts: 4,131
M
Matt_Aufderheide Offline OP
Expert
Matt_Aufderheide  Offline OP
Expert
M

Joined: Oct 2003
Posts: 4,131
ok I figured it out...my setup should be like this:

vec_set(CELL.p[0],vector(x,y,z));
vec_set(CELL.p[1],vector(x+1,y,z));
vec_set(CELL.p[2],vector(x+1,y,z+1));
vec_set(CELL.p[3],vector(x,y,z+1));

vec_set(CELL.p[4],vector(x,y+1,z));
vec_set(CELL.p[5],vector(x+1,y+1,z));
vec_set(CELL.p[6],vector(x+1,y+1,z+1));
vec_set(CELL.p[7],vector(x,y+1,z+1));

CELL.val[0]=voxel[x][y][z];
CELL.val[1]=voxel[x+1][y][z];
CELL.val[2]=voxel[x+1][y][z+1];
CELL.val[3]=voxel[x][y][z+1];

CELL.val[4]=voxel[x][y+1][z];
CELL.val[5]=voxel[x+1][y+1][z];
CELL.val[6]=voxel[x+1][y+1][z+1];
CELL.val[7]=voxel[x][y+1][z+1];


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1