Improved error-handling for scaling #925
Merged
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 #912.
This refactors the error-handling for scaling introduced in #810.
The current usage of
JPH::Shape::IsValidScale
poses some problems in the context of Godot, since the tolerance ofJPH::Shape::IsValidScale
is (understandably) quite small, and Godot doesn't do any sort of automatic orthonormalization of its transforms, which means that it doesn't take many frames for something like the rotation of aCharacterBody3D
to start messing with the orthogonality of its transforms, thereby resulting in weird scaling and potentially causingJPH::Shape::IsValidScale
to fail.The technically correct resolution to this would of course be for the user to just orthonormalize its transforms, or for this extension to disregard scaling completely (like Godot Physics does), but given the friction involved with this, and the fact that some users have come to appreciate and rely on the (undocumented) support for scaling in this extension, a compromise has been reached instead.
This PR makes use of the newly introduced
JPH::Shape::MakeScaleValid
, which takes any arbitrary scaling and changes it just enough to be valid for the given shape. This means that we can make sure that Jolt always receives a correct scaling, but better yet we can also check to see how different this new valid scaling is from the one we put in, and emit an error based on a tolerance that we define ourselves.So this effectively raises the tolerance from
0.0001
-ish to0.01
. This will make sure that clearly incorrect scaling, such as deliberately scaling a capsule or sphere non-uniformly, will emit errors, but scaling as a result of accumulative precision errors are only reported if they're really bad.Note that the correction of the scale (i.e.
JPH::Shape::MakeScaleValid
) happens regardless of build, whereas the error-reporting only happens in editor/debug builds.