コード例 #1
0
        private static List <List <Vec2> > PolygonToTriangleStrips(Dictionary <Vec2, int> .KeyCollection keyCollection)
        {
            List <Vec2> temp = new List <Vec2>();

            foreach (Vec2 v in keyCollection)
            {
                temp.Add(v);
            }
            Polygon             p   = new Polygon(temp);
            TriStrip            t   = p.ToTriangleStrip();
            List <List <Vec2> > ret = new List <List <Vec2> >();

            if (t.Count == 0)
            {
                return(ret); // throw new Exception("No triangle strip");
            }
            foreach (List <Vec2d> vl in t.Strips)
            {
                List <Vec2> vertList = new List <Vec2>();
                foreach (Vec2d v in vl)
                {
                    vertList.Add(GetFromList(temp, new Vec2((float)v.X, (float)v.Y)));
                }
                ret.Add(vertList);
            }
            return(ret);
        }
コード例 #2
0
        public static TriStrip PolygonToTristrip(Polygon polygon)
        {
            gpc_tristrip gpc_strip = new gpc_tristrip();
            gpc_polygon  gpc_pol   = GpcWrapper.PolygonTo_gpc_polygon(polygon);

            gpc_polygon_to_tristrip(ref gpc_pol, ref gpc_strip);
            TriStrip tristrip = GpcWrapper.gpc_strip_ToTristrip(gpc_strip);

            GpcWrapper.Free_gpc_polygon(gpc_pol);
            GpcWrapper.gpc_free_tristrip(ref gpc_strip);

            return(tristrip);
        }
コード例 #3
0
        public static TriStrip ClipToTristrip(GpcOperation operation, Polygon subject_polygon, Polygon clip_polygon)
        {
            gpc_tristrip gpc_strip           = new gpc_tristrip();
            gpc_polygon  gpc_subject_polygon = GpcWrapper.PolygonTo_gpc_polygon(subject_polygon);
            gpc_polygon  gpc_clip_polygon    = GpcWrapper.PolygonTo_gpc_polygon(clip_polygon);

            gpc_tristrip_clip(operation, ref gpc_subject_polygon, ref gpc_clip_polygon, ref gpc_strip);
            TriStrip tristrip = GpcWrapper.gpc_strip_ToTristrip(gpc_strip);

            GpcWrapper.Free_gpc_polygon(gpc_subject_polygon);
            GpcWrapper.Free_gpc_polygon(gpc_clip_polygon);
            GpcWrapper.gpc_free_tristrip(ref gpc_strip);

            return(tristrip);
        }
コード例 #4
0
        internal static List <List <Vec2i> > PolygonToTriangleStrips(List <Vec2i> vecs)
        {
            Polygon              p   = new Polygon(vecs);
            TriStrip             t   = p.ToTriangleStrip();
            List <List <Vec2i> > ret = new List <List <Vec2i> >();

            if (t.Count == 0)
            {
                return(ret); // throw new Exception("No triangle strip");
            }
            foreach (List <Vec2d> vl in t.Strips)
            {
                ret.Add(Vec2i.FromVec2dList(vl));
            }
            return(ret);
        }
コード例 #5
0
        private static TriStrip gpc_strip_ToTristrip(gpc_tristrip gpc_strip)
        {
            int      numStrips = gpc_strip.num_strips;
            TriStrip tristrip  = new TriStrip(numStrips);
            IntPtr   ptr       = gpc_strip.strip;

            for (int i = 0; i < numStrips; ++i)
            {
                gpc_vertex_list gpc_vtx_list = (gpc_vertex_list)Marshal.PtrToStructure(ptr, typeof(gpc_vertex_list));
                int             numVertices  = gpc_vtx_list.num_vertices;
                tristrip[i].Capacity = numVertices;
                IntPtr ptr2 = gpc_vtx_list.vertex;
                for (int j = 0; j < numVertices; ++j)
                {
                    gpc_vertex gpc_vtx = (gpc_vertex)Marshal.PtrToStructure(ptr2, typeof(gpc_vertex));
                    tristrip[i].Add(new Vec2d(gpc_vtx.x, gpc_vtx.y));
                    ptr2 = (IntPtr)(((int)ptr2) + Marshal.SizeOf(gpc_vtx));
                }
                ptr = (IntPtr)(((int)ptr) + Marshal.SizeOf(gpc_vtx_list));
            }
            return(tristrip);
        }