Example #1
0
    public virtual void OnDrawGizmos()
    {
        if (!ShowCurve || !P0 || !P1 || !P0_Tangent || !P1_Tangent)
        {
            return;
        }

        //draw tangents
        Gizmos.color = new Color(1, 0, 0, 1.0f);
        Gizmos.DrawLine(P0.transform.position, P0_Tangent.transform.position);
        Gizmos.color = new Color(1, 0, 0, 1.0f);
        Gizmos.DrawLine(P1.transform.position, P1_Tangent.transform.position);

        //draw curve
        Vector3 prevPos = P0.transform.position;

        for (int c = 1; c <= Resolution; c++)
        {
            float   t       = (float)c / Resolution;
            Vector3 currPos = CurveMath.CalculateBezierPoint(t, P0.transform.position, P0_Tangent.transform.position, P1_Tangent.transform.position, P1.transform.position);
            Vector3 currTan = (currPos - prevPos).normalized;
            float   mag     = (currPos - prevPos).magnitude;

            Gizmos.color = new Color(0, 0, mag, 1);
            Gizmos.DrawLine(prevPos, currPos);

            prevPos = currPos;
        }
    }
    void BezierCurve(BezierSegment otherSegment)
    {
        int segments = SegmentCount;

        for (int i = 1; i <= segments; i++)
        {
            float   t = i / (float)segments;
            Vector2 pointToAddWithZIsIndex = CurveMath.CalculateBezierPoint(t, otherSegment.Point, otherSegment.SecondHandle, FirstHandle, Point);
            segmentPoints[i - 1] = pointToAddWithZIsIndex;
        }
        _pathObject.UpdateLineRenderer(this);
    }
Example #3
0
    private void GetCorePoints(ref Vector3[] pos)
    {
        Vector3 prevPos = P0.transform.position;

        pos[0] = prevPos;
        float lastId = (float)(Resolution - 1);

        for (int c = 1; c < Resolution; c++)
        {
            float t = c / lastId;
            pos[c]  = CurveMath.CalculateBezierPoint(t, P0.transform.position, P0_Tangent.transform.position, P1_Tangent.transform.position, P1.transform.position);
            prevPos = pos[c];
        }
    }
Example #4
0
    public void CalculateVelocityField()
    {
        VelocityField.Clear();

        Vector3 prevPos = P0.transform.position;

        for (int c = 1; c <= Resolution; c++)
        {
            float   t       = (float)c / Resolution;
            Vector3 currPos = CurveMath.CalculateBezierPoint(t, P0.transform.position, P0_Tangent.transform.position, P1_Tangent.transform.position, P1.transform.position);
            Vector3 currTan = (currPos - prevPos).normalized;
            float   mag     = VelocityMagCurve.Evaluate(t);

            VelocityFieldNode ti = new VelocityFieldNode();
            ti.TargetPosition = prevPos;
            ti.TargetVelocity = currTan;
            ti.Mag            = mag;
            VelocityField.Add(ti);
            prevPos = currPos;
        }
    }
Example #5
0
 public void GetPositionAt(float val, ref Vector3 pos)
 {
     val = Mathf.Clamp(val, 0.0f, 1.0f);
     pos = CurveMath.CalculateBezierPoint(val, P0.transform.position, P0_Tangent.transform.position, P1_Tangent.transform.position, P1.transform.position);
 }