目前,我有一个随机地形生成器,我确信它可以正常工作,但是,当我尝试构建一组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);
}
我怎样才能让它看起来像这样:
答案 0 :(得分:0)
如果要绘制TriangleStrip,则必须按照用于绘制三角形的顺序添加顶点;现在你从上到下,从左到右添加顶点。此外,要渲染高度贴图,您需要使用多个TriangleStrips。