public static Vector3 GetNearestPointBezierCurveArrow2D(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, Vector2 mousePos)
 {
     float distance = float.MaxValue;
     Vector3 point = p0;
     int segments = 20;//とりあえず計算量を考慮して固定
     var step = 1f / segments;
     Vector3 from = p0;
     Vector3 to;
     for (float t = step; t < 1; t += step)
     {
         to = CubicBezier.GetPoint(p0, p1, p2, p3, t);
         Gizmos.DrawLine(from, to);
         Vector3 tmpVec = MidD2(mousePos, from, to);
         if(tmpVec.z < distance)
         {
             distance = tmpVec.z;
             point = tmpVec;
         }
         from = to;
     }
     to = p3;
     Gizmos.DrawLine(from, to);
     from = CubicBezier.GetPoint(p0, p1, p2, p3, 0.5f - step);
     to = CubicBezier.GetPoint(p0, p1, p2, p3, 0.5f);
     DrawArrow2D(from, to);
     return point;
 }
 public static void DrawBezierCurve2D(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, int segments = 20)
 {
     if (segments == 0) return;
     var step = 1f / segments;
     Vector3 from = CubicBezier.GetPoint(p0, p1, p2, p3, 0);
     Vector3 to;
     for (float t = step; t < 1; t += step)
     {
         to = CubicBezier.GetPoint(p0, p1, p2, p3, t);
         Gizmos.DrawLine(from, to);
         from = to;
     }
     to = CubicBezier.GetPoint(p0, p1, p2, p3, 1);
     Gizmos.DrawLine(from, to);
 }
Exemplo n.º 3
0
    // Update is called once per frame
    protected override void Update()
    {
        t     = overTime % 1;
        index = (int)overTime - loopTime * (maxIndex);
        if (index == maxIndex)
        {
            t     = 1;
            index = maxIndex - 1;
        }
        from       = pivot + (Vector3)path[index].Anchore;
        fromHandle = from + (Vector3)path[index].Handle2;
        int tmpIndex = index + 1;

        if (openEnded && tmpIndex == maxIndex)
        {
            tmpIndex = 0;
        }
        to                 = pivot + (Vector3)path[tmpIndex].Anchore;
        toHandle           = to + (Vector3)path[tmpIndex].Handle1;
        transform.position = CubicBezier.GetPoint(from, fromHandle, toHandle, to, t);
        base.Update();
    }
Exemplo n.º 4
0
 // Update is called once per frame
 protected override void Update()
 {
     transform.position = CubicBezier.GetPoint(startPoint.Anchore, startPoint.Anchore + startPoint.Handle2, startPoint.Anchore + endPoint.Anchore + endPoint.Handle1, startPoint.Anchore + endPoint.Anchore, t);
     base.Update();
 }