-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Fixes #16480: Prevent exponential denormalization on Transform::rotate_axis
#17604
Conversation
Welcome, new contributor! Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
@@ -314,7 +314,7 @@ impl Transform { | |||
/// If this [`Transform`] has a parent, the `axis` is relative to the rotation of the parent. | |||
#[inline] | |||
pub fn rotate_axis(&mut self, axis: Dir3, angle: f32) { | |||
self.rotate(Quat::from_axis_angle(axis.into(), angle)); | |||
self.rotation = ((Quat::from_axis_angle(axis.into(), angle)) * self.rotation).normalize(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Link the issue here in a comment please; this normalization looks out of place otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! Is it fine like this or should I add the full link?
0f2a51d
to
a4a1078
Compare
a4a1078
to
e23fe5f
Compare
TLDR: I think this is a pragmatic and narrowly scoped fix to an issue that particularly affects new users. There was discord discussion on the broader topic of exploding rotations. The two most popular opinions seemed to be:
But there wasn't any consensus on this particular PR, which only changes a few functions on So I'm gonna throw out my take - it's fine, and should be extended to all the
A specific scenario this fixes is a user who copies the Alternatives:
|
e23fe5f
to
16bf056
Compare
I added the same fix to Also opened an alternative PR, #17646 that instead just adds warnings and docs. |
Ultimately I feel like a solid half of the issue here comes down to using quaternions for 2D. |
… (alternative to #17604) (#17646) # Objective - When obtaining an axis from the transform and putting that into `Transform::rotate_axis` or `Transform::rotate_axis_local`, floating point errors could accumulate exponentially, resulting in denormalized rotation. - This is an alternative to and closes #17604, due to lack of consent around this in the [discord discussion](https://discord.com/channels/691052431525675048/1203087353850364004/1334232710658392227) - Closes #16480 ## Solution - Add a warning of this issue and a recommendation to normalize to the API docs. - Add a runtime warning that checks for denormalized axis in debug mode, with a reference to the API docs.
… (alternative to bevyengine#17604) (bevyengine#17646) # Objective - When obtaining an axis from the transform and putting that into `Transform::rotate_axis` or `Transform::rotate_axis_local`, floating point errors could accumulate exponentially, resulting in denormalized rotation. - This is an alternative to and closes bevyengine#17604, due to lack of consent around this in the [discord discussion](https://discord.com/channels/691052431525675048/1203087353850364004/1334232710658392227) - Closes bevyengine#16480 ## Solution - Add a warning of this issue and a recommendation to normalize to the API docs. - Add a runtime warning that checks for denormalized axis in debug mode, with a reference to the API docs.
… (alternative to bevyengine#17604) (bevyengine#17646) # Objective - When obtaining an axis from the transform and putting that into `Transform::rotate_axis` or `Transform::rotate_axis_local`, floating point errors could accumulate exponentially, resulting in denormalized rotation. - This is an alternative to and closes bevyengine#17604, due to lack of consent around this in the [discord discussion](https://discord.com/channels/691052431525675048/1203087353850364004/1334232710658392227) - Closes bevyengine#16480 ## Solution - Add a warning of this issue and a recommendation to normalize to the API docs. - Add a runtime warning that checks for denormalized axis in debug mode, with a reference to the API docs.
Objective
Fixes #16480
When repeatedly using
Transform::roatate_axis
and feeding aaxis
that is based on the currentTransform::rotation
, the floating point errors could accumulate exponentially, resulting in denormalized rotation, which panics.Solution
Normalize the quaternion in
Transform::rotate_axis
.Testing
I confirmed that this fixes the issue reported in #16480.