Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
AnimationCurveEvaluatorDirectQuaternionGroup.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 AnimationCurveEvaluatorDirectQuaternionGroup : AnimationCurveEvaluatorDirectGroup<Quaternion>
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  Interpolator.Quaternion.Cubic(
31  ref keyFramesItems[currentIndex > 0 ? currentIndex - 1 : 0].Value,
32  ref keyFramesItems[currentIndex].Value,
33  ref keyFramesItems[currentIndex + 1].Value,
34  ref keyFramesItems[currentIndex + 2 >= keyFramesCount ? currentIndex + 1 : currentIndex + 2].Value,
35  t,
36  out *(Quaternion*)(location + channel.Offset));
37  }
38  else if (channel.InterpolationType == AnimationCurveInterpolationType.Linear)
39  {
40  Interpolator.Quaternion.SphericalLinear(
41  ref keyFramesItems[currentIndex].Value,
42  ref keyFramesItems[currentIndex + 1].Value,
43  t,
44  out *(Quaternion*)(location + channel.Offset));
45  }
46  else
47  {
48  throw new NotImplementedException();
49  }
50  }
51  }
52 }
AnimationCurveInterpolationType
Describes how a curve should be interpolated.
Represents a four dimensional mathematical quaternion.
Definition: Quaternion.cs:45
unsafe override void ProcessChannel(ref Channel channel, CompressedTimeSpan newTime, IntPtr location)