Exemplo n.º 1
0
 public void AddSegment(Vector2 anchorPos)
 {
     points.Add(new Point(points[points.Count - 1].Position * 2 - points[points.Count - 2].Position, PointType.Handle));
     points.Add(new Point((points[points.Count - 1].Position + anchorPos) * .5f, PointType.Handle));
     points.Add(new Point(anchorPos, PointType.Point));
     length = PathCreator.ApproxBezierLength(this);
 }
Exemplo n.º 2
0
    public void MovePoint(int i, Vector2 pos)
    {
        Vector2 deltaMove = pos - points[i].Position;

        points[i].Position = pos;

        if (i % 3 == 0)
        {
            if (i + 1 < points.Count)
            {
                points[i + 1].Position += deltaMove;
            }
            if (i - 1 >= 0)
            {
                points[i - 1].Position += deltaMove;
            }
        }
        else
        {
            bool nextPointIsAnchor         = (i + 1) % 3 == 0;
            int  correspondingControlIndex = (nextPointIsAnchor) ? i + 2 : i - 2;
            int  anchorIndex = (nextPointIsAnchor) ? i + 1 : i - 1;

            if (correspondingControlIndex >= 0 && correspondingControlIndex < points.Count)
            {
                float   dst = (points[anchorIndex].Position - points[correspondingControlIndex].Position).magnitude;
                Vector2 dir = (points[anchorIndex].Position - pos).normalized;
                points[correspondingControlIndex].Position = points[anchorIndex].Position + dir * dst;
            }
        }

        length = PathCreator.ApproxBezierLength(this);
    }
Exemplo n.º 3
0
    public Path(Vector2 centre)
    {
        points = new List <Point>
        {
            new Point(centre + Vector2.left, PointType.Point),
            new Point(centre + (Vector2.left + Vector2.up) * .5f, PointType.Handle),
            new Point(centre + (Vector2.right + Vector2.down) * .5f, PointType.Handle),
            new Point(centre + Vector2.right, PointType.Point)
        };

        length = PathCreator.ApproxBezierLength(this);
    }