Exemplo n.º 1
0
        public void UpdateSegments(BodyPoint[] pts, ref BezierPathSegment[] segs)
        {
            float y = -1f;

            for (int i = 0; i < pts.Length; i++)
            {
                BodyPoint point = pts[i];

                // Next point...

                bool      last      = i >= pts.Length - 1;
                BodyPoint nextPoint = last ? pts[0] : pts[i + 1];


                // UPDATE segment

                segs[i].P0.x = point.p.x;
                segs[i].P0.y = point.p.y * y;

                segs[i].P1.x = point.p.x + point.o.x;
                segs[i].P1.y = (point.p.y + point.o.y) * y;

                segs[i].P2.x = nextPoint.p.x + nextPoint.i.x;
                segs[i].P2.y = (nextPoint.p.y + nextPoint.i.y) * y;
            }

            int l = segs.Length - 1;

            segs[l].P0.x = pts[0].p.x;
            segs[l].P0.y = pts[0].p.y * y;

            segs[l].P1.x = segs[l].P1.y = segs[l].P2.x = segs[l].P2.y = 0;
        }
Exemplo n.º 2
0
        public BezierPathSegment[] ConvertPointsToSegments(BodyPoint[] pts)
        {
            float y = -1f;

            int cnt = pts.Length + (closed ? 1 : 0);

            BezierPathSegment[] segs = new BezierPathSegment[cnt];

            int i = 0;

            for (int j = 0; j < pts.Length; j++)
            {
                BodyPoint point = pts[j];

                // Next point...

                bool      last      = i >= pts.Length - 1;
                BodyPoint nextPoint = last ? pts[0] : pts[i + 1];


                // Make segment

                BezierPathSegment s = new BezierPathSegment()
                {
                    P0 = new Vector2(point.p.x, point.p.y * y),
                    P1 = new Vector2((point.p.x + point.o.x), (point.p.y + point.o.y) * y),
                    P2 = new Vector2((nextPoint.p.x + nextPoint.i.x), (nextPoint.p.y + nextPoint.i.y) * y)
                };

                segs[i] = s;
                i      += 1;
            }

            if (pts.Length > 0 && i == cnt - 1)
            {
                BezierPathSegment final = new BezierPathSegment()
                {
                    P0 = new Vector2(pts[0].p.x, pts[0].p.y * y)
                };

                segs[i] = final;
            }


            /* READOUT */

            //foreach (BezierPathSegment s in segs)
            //{
            //    Debug.Log("P0: " + s.P0 + "  P1: " + s.P1 + "  P2: " + s.P2);
            //}

            return(segs);
        }