Exemple #1
0
        /// <summary>
        /// Renders the list of primitives to the device.
        /// </summary>
        /// <param name="device">The device to use for rendering the primitives.</param>
        /// <param name="renderList">The list of primitives to render.</param>
        protected virtual void Render(Device device, ArrayList renderList)
        {
            PointF[] points = (PointF[])renderList.ToArray(typeof(PointF));
            device.VertexFormat = CustomVertex.PositionColored.Format;

            for (int i = 0; i < renderListTypes.Count; i++)
            {
                PrimitiveTypeInfo pti = (PrimitiveTypeInfo)renderListTypes[i];
                int numVerts          = (pti.End - pti.Start + 1);

                CustomVertex.PositionColored[] colVerts = new CustomVertex.PositionColored[numVerts];
                P3Util.CreateColoredVertexList(colVerts, points, pti.Start, 0, numVerts, pti.Color);

                switch (pti.Type)
                {
                case PrimitiveType.TriangleFan:
                    device.DrawUserPrimitives(PrimitiveType.TriangleFan, colVerts.Length - 2, colVerts);
                    break;

                case PrimitiveType.TriangleList:
                    device.DrawUserPrimitives(PrimitiveType.TriangleList, colVerts.Length / 3, colVerts);
                    break;

                case PrimitiveType.TriangleStrip:
                    device.DrawUserPrimitives(PrimitiveType.TriangleStrip, colVerts.Length - 2, colVerts);
                    break;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Renders the flattened path to the device using the specified color.
        /// </summary>
        /// <param name="device">The device to use for rendering the path.</param>
        /// <param name="color">The color to use for the vertices.</param>
        /// <param name="flattenedPath">The path to render.</param>
        protected virtual void Render(Device device, int color, GraphicsPath flattenedPath)
        {
            PointF[] points = flattenedPath.PathPoints;
            device.VertexFormat = CustomVertex.PositionColored.Format;

            bool isClosed;
            GraphicsPathIterator pi = new GraphicsPathIterator(flattenedPath);

            while (pi.NextSubpath(flattenedPath, out isClosed) != 0)
            {
                byte type;
                int  start, end;

                while (pi.NextPathType(out type, out start, out end) != 0)
                {
                    int numDistinctPoints = end - start + 1;
                    int totNumPoints      = numDistinctPoints;
                    if (isClosed)
                    {
                        totNumPoints++;
                    }

                    CustomVertex.PositionColored[] colVerts = new CustomVertex.PositionColored[totNumPoints];
                    P3Util.CreateColoredVertexList(colVerts, points, start, 0, numDistinctPoints, color);

                    if (isClosed)
                    {
                        colVerts[numDistinctPoints] = colVerts[0];
                    }

                    device.DrawUserPrimitives(PrimitiveType.LineStrip, totNumPoints - 1, colVerts);
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Overridden.  See <see cref="P3Node.FillVertexBuffer">P3Node.FillVertexBuffer</see>.
        /// </summary>
        protected override void FillVertexBuffer(VertexBuffer vb)
        {
            GraphicsStream stm = vb.Lock(0, 0, 0);

            CustomVertex.PositionColored[] colVerts = new CustomVertex.PositionColored[renderList.Count];

            PointF[] points = (PointF[])renderList.ToArray(typeof(PointF));
            foreach (PrimitiveTypeInfo pti in renderListTypes)
            {
                P3Util.CreateColoredVertexList(colVerts, points, pti.Start, pti.Start, pti.End - pti.Start + 1, pti.Color);
            }

            stm.Write(colVerts);
            vb.Unlock();
        }