[C#] Fix Transform3D.InterpolateWith
applying rotation before scale
#89843
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.
Seen a user confused by
Transform3D transformC = transformA.InterpolateWith(transformB, 0.0f);
resulting in atransformC
being way different thantransformA
(specificallytransformC.Scale
not matchingtransformA.Scale
). Turns out there's a bug in the C# implementation of the method.Transform3D.InterpolateWith(Transform3D, real_t)
has the same implementation as in the core:godot/modules/mono/glue/GodotSharp/GodotSharp/Core/Transform3D.cs
Lines 129 to 146 in 99ff024
godot/core/math/transform_3d.cpp
Lines 97 to 112 in 99ff024
The issue is hidden in
Basis.SetQuaternionScale(Quaternion, Vector3)
which itself is the same as in the core, but the privateBasis.Rotate(Quaternion)
method used within is rotating locally instead of parentwise, as in the core:godot/modules/mono/glue/GodotSharp/GodotSharp/Core/Basis.cs
Lines 207 to 216 in 99ff024
godot/core/math/basis.cpp
Lines 889 to 892 in 99ff024
godot/core/math/basis.cpp
Lines 379 to 385 in 99ff024
This PR fixes this. Both
private Basis.Rotate(Quaternion)
andinternal Basis.SetQuaternionScale(Quaternion, Vector3)
affected by this change are not used anywhere else so shouldn't break anything else.Example:
Before (v4.2.1.stable.mono.official [b09f793]):
(
Transform3D transformC = transformA.InterpolateWith(transformB, 0.0f);
)After (this PR):