Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
AnimationCurveEvaluatorDirectFloatGroup.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 using SiliconStudio.Core.Mathematics;
5 
6 namespace SiliconStudio.Paradox.DataModel
7 {
8  public class AnimationCurveEvaluatorDirectFloatGroup : AnimationCurveEvaluatorDirectGroup<float>
9  {
10  protected unsafe override void ProcessChannel(ref Channel channel, CompressedTimeSpan newTime, IntPtr location)
11  {
12  SetTime(ref channel, newTime);
13 
14  var currentTime = channel.CurrentTime;
15  var currentIndex = channel.CurrentIndex;
16 
17  var keyFrames = channel.Curve.KeyFrames;
18  var keyFramesItems = keyFrames.Items;
19  var keyFramesCount = keyFrames.Count;
20 
21  // Extract data
22  int timeStart = keyFrames[currentIndex + 0].Time.Ticks;
23  int timeEnd = keyFrames[currentIndex + 1].Time.Ticks;
24 
25  // Compute interpolation factor
26  float t = ((float)currentTime.Ticks - (float)timeStart) / ((float)timeEnd - (float)timeStart);
27 
28  if (channel.InterpolationType == AnimationCurveInterpolationType.Cubic)
29  {
30  *(float*)(location + channel.Offset) = Interpolator.Cubic(
31  keyFramesItems[currentIndex > 0 ? currentIndex - 1 : 0].Value,
32  keyFramesItems[currentIndex].Value,
33  keyFramesItems[currentIndex + 1].Value,
34  keyFramesItems[currentIndex + 2 >= keyFramesCount ? currentIndex + 1 : currentIndex + 2].Value,
35  t);
36  }
37  else if (channel.InterpolationType == AnimationCurveInterpolationType.Linear)
38  {
39  *(float*)(location + channel.Offset) = MathUtil.Lerp(keyFramesItems[currentIndex].Value, keyFramesItems[currentIndex + 1].Value, t);
40  }
41  else
42  {
43  throw new NotImplementedException();
44  }
45  }
46  }
47 }
AnimationCurveInterpolationType
Describes how a curve should be interpolated.
unsafe override void ProcessChannel(ref Channel channel, CompressedTimeSpan newTime, IntPtr location)