0

Hey im making a game out of primitive objects. To make these objects im using the Vertex Buffer. The problem im having is that when i am rendering a cube it looks perfect... But when i scale it bigger the cube deforms leaving holes and jagged ends. Ive tried numerous ways to make the cube and i cant figure it out. The idea of scaling the cube bigger is to make a Skybox.

Here is some images:

Deformed Cube: https://i.stack.imgur.com/0WWkI.png

Perfect small cube: https://i.stack.imgur.com/amb4B.png

My code:

Path Data for the Skybox using vertices.

   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);
        }

    }

Thanks for the help in advance. Its greaty appreciated.

  • Fixed the top part but the bottom part remains deformed... The bottom corner appears to be connected to the top corner... No matter what i do it stays that way – user3455015 Apr 20 '14 at 23:44
  • Seems that you have to change your far and near camera plane distances – Blau Apr 21 '14 at 14:07

0 Answers0