Skip to content

2D Translations #12364

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

Closed
ethantstanger opened this issue Mar 7, 2024 · 1 comment
Closed

2D Translations #12364

ethantstanger opened this issue Mar 7, 2024 · 1 comment
Labels
A-Transform Translations, rotations and scales C-Feature A new feature, making something new possible

Comments

@ethantstanger
Copy link

In Bevy, we use Vec3 for both 3D and 2D translations. The additional z value is useful as a z-index in 2D, so we want to keep that around in some way or another. However, the basic functions that you get with Vec3 (length(), distance(), etc.) use the z value as another dimension rather than a z-index, so two entities with the same x and y values but different z values are considered to be in different positions, when you would expect them to be in the exact same position working in 2D.

The solution is to create our own type for working in 2D that just uses the Vec2 from the standard library:

struct Translation2D {
    position: Vec2,
    z_index: f32,
}

An alternative is to manually implement 2D math functions for Vec3. I imagine we could just append _2d to the names of the functions so that we get length_2d() and distance_2d() functions. The downside is that we'd have to manually re-implement them all, and the idea of maintaining our own copy of standard functionality doesn't sound good.

@ethantstanger ethantstanger added C-Feature A new feature, making something new possible S-Needs-Triage This issue needs to be labelled labels Mar 7, 2024
@rparrett
Copy link
Contributor

rparrett commented Mar 7, 2024

This is a common point of frustration / confusion, and a slightly controversial idea. Though it seems like we are trending towards consensus on "the 2d split."

See #1275 and #7876 for discussion about 2d transform APIs, and #2548 for 2d-ergonomics-for-3d-transforms.

@rparrett rparrett closed this as completed Mar 7, 2024
@rparrett rparrett added A-Transform Translations, rotations and scales and removed S-Needs-Triage This issue needs to be labelled labels Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Transform Translations, rotations and scales C-Feature A new feature, making something new possible
Projects
None yet
Development

No branches or pull requests

2 participants