Esempio n. 1
0
 protected unsafe override void ProcessChannel(ref Channel channel, CompressedTimeSpan currentTime, IntPtr location, float factor)
 {
     if (channel.InterpolationType == AnimationCurveInterpolationType.Cubic)
     {
         *(float *)(location + channel.Offset) = Interpolator.Cubic(
             channel.ValuePrev.Value,
             channel.ValueStart.Value,
             channel.ValueEnd.Value,
             channel.ValueNext.Value,
             factor);
     }
     else if (channel.InterpolationType == AnimationCurveInterpolationType.Linear)
     {
         *(float *)(location + channel.Offset) = Interpolator.Linear(
             channel.ValueStart.Value,
             channel.ValueEnd.Value,
             factor);
     }
     else if (channel.InterpolationType == AnimationCurveInterpolationType.Constant)
     {
         *(float *)(location + channel.Offset) = channel.ValueStart.Value;
     }
     else
     {
         throw new NotImplementedException();
     }
 }
Esempio n. 2
0
        protected unsafe override void ProcessChannel(ref Channel channel, CompressedTimeSpan newTime, IntPtr location)
        {
            SetTime(ref channel, newTime);

            var currentTime  = channel.CurrentTime;
            var currentIndex = channel.CurrentIndex;

            var keyFrames      = channel.Curve.KeyFrames;
            var keyFramesItems = keyFrames.Items;
            var keyFramesCount = keyFrames.Count;

            // Extract data
            int timeStart = keyFrames[currentIndex + 0].Time.Ticks;
            int timeEnd   = keyFrames[currentIndex + 1].Time.Ticks;

            // Compute interpolation factor and avoid NaN operations when timeStart >= timeEnd
            float t = (timeEnd <= timeStart) ? 0 : ((float)currentTime.Ticks - (float)timeStart) / ((float)timeEnd - (float)timeStart);

            if (channel.InterpolationType == AnimationCurveInterpolationType.Cubic)
            {
                *(float *)(location + channel.Offset) = Interpolator.Cubic(
                    keyFramesItems[currentIndex > 0 ? currentIndex - 1 : 0].Value,
                    keyFramesItems[currentIndex].Value,
                    keyFramesItems[currentIndex + 1].Value,
                    keyFramesItems[currentIndex + 2 >= keyFramesCount ? currentIndex + 1 : currentIndex + 2].Value,
                    t);
            }
            else if (channel.InterpolationType == AnimationCurveInterpolationType.Linear)
            {
                *(float *)(location + channel.Offset) = MathUtil.Lerp(keyFramesItems[currentIndex].Value, keyFramesItems[currentIndex + 1].Value, t);
            }
            else if (channel.InterpolationType == AnimationCurveInterpolationType.Constant)
            {
                *(float *)(location + channel.Offset) = keyFrames[currentIndex].Value;
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Esempio n. 3
0
 /// <inheritdoc/>
 public override void Linear(ref float value1, ref float value2, float t, out float result)
 {
     result = Interpolator.Linear(value1, value2, t);
 }
Esempio n. 4
0
 /// <inheritdoc/>
 public override void Cubic(ref float value1, ref float value2, ref float value3, ref float value4, float t, out float result)
 {
     result = Interpolator.Cubic(value1, value2, value3, value4, t);
 }