嘿我用原始物体制作游戏。使用Vertex Buffer创建这些对象。我遇到的问题是,当我渲染一个立方体时它看起来很完美......但是当我将它缩放得更大时,立方体变形会留下孔和锯齿状的末端。我已经尝试了很多方法来制作立方体,我无法弄明白。将立方体扩大的想法是制作一个Skybox。
以下是一些图片:
变形立方体: http://i.imgur.com/5aGu7mF.png
完美的小方块: http://i.imgur.com/FmMBb4X.png
我的代码:
使用顶点的Skybox的路径数据。
private void loadSkyboxData(Color color)
{
VertexPositionColorTexture[] verts = new VertexPositionColorTexture[25];
//Top Left
verts[0] = new VertexPositionColorTexture(new Vector3(-500, 500, -500), color, new Vector2(0, 0));
verts[1] = new VertexPositionColorTexture(new Vector3(500, 500, -500), color, new Vector2(0, 0));
verts[2] = new VertexPositionColorTexture(new Vector3(-500, -500, -500), color, new Vector2(0, 0));
verts[3] = new VertexPositionColorTexture(new Vector3(500, -500, -500), color, new Vector2(0, 0));
//Top Left
verts[4] = new VertexPositionColorTexture(new Vector3(500, 500, -500), color, new Vector2(0, 0));
verts[5] = new VertexPositionColorTexture(new Vector3(500, 500, 500), color, new Vector2(0, 0));
verts[6] = new VertexPositionColorTexture(new Vector3(500, -500, -500), color, new Vector2(0, 0));
verts[7] = new VertexPositionColorTexture(new Vector3(500, -500, 500), color, new Vector2(0, 0));
//Top Left
verts[8] = new VertexPositionColorTexture(new Vector3(-500, 500, 500), color, new Vector2(0, 0));
verts[9] = new VertexPositionColorTexture(new Vector3(500, 500, 500), color, new Vector2(0, 0));
verts[10] = new VertexPositionColorTexture(new Vector3(-500, 500, 500), color, new Vector2(0, 0));
verts[11] = new VertexPositionColorTexture(new Vector3(500, 500, -500), color, new Vector2(0, 0));
//Top Left
verts[12] = new VertexPositionColorTexture(new Vector3(500, 500, 500), color, new Vector2(0, 0));
verts[13] = new VertexPositionColorTexture(new Vector3(-500, 500, 500), color, new Vector2(0, 0));
verts[14] = new VertexPositionColorTexture(new Vector3(500, -500, 500), color, new Vector2(0, 0));
verts[15] = new VertexPositionColorTexture(new Vector3(-500, -500, 500), color, new Vector2(0, 0));
//Top Left
verts[16] = new VertexPositionColorTexture(new Vector3(-500, 500, 500), color, new Vector2(0, 0));
verts[17] = new VertexPositionColorTexture(new Vector3(-500, 500, -500), color, new Vector2(0, 0));
verts[18] = new VertexPositionColorTexture(new Vector3(-500, -500, 500), color, new Vector2(0, 0));
verts[19] = new VertexPositionColorTexture(new Vector3(500, -500, -500), color, new Vector2(0, 0));
//Top Left
verts[20] = new VertexPositionColorTexture(new Vector3(-500, -500 ,-500), color, new Vector2(0, 0));
verts[21] = new VertexPositionColorTexture(new Vector3(500, -500, -500), color, new Vector2(0, 0));
verts[23] = new VertexPositionColorTexture(new Vector3(-500, -500, 500), color, new Vector2(0, 0));
verts[24] = new VertexPositionColorTexture(new Vector3(500, -500, 500), color, new Vector2(0, 0));
vertexDictionary.Add("Skybox", new BufferedVertexTextureData(verts, PrimitiveType.TriangleStrip, 21));
BufferedVertexTextureData.cs
public class BufferedVertexTextureData : VertexTextureData
{
protected VertexBuffer vertsBuffer;
public BufferedVertexTextureData(VertexPositionColorTexture[] verts, PrimitiveType primitiveType, int primitiveCount)
: base(verts, primitiveType, primitiveCount)
{
this.vertsBuffer = new VertexBuffer(Object3D.Game.GraphicsDevice, typeof(VertexPositionColorTexture), verts.Length, BufferUsage.WriteOnly);
this.vertsBuffer.SetData(verts, 0, verts.Length);
}
public override void Draw(BasicEffect effect)
{
//apply all changes
effect.CurrentTechnique.Passes[0].Apply();
//instruct gfx card to use vertsbuffer
Game.GraphicsDevice.SetVertexBuffer(vertsBuffer);
//draw
Game.GraphicsDevice.DrawPrimitives(PrimitiveType, 0, PrimitiveCount);
}
}
提前感谢您的帮助。它的伟大赞赏。