Rounding keyframe transformations
This can be a bit tricky. You can't just say "two vectors are almost the same so they should be deleted" because if you apply this same rule to all your vectors one after the other, then you will end up with no vectors!...cause they will all be close to the one that precedes it.
So instead I would suggest adding each vector together, from start to end, till the angle between the last direction and the resulting direction have deviated enough to warrant a new key frame. Basically, if the last vector plus the new vector point in the same direction, then merge the points.
Thanks for your response, Nyssa!
I understand the issue you point out but what you are proposing appears to suffer from the same issue. You say 'if they have deviated enough to warrant a new keyframe' which is exactly the same as what I am doing. The only difference (if I understand your method properly) is you are measuring the direction of (A+B) relative to A, and I am measuring the components of A vs. the components of B. The difference in direction of A from (A+B) is just as likely to be too small and incorrectly eliminate a keyframe. I think its just a question of how strict you are with the comparisons. i.e. how much is 'enough' to warrant a new keyframe.
Moreover, your method only takes direction into account and would incorrectly merge the vectors (1,1,1) and (2,2,2) since their sum (3,3,3) is in the same direction as (1,1,1). Unless I misunderstand your approach, that is.
Moreover, your method only takes direction into account and would incorrectly merge the vectors (1,1,1) and (2,2,2) since their sum (3,3,3) is in the same direction as (1,1,1).
That's correct. Sorry, I shouldn't have been talking about adding vectors together. Lets say you have 4 points (1,1,1), (2,2,2), (3,3,3), (4,4,4). If you place these points on a graph then the resulting line would be straight. Therefore there is no need for points (2,2,2) and (3,3,3) so you would just keep keys (1,1,1) and (4,4,4).
If however we have the points (1,1,1), (2,2,2), (3,-20,3), (4,4,4) you would need to keep all the points otherwise your animations won't follow the correct paths.
You would always store the first keyframe and the last keyframe anyway so that your animation runs from the first position to the end position correctly. Then you would make the direction from A to B the first comparison direction. Then test the direction from A to C. If the direction is about the same as the first comparison direction then throw away B. The next test would be from A to D and so on....
If the direction from A to C wasn't in the same direction as A to B then you would need to keep B. Because without this point your animations wouldn't follow the correct path. The direction from B to C would become your new comparison direction and you would repeat the above test for B to D and so on...
Yes! This is part of what I was planning after the next step. After coming up with a suitable comparison function, the next step is to use it to A. eliminate duplicate key frames, and B. eliminate key frames that are equivalent to interpolation. I had essentially the same algorithm in mind, except I would do the following:
For a key-frame B at time t, between key-frames A and C: interpolate A and C and evaluate it at t. Now call Compare ( B, interpolate(A,C,t)) and eliminate B if they are close enough.
They would only be straight if they were timed equally far apart.
That's correct. Sorry, I shouldn't have been talking about adding vectors together. Lets say you have 4 points (1,1,1), (2,2,2), (3,3,3), (4,4,4). If you place these points on a graph then the resulting line would be straight. Therefore there is no need for points (2,2,2) and (3,3,3) so you would just keep keys (1,1,1) and (4,4,4).
Just like having (1,1,1) and then (1,1,1) and then (10,10,10). The extra (1,1,1) is there to hold the pose for a specific time frame so the first (1,1,1) doesn't start immediately interpolating towards (10,10,10). This means the second (1,1,1) is not an unneeded duplicate. Removing it breaks the animation.
They would only be straight if they were timed equally far apart.
That's true Daaark.
mv, are the errors you're talking about also occurring in a frames time stamp? If you have multiple frames with the same time stamp you could simply remove any duplicates?
relative_difference(v,w) := length(v-w)/sqrt(length(v)*length(w))
If you want to compare that quantity to a threshold, you can compute the fourth power --which doesn't involve any square roots-- and compare that to the fourth power of the threshold.
bool canRemoveMiddleFrame(vec3 v0, vec3 v1, vec3 v2, float diff)
{
vec3 va = v1 - v0;
vec3 vb = v2 - v1;
vec3 vc = va - vb;
return (abs(vc.x) < diff) && (abs(vc.y) < diff) && (abs(vc.z) < diff);
}
bool canRemoveMiddleFrame(quat v0, quat v1, quat v2, float diff)
{
quat va = v1 * invert(v0);
quat vb = v2 * invert(v1);
float difference = dot(va, vb);
return abs( difference - 1 ) < diff;
}