我对使用三角形网格绘制的网格和使用AndEngine绘制的line_strip有疑问。
我使用triangle_strip生成2d地形,以这种方式创建三角形
1 3
|\ |\
| \| \
0 2 4
final int pSegmentsCount = 51;
final int pVertexCount = ( Mesh.VERTEX_SIZE * (pSegmentsCount) );
final float pColor = new Color(0f,0f,0f).getABGRPackedFloat();
final float pSegmentWidth = ( CAMERA_WIDTH/pSegmentsCount );
float[] pBufferData = new float[pVertexCount];
mHeightOffsetCurrent = new float[pVertexCount];
float x = 0f,y = 0f;
for (int i = 0;i<(pSegmentsCount);i++){
if (i%2!=0) { //every 3rd point goes up 2-4-6 , 0-1-3-5 stays down at 0 , x increments every third point
y = 200;
} else {
x = pSegmentWidth*i; //step right by segment
y = 0;
}
mHeightOffsetCurrent[i] = 0; //init default offset
pBufferData[(i * Mesh.VERTEX_SIZE) + Mesh.VERTEX_INDEX_X] = x;
pBufferData[(i * Mesh.VERTEX_SIZE) + Mesh.VERTEX_INDEX_Y] = y;
pBufferData[(i * Mesh.VERTEX_SIZE) + Mesh.COLOR_INDEX] = pColor;
}
pBufferData[((pSegmentsCount-1) * Mesh.VERTEX_SIZE) + Mesh.VERTEX_INDEX_Y] = -300;
final VertexBufferObjectManager VBOM = getVertexBufferObjectManager();
final HighPerformanceMeshVertexBufferObject pMeshVBO = new HighPerformanceMeshVertexBufferObject(VBOM, pBufferData, pVertexCount, DrawType.DYNAMIC, true, Mesh.VERTEXBUFFEROBJECTATTRIBUTES_DEFAULT);
pMesh = new Mesh(0, 0,pVertexCount,DrawMode.LINE_STRIP,pMeshVBO);
我正在改变最后一个顶点y位置以更好地说明它
这是我得到的,
line_strip
triangle_strip
当我将最后一个点的Y设置为0时,我仍然看到渐变到起点的线。
我做错了什么?为什么最后一个元素与第一个元素连接以及如何解决这个问题? 数组由glDrawArrays绘制。
public static final int VERTEX_INDEX_X = 0;
public static final int VERTEX_INDEX_Y = Mesh.VERTEX_INDEX_X + 1;
public static final int COLOR_INDEX = Mesh.VERTEX_INDEX_Y + 1;
public static final int VERTEX_SIZE = 2 + 1;