From c7cd36b6c954c0f0cd2bf0b96b07c99690531096 Mon Sep 17 00:00:00 2001 From: Nicolas Sarlin Date: Sat, 26 Feb 2022 21:29:23 +0100 Subject: [PATCH] Add the possibility to create 2d cameras at custom positions --- crates/bevy_render/src/camera/bundle.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/bevy_render/src/camera/bundle.rs b/crates/bevy_render/src/camera/bundle.rs index 920a12bb35335..de85b8df33ee9 100644 --- a/crates/bevy_render/src/camera/bundle.rs +++ b/crates/bevy_render/src/camera/bundle.rs @@ -93,9 +93,18 @@ impl OrthographicCameraBundle { /// corresponding to `Z=+999.9` (closest to camera) to `Z=-0.1` (furthest away from /// camera) in world space. pub fn new_2d() -> Self { + Self::new_2d_with_far(1000.0) + } + + /// Create an orthographic projection camera with a custom Z position. + /// + /// The camera is placed at `Z=far-0.1`, looking toward the world origin `(0,0,0)`. + /// Its orthographic projection extends from `0.0` to `-far` in camera view space, + /// corresponding to `Z=far-0.1` (closest to camera) to `Z=-0.1` (furthest away from + /// camera) in world space. + pub fn new_2d_with_far(far: f32) -> Self { // we want 0 to be "closest" and +far to be "farthest" in 2d, so we offset // the camera's translation by far and use a right handed coordinate system - let far = 1000.0; let orthographic_projection = OrthographicProjection { far, depth_calculation: DepthCalculation::ZDifference,