-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Bug in the Mul
impl for Transform
and GlobalTransform
#4910
Comments
if this gets fixed, this should be updated as well #4891 |
It's impossible to fix this in general without changing the representation, because TRS can't represent shear, which will happen when using non-uniform scale and arbitrary rotations. |
@HackerFoo In that case I think bevy should either adopt a more general representation or remove support for support non-uniform scales altogether. Personally, I don't think there is any reason to keep non-uniform scale as it is currently implemented, as it is a huge footgun. It has caused me and my coworkers to waste multiple hours on a bug, because we never considered that bevys mul implementation would not match matrix multiplication. |
I worked around this bug in my app for a while, but ultimately wrote #4379 as a compromise, because changing Just using an |
The current implementation is not even associative as illustrated by this example: let t1 = Transform::from_scale(Vec3::new(2.0, 1.0, 1.0));
let t2 = Transform::from_rotation(Quat::from_rotation_z(TAU / 4.0));
let t3 = Transform::from_translation(Vec3::new(1.0, 0.0, 0.0));
let left = (t1 * t2) * t3;
let right = t1 * (t2 * t3);
assert_eq!(left.translation.y.round(), 2.0);
assert_eq!(right.translation.y.round(), 1.0); |
@HackerFoo Good point re: shear. Seems like nonuniform scaling is completely unusable with TRS representation, and should probably be removed if that's the representation we're sticking with. Unless I'm overlooking a use case for scaling that is always aligned to the world axes regardless of object rotation?
Do you have a specific problem/usage in mind? I think I remember reading some discussion about this in one of the other related issues but I can't find it. |
I think #4379 as it looks right now solves this issue for Would it be a big problem if the |
I have proposed removing it. |
It is possible to keep the |
To some extent this is a question of resolving conflicting requirements. The way I see it most solutions are going to fall broadly into one of three categories.
|
Other possible representations that support multiplication are:
This is why #4379 only modifies |
Bevy version
I have tested both the current master as of this writing (9976ecb) and v0.7.0.
What you did
I think there is a bug in the
Mul
implementation ofTransform
andGlobalTransform
. I would expect these two expressions to be equivalent (up to rounding errors):I would expect this, because computing the same transform using matrix multiplications yields the expected result:
What went wrong
I was expecting the two transforms to be equivalent up to rounding point errors. However
t2
ends up scaling they
-axis instead of thex
-axis.Additional information
I believe the bug is in
mul_transform
where the scales from the two transforms are multiplied together without taking the rotation into account.I think there is a similar bug in
rotate
androtate_around
as well.The text was updated successfully, but these errors were encountered: