Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix quaternion keyframe optimization for collinear rotation over 180 degrees #87817

Merged
merged 1 commit into from
Feb 12, 2024
Merged

Conversation

Dheatly23
Copy link
Contributor

@Dheatly23 Dheatly23 commented Feb 1, 2024

Fixes: #87813

Change the correct great-arc distance for 180 degrees rotation.

Bugsquad Edited:
Fixes #75159

@fire
Copy link
Member

fire commented Feb 1, 2024

@TokageItLab I am not sure about this. What do you think?

@TokageItLab
Copy link
Member

It sounds like it makes sense to check the angles before the axes check.

I remember there are a couple of issues related to this and will test to see if it works correctly (if it is possible to optimize without over thinning the keys) when I have time.

@Dheatly23
Copy link
Contributor Author

Dheatly23 commented Feb 3, 2024

After thinking about it, the original checks is sort-of correct. It just missing one key quirk of quaternion.

In short, unit quaternion is a double-covering of SO3 (rotation group). Rotating 360 degrees once brings a quaternion to it's negative. It requires 720 degrees rotation to bring it back to it's original state.

(See plate trick and quantum spin, if you'd like to know more)

So, doing a great arc distance (acos(q1.dot(q2))) gives half the angle rotated between the two quaternions. You can clearly tell by simply computing the distance between a quaternion and it's negative (360 degrees rotated). So 180 degrees rotation would be separated by PI/2, not PI.

PS: Arcsin is a bit numerically better than arccos, particularly with small angles.

Copy link
Member

@TokageItLab TokageItLab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@AThousandShips AThousandShips changed the title Fix quaternion keyframe optimization for colinear rotation over 180 degrees Fix quaternion keyframe optimization for collinear rotation over 180 degrees Feb 11, 2024
@akien-mga akien-mga merged commit 27575c4 into godotengine:master Feb 12, 2024
16 checks passed
@akien-mga
Copy link
Member

Thanks! And congrats for your first merged Godot contribution 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants