Skip to content

Commit 0850975

Browse files
committed
Add the possibility to create custom 2d orthographic cameras (#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`.
1 parent ec30822 commit 0850975

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

crates/bevy_render/src/camera/bundle.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,18 @@ impl OrthographicCameraBundle<Camera2d> {
133133
/// corresponding to `Z=+999.9` (closest to camera) to `Z=-0.1` (furthest away from
134134
/// camera) in world space.
135135
pub fn new_2d() -> Self {
136+
Self::new_2d_with_far(1000.0)
137+
}
138+
139+
/// Create an orthographic projection camera with a custom Z position.
140+
///
141+
/// The camera is placed at `Z=far-0.1`, looking toward the world origin `(0,0,0)`.
142+
/// Its orthographic projection extends from `0.0` to `-far` in camera view space,
143+
/// corresponding to `Z=far-0.1` (closest to camera) to `Z=-0.1` (furthest away from
144+
/// camera) in world space.
145+
pub fn new_2d_with_far(far: f32) -> Self {
136146
// we want 0 to be "closest" and +far to be "farthest" in 2d, so we offset
137147
// the camera's translation by far and use a right handed coordinate system
138-
let far = 1000.0;
139148
let orthographic_projection = OrthographicProjection {
140149
far,
141150
depth_calculation: DepthCalculation::ZDifference,

0 commit comments

Comments
 (0)