Skip to content

Commit

Permalink
Add the possibility to create custom 2d orthographic cameras
Browse files Browse the repository at this point in the history
  • Loading branch information
nsarlin committed Feb 26, 2022
1 parent b697e73 commit 8ca2da0
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion crates/bevy_render/src/camera/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,16 @@ 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::custom_2d(1000.0, 1.0)
}

/// Create an orthographic projection camera with a custom Z position and scale.
pub fn custom_2d(far: f32, scale: 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,
scale,
depth_calculation: DepthCalculation::ZDifference,
..Default::default()
};
Expand Down

0 comments on commit 8ca2da0

Please sign in to comment.