0

目前,我有一个随机地形生成器,我确信它可以正常工作,但是,当我尝试构建一组时VertexPositionColor,它不能正确渲染。这是我目前拥有的(俯视图): 俯视图

我的代码:

List<VertexPositionColor> w = new List<VertexPositionColor>();
int width = 20;
int height = 20;
float terrainScale = 2.0f;
long seed = (DateTime.Now.Millisecond + DateTime.Now.Second * DateTime.Now.Hour);
ProceduralLayeredMapGenerator plmg = new ProceduralLayeredMapGenerator(seed);
Random rand = new Random((int)seed);
for (int y = 0; y < height; y++)
{
    for (int x = 0; x < width; x++)
    {
        Vector3 position = new Vector3();
        position.X = x;//(x - width / 2) * terrainScale;
        position.Z = y;//(y - height / 2) * terrainScale;
        float point = plmg.getPoint(x, y);
        Color computedColor = new Color(rand.Next(255), rand.Next(255), rand.Next(255));
        position.Y = (point * 2);
        w.Add(new VertexPositionColor(position, computedColor));
    }
}
colors = w.ToArray();

然后绘制代码:

foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
    pass.Apply();
    GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleStrip, colors, 0, colors.Length / 3, VertexPositionColor.VertexDeclaration);
}

我怎样才能让它看起来更像这样:

在此处输入图像描述

4

1 回答 1

0

如果要绘制 TriangleStrip,则必须按照用于绘制三角形的顺序添加顶点;现在,您正在从上到下、从左到右添加顶点。此外,要渲染这样的高度图,您需要使用多个 TriangleStrips。

于 2013-01-28T16:51:24.607 回答