0

我正在尝试从 Vector3 元素列表中绘制三角形。

以前我使用高度图来创建顶点和索引,但是效果很好,因为它是二维数组中的矩形而不是列表。

我将如何处理(或修改)我现有的代码来处理列表而不是二维数组。

我现有的顶点代码:

public VertexPositionNormalTexture[] getVerticies(float[,] heightData)
    {
        VertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[terrainLength * terrainWidth];

        for (int y = 0; y < terrainLength; y++)
        {
            for (int x = 0; x < terrainWidth; x++)
            {

                // position the vertices so that the heightfield is centered
                // around x=0,z=0
                vertices[x + y * terrainWidth].Position.X = terrainScale * (x - ((terrainWidth - 1) / 2.0f));
                vertices[x + y * terrainWidth].Position.Z = terrainScale * (y - ((terrainLength - 1) / 2.0f));

                vertices[x + y * terrainWidth].Position.Y = (heightData[x, y] - 1);

                vertices[x + y * terrainWidth].TextureCoordinate.X = (float)x / terrainScale;
                vertices[x + y * terrainWidth].TextureCoordinate.Y = (float)y / terrainScale;
            }
        }

        return vertices;
    }

这是索引的代码:

public int[] getIndicies()
    {
        int counter = 0;
        int [] indices = new int[(terrainWidth - 1) * (terrainLength - 1) * 6];

        for (int y = 0; y < terrainLength - 1; y++)
        {
            for (int x = 0; x < terrainWidth - 1; x++)
            {
                int lowerLeft = x + y * terrainWidth;
                int lowerRight = (x + 1) + y * terrainWidth;
                int topLeft = x + (y + 1) * terrainWidth;
                int topRight = (x + 1) + (y + 1) * terrainWidth;

                indices[counter++] = topLeft;
                indices[counter++] = lowerRight;
                indices[counter++] = lowerLeft;

                indices[counter++] = topLeft;
                indices[counter++] = topRight;
                indices[counter++] = lowerRight;
            }
        }

        return indices;
    }
4

1 回答 1

0

您将在List<List<float>此处查看或正在使用的任何类型。

语法可能会略有变化。

于 2013-07-19T14:43:32.900 回答