C# 索引未呈现-XNA
我最终决定给我的minecraft引擎添加索引支持,但问题是,一旦我添加了索引,就什么都没有出现。。。我知道这不是很好的描述,但有人能检查一下我的代码,看看我是否做错了什么;)谢谢 有什么想法吗C# 索引未呈现-XNA,c#,xna,buffer,vertex,indices,C#,Xna,Buffer,Vertex,Indices,我最终决定给我的minecraft引擎添加索引支持,但问题是,一旦我添加了索引,就什么都没有出现。。。我知道这不是很好的描述,但有人能检查一下我的代码,看看我是否做错了什么;)谢谢 有什么想法吗 谢谢,尊敬的,Darestium当我创建缓冲区时,我使用整数而不是short(我用于保存索引的列表)分配了太多内存 而不是 SolidIndices = new IndexBuffer(Variables.GRAPHICS_DEVICE, typeof(short), IndexList.Count,
谢谢,尊敬的,Darestium当我创建缓冲区时,我使用整数而不是short(我用于保存索引的列表)分配了太多内存 而不是
SolidIndices = new IndexBuffer(Variables.GRAPHICS_DEVICE, typeof(short), IndexList.Count, BufferUsage.WriteOnly);
SolidIndices.SetData(IndexList.ToArray());
我想你最好自己调试一下。尝试使用PIX(在DirectX SDK中)查看实际渲染的内容。
public void BuildFaceVertices(Block block, Vector3 pos, BlockFaceDirection blockFaceDirection)
{
Vector3 topLeftFront = new Vector3(0f, 1f, 0f) + pos;
Vector3 bottomLeftFront = new Vector3(0f, 0f, 0f) + pos;
Vector3 topRightFront = new Vector3(1f, 1f, 0f) + pos;
Vector3 bottomRightFront = new Vector3(1f, 0f, 0f) + pos;
Vector3 topLeftBack = new Vector3(0f, 1f, -1f) + pos;
Vector3 topRightBack = new Vector3(1f, 1f, -1f) + pos;
Vector3 bottomLeftBack = new Vector3(0f, 0f, -1f) + pos;
Vector3 bottomRightBack = new Vector3(1f, 0f, -1f) + pos;
int row = (int)block.BlockType / Variables.TILE_ALAIS.NumberOfColumns;
int column = (int)block.BlockType - row * Variables.TILE_ALAIS.NumberOfColumns;
float unit = 1.0f / (float)Variables.TILE_ALAIS.NumberOfColumns;
float x = column * unit;
float y = row * unit;
Vector2 topLeft = new Vector2(x, y);
Vector2 topRight = new Vector2(x + unit, y);
Vector2 bottomLeft = new Vector2(x, y + unit);
Vector2 bottomRight = new Vector2(x + unit, y + unit);
switch (blockFaceDirection)
{
case BlockFaceDirection.ZIncreasing:
SolidVertices.Add(new VertexPositionTexture(topRightFront, topRight));
SolidVertices.Add(new VertexPositionTexture(bottomRightFront, bottomRight));
SolidVertices.Add(new VertexPositionTexture(bottomLeftFront, bottomLeft));
SolidVertices.Add(new VertexPositionTexture(topRightFront, topRight));
SolidVertices.Add(new VertexPositionTexture(bottomLeftFront, bottomLeft));
SolidVertices.Add(new VertexPositionTexture(topLeftFront, topLeft));
break;
case BlockFaceDirection.ZDecreasing:
// Clockwise
SolidVertices.Add(new VertexPositionTexture(bottomRightBack, bottomLeft));
SolidVertices.Add(new VertexPositionTexture(topRightBack, topLeft));
SolidVertices.Add(new VertexPositionTexture(topLeftBack, topRight));
SolidVertices.Add(new VertexPositionTexture(bottomLeftBack, bottomRight));
SolidVertices.Add(new VertexPositionTexture(bottomRightBack, bottomLeft));
SolidVertices.Add(new VertexPositionTexture(topLeftBack, topRight));
break;
case BlockFaceDirection.YIncreasing:
SolidVertices.Add(new VertexPositionTexture(topRightBack, topRight));
SolidVertices.Add(new VertexPositionTexture(topRightFront, bottomRight));
SolidVertices.Add(new VertexPositionTexture(topLeftFront, bottomLeft));
SolidVertices.Add(new VertexPositionTexture(topRightBack, topRight));
SolidVertices.Add(new VertexPositionTexture(topLeftFront, bottomLeft));
SolidVertices.Add(new VertexPositionTexture(topLeftBack, topLeft));
break;
case BlockFaceDirection.YDecreasing:
SolidVertices.Add(new VertexPositionTexture(bottomLeftFront, topLeft));
SolidVertices.Add(new VertexPositionTexture(bottomRightFront, topRight));
SolidVertices.Add(new VertexPositionTexture(bottomLeftBack, bottomLeft));
SolidVertices.Add(new VertexPositionTexture(bottomRightFront, topRight));
SolidVertices.Add(new VertexPositionTexture(bottomRightBack, bottomRight));
SolidVertices.Add(new VertexPositionTexture(bottomLeftBack, bottomLeft));
break;
case BlockFaceDirection.XIncreasing:
SolidVertices.Add(new VertexPositionTexture(topRightBack, topRight));
SolidVertices.Add(new VertexPositionTexture(bottomRightFront, bottomLeft));
SolidVertices.Add(new VertexPositionTexture(topRightFront, topLeft));
SolidVertices.Add(new VertexPositionTexture(topRightBack, topRight));
SolidVertices.Add(new VertexPositionTexture(bottomRightBack, bottomRight));
SolidVertices.Add(new VertexPositionTexture(bottomRightFront, bottomLeft));
break;
case BlockFaceDirection.XDecreasing:
SolidVertices.Add(new VertexPositionTexture(topLeftBack, topLeft));
SolidVertices.Add(new VertexPositionTexture(topLeftFront, topRight));
SolidVertices.Add(new VertexPositionTexture(bottomLeftFront, bottomRight));
SolidVertices.Add(new VertexPositionTexture(topLeftBack, topLeft));
SolidVertices.Add(new VertexPositionTexture(bottomLeftFront, bottomRight));
SolidVertices.Add(new VertexPositionTexture(bottomLeftBack, bottomLeft));
break;
}
}
SolidIndices = new IndexBuffer(Variables.GRAPHICS_DEVICE, typeof(int), IndexList.Count, BufferUsage.WriteOnly);
SolidIndices.SetData(IndexList.ToArray());
SolidIndices = new IndexBuffer(Variables.GRAPHICS_DEVICE, typeof(short), IndexList.Count, BufferUsage.WriteOnly);
SolidIndices.SetData(IndexList.ToArray());