Exemple #1
0
        private void CreateVertexBinding()
        {
            RemoveAndDispose(ref indexBuffer);

            // Retrieve our SharpDX.Direct3D11.Device1 instance
            var device = this.DeviceManager.Direct3DDevice;
            var color  = Color.SaddleBrown;
            var data   = new Vertex[] {
                /*  Vertex Position    Color */
                new Vertex(new Vector3(-1f, 1f, -.5f), color),  // 0-Top-left
                new Vertex(new Vector3(1f, 1f, -.5f), color),   // 1-Top-right
                new Vertex(new Vector3(1f, -1f, -.5f), color),  // 2-Base-right
                new Vertex(new Vector3(-1f, -1f, -.5f), color), // 3-Base-left

                new Vertex(new Vector3(-1f, 1f, .5f), color),   // 4-Top-left
                new Vertex(new Vector3(1f, 1f, .5f), color),    // 5-Top-right
                new Vertex(new Vector3(1f, -1f, .5f), color),   // 6-Base-right
                new Vertex(new Vector3(-1f, -1f, .5f), color),  // 7-Base-left
            };

            // Create vertex buffer for cube
            buffer_        = ToDispose(Buffer.Create(device, BindFlags.VertexBuffer, data));
            vertexBinding_ = new VertexBufferBinding(buffer_, Utilities.SizeOf <Vertex>(), 0);

            // Front    Right    Top      Back     Left     Bottom
            // v0    v1 v1    v5 v1    v0 v5    v4 v4    v0 v3    v2
            // |-----|  |-----|  |-----|  |-----|  |-----|  |-----|
            // | \ A |  | \ A |  | \ A |  | \ A |  | \ A |  | \ A |
            // | B \ |  | B \ |  | B \ |  | B \ |  | B \ |  | B \ |
            // |-----|  |-----|  |-----|  |-----|  |-----|  |-----|
            // v3    v2 v2    v6 v5    v4 v6    v7 v7    v3 v7    v6
            indexBuffer = ToDispose(Buffer.Create(device, BindFlags.IndexBuffer, new ushort[] {
                0, 1, 2, // Front A
                0, 2, 3, // Front B
                1, 5, 6, // Right A
                1, 6, 2, // Right B
                1, 0, 4, // Top A
                1, 4, 5, // Top B
                5, 4, 7, // Back A
                5, 7, 6, // Back B
                4, 0, 3, // Left A
                4, 3, 7, // Left B
                3, 2, 6, // Bottom A
                3, 6, 7, // Bottom B
            }));
            //indexBuffer = ToDispose(Buffer.Create(device, BindFlags.IndexBuffer, new ushort[] {
            //    2, 1, 0, // Front A
            //    0, 3, 2, // Front B
            //    6, 5, 1, // Right A
            //    1, 2, 6, // Right B
            //    4, 0, 1, // Top A
            //    1, 5, 4, // Top B
            //    7, 4, 5, // Back A
            //    5, 6, 7, // Back B
            //    3, 0, 4, // Left A
            //    4, 7, 3, // Left B
            //    6, 2, 3, // Bottom A
            //    3, 7, 6, // Bottom B
            //}));
            PrimitiveCount = Utilities.SizeOf <Vertex>();

            var max    = data.Max().Position;
            var min    = data.Min().Position;
            var center = (max - min) * .5f;

            meshExtent = new Mesh.MeshExtent
            {
                Min    = min,
                Max    = max,
                Radius = 0.5f,
                Center = center
            };
        }