Ejemplo n.º 1
0
        /// <summary>
        /// Triangulates the shape and adds all of the points (in triangle list layout) to the provided output.
        /// </summary>
        /// <param name="output">The output list.</param>
        public void Triangulate(IList <Vector2> output, Vector2 offset, float scale = 1.0f)
        {
            Points.Reverse();
            SweepContext tcx = new SweepContext();

            tcx.AddPoints(Points);

            // Hole edges
            foreach (Shape h in Holes)
            {
                tcx.AddHole(h.Points);
            }

            tcx.InitTriangulation();
            Sweep sweep = new Sweep();

            sweep.Triangulate(tcx);

            List <Triangle> triangles = tcx.GetTriangles();

            foreach (Triangle tri in triangles)
            {
                //tri.ReversePointFlow();
                output.Add(((Vector2)tri.Points[0] * scale) + offset);
                output.Add(((Vector2)tri.Points[2] * scale) + offset);
                output.Add(((Vector2)tri.Points[1] * scale) + offset);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Triangulates the shape and adds all of the triangles to the provided output.
        /// </summary>
        /// <param name="output">The output list.</param>
        public void Triangulate(IList <Triangle> output)
        {
            SweepContext tcx = new SweepContext();

            tcx.AddPoints(Points);

            foreach (Shape p in Holes)
            {
                tcx.AddHole(p.Points);
            }

            tcx.InitTriangulation();
            Sweep sweep = new Sweep();

            sweep.Triangulate(tcx);

            List <Triangle> triangles = tcx.GetTriangles();

            foreach (Triangle tri in triangles)
            {
                output.Add(tri);
            }
        }