Skip to content
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

Merged
merged 2 commits into from
Jan 25, 2021

Conversation

RedlineTriad
Copy link
Contributor

@RedlineTriad RedlineTriad commented Jan 24, 2021

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

@RedlineTriad RedlineTriad changed the title Add more transform relative vectors (#1298) Add more transform relative vectors Jan 24, 2021
Copy link
Member

@DJMcNab DJMcNab left a 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

@alice-i-cecile
Copy link
Member

I think that including the left etc variants of this make sense for code clarity. It's easy to miss a negative sign, but much harder to mistype or misread right when you mean left.

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.

Copy link
Member

@alice-i-cecile alice-i-cecile left a 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()

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.)

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".

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. 😅

Copy link
Member

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 😄

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... 😅

Copy link
Member

@cart cart Jan 25, 2021

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 :)

Copy link
Contributor Author

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.

@cart
Copy link
Member

cart commented Jan 25, 2021

Yup this looks good to me. Thanks!

@cart cart merged commit 7e368e0 into bevyengine:master Jan 25, 2021
@RedlineTriad RedlineTriad deleted the transform-relative-vectors branch January 25, 2021 10:59
rparrett pushed a commit to rparrett/bevy that referenced this pull request Jan 27, 2021
* Add more transform relative vectors (bevyengine#1298)

* Add inverse of relative directions (bevyengine#1298)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add other directions for Transform
5 participants