Question

I am trying to understand Marching Cube Algorithm, so for I think I have understood how triangles are formed and how normals are calculated in each grid. I can see there is a linked list kind of structure that links each grid to another. But when I come across GetDepth(t[m]) which passes each triangles (those triangles of each grid) (t[0],..,..)individually, it returns depth of the node.

The function,

float GetDepth(TRIANGLE t) {

    float z;
    z = t.p[0].z;
    z = t.p[1].z > z? t.p[1].z: z;
    z = t.p[2].z > z? t.p[2].z: z;
    return z;
}

It looks like its trying to find max z(is it true). I can see that it compares " > " and then I lost it. Can any one please explain what is happening here.

Was it helpful?

Solution

It would seem that you are unfamiliar with ? as a ternary operator. The code you posted is equivalent to the following:

float GetDepth(TRIANGLE t) {

float z;
z = t.p[0].z;
if (t.p[1].z > z) {z = t.p[1].z;} else {z = z;}
if (t.p[2].z > z) {z = t.p[2].z;} else {z = z;}
return z;
}

And yes, this does find the maximum z in the p array.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top