Esempio n. 1
0
        public void Create(short prismSides, float baseRadius, float height)
        {
            topBase = new Base();
            bottomBase = new Base();
            side = new Side();

            topBase.Create(prismSides, baseRadius, height, true);
            bottomBase.Create(prismSides, baseRadius, 0, false, topBase.Vertices.Length);
            side.Create(prismSides, bottomBase, topBase);

            side.GenerateNormals();

            indices = new short[topBase.Indices.Length * 2 + side.Indices.Length];
            topBase.Indices.CopyTo(indices, 0);
            bottomBase.Indices.CopyTo(indices, topBase.Indices.Length);
            side.Indices.CopyTo(indices, topBase.Indices.Length + bottomBase.Indices.Length);

            vertices = new VertexPositionNormalTexture[topBase.Vertices.Length * 4];
            topBase.Vertices.CopyTo(vertices, 0);
            bottomBase.Vertices.CopyTo(vertices, topBase.Vertices.Length);
            side.Vertices.CopyTo(vertices, topBase.Vertices.Length + bottomBase.Vertices.Length);

            primitiveCountPerBase = prismSides*2-1;
            primitiveCountSide = prismSides*2;

            indexBuffer = new IndexBuffer(graphicsDevice, typeof(short),
                indices.Length, BufferUsage.WriteOnly);
            vertexBuffer = new VertexBuffer(graphicsDevice, VertexPositionNormalTexture.VertexDeclaration,
                vertices.Length, BufferUsage.WriteOnly);

            vertexBuffer.SetData(vertices);
            indexBuffer.SetData(indices);
        }