Bezier.BezierPath.GetBezierPointInfo C# (CSharp) Метод

GetBezierPointInfo() публичный Метод

public GetBezierPointInfo ( float ratio ) : BezierPointInfo
ratio float
Результат BezierPointInfo
        public BezierPointInfo GetBezierPointInfo( float ratio )
        {
            float added = 0.0f;
            for(int i = 0; i < lengthRatio.Length; i++){
                added += lengthRatio[i];
                if(added >= ratio){
                    float t = (ratio-(added-lengthRatio[i])) / lengthRatio[i] ;
                    return beziers[i].GetPointInfo(t);
                }
            }
            return beziers[lengthRatio.Length-1].GetPointInfo( 1.0f );
        }

Usage Example

Пример #1
0
    // Update is called once per frame
    void OnDrawGizmos()
    {
        List<Quaternion> rotList = new List<Quaternion> ();
        for (int i = 0; i < bPoints.Count; i++) {
            BezierPt b = bPoints [i];
            rotList.Add (b.transform.rotation);
        }

        List<Vector3> nodes = new List<Vector3> ();
        for (int i = 0; i < bPoints.Count-1; i++) {
            BezierPt start = bPoints [i];
            BezierPt end = bPoints [i + 1];

            nodes.Add (start.transform.position);
            nodes.Add (end.inTrans.position);
            nodes.Add (start.outTrans.position);
            nodes.Add (end.transform.position);
        }

        path = new BezierPath (nodes.ToArray (), rotList.ToArray ());

        // draw
        float delta = 1.0f / split;

        Gizmos.color = drawColor;
        for (int i = 0; i < split-1; i++) {
            float t0 = delta * i;
            float t1 = delta * (i + 1);
            Vector3 pos0 = this.GetPointAt (t0);
            Vector3 pos1 = this.GetPointAt (t1);

            Gizmos.DrawLine (pos0, pos1);
        }

        for (int i = 0; i < split; i++) {

        //			float v = (float)i / split;
            float v = delta * i;

            BezierPointInfo pInfo = path.GetBezierPointInfo(v);

            Vector3 pt = pInfo.point;
            Gizmos.color = drawColor;
            Gizmos.DrawWireSphere (pt, 0.25f);

            // tangent
            Gizmos.color = Color.blue;
            Vector3 tangent = pInfo.tangent;
            Gizmos.DrawRay (pt, tangent);

            Quaternion quat = pInfo.rotation;
            Gizmos.color = Color.green;
            Gizmos.DrawRay (pt, quat* Vector3.up);
            Gizmos.color = Color.red;
            Gizmos.DrawRay (pt, quat* Vector3.right);
        }
    }