Skip to content

Commit

Permalink
Add the possibility to create 2d cameras at custom positions
Browse files Browse the repository at this point in the history
  • Loading branch information
nsarlin committed Feb 27, 2022
1 parent b697e73 commit c7cd36b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion crates/bevy_render/src/camera/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit c7cd36b

Please sign in to comment.