-
-
Notifications
You must be signed in to change notification settings - Fork 21.8k
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
Fix broken negative scaling when using Jolt Physics #103440
Open
mihe
wants to merge
1
commit into
godotengine:master
Choose a base branch
from
mihe:jolt/transform-decomposition
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+155
−26
Conversation
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
2533b0d
to
7e85cd5
Compare
mihe
commented
Mar 1, 2025
jrouwe
reviewed
Mar 1, 2025
7e85cd5
to
b125f2e
Compare
b125f2e
to
62e8b1e
Compare
jrouwe
approved these changes
Mar 2, 2025
akien-mga
approved these changes
Mar 2, 2025
In godot engine the common conversion from Basis to quaternion is get_rotation_quaternion. I don't know why we're doing it this way. |
fire
requested changes
Mar 3, 2025
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.
Please explain why we can't use get_rotation_quaternion or orthogonalize?
https://github.com/godotengine/godot/blob/master/core/math/basis.cpp#L80
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #103408.
Supersedes #103426.
This PR effectively just brings back some code (derived in part from Jolt's own
JPH::Mat44::Decompose
) that I had left behind when porting the Jolt integration from the Godot Jolt extension in #99895, due to wanting to keep things as minimal as possible.What this code is meant to do is take a potentially scaled
Basis
(orTransform3D
) and decompose it into a rotation part and a scale part, which must be done before passing any transform into Jolt, as Jolt takes scale separately from the rest of the transform in its API, and sometimes also takes rotation separately, in the form of a quaternion.I had mistaken the following code:
... as being a valid substitute for this code:
... which it is not, because while
Basis::orthonormalize
does also use the Gram-Schmidt process to perform the orthonormalization, much like this "new"decompose
function, it does not handle reflection (i.e. negative scaling) in any way, meaning we can end up with aBasis
that is orthonormal, but is not in fact a valid (right-handed) rotation, which causes problems with things likeBasis::get_quaternion
, as it assumes a valid (right-handed) rotation.This "new"
decompose
function solves this by essentially just flipping all the axes of theBasis
when we find ourselves with a negative determinant (i.e. negative scaling) which seems to line up with the convention used by otherBasis
methods, likeBasis::get_scale
andBasis::get_rotation_quaternion
.It also serves as a minor optimization, since we can avoid some of the redundant vector normalizations that are shared between
Basis::get_scale
andBasis::orthonormalize
.