-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# 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.
- Loading branch information
Showing
2 changed files
with
122 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters