Ejemplo n.º 1
0
        public Poly MergeList()
        {
            Brush clippedList = CopyList();
            Brush clip = clippedList;
            Brush brush = null;
            Poly polyList = null;

            bool clipOnPlane = false;


            for (int i = 0; i < GetNumberOfBrushes; i++)
            {
                brush = this;
                clipOnPlane = false;

                for (int j = 0; j < GetNumberOfBrushes; j++)
                {
                    if (i == j)
                    {
                        clipOnPlane = true;
                    }
                    else
                    {
                        if (clip.AABBIntersect(brush))
                        {
                            clip.ClipToBrush(brush, clipOnPlane);
                        }
                    }

                    brush = brush.Next;
                }

                clip = clip.Next;
            }

            clip = clippedList;

            while (clip != null)
            {
                if (clip.GetNumberOfPolys != 0)
                {
                    // Extract brushes left over polygons and add them to the list
                    Poly p = clip.Polys.CopyList();

                    if (polyList == null)
                    {
                        polyList = p;
                    }
                    else
                    {
                        polyList.AddPoly(p);
                    }

                    clip = clip.Next;
                }
                else
                {
                    // Brush has no polygons and should be deleted
                    if (clip == clippedList)
                    {
                        clip = clippedList.Next;
                        clippedList.SetNext(null);
                        clippedList = clip;
                    }
                    else
                    {
                        Brush temp = clippedList;
                        while (temp != null)
                        {
                            if (temp.Next == clip)
                                break;

                            temp = temp.Next;
                        }

                        temp.Next = clip.Next;
                        clip.SetNext(null);
                        clip = temp.Next;
                    }
                }
            }

            return polyList;
        }