-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
[Merged by Bors] - Add the possibility to create custom 2d orthographic cameras #4048
Conversation
Self::custom_2d(1000.0, 1.0) | ||
} | ||
|
||
/// Create an orthographic projection camera with a custom Z position and scale. |
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.
Might want to add some documentation indicating that the camera will be placed at a z-position of far - 0.1
looking toward the world origin (like in the documentation for new_2d()
).
Since you can already express this with let bundle = OrthographicCameraBundle {
orthographic_projection: OrphographicProjection {
far: 1000.0,
scale: 1.0,
depth_calculation: DepthCalculation::ZDifference,
..Default::default()
},
..OrthographicCameraBundle::new_2d(),
}; I wonder whether having a custom contructor is worth it. Usually in bevy the recommended way to configure bundles is by overriding some fields and extending When you have a custom contructor you need to decide between having a very long |
I don't think this would work in that case because other components of the bundle would still be set with |
Oh right, the value is used both in the I don't like the name |
} | ||
|
||
/// Create an orthographic projection camera with a custom Z position and scale. | ||
pub fn custom_2d(far: f32, scale: f32) -> Self { |
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.
The other option for clarity here is that we could use custom CameraPlane::Far(f32)
and CameraScale(f32)
types for these.
A longer name is probably better, but I thought it was worth bringing up
Alternatively, we could just have it set the far plane since that's the tricky one. Users could then just mutate the scale after construction via |
That's a good point. Maybe with the name |
8ca2da0
to
c7cd36b
Compare
I'm not completely a fan of the |
I prefer the current approach. Otherwise I feel like for API consistency we should have |
This is probably a silly concern here; 99% of games will have exactly one camera built ever ;) |
bors r+ |
# Objective - The `OrthographicCameraBundle` constructor for 2d cameras uses a hardcoded value for Z position and scale of the camera. It could be useful to be able to customize these values. ## Solution - Add a new constructor `custom_2d` that takes `far` (Z position) and `scale` as parameters. The default constructor `new_2d` uses this constructor with `far = 1000.0` and `scale = 1.0`.
…ine#4048) # Objective - The `OrthographicCameraBundle` constructor for 2d cameras uses a hardcoded value for Z position and scale of the camera. It could be useful to be able to customize these values. ## Solution - Add a new constructor `custom_2d` that takes `far` (Z position) and `scale` as parameters. The default constructor `new_2d` uses this constructor with `far = 1000.0` and `scale = 1.0`.
…ine#4048) # Objective - The `OrthographicCameraBundle` constructor for 2d cameras uses a hardcoded value for Z position and scale of the camera. It could be useful to be able to customize these values. ## Solution - Add a new constructor `custom_2d` that takes `far` (Z position) and `scale` as parameters. The default constructor `new_2d` uses this constructor with `far = 1000.0` and `scale = 1.0`.
Objective
OrthographicCameraBundle
constructor for 2d cameras uses a hardcoded value for Z position and scale of the camera. It could be useful to be able to customize these values.Solution
custom_2d
that takesfar
(Z position) andscale
as parameters. The default constructornew_2d
uses this constructor withfar = 1000.0
andscale = 1.0
.