问题描述
我想制作一个只有一些颠簸和高度变化的简单2D地形:
I want to make a simple 2d terrain with just a few bumps and height changes:
我考虑过仅使用随机数来描述某个顶点的高度,但是我看不到如何从中制作一个网格.我正在寻找一种查找地形的顶点和索引缓冲区的方法.
我该怎么做?
I thought about just using random numbers to describe the height of a certain vertex, but I don't see how I can make one mesh from this. I'm looking for a way to find the vertex and indices buffers for the terrain.
How do I do this?
推荐答案
您可以只使用GL_POLYGON并在视图下方包含所有顶点的列表,其中第一个和最后一个顶点为
You could just use GL_POLYGON with a list of all the vertices with the first and last vertice below the view.
如果要使用三角形网格,则必须在每个高度点(视线之外)的正下方创建一个点,然后图案(用于顺时针排序)将是:
if you want to use a triangle mesh you'll have to create a point directly below each height point(out of view) then the pattern(for clockwise ordering) would be:
for (number of height points-1)
//vertices
vertice below height;
height vertice;
next_height vertice;
next height vertice;
vertice below next height;
vertice below height;
然后计算索引取决于您存储顶点的方式,但是数组中会有类似的模式.
then working out the indices depends on how you store the vertices, but there will be a similar pattern in the array.
这篇关于如何使用opengl制作2D地形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!