Example #1
0
        /// <summary>
        /// Tesselates the specified path, notifying the
        /// <see cref="UMD.HCIL.PiccoloDirect3D.Util.TesselationVisitor">TesselationVisitor</see>
        /// as each new triangle primitive is added.
        /// </summary>
        /// <param name="path">The path to tesselate.</param>
        /// <param name="visitor">The tesselation visitor to notify.</param>
        public virtual void Tesselate(GraphicsPath path, TesselationVisitor visitor)
        {
            this.visitor = visitor;

            switch (path.FillMode)
            {
            case FillMode.Alternate:                     //even/odd
                P3Util.SetWindingRule(tess, P3Util.GlTessWinding.WindingOdd);
                break;

            case FillMode.Winding:                     //nonzero
                P3Util.SetWindingRule(tess, P3Util.GlTessWinding.WindingNonzero);
                break;
            }

            P3Util.GluTessBeginPolygon(tess, IntPtr.Zero);

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

            PointF[] points = path.PathPoints;

            while (pi.NextSubpath(path, out isClosed) != 0)
            {
                byte type;
                int  start, end;
                while (pi.NextPathType(out type, out start, out end) != 0)
                {
                    PathPointType ppType = (PathPointType)type;

                    P3Util.GluTessBeginContour(tess);

                    for (int i = start; i <= end; i++)
                    {
                        PointF   point  = points[i];
                        double[] coords = new double[3];
                        coords[0] = point.X;
                        coords[1] = point.Y;
                        coords[2] = 0;
                        GCHandle handle = GCHandle.Alloc(coords, GCHandleType.Pinned);
                        P3Util.GluTessVertex(tess, coords, (IntPtr)handle);
                        handles.Add(handle);
                    }

                    P3Util.GluTessEndContour(tess);
                }
            }

            P3Util.GluTessEndPolygon(tess);

            ClearHandles();
        }