Beispiel #1
0
        public static void SetLengthIn(this Key2 k, float len)
        {
            var dir = (k.inTan - k.vector.f);

            if (dir != Vector2.zero)
            {
                dir = dir.normalized;
            }
            k.inTan = k.vector + dir * len;
        }
Beispiel #2
0
 private int SortList(Key2 a, Key2 b)
 {
     if (a.time > b.time)
     {
         return(1);
     }
     else if (a.time < b.time)
     {
         return(-1);
     }
     return(0);
 }
Beispiel #3
0
        Vector2 EvaluateAOut(Key2 a, Key2 b, float t)
        {
            var points = new Vector2[4];

            points[0] = a.vector;
            points[1] = a.outTan;
            points[2] = b.vector;
            var Points2 = new Vector2[2];

            for (int i = 0; i < 2; i++)
            {
                Points2[i] = Vector2.Lerp(points[i], points[i + 1], t);
            }
            return(Vector2.Lerp(Points2[0], Points2[1], t));
        }
Beispiel #4
0
        /// <summary>
        /// 注意顺序:a在前b在后,使用a的outT,b的InT
        /// </summary>
        public static Vector2 Evaluate(Key2 a, Key2 b, float t)
        {
            var list = new List <Vector2>();

            list.Add(a.vector);
            if (a.outMode == KeyMode.Bezier)
            {
                list.Add(a.outTan);
            }
            if (b.inMode == KeyMode.Bezier)
            {
                list.Add(b.inTan);
            }
            list.Add(b.vector);
            return(Evaluate1to4(list, t));
        }
Beispiel #5
0
 public static Vector2 LocalIn(this Key2 k)
 {
     return(k.inTan - k.vector.f);
 }
Beispiel #6
0
 public static Vector2 SetLocalOut(this Key2 k, Vector2 v)
 {
     return(k.outTan = k.vector + v);
 }
Beispiel #7
0
 public static Vector2 LocalOut(this Key2 k)
 {
     return(k.outTan - k.vector.f);
 }
Beispiel #8
0
 public static Vector2 SetLocalIn(this Key2 k, Vector2 v)
 {
     return(k.inTan = k.vector + v);
 }
Beispiel #9
0
        /// <summary>
        /// add key and Sort
        /// </summary>
        /// <param name="key"></param>
        public void InsertKey(Key2 key) // 插入帧并且立即排序
        {
            var k = IdxOf(key.idx);

            if (k != null)
            {
                k.value = key.value; return;
            }

            Add(key);
            Sort();
            var     i = IndexOf(key);
            float   len;
            Vector2 dir;

            if (i > 0 && i < Count - 1)
            {
                var a = this[i - 1];
                var b = this[i + 1];
                //var localT = (key.time - a.time) / (b.time - a.time);
                //var t1 = Mathf.Max(0, localT - 0.2f);
                //var t2 = Mathf.Min(1, localT + 0.2f);
                //Debug.Log("LocalT: " + localT.ToString());
                //Debug.Log("t1: " + t1.ToString());
                //Debug.Log("t2: " + t2.ToString());
                //Debug.Log("v1: " + a.vector);
                //Debug.Log("v2: " + b.vector);
                //key.inTangent = Evaluate(a, b, t1);
                //key.outTangent = Evaluate(a, b, t2);
                key.inTan  = Vector2.Lerp(key.vector, a.vector, 0.33f);
                key.outTan = Vector2.Lerp(key.vector, b.vector, 0.33f);
                var lenA = a.LocalOut();
                if (lenA != Vector2.zero)
                {
                    a.SetLocalOut(lenA.normalized * lenA.magnitude * 0.5f);
                }
                var lenB = b.LocalIn();
                if (lenB != Vector2.zero)
                {
                    b.SetLocalIn(lenB.normalized * lenB.magnitude * 0.5f);
                }
            }
            else if (i > 0) // i == count -1
            {
                len         = (key.time - this[i - 1].time) * 0.4f;
                dir         = ((this[i - 1].vector.f - key.vector.f) * Vector2.right).normalized;
                key.inTan   = key.vector + dir.normalized * len;
                key.outMode = KeyMode.None;
            }
            else if (i < Count - 1) // i == 0
            {
                len        = (this[i + 1].time - key.time) * 0.4f;
                dir        = ((this[i + 1].vector.f - key.vector.f) * Vector2.right).normalized;
                key.outTan = key.vector + dir.normalized * len;
                key.inMode = KeyMode.None;
            }
            else // i == 0 and Count == 0
            {
                dir        = Vector2.right * 0.4f;
                key.outTan = key.vector + dir;
                key.inMode = KeyMode.None;
            }
        }