HarbourMasters / HarbourMasters/Shipwright
Frame Interpolation: Incorrect linear interpolation of rotations
- Dominant language
- C
- Stars
- 5.4k
- Forks
- 837
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 72
Description
While I'm a big fan of the frame interpolation system, it has a central flaw: currently it simply Lerps between two transformation matrices. That is mathematically incorrect, since those transformation matrices might contain rotation information. Here's a good visualization of the issue, that also hints at the proper solution: https://www.mdpi.com/sensors/sensors-15-19302/article_deploy/html/images/sensors-15-19302-g004-1024.png
To test this, I created a branch where I modified the signs to rotate by 90° in each frame, the sign in front of link's house is in a good place to examine the issue.
Branch: https://github.com/tdc22/Shipwright/tree/interpolation-rotation-inaccuracy
Commit: https://github.com/tdc22/Shipwright/commit/c4b462d396de141a0f3214a3a92234165911c809
Just compile this, go in front of links house with interpolation turned off. You should see that sign spinning by 90° per frame. Now turn up Interpolation all the way and check the results: the sign is deforming (scaling) while rotating.
Video of the result: https://www.youtube.com/watch?v=R5mZs9G5JvM&t=22
The solution to this is to isolate rotations from the matrix, convert them to a quaternion and apply a Slerp interpolation, instead of a simple Lerp. The remaining parts of the matrix can still be interpolated linearily (I think, I'm not sure about sheering right now). Then recombine the (rotation) quaternion and the rest of the matrix back into a single transformation matrix.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.