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

Const functions for initializing transforms #2097

Closed
alice-i-cecile opened this issue May 4, 2021 · 2 comments
Closed

Const functions for initializing transforms #2097

alice-i-cecile opened this issue May 4, 2021 · 2 comments
Labels
C-Feature A new feature, making something new possible D-Trivial Nice and easy! A great choice to get started with Bevy

Comments

@alice-i-cecile
Copy link
Member

What problem does this solve or what need does it fill?

Transforms are common configuration points, but there's no current way to initialize them as constants that are easily referred to and shared.

What solution would you like?

Follow the example set by glam and provide const fn and macros to initialize const Transform structs.

What alternative(s) have you considered?

Currently, I'm just storing these values as local non-const variables within my systems.

You could instead use resources as pseudo-consts?

In heavier games, you could also store this information as part of a scene.

Additional context

Inspired by work in #2094, but out of scope for that.

See bitshifter/glam-rs#76 for more discussion on the challenges involved in doing so, and why they can't just use simple const fn.

For those familiar with Rust's macro system, this should be a simple enough first issue and require very little knowledge of Bevy's internals.

@alice-i-cecile alice-i-cecile added C-Feature A new feature, making something new possible D-Trivial Nice and easy! A great choice to get started with Bevy core labels May 4, 2021
@cart
Copy link
Member

cart commented May 4, 2021

Defining const Transforms is already possible using glam's macros. I think this is clearer than most equivalent macro impls as its explicit about each field:

use bevy_math::*;
pub const IDENTITY: Transform = Transform {
    translation: const_vec3!([0.0, 0.0, 0.0]),
    rotation: const_quat!([0.0, 0.0, 0.0, 1.0]),
    scale: const_vec3!([0.0, 0.0, 0.0]),
};

Compare that to some theoretical Transform macro:

pub const IDENTITY: Transform = const_transform!(
    [0.0, 0.0, 0.0],
    [0.0, 0.0, 0.0, 1.0],
    [0.0, 0.0, 0.0],
);

Its less boilerplate, but much harder to tell whats going on.

@alice-i-cecile
Copy link
Member Author

Oh cool! Thanks @cart; I'll close this and add it to the Breakout example :3

alice-i-cecile added a commit to alice-i-cecile/bevy that referenced this issue May 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Feature A new feature, making something new possible D-Trivial Nice and easy! A great choice to get started with Bevy
Projects
None yet
Development

No branches or pull requests

2 participants