Beispiel #1
0
        protected static void _PrepareLine(ref Internal.VertexBuffer <GeometryVertex> vb, ref Internal.IndexBuffer ib, ref GeometryDrawCall dc)
        {
            var vw = vb.GetWriter(2);
            var iw = ib.GetWriter(LineIndices.Length, ref vw);

            vw.Write(MakeVertex(dc.Vector0.X, dc.Vector0.Y, dc.Z, dc.Color0));
            vw.Write(MakeVertex(dc.Vector1.X, dc.Vector1.Y, dc.Z, dc.Color1));

            iw.Write(LineIndices);
        }
Beispiel #2
0
        public static unsafe void _PrepareRing(ref Internal.VertexBuffer <GeometryVertex> vb, ref Internal.IndexBuffer ib, ref GeometryDrawCall dc)
        {
            int numPoints = ComputeRingPoints(ref dc.Vector2);

            const int vertexStride = 2;
            const int indexStride  = 6;

            var vw = vb.GetWriter(numPoints * vertexStride);
            var iw = ib.GetWriter((numPoints - 1) * indexStride, ref vw);

            float a = dc.Scalar0;
            float step = (float)((dc.Scalar1 - dc.Scalar0) / (numPoints - 1));
            float cos, sin;
            float colorA = 0, colorStep = 1.0f / (numPoints - 1);
            var   vertexInner = new GeometryVertex(new Vector3(0, 0, dc.Z), dc.Color0);
            var   vertexOuter = new GeometryVertex(new Vector3(0, 0, dc.Z), dc.Color1);

            fixed(GeometryVertex *pVertices = &vw.Storage.Array[vw.Storage.Offset])
            fixed(ushort *pIndices = &iw.Storage.Array[iw.Storage.Offset])
            for (int i = 0, j = 0, k = 0; i < numPoints; i++, j += vertexStride, k += indexStride)
            {
                cos = (float)Math.Cos(a);
                sin = (float)Math.Sin(a);

                vertexInner.Position.X = dc.Vector0.X + (float)(cos * dc.Vector1.X);
                vertexInner.Position.Y = dc.Vector0.Y + (float)(sin * dc.Vector1.Y);
                vertexInner.Color      = Color.Lerp(dc.Color0, dc.Color2, colorA);
                pVertices[j]           = vertexInner;

                vertexOuter.Position.X = dc.Vector0.X + (float)(cos * dc.Vector2.X);
                vertexOuter.Position.Y = dc.Vector0.Y + (float)(sin * dc.Vector2.Y);
                vertexOuter.Color      = Color.Lerp(dc.Color1, dc.Color3, colorA);
                pVertices[j + 1]       = vertexOuter;

                if (i == (numPoints - 1))
                {
                    break;
                }

                pIndices[k]     = (ushort)(j + vw.IndexOffset);
                pIndices[k + 1] = (ushort)(j + 1 + vw.IndexOffset);
                pIndices[k + 2] = (ushort)(j + 3 + vw.IndexOffset);
                pIndices[k + 3] = (ushort)(j + 2 + vw.IndexOffset);
                pIndices[k + 4] = (ushort)(j + vw.IndexOffset);
                pIndices[k + 5] = (ushort)(j + 3 + vw.IndexOffset);

                a      += step;
                colorA += colorStep;
            }
        }
Beispiel #3
0
        protected static void _PrepareQuadBorder(ref Internal.VertexBuffer <GeometryVertex> vb, ref Internal.IndexBuffer ib, ref GeometryDrawCall dc)
        {
            var vw = vb.GetWriter(8);
            var iw = ib.GetWriter(QuadBorderIndices.Length, ref vw);

            var tl = dc.Vector0;
            var br = dc.Vector1;

            var border = dc.Scalar0;

            var vInner = new GeometryVertex(new Vector3(tl.X, tl.Y, dc.Z), dc.Color0);
            var vOuter = new GeometryVertex(new Vector3(tl.X - border, tl.Y - border, dc.Z), dc.Color1);

            vw.Write(ref vInner);
            vw.Write(ref vOuter);

            vInner.Position.X = br.X;
            vOuter.Position.X = br.X + border;

            vw.Write(ref vInner);
            vw.Write(ref vOuter);

            vInner.Position.Y = br.Y;
            vOuter.Position.Y = br.Y + border;

            vw.Write(ref vInner);
            vw.Write(ref vOuter);

            vInner.Position.X = tl.X;
            vOuter.Position.X = tl.X - border;

            vw.Write(ref vInner);
            vw.Write(ref vOuter);

            iw.Write(QuadBorderIndices);
        }