mirror of
https://github.com/bevyengine/bevy.git
synced 2026-05-06 14:17:00 -04:00
637eeec352
## Objective This PR adds animation support for 2D rotations by implementing the `Animatable` trait for `Rot2`. This enables developers to smoothly animate 2D entities and UI elements. *(Note: This is a clean, cherry-picked recreation of #23618 targeting the `main` branch, as suggested by @alice-i-cecile .)* ## Solution To ensure mathematical correctness and consistency with existing Bevy math types (like `Quat`), this implementation includes: - **Shortest-path interpolation:** Uses spherical linear interpolation (`slerp`) so that rotations naturally take the shortest route (e.g., passing through 0° rather than 180° when moving from 89° to -89°). - **Standardized blending:** Implements precise cumulative and additive blending logic that perfectly mirrors the behavior of `Quat`. - **Comprehensive Unit Tests:** Added tests specifically to verify: - Shortest path interpolation. - Absolute blending with equal weights. - Cumulative multi-way blending. - Additive blending. - **Example Update:** Updated the `animated_ui` example to showcase the new `Rot2` animation capabilities. ## Testing - [x] All new unit tests pass (`cargo test -p bevy_animation --lib animatable`). - [x] Ran `cargo fmt` and `cargo clippy`. - [x] Tested the `animated_ui` example locally to ensure the 2D rotation curve behaves as expected. --------- Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>