Esempio n. 1
0
 private static Vector3 Herp(float term, float time, Vector3 p1, Vector3 p2, Vector3 tan)
 {
     return(new Vector3()
     {
         X = AnimationInterpolationHelper.SplineGetHermite(term, time, p1.X, p2.X, -tan.X, tan.X),
         Y = AnimationInterpolationHelper.SplineGetHermite(term, time, p1.Y, p2.Y, -tan.Y, tan.Y),
         Z = AnimationInterpolationHelper.SplineGetHermite(term, time, p1.Z, p2.Z, -tan.Z, tan.Z),
     });
 }
Esempio n. 2
0
        public MOT_KEY GetKey(float time)
        {
            if (Keys.Count == 0)
            {
                return(null);
            }

            if (Keys.Count == 1)
            {
                return(Keys[0]);
            }

            if (Keys[0].Time > time)
            {
                return(Keys[0]);
            }

            // Keys.FindIndex should not return 0 here due to above check
            var index = Keys.FindIndex(e => e.Time > time) - 1;

            // If index is negative all keys come before the provided time, pick the last one
            if (index < 0)
            {
                return(Keys[Keys.Count - 1]);
            }

            var weight = (time - Keys[index].Time) / (Keys[index + 1].Time - Keys[index].Time);

            return(new MOT_KEY()
            {
                Time = time,
                X = AnimationInterpolationHelper.Lerp(Keys[index].X, Keys[index + 1].X, weight),
                Y = AnimationInterpolationHelper.Lerp(Keys[index].Y, Keys[index + 1].Y, weight),
                Z = AnimationInterpolationHelper.Lerp(Keys[index].Z, Keys[index + 1].Z, weight),
                W = AnimationInterpolationHelper.Lerp(Keys[index].W, Keys[index + 1].W, weight),
            });
        }