Example #1
0
        public DX11VertexGeometry BoxLine(Box settings)
        {
            float sx = 0.5f * settings.Size.X;
            float sy = 0.5f * settings.Size.Y;
            float sz = 0.5f * settings.Size.Z;

            Vector3 s3   = new Vector3(sx, sy, sz);
            Vector4 size = new Vector4(sx, sy, sz, 1.0f);

            DX11VertexGeometry geom = new DX11VertexGeometry(device);

            geom.Tag            = settings;
            geom.PrimitiveType  = settings.PrimitiveType;
            geom.Topology       = PrimitiveTopology.LineList;
            geom.VerticesCount  = 24;
            geom.VertexSize     = Pos4Vertex.VertexSize;
            geom.InputLayout    = Pos4Vertex.Layout;
            geom.HasBoundingBox = true;
            geom.BoundingBox    = new BoundingBox(-s3, s3);

            DataStream vertexstream = new DataStream(24 * Pos4Vertex.VertexSize, true, true);

            vertexstream.Position = 0;

            //Front Face
            vertexstream.Write <Vector4>(BoxData.BottomLeftFront.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.BottomRightFront.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.BottomRightFront.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.TopRightFront.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.TopRightFront.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.TopLeftFront.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.TopLeftFront.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.BottomLeftFront.MulComp(size));

            //Back face
            vertexstream.Write <Vector4>(BoxData.BottomLeftBack.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.BottomRightBack.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.BottomRightBack.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.TopRightBack.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.TopRightBack.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.TopLeftBack.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.TopLeftBack.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.BottomLeftBack.MulComp(size));

            //Connections
            vertexstream.Write <Vector4>(BoxData.BottomLeftFront.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.BottomLeftBack.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.TopLeftFront.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.TopLeftBack.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.TopRightFront.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.TopRightBack.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.BottomRightFront.MulComp(size));
            vertexstream.Write <Vector4>(BoxData.BottomRightBack.MulComp(size));

            var vbo = DX11VertexBuffer.CreateImmutable <Vector4>(device, vertexstream);

            geom.VertexBuffer = vbo.Buffer;
            vertexstream.Dispose();
            return(geom);
        }
Example #2
0
        public DX11IndexedGeometry LoadFromMesh(Assimp.Mesh mesh, AssimpLoadInformation loadInfo, bool allowRawView = false)
        {
            uint[] inds = mesh.GetIndices();

            if (inds.Length > 0 && mesh.VertexCount > 0)
            {
                int vertexsize;
                var layout = mesh.InputLayout(loadInfo, out vertexsize);

                BoundingBox bb;
                DataStream  ds = mesh.LoadVertices(loadInfo, vertexsize, out bb);

                DX11IndexedGeometry geom = new DX11IndexedGeometry(device)
                {
                    HasBoundingBox = true,
                    BoundingBox    = bb,
                    IndexBuffer    = DX11IndexBuffer.CreateImmutable(device, inds, allowRawView),
                    InputLayout    = layout,
                    PrimitiveType  = "AssimpModel",
                    Tag            = null,
                    Topology       = SharpDX.Direct3D.PrimitiveTopology.TriangleList,
                    VertexBuffer   = DX11VertexBuffer.CreateImmutable(device, mesh.VertexCount, vertexsize, ds, allowRawView)
                };

                ds.Dispose();
                return(geom);
            }

            return(null);
        }
Example #3
0
        public DX11VertexGeometry QuadLine(Quad settings)
        {
            Vector2 size = settings.Size;

            float sx = 0.5f * size.X;
            float sy = 0.5f * size.Y;

            DX11VertexGeometry geom = new DX11VertexGeometry(device);

            geom.Tag            = settings;
            geom.PrimitiveType  = settings.PrimitiveType;
            geom.Topology       = PrimitiveTopology.LineStrip;
            geom.InputLayout    = Pos4Vertex.Layout;
            geom.VerticesCount  = 5;
            geom.VertexSize     = Pos4Vertex.VertexSize;
            geom.HasBoundingBox = true;
            geom.BoundingBox    = new BoundingBox(new Vector3(-sx, -sy, 0.0f), new Vector3(sx, sy, 0.0f));

            Vector4[] verts = new Vector4[]
            {
                new Vector4(-sx, -sy, 0.0f, 1.0f),
                new Vector4(sx, -sy, 0.0f, 1.0f),
                new Vector4(sx, sy, 0.0f, 1.0f),
                new Vector4(-sx, sy, 0.0f, 1.0f),
                new Vector4(-sx, -sy, 0.0f, 1.0f)
            };
            geom.VertexBuffer = DX11VertexBuffer.CreateImmutable <Vector4>(device, verts).Buffer;
            return(geom);
        }
Example #4
0
        public void CreateImmutable()
        {
            Vector3[]        v   = new Vector3[16];
            DX11VertexBuffer vbo = DX11VertexBuffer.CreateImmutable <Vector3>(Device, v);

            Assert.IsNotNull(vbo.Buffer, "Buffer Is Null");

            vbo.Dispose();
        }
Example #5
0
        private DX11IndexedGeometry FromAppender(AbstractPrimitiveDescriptor descriptor, ListGeometryAppender appender, PrimitiveInfo info)
        {
            DX11IndexedGeometry geom = new DX11IndexedGeometry(device);

            geom.Tag            = descriptor;
            geom.PrimitiveType  = descriptor.PrimitiveType;
            geom.VertexBuffer   = DX11VertexBuffer.CreateImmutable(device, appender.Vertices.ToArray());
            geom.IndexBuffer    = DX11IndexBuffer.CreateImmutable(device, appender.Indices.ToArray());
            geom.InputLayout    = Pos4Norm3Tex2Vertex.Layout;
            geom.Topology       = PrimitiveTopology.TriangleList;
            geom.HasBoundingBox = info.IsBoundingBoxKnown;
            geom.BoundingBox    = info.BoundingBox;
            return(geom);
        }
        public DX11IndexedGeometry RoundRect(RoundRect settings)
        {
            Vector2 inner = settings.InnerRadius;
            float   outer = settings.OuterRadius;
            int     ires  = settings.CornerResolution;

            DX11IndexedGeometry geom = new DX11IndexedGeometry(device);

            geom.PrimitiveType = settings.PrimitiveType;
            geom.Tag           = settings;
            List <Pos4Norm3Tex2Vertex> vl = new List <Pos4Norm3Tex2Vertex>();
            List <int> il = new List <int>();

            int idx = 0;

            float ucy = Convert.ToSingle(inner.Y + outer);
            float ucx = Convert.ToSingle(inner.X + outer);

            float mx = ucx * 2.0f;
            float my = ucy * 2.0f;

            //Need 1 quad for center
            if (settings.EnableCenter)
            {
                idx = SetQuad(vl, il, 0.0f, 0.0f, inner.X, inner.Y, idx, mx, my);
            }

            //Need 2 quads up/down
            idx = SetQuad(vl, il, 0.0f, ucy, inner.X, (float)outer, idx, mx, my);
            idx = SetQuad(vl, il, 0.0f, -ucy, inner.X, (float)outer, idx, mx, my);

            //Need 2 quads left/right
            idx = SetQuad(vl, il, -ucx, 0.0f, (float)outer, inner.Y, idx, mx, my);
            idx = SetQuad(vl, il, ucx, 0.0f, (float)outer, inner.Y, idx, mx, my);

            float radius = (float)outer * 2.0f;

            //Add the 4 corners
            idx = SetSegment(vl, il, inner.X, inner.Y, 0.0f, radius, ires, idx, mx, my);
            idx = SetSegment(vl, il, -inner.X, inner.Y, 0.25f, radius, ires, idx, mx, my);
            idx = SetSegment(vl, il, -inner.X, -inner.Y, 0.5f, radius, ires, idx, mx, my);
            idx = SetSegment(vl, il, inner.X, -inner.Y, 0.75f, radius, ires, idx, mx, my);

            geom.VertexBuffer   = DX11VertexBuffer.CreateImmutable <Pos4Norm3Tex2Vertex>(device, vl.ToArray());
            geom.IndexBuffer    = DX11IndexBuffer.CreateImmutable(device, il.ToArray());
            geom.InputLayout    = Pos4Norm3Tex2Vertex.Layout;
            geom.Topology       = PrimitiveTopology.TriangleList;
            geom.HasBoundingBox = false;
            return(geom);
        }
Example #7
0
        private DX11IndexedGeometry QuadTextured()
        {
            DX11IndexedGeometry geom = new DX11IndexedGeometry(this.device);
            float sx = 1.0f;
            float sy = 1.0f;

            Pos4Tex2Vertex[] vertices = new Pos4Tex2Vertex[]
            {
                new Pos4Tex2Vertex()
                {
                    Position  = new Vector4(-sx, sy, 0.0f, 1.0f),
                    TexCoords = new Vector2(0, 0)
                },
                new Pos4Tex2Vertex()
                {
                    Position  = new Vector4(sx, sy, 0.0f, 1.0f),
                    TexCoords = new Vector2(1, 0)
                },
                new Pos4Tex2Vertex()
                {
                    Position  = new Vector4(-sx, -sy, 0.0f, 1.0f),
                    TexCoords = new Vector2(0, 1)
                },
                new Pos4Tex2Vertex()
                {
                    Position  = new Vector4(sx, -sy, 0.0f, 1.0f),
                    TexCoords = new Vector2(1, 1)
                },
            };
            int[] indices = new int[] { 0, 1, 3, 3, 2, 0 };

            geom.VertexBuffer             = DX11VertexBuffer.CreateImmutable(device, vertices);;
            geom.IndexBuffer              = DX11IndexBuffer.CreateImmutable(device, indices);
            geom.InputLayout              = Pos4Tex2Vertex.Layout;
            geom.VertexBuffer.InputLayout = geom.InputLayout;
            geom.Topology       = PrimitiveTopology.TriangleList;
            geom.HasBoundingBox = true;
            geom.BoundingBox    = new BoundingBox(new Vector3(-sx, -sy, 0.0f), new Vector3(sx, sy, 0.0f));

            return(geom);
        }
Example #8
0
        public DX11IndexedGeometry Box(Box settings)
        {
            DX11IndexedGeometry geom = new DX11IndexedGeometry(device);

            geom.Tag           = settings;
            geom.PrimitiveType = settings.PrimitiveType;

            DataStream vertexstream = new DataStream(24 * Pos4Norm3Tex2Vertex.VertexSize, true, true);

            vertexstream.Position = 0;

            var indexstream = new DataStream(36 * 4, true, true);

            float sx = 0.5f * settings.Size.X;
            float sy = 0.5f * settings.Size.Y;
            float sz = 0.5f * settings.Size.Z;

            Vector3 s3   = new Vector3(sx, sy, sz);
            Vector4 size = new Vector4(sx, sy, sz, 1.0f);

            this.WriteFrontFace(vertexstream, indexstream, size);
            this.WriteBackFace(vertexstream, indexstream, size);
            this.WriteRightFace(vertexstream, indexstream, size);
            this.WriteLeftFace(vertexstream, indexstream, size);
            this.WriteTopFace(vertexstream, indexstream, size);
            this.WriteBottomFace(vertexstream, indexstream, size);

            geom.VertexBuffer             = DX11VertexBuffer.CreateImmutable(device, 24, Pos4Norm3Tex2Vertex.VertexSize, vertexstream);
            geom.IndexBuffer              = DX11IndexBuffer.CreateImmutable(device, 36, indexstream, true);
            geom.InputLayout              = Pos4Norm3Tex2Vertex.Layout;
            geom.VertexBuffer.InputLayout = geom.InputLayout;
            geom.Topology       = PrimitiveTopology.TriangleList;
            geom.HasBoundingBox = true;
            geom.BoundingBox    = new BoundingBox(-s3, s3);

            vertexstream.Dispose();
            indexstream.Dispose();

            return(geom);
        }
        public DX11IndexedGeometry Segment(Segment settings)
        {
            SegmentBuilder       builder  = new SegmentBuilder();
            ListGeometryAppender appender = new ListGeometryAppender();
            PrimitiveInfo        info     = builder.GetPrimitiveInfo(settings);

            Vector3 max = new Vector3(float.MinValue, float.MinValue, float.MinValue);
            Vector3 min = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);

            builder.Construct(settings, (v, n, u) =>
                              { appender.AppendVertex(v, n, u); min = Vector3.Min(min, v); max = Vector3.Max(max, v); }, appender.AppendIndex);

            DX11IndexedGeometry geom = new DX11IndexedGeometry(device);

            geom.Tag            = settings;
            geom.PrimitiveType  = settings.PrimitiveType;
            geom.VertexBuffer   = DX11VertexBuffer.CreateImmutable(device, appender.Vertices.ToArray());
            geom.IndexBuffer    = DX11IndexBuffer.CreateImmutable(device, appender.Indices.ToArray());
            geom.InputLayout    = Pos4Norm3Tex2Vertex.Layout;
            geom.Topology       = PrimitiveTopology.TriangleList;
            geom.HasBoundingBox = true;
            geom.BoundingBox    = new BoundingBox(min, max);
            return(geom);
        }
        public DX11IndexedGeometry SegmentZ(SegmentZ settings)
        {
            int   res    = settings.Resolution;
            float cycles = settings.Cycles;
            float phase  = settings.Phase;
            float inner  = settings.InnerRadius;
            float z      = settings.Z;

            DX11IndexedGeometry geom = new DX11IndexedGeometry(device);

            geom.Tag           = settings;
            geom.PrimitiveType = settings.PrimitiveType;

            int vcount = res * 2;
            int icount = (res - 1) * 6;

            float inc = Convert.ToSingle((Math.PI * 2.0 * cycles) / (res - 1.0));
            float phi = Convert.ToSingle(phase * (Math.PI * 2.0));

            List <Pos4Norm3Tex2Vertex> vlist = new List <Pos4Norm3Tex2Vertex>();
            List <int> ilist = new List <int>();

            Pos4Norm3Tex2Vertex innerv = new Pos4Norm3Tex2Vertex();

            innerv.Normals = new Vector3(0.0f, 0.0f, 1.0f);

            Pos4Norm3Tex2Vertex outerv = new Pos4Norm3Tex2Vertex();

            outerv.Normals = new Vector3(0.0f, 0.0f, 1.0f);

            Pos4Norm3Tex2Vertex[] vertices = new Pos4Norm3Tex2Vertex[res * 2];

            #region Append front face
            for (int i = 0; i < res; i++)
            {
                float x = Convert.ToSingle(0.5 * inner * Math.Cos(phi));
                float y = Convert.ToSingle(0.5 * inner * Math.Sin(phi));

                innerv.Position = new Vector4(x, y, z, 1.0f);

                x = Convert.ToSingle(0.5 * Math.Cos(phi));
                y = Convert.ToSingle(0.5 * Math.Sin(phi));

                outerv.Position = new Vector4(x, y, z, 1.0f);

                vertices[i]       = innerv;
                vertices[i + res] = outerv;
                phi += inc;
            }

            int   indstep = 0;
            int[] indices = new int[icount];
            for (int i = 0; i < res - 1; i++)
            {
                //Triangle from low to high
                indices[indstep]     = i;
                indices[indstep + 1] = res + i;
                indices[indstep + 2] = i + 1;


                //Triangle from high to low
                indices[indstep + 3] = i + 1;
                indices[indstep + 4] = res + i;
                indices[indstep + 5] = res + i + 1;

                indstep += 6;
            }

            vlist.AddRange(vertices);
            ilist.AddRange(indices);
            #endregion

            #region Append Back Face
            //Second layer just has Z inverted
            for (int i = 0; i < res * 2; i++)
            {
                vertices[i].Position.Z = -vertices[i].Position.Z;
                vertices[i].Normals.Z  = -vertices[i].Normals.Z;
                phi += inc;
            }

            //Here we also flip triangles for cull
            indstep = 0;
            int offset = res * 2;
            for (int i = offset; i < offset + res - 1; i++)
            {
                //Triangle from low to high
                indices[indstep]     = i;
                indices[indstep + 2] = res + i;
                indices[indstep + 1] = i + 1;


                //Triangle from high to low
                indices[indstep + 3] = i + 1;
                indices[indstep + 5] = res + i;
                indices[indstep + 4] = res + i + 1;

                indstep += 6;
            }

            vlist.AddRange(vertices);
            ilist.AddRange(indices);
            #endregion


            //We need to append new set of indices, as we want nice normals
            #region Append Outer
            phi = Convert.ToSingle(phase * (Math.PI * 2.0));
            for (int i = 0; i < res; i++)
            {
                float x = Convert.ToSingle(0.5 * Math.Cos(phi));
                float y = Convert.ToSingle(0.5 * Math.Sin(phi));

                innerv.Position = new Vector4(x, y, z, 1.0f);
                outerv.Position = new Vector4(x, y, -z, 1.0f);
                innerv.Normals  = Vector3.Normalize(new Vector3(innerv.Position.X, innerv.Position.Y, 0.0f));
                outerv.Normals  = Vector3.Normalize(new Vector3(innerv.Position.X, innerv.Position.Y, 0.0f));

                vertices[i]       = innerv;
                vertices[i + res] = outerv;
                phi += inc;
            }

            indstep = 0;
            offset += (res * 2);
            for (int i = offset; i < offset + res - 1; i++)
            {
                //Triangle from low to high
                indices[indstep]     = i;
                indices[indstep + 1] = res + i;
                indices[indstep + 2] = i + 1;


                //Triangle from high to low
                indices[indstep + 3] = i + 1;
                indices[indstep + 4] = res + i;
                indices[indstep + 5] = res + i + 1;

                indstep += 6;
            }

            vlist.AddRange(vertices);
            ilist.AddRange(indices);
            #endregion

            #region Append Inner
            phi = Convert.ToSingle(phase * (Math.PI * 2.0));
            for (int i = 0; i < res; i++)
            {
                float x = Convert.ToSingle(0.5 * inner * Math.Cos(phi));
                float y = Convert.ToSingle(0.5 * inner * Math.Sin(phi));

                innerv.Position = new Vector4(x, y, z, 1.0f);
                outerv.Position = new Vector4(x, y, -z, 1.0f);
                innerv.Normals  = -Vector3.Normalize(new Vector3(innerv.Position.X, innerv.Position.Y, 0.0f));
                outerv.Normals  = -Vector3.Normalize(new Vector3(innerv.Position.X, innerv.Position.Y, 0.0f));

                vertices[i]       = innerv;
                vertices[i + res] = outerv;
                phi += inc;
            }

            indstep = 0;
            offset += (res * 2);
            for (int i = offset; i < offset + res - 1; i++)
            {
                //Triangle from low to high
                indices[indstep]     = i;
                indices[indstep + 2] = res + i;
                indices[indstep + 1] = i + 1;


                //Triangle from high to low
                indices[indstep + 3] = i + 1;
                indices[indstep + 5] = res + i;
                indices[indstep + 4] = res + i + 1;

                indstep += 6;
            }

            vlist.AddRange(vertices);
            ilist.AddRange(indices);
            #endregion

            #region Append Border

            //Append border low (quad)
            phi = Convert.ToSingle(phase * (Math.PI * 2.0));
            float x2 = Convert.ToSingle(0.5 * inner * Math.Cos(phi));
            float y2 = Convert.ToSingle(0.5 * inner * Math.Sin(phi));

            float x3 = Convert.ToSingle(0.5 * Math.Cos(phi));
            float y3 = Convert.ToSingle(0.5 * Math.Sin(phi));

            Pos4Norm3Tex2Vertex q1 = new Pos4Norm3Tex2Vertex();
            Pos4Norm3Tex2Vertex q2 = new Pos4Norm3Tex2Vertex();
            Pos4Norm3Tex2Vertex q3 = new Pos4Norm3Tex2Vertex();
            Pos4Norm3Tex2Vertex q4 = new Pos4Norm3Tex2Vertex();

            q1.Position = new Vector4(x2, y2, z, 1.0f);
            q2.Position = new Vector4(x2, y2, -z, 1.0f);
            q3.Position = new Vector4(x3, y3, z, 1.0f);
            q4.Position = new Vector4(x3, y3, -z, 1.0f);

            Vector3 e1 = new Vector3(q2.Position.X - q1.Position.X,
                                     q2.Position.Y - q1.Position.Y,
                                     q2.Position.Z - q1.Position.Z);

            Vector3 e2 = new Vector3(q3.Position.X - q2.Position.X,
                                     q3.Position.Y - q2.Position.Y,
                                     q3.Position.Z - q2.Position.Z);

            Vector3 n = Vector3.Cross(e1, e2);
            q1.Normals = n;
            q2.Normals = n;
            q3.Normals = n;
            q4.Normals = n;

            vlist.Add(q1); vlist.Add(q2); vlist.Add(q3); vlist.Add(q4);

            offset += (res * 2);
            ilist.Add(offset); ilist.Add(offset + 1); ilist.Add(offset + 2);
            ilist.Add(offset + 2); ilist.Add(offset + 1); ilist.Add(offset + 3);


            offset += 4;

            //Totally crapply unoptimized, but phi can be negative
            phi = Convert.ToSingle(phase * (Math.PI * 2.0));
            for (int i = 0; i < res - 1; i++)
            {
                phi += inc;
            }

            x2 = Convert.ToSingle(0.5 * inner * Math.Cos(phi));
            y2 = Convert.ToSingle(0.5 * inner * Math.Sin(phi));

            x3 = Convert.ToSingle(0.5 * Math.Cos(phi));
            y3 = Convert.ToSingle(0.5 * Math.Sin(phi));

            q1.Position = new Vector4(x2, y2, z, 1.0f);
            q2.Position = new Vector4(x2, y2, -z, 1.0f);
            q3.Position = new Vector4(x3, y3, z, 1.0f);
            q4.Position = new Vector4(x3, y3, -z, 1.0f);

            e1 = new Vector3(q2.Position.X - q1.Position.X,
                             q2.Position.Y - q1.Position.Y,
                             q2.Position.Z - q1.Position.Z);

            e2 = new Vector3(q3.Position.X - q2.Position.X,
                             q3.Position.Y - q2.Position.Y,
                             q3.Position.Z - q2.Position.Z);

            n          = Vector3.Cross(e2, e1);
            q1.Normals = n;
            q2.Normals = n;
            q3.Normals = n;
            q4.Normals = n;

            vlist.Add(q1); vlist.Add(q2); vlist.Add(q3); vlist.Add(q4);

            ilist.Add(offset); ilist.Add(offset + 2); ilist.Add(offset + 1);
            ilist.Add(offset + 2); ilist.Add(offset + 3); ilist.Add(offset + 1);



            #endregion

            float minx = float.MaxValue, miny = float.MaxValue, minz = float.MaxValue;
            float maxx = float.MinValue, maxy = float.MinValue, maxz = float.MinValue;

            foreach (Pos4Norm3Tex2Vertex v in vlist)
            {
                minx = v.Position.X < minx ? v.Position.X : minx;
                miny = v.Position.Y < miny ? v.Position.Y : miny;
                minz = v.Position.Z < minz ? v.Position.Z : minz;

                maxx = v.Position.X > maxx ? v.Position.X : maxx;
                maxy = v.Position.Y > maxy ? v.Position.Y : maxy;
                maxz = v.Position.Z > maxz ? v.Position.Z : maxz;
            }

            geom.VertexBuffer = DX11VertexBuffer.CreateImmutable <Pos4Norm3Tex2Vertex>(device, vlist.ToArray());
            geom.IndexBuffer  = DX11IndexBuffer.CreateImmutable(device, ilist.ToArray());
            geom.InputLayout  = Pos4Norm3Tex2Vertex.Layout;
            geom.Topology     = PrimitiveTopology.TriangleList;

            geom.HasBoundingBox = true;
            geom.BoundingBox    = new BoundingBox(new Vector3(minx, miny, minz), new Vector3(maxx, maxy, maxz));

            return(geom);
        }
        public DX11IndexedGeometry Polygon2d(Polygon2d settings)
        {
            DX11IndexedGeometry geom = new DX11IndexedGeometry(device);

            geom.Tag           = settings;
            geom.PrimitiveType = settings.PrimitiveType;

            int count = settings.Vertices.Length;

            Pos4Norm3Tex2Vertex[] verts = new Pos4Norm3Tex2Vertex[count + 1];

            float cx = 0;
            float cy = 0;
            float x = 0, y = 0;

            float minx = float.MaxValue, miny = float.MaxValue;
            float maxx = float.MinValue, maxy = float.MinValue;

            for (int j = 0; j < count; j++)
            {
                verts[j + 1].Position  = new Vector4(settings.Vertices[j].X, settings.Vertices[j].Y, 0.0f, 1.0f);
                verts[j + 1].Normals   = new Vector3(0, 0, 1);
                verts[j + 1].TexCoords = new Vector2(0.0f, 0.0f);
                cx += x;
                cy += y;

                if (x < minx)
                {
                    minx = x;
                }
                if (x > maxx)
                {
                    maxx = x;
                }
                if (y < miny)
                {
                    miny = y;
                }
                if (y > maxy)
                {
                    maxy = y;
                }
            }

            verts[0].Position  = new Vector4(cx / (float)count, cy / (float)count, 0.0f, 1.0f);
            verts[0].Normals   = new Vector3(0, 0, 1);
            verts[0].TexCoords = new Vector2(0.5f, 0.5f);

            float w = maxx - minx;
            float h = maxy - miny;

            for (int j = 0; j < count; j++)
            {
                verts[0].TexCoords = new Vector2((verts[j + 1].Position.X - minx) / w, (verts[j + 1].Position.Y - miny) / h);
            }

            List <int> inds = new List <int>();

            for (int j = 0; j < count - 1; j++)
            {
                inds.Add(0);
                inds.Add(j + 1);
                inds.Add(j + 2);
            }

            inds.Add(0);
            inds.Add(verts.Length - 1);
            inds.Add(1);

            geom.VertexBuffer = DX11VertexBuffer.CreateImmutable(device, verts);
            geom.IndexBuffer  = DX11IndexBuffer.CreateImmutable(device, inds.ToArray());
            geom.InputLayout  = Pos4Norm3Tex2Vertex.Layout;
            geom.Topology     = PrimitiveTopology.TriangleList;


            geom.HasBoundingBox = true;
            geom.BoundingBox    = new BoundingBox()
            {
                Minimum = new Vector3(minx, miny, 0.0f),
                Maximum = new Vector3(maxx, maxy, 0.0f)
            };

            return(geom);
        }