Я работаю над рендерингом сетки в sharpdx
private (int[], DVertexType[]) GetBuffers()
{
VertexCount = (m_TerrainWidth) * (m_TerrainHeight) * 8;
IndexCount = VertexCount;
int[] indices = new int[IndexCount];
DVertexType[] vertices = new DVertexType[VertexCount];
int index = 0;
int i = 0;
for (int j = 0; j < m_TerrainHeight; j++)
{
for (i = 0; i < m_TerrainWidth; i++)
{
float positionX = (float)i;
float positionZ = (float)j;
vertices[index].position = new Vector3(positionX, _surface.Grid[i][j].Height / 100, positionZ);
vertices[index].color = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);
index++;
}
}
indices = new int[m_TerrainWidth * m_TerrainWidth * 6];
index = 0;
for (int x = 0; x < m_TerrainWidth - 1; x++)
{
for (int z = 0; z < m_TerrainWidth - 1; z++)
{
int offset = x * m_TerrainWidth + z;
indices[index] = (short)(offset + 0);
indices[index + 1] = (short)(offset + 1);
indices[index + 2] = (short)(offset + m_TerrainWidth);
indices[index + 3] = (short)(offset + 1);
indices[index + 4] = (short)(offset + m_TerrainWidth + 1);
indices[index + 5] = (short)(offset + m_TerrainWidth);
index += 6;
}
}
return (indices,vertices);
}
Привязки
VertexBuffer = SharpDX.Direct3D11.Buffer.Create(device, BindFlags.VertexBuffer, vertices);
IndexBuffer = SharpDX.Direct3D11.Buffer.Create(device, BindFlags.IndexBuffer, indices);
Визуализация
deviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(VertexBuffer,Utilities.SizeOf<DVertexType>(), 0));
deviceContext.InputAssembler.SetIndexBuffer(IndexBuffer, Format.R32_UInt, 0);
deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.LineStrip;
Все как и ожидалось, но вместо верхней линии я получил странную диагональ (от верхней левой вершины до нижней + 1 правой).
Я часами пытаюсь отладить и искать различные виды порядка указаний, но безрезультатно, не хотите ли вы мне помочь?
Редактировать: когда я начал двигаться вверх и вниз по вершинам, я заметил, что есть прямые линии слева направо. Вероятно, диагональ является одним из них, но переехал, мне нужно избавиться от всех из них