Пример #1
0
        private void PathCurveTo(string coords, PathSegment.Type type, bool relative)
        {
            PathSegment[] segment = ParsePathSegment(coords, type);
            for (int i = 0; i < segment.Length; i++)
            {
                SplinePoint p = buffer.GetLastPoint();
                p.type = SplinePoint.Type.Broken;

                //Get the control points
                Vector3 startPoint   = p.position;
                Vector3 endPoint     = segment[i].endPoint;
                Vector3 startTangent = segment[i].startTangent;
                Vector3 endTangent   = segment[i].endTangent;

                switch (type)
                {
                case PathSegment.Type.CubicShort: startTangent = startPoint - p.tangent; break;

                case PathSegment.Type.Quadratic:
                    buffer.tangent = segment[i].startTangent;
                    startTangent   = startPoint + 2f / 3f * (buffer.tangent - startPoint);
                    endTangent     = endPoint + 2f / 3f * (buffer.tangent - endPoint);
                    break;

                case PathSegment.Type.QuadraticShort:
                    Vector3 reflection = startPoint + (startPoint - buffer.tangent);
                    startTangent = startPoint + 2f / 3f * (reflection - startPoint);
                    endTangent   = endPoint + 2f / 3f * (reflection - endPoint);
                    break;
                }

                if (type == PathSegment.Type.CubicShort || type == PathSegment.Type.QuadraticShort)
                {
                    p.type = SplinePoint.Type.SmoothMirrored;                                                                                 //Smooth the previous point
                }
                else
                {
                    if (relative)
                    {
                        p.SetTangent2Position(startPoint + startTangent);
                    }
                    else
                    {
                        p.SetTangent2Position(startTangent);
                    }
                }
                buffer.SetLastPoint(p);
                if (relative)
                {
                    buffer.position += endPoint;
                    buffer.tangent   = startPoint + endTangent;
                }
                else
                {
                    buffer.position = endPoint;
                    buffer.tangent  = endTangent;
                }
                buffer.CreateBroken();
            }
        }
Пример #2
0
        private void PathCurveTo(string coords, PathSegment.Type type, bool relative)
        {
            PathSegment[] array = ParsePathSegment(coords, type);
            for (int i = 0; i < array.Length; i++)
            {
                SplinePoint lastPoint = buffer.GetLastPoint();
                lastPoint.type = SplinePoint.Type.Broken;
                Vector3 position = lastPoint.position;
                Vector3 endPoint = array[i].endPoint;
                Vector3 vector   = array[i].startTangent;
                Vector3 vector2  = array[i].endTangent;
                switch (type)
                {
                case PathSegment.Type.CubicShort:
                    vector = position - lastPoint.tangent;
                    break;

                case PathSegment.Type.Quadratic:
                    buffer.tangent = array[i].startTangent;
                    vector         = position + 2f / 3f * (buffer.tangent - position);
                    vector2        = endPoint + 2f / 3f * (buffer.tangent - endPoint);
                    break;

                case PathSegment.Type.QuadraticShort:
                {
                    Vector3 a = position + (position - buffer.tangent);
                    vector  = position + 2f / 3f * (a - position);
                    vector2 = endPoint + 2f / 3f * (a - endPoint);
                    break;
                }
                }
                if (type == PathSegment.Type.CubicShort || type == PathSegment.Type.QuadraticShort)
                {
                    lastPoint.type = SplinePoint.Type.SmoothMirrored;
                }
                else if (relative)
                {
                    lastPoint.SetTangent2Position(position + vector);
                }
                else
                {
                    lastPoint.SetTangent2Position(vector);
                }
                buffer.SetLastPoint(lastPoint);
                if (relative)
                {
                    buffer.position += endPoint;
                    buffer.tangent   = position + vector2;
                }
                else
                {
                    buffer.position = endPoint;
                    buffer.tangent  = vector2;
                }
                buffer.CreateBroken();
            }
        }
Пример #3
0
        private PathSegment[] ParsePathSegment(string coord, PathSegment.Type type)
        {
            List <float> list = ParseFloatArray(coord.Substring(1));
            int          num  = 0;

            switch (type)
            {
            case PathSegment.Type.Cubic:
                num = list.Count / 6;
                break;

            case PathSegment.Type.Quadratic:
                num = list.Count / 4;
                break;

            case PathSegment.Type.CubicShort:
                num = list.Count / 4;
                break;

            case PathSegment.Type.QuadraticShort:
                num = list.Count / 2;
                break;
            }
            if (num == 0)
            {
                return(new PathSegment[1]
                {
                    new PathSegment()
                });
            }
            PathSegment[] array = new PathSegment[num];
            for (int i = 0; i < num; i++)
            {
                switch (type)
                {
                case PathSegment.Type.Cubic:
                    array[i] = new PathSegment(new Vector2(list[6 * i], 0f - list[1 + 6 * i]), new Vector2(list[2 + 6 * i], 0f - list[3 + 6 * i]), new Vector2(list[4 + 6 * i], 0f - list[5 + 6 * i]));
                    break;

                case PathSegment.Type.Quadratic:
                    array[i] = new PathSegment(new Vector2(list[4 * i], 0f - list[1 + 4 * i]), Vector2.zero, new Vector2(list[2 + 4 * i], 0f - list[3 + 4 * i]));
                    break;

                case PathSegment.Type.CubicShort:
                    array[i] = new PathSegment(Vector2.zero, new Vector2(list[4 * i], 0f - list[1 + 4 * i]), new Vector2(list[2 + 4 * i], 0f - list[3 + 4 * i]));
                    break;

                case PathSegment.Type.QuadraticShort:
                    array[i] = new PathSegment(Vector2.zero, Vector2.zero, new Vector2(list[4 * i], 0f - list[1 + 4 * i]));
                    break;
                }
            }
            return(array);
        }
Пример #4
0
        private PathSegment[] ParsePathSegment(string coord, PathSegment.Type type)
        {
            List <float> list  = ParseFloatArray(coord.Substring(1));
            int          count = 0;

            switch (type)
            {
            case PathSegment.Type.Cubic: count = list.Count / 6; break;

            case PathSegment.Type.Quadratic: count = list.Count / 4; break;

            case PathSegment.Type.CubicShort: count = list.Count / 4; break;

            case PathSegment.Type.QuadraticShort: count = list.Count / 2; break;
            }

            if (count == 0)
            {
                Debug.Log("Error in " + coord + " " + type);
                return(new PathSegment[] { new PathSegment() });
            }
            PathSegment[] data = new PathSegment[count];
            for (int i = 0; i < count; i++)
            {
                switch (type)
                {
                case PathSegment.Type.Cubic: data[i] = new PathSegment(new Vector2(list[0 + 6 * i], -list[1 + 6 * i]), new Vector2(list[2 + 6 * i], -list[3 + 6 * i]), new Vector2(list[4 + 6 * i], -list[5 + 6 * i])); break;

                case PathSegment.Type.Quadratic: data[i] = new PathSegment(new Vector2(list[0 + 4 * i], -list[1 + 4 * i]), Vector2.zero, new Vector2(list[2 + 4 * i], -list[3 + 4 * i])); break;

                case PathSegment.Type.CubicShort: data[i] = new PathSegment(Vector2.zero, new Vector2(list[0 + 4 * i], -list[1 + 4 * i]), new Vector2(list[2 + 4 * i], -list[3 + 4 * i])); break;

                case PathSegment.Type.QuadraticShort: data[i] = new PathSegment(Vector2.zero, Vector2.zero, new Vector2(list[0 + 4 * i], -list[1 + 4 * i])); break;
                }
            }
            return(data);
        }