mirror of
https://github.com/bevyengine/bevy
synced 2024-09-20 22:42:08 +00:00
6f2eec8f78
# Objective It's often necessary to rotate directions, but it currently has to be done like this: ```rust Direction3d::new_unchecked(quat * *direction) ``` It'd be nice if you could rotate `Direction3d` directly: ```rust quat * direction ``` ## Solution Implement `Mul<Direction3d>` for `Quat` ~~and the other way around.~~ (Glam doesn't impl `Mul<Quat>` or `MulAssign<Quat>` for `Vec3`) The quaternion must be a unit quaternion to keep the direction normalized, so there is a `debug_assert!` to be sure. Almost all `Quat` constructors produce unit quaternions, so there should only be issues if doing something like `quat + quat` instead of `quat * quat`, using `Quat::from_xyzw` directly, or when you have significant enough drift caused by e.g. physics simulation that doesn't normalize rotation. In general, these would probably cause unexpected results anyway. I also moved tests around slightly to make `dim2` and `dim3` more consistent (`dim3` had *two* separate `test` modules for some reason). In the future, we'll probably want a `Rotation2d` type that would support the same for `Direction2d`. I considered implementing `Mul<Mat2>` for `Direction2d`, but that would probably be more questionable since `Mat2` isn't as clearly associated with rotations as `Quat` is. |
||
---|---|---|
.. | ||
src | ||
Cargo.toml |