-
-
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
Add more transform relative vectors #1300
Add more transform relative vectors #1300
Conversation
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.
Makes sense to me, implementation seems correct.
Another place which uses the forward
, right
, up
terminology is Transform::look_at
I think that including the I don't think there's any measurable cost to adding them either, given that they should impose 0 tech debt and won't be included in compiled executable if they're not used. |
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.
Looks good, I think this is ready to merge.
@@ -74,11 +74,36 @@ impl GlobalTransform { | |||
Mat4::from_scale_rotation_translation(self.scale, self.rotation, self.translation) | |||
} | |||
|
|||
#[inline] | |||
pub fn right(&self) -> Vec3 { | |||
self.rotation * Vec3::unit_x() |
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.
If Bevy is right-handed y-up, and we're calling +z forward, then doesn't that make +x left, not right?
(Sorry about my previous deleted comment; got momentarily confused about the whole "-handed" naming convention.)
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.
I.e. I expect the direction called "left" to be to my left if I'm looking down the direction called "forward".
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.
Ah! Unity (referenced above) is left-handed — maybe that's where the oddness came from. I was beginning to worry that there were two different conventions for what's called "left", i.e. because -x is left on screen in Bevy when doing 2D rendering. 😅
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.
haha yeah fortunately left still means left 😄
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.
I think I communicated that poorly. I was actually trying to say that I think the code in this PR is actually "wrong" as it stands, at least in that by one obvious interpretation it appears internally inconsistent.
Let me try again. 😊
Unity, which appears to have inspired this code, is left-handed. In that left-handed context, all of the function names in this PR would actually match up to their implementations.
But Bevy is right-handed, and so they appear to be inconsistent. If forward
means "along the positive z-axis", as it is defined in this PR, then right
should be whatever direction you end up facing by turning 90 degrees clockwise from forward. Which in Bevy would mean you are now pointing along the negative x-axis, whereas this PR defines right
as pointing down the positive x-axis.
I suspect the confusion exists because of mixing the idea of absolute directions in screen space with relative orientation in 3D space — and in particular the fact that you can actually do that without consequence in Unity, but not in Bevy. Or of course it could be as simple as just having copied the definitions from Unity without correcting for the differing handedness.
Or... there could be a third explanation that I haven't thought of, which makes the code in this PR "as intended". But if that's so, then I feel this whole API as it stands — at least in the context of a right-handed coordinate system like Bevy's — is likely to provide more confusion than utility, because there are so many obvious interpretations of it that make it look wrong.
I hope I'm making sense... 😅
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.
Ahh yeah I see your point now. And I do think you were clear enough in your initial description, I just didn't think enough about it / fixated too much on your last message. In 2d this "works" because +x is "the viewer's right". However from the perspective of the transform, +x is left (which is also true for 3d).
This should definitely be fixed. I think the functionality is still useful, but we need new names for it. Maybe just something like "local_positive_x" and "local_negative_x"?
We could also consider just flipping the signs on the x-axis, but that also makes things a little weird in 2d, as "left" would be the viewer's "right".
If anyone has better ideas, let me know :)
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.
I needed these functions when making a 2d game, and I tested it in that context, so I didn't choose the +x direction because of Unity but because it seemed to do the right thing.
Yup this looks good to me. Thanks! |
* Add more transform relative vectors (bevyengine#1298) * Add inverse of relative directions (bevyengine#1298)
I added the equivalent of
Transform::forward
for the other two axis's, I used Unity as the base for naming:https://docs.unity3d.com/ScriptReference/Transform-right.html
https://docs.unity3d.com/ScriptReference/Transform-up.html
https://docs.unity3d.com/ScriptReference/Transform-forward.html
This closes #1298