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

Add linear/cubic angle interpolation to Animation::InterpolationType for shortest 2D rotation #64924

Merged
merged 1 commit into from
Aug 27, 2022

Conversation

TokageItLab
Copy link
Member

@TokageItLab TokageItLab commented Aug 26, 2022

Fixes godotengine/godot-proposals#5245.

Add INTERPOLATION_LINEAR_ANGLE and INTERPOLATION_CUBIC_ANGLE to perform 2D rotation in the shortest path.

2d_rot_prev1.mp4

The result of the rotation is always normalized and may not match the key. But of course, the visual angle is the same. Also it needs more than three keyframes are needed for 360 degree rotation, but this is the same as Quaternion and Spine http://ja.esotericsoftware.com/forum/full-360-rotation-1031.

2d_rot_prev2.mp4

If there is more than one track to be blended that uses Angle interpolation, the blend will not exceed 180 degrees with respect to 0 or ResetTrack.

This is the same as the Quaternion blend, as commented in #57675 (comment), since only one value can be used as a basis for the path for consistent blending results.1

Since the fix of #60093, the 3D skeleton will use rest as the reference, but otherwise ResetTrack will be used as the reference. That documentation is my todo so I will write it in the future...

Footnotes

  1. This prevents bone fractures and body penetration in Skeleton3D, but I don't know what will happen in Skeleton2D yet. In the worst case scenario, anyone may need to workaround the ResetTrack to change it in the middle of the animation, but for now, I will leave it.

@@ -253,6 +253,35 @@ class Math {
(-p_pre + 3.0f * p_from - 3.0f * p_to + p_post) * (p_weight * p_weight * p_weight));
}

static _ALWAYS_INLINE_ double cubic_interpolate_angle(double p_from, double p_to, double p_pre, double p_post, double p_weight) {
Copy link
Member Author

Choose a reason for hiding this comment

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

I implemented this for consistency. However, Animation uses cubic_interpolate_angle_in_time(), so I am not sure if this is necessary.

@TokageItLab
Copy link
Member Author

Added document.

@akien-mga
Copy link
Member

Thanks!

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

Successfully merging this pull request may close these issues.

Add ability to control rotation direction in AnimationPlayer
4 participants