- #1
twoski
- 181
- 2
I am trying to implement animation smoothing for a given set of keyframes. Some keyframes have "jitter" which i have to remove through my own algorithms. I am using the Unity game engine which has its own quaternion classes and such.
I looked into it, and using an Exponential Moving Average seems like a good idea. This approach works well for removing positional jitter, however when i use it with quaternions it causes some errors with rotations.
I am currently converting quaternions to euler angles, averaging, then converting back. However this doesn't seem to work. It causes my models to rotate in the wrong directions.
Here is the code i use:
Can anyone spot any obvious bugs?
I looked into it, and using an Exponential Moving Average seems like a good idea. This approach works well for removing positional jitter, however when i use it with quaternions it causes some errors with rotations.
I am currently converting quaternions to euler angles, averaging, then converting back. However this doesn't seem to work. It causes my models to rotate in the wrong directions.
Here is the code i use:
Code:
void UpdateRotationEMA(int i, Quaternion q)
{
if (transforms[i] != null)
{
if (frameList[i] != null)
{
Vector3 pos = AvgPos(frameList[i], q.eulerAngles); //T1
transforms[i].rotation = Quaternion.Euler(pos);
frameList[i] = pos;
}
else
{
transforms[i].rotation = q;
frameList[i] = q.eulerAngles;
}
}
}
Vector3 AvgPos(Vector3 lastPos, Vector3 pos)
{
return (emaAlpha * pos + ((1f - emaAlpha) * lastPos));
}
Can anyone spot any obvious bugs?