Fixing tracked rotations

Project Page Next project post Post History

In a recent post, I made an update that talked about some having issues I was having with the tracked rotational values. Let me try explain briefly - it's a little techy but that's just what it is...

The tracked rotation values are always between 0 and 360 degrees. This makes a full circle. If you track something past a full circle, it just goes back to the start again. So, 361 degrees becomes 1 degree. Or, -1 degree becomes 359 degrees. So everything is kept within a single full rotation. However, I found this was causing some issues when I needed to interpolate in between tracking keyframes and the values were reset when they went beyond, or below, the normal full rotation spread. It was just pot luck that I managed to see this happening, because when I recorded a rigid body with the new motion capture system, I managed to record it in a way where the values kept jumping at each of the value ends (again, anything less than zero became 350-odd, and anything more than 360 degrees became single digits).

The following images are an example of what was happening. You can see in the first frame, everything is OK. In the second frame, things are wildly rotated. And in the third frame, they're back to normal.

Frame 1: keyframe correct
Frame 2: interpolated rotation, not right
Frame 3: keyframe correct

This is happening because the data has been captured with differing frame rates, where the rotation values have been capped to between 0 and 360 degrees. Meaning, when it passes either end, it reverts to the other end of the scale. So, an angle of -1 degrees becomes 359. Which means, if you're sampling in-between keyframes, like above, it will interpolate the values for you, which could result in the interpolated rotation being done the wrong way.

I was able to come up with a novel way to fix this. I started at the first keyframe, and from then on I set the rotation values by the difference between the current index and the previous keyframe index. And now any rotations past 360 or less than zero are handled.