Beispiel #1
0
        /// <summary>
        /// mirror a curve, do return new curve Clone
        /// </summary>
        public static Curve2 Mirror(this Curve2 curve)
        {
            var mir = curve.Clone();

            Mirror(mir, 0.01f);
            return(mir);
        }
Beispiel #2
0
        public static void Mirror(this Curve2 curve, float mirrorError, Curve2 origin = null)
        {
            var axis   = 0.5f;//mirrorAxis
            var append = new List <Key2>();

            foreach (var k in curve)
            {
                if (Mathf.Abs(k.time - axis) < mirrorError)//points on mirror axis
                {
                    if (origin != null)
                    {
                        var key = origin[curve.IndexOf(k)];
                        key.SetVector(new Vector2(axis, k.value));
                        //key.outMode = key.inMode;
                        //key.outMode = KeyMode.None;
                    }
                    k.SetVector(new Vector2(axis, k.value));
                    k.outTan  = k.inTan.MirrorX(axis);
                    k.outMode = k.inMode;
                }
                else
                {
                    var n = k.Clone();
                    ComTool.Swap(ref n.inTan, ref n.outTan);//先把切线翻转
                    n.inTan  = n.inTan.MirrorX(n.time);
                    n.outTan = n.outTan.MirrorX(n.time);
                    n.SetVector(n.vector.MirrorX(axis)); // 然后SetVector一起拉过去
                    ComTool.Swap(ref n.inMode, ref n.outMode);
                    append.Add(n);
                }
            }
            curve.keys.AddRange(append);
            curve.Sort();
        }
Beispiel #3
0
        static Curve2()
        {
            t0v1_t1v1 = new Curve2(Vector2.up, Vector2.right + Vector2.up);

            t0v0_t05v1_t1v0 = new Curve2(Vector2.zero, Vector2.right);
            t0v0_t05v1_t1v0.InsertKey(new Key2(0.5f, 1f));
            t0v0_t05v1_t1v0.time1D = false;

            t0v0_t1v0 = new Curve2(Vector2.zero, Vector2.right);
        }
Beispiel #4
0
        int RemoveAtTime(Curve2 curve, float time)
        {
            int c = 0;

            if (curve.keys != null && curve.keys.Count > 0)
            {
                c += RemoveTimeOf(curve, time);
            }
            return(c);
        }
Beispiel #5
0
        public Curve2 Clone()
        {
            var n     = new Curve2();
            var nKeys = new List <Key2>();

            foreach (var k in keys)
            {
                nKeys.Add(k.Clone());
            }
            n.keys   = nKeys;
            n.time1D = time1D;
            return(n);
        }
Beispiel #6
0
        // return remove count
        int RemoveTimeOf(Curve2 curve, float time)
        {
            int c = 0;
            var t = new List <Key2>(curve);

            foreach (var key in t)
            {
                if (MathTool.Approx(key.time, time, 3))
                {
                    curve.Remove(key); c++;
                }
            }
            return(c);
        }
Beispiel #7
0
        /// <summary>
        /// return new Curve contain keys before/include "time", not return new curve Clone
        /// </summary>
        public static Curve2 Before(this Curve2 curve, float time)
        {
            var list = new List <Key2>();

            foreach (var k in curve.keys)
            {
                if (k.time > time)
                {
                    break;
                }
                list.Add(k);
            }
            curve.keys = list;
            return(curve);
        }
Beispiel #8
0
 public bool IsMirror(Curve2 c)
 {
     if (c == null)
     {
         return(false);
     }
     if (Count != c.Count)
     {
         return(false);
     }
     for (int i = 0; i < Count; i++)
     {
         if (!keys[i].vector.f.IsMirrorX(c.keys[i].vector) ||
             !keys[i].inTan.IsMirrorX(c.keys[i].inTan) ||
             !keys[i].outTan.IsMirrorX(c.keys[i].outTan) ||
             keys[i].inMode != c.keys[i].inMode ||
             keys[i].outMode != c.keys[i].outMode)
         {
             return(false);
         }
     }
     return(true);
 }
Beispiel #9
0
 public CurveXYZ()
 {
     x = new Curve2();
     y = new Curve2();
     z = new Curve2();
 }