请问如何在MarchingCube算法getdepth功能的工作?算法、功能、如何在、工作

2023-09-11 07:07:20 作者:红了樱桃绿了芭蕉

我想了解移动立方体算法,所以我想我已经知道如何三角形的形成,以及如何法线计算每个网格研究。我可以看到有一个链表的一种结构,每个格链接到另一个。但是,当我遇到GetDepth(T [M]),后者每一个三角形(每个网格的这些三角形)(T [0],...,..)单独,它返回节​​点的深度。

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.

函数,

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;
}

它看起来像它试图找到最大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.

推荐答案

这似乎是你不熟悉?作为三元运算符。 您发布的code是等同于以下内容:

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;
}

是的,这确实发现在p数组中的最大的Z-。

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