コード例 #1
0
 private static void SmoothLocalInterpolation(BezierKeyframe previous, float previousTime, ref BezierKeyframe current, BezierKeyframe next, float nextTime)
 {
     if (next.HasValue() && previous.HasValue())
     {
         var inHandle             = (current.value - previous.value) / 3f;
         var outHandle            = (next.value - current.value) / 3f;
         var bothSegmentsDuration = nextTime - previousTime;
         var inRatio  = (current.time - previousTime) / bothSegmentsDuration;
         var outRatio = (nextTime - current.time) / bothSegmentsDuration;
         var avg      = inHandle * inRatio + outHandle * outRatio;
         if (inRatio > outRatio)
         {
             current.controlPointIn  = current.value - avg;
             current.controlPointOut = current.value + avg * outRatio;
         }
         else
         {
             current.controlPointIn  = current.value - avg * inRatio;
             current.controlPointOut = current.value + avg;
         }
     }
     else if (previous.IsNull())
     {
         current.controlPointIn  = current.value;
         current.controlPointOut = current.value + (next.value - current.value) / 3f;
     }
     else if (next.IsNull())
     {
         current.controlPointIn  = current.value - (current.value - previous.value) / 3f;
         current.controlPointOut = current.value;
     }
 }
コード例 #2
0
        private static void SmoothLocalInterpolation(BezierKeyframe previous, float previousTime, ref BezierKeyframe current, BezierKeyframe next, float nextTime)
        {
            if (next.HasValue() && previous.HasValue())
            {
                var inHandle             = (current.value - previous.value) / 3f;
                var outHandle            = (next.value - current.value) / 3f;
                var bothSegmentsDuration = nextTime - previousTime;
                var inRatio  = (current.time - previousTime) / bothSegmentsDuration;
                var outRatio = (nextTime - current.time) / bothSegmentsDuration;

                /* // SMOOTH
                 * // The larger the incoming curve, the weaker the effect on the other side
                 * var weightedAvg = inHandle * outRatio + outHandle * inRatio;
                 * if (inRatio > outRatio)
                 * {
                 *  current.controlPointIn = current.value - weightedAvg * (inRatio / outRatio);
                 *  current.controlPointOut = current.value + weightedAvg;
                 * }
                 * else
                 * {
                 *  current.controlPointIn = current.value - weightedAvg;
                 *  current.controlPointOut = current.value + weightedAvg * (outRatio / inRatio);
                 * }
                 */
                // NO_OVERSHOOT
                // The larger the incoming curve, the stronger the effect on the other side
                var weightedAvg = inHandle * inRatio + outHandle * outRatio;
                if (inRatio > outRatio)
                {
                    current.controlPointIn  = current.value - weightedAvg;
                    current.controlPointOut = current.value + weightedAvg * (outRatio / inRatio);
                }
                else
                {
                    current.controlPointIn  = current.value - weightedAvg * (inRatio / outRatio);
                    current.controlPointOut = current.value + weightedAvg;
                }
            }
            else if (previous.IsNull())
            {
                current.controlPointIn  = current.value;
                current.controlPointOut = current.value + (next.value - current.value) / 3f;
            }
            else if (next.IsNull())
            {
                current.controlPointIn  = current.value - (current.value - previous.value) / 3f;
                current.controlPointOut = current.value;
            }
        }
コード例 #3
0
 private static void LinearInterpolation(BezierKeyframe previous, ref BezierKeyframe current, BezierKeyframe next)
 {
     if (previous.HasValue())
     {
         current.controlPointIn = current.value - (current.value - previous.value) / 3f;
     }
     else
     {
         current.controlPointIn = current.value;
     }
     if (next.HasValue())
     {
         current.controlPointOut = current.value + (next.value - current.value) / 3f;
     }
     else
     {
         current.controlPointOut = current.value;
     }
 }