From 57557370f5c81ff2cb4a6f6a247b138147342555 Mon Sep 17 00:00:00 2001 From: Jasen Borisov Date: Mon, 31 Aug 2020 01:36:26 +0200 Subject: [PATCH 01/18] add normalized orthographic projection --- crates/bevy_render/src/camera/projection.rs | 55 +++++++++++++++++++++ crates/bevy_render/src/lib.rs | 7 ++- 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/crates/bevy_render/src/camera/projection.rs b/crates/bevy_render/src/camera/projection.rs index 7e9e8a4ab6cfa..ed835df2f0503 100644 --- a/crates/bevy_render/src/camera/projection.rs +++ b/crates/bevy_render/src/camera/projection.rs @@ -112,3 +112,58 @@ impl Default for OrthographicProjection { } } } + +#[derive(Debug, Clone, Reflect)] +#[reflect(Component)] +pub struct ScaledOrthographicProjection { + pub aspect_ratio: f32, + pub near: f32, + pub far: f32, + pub window_origin: WindowOrigin, +} + +impl CameraProjection for ScaledOrthographicProjection { + fn get_projection_matrix(&self) -> Mat4 { + match self.window_origin { + WindowOrigin::Center => { + Mat4::orthographic_rh( + -self.aspect_ratio, + self.aspect_ratio, + -1.0, + 1.0, + self.near, + self.far, + ) + } + WindowOrigin::BottomLeft => { + Mat4::orthographic_rh( + 0.0, + self.aspect_ratio, + 0.0, + 1.0, + self.near, + self.far, + ) + } + } + } + + fn update(&mut self, width: f32, height: f32) { + self.aspect_ratio = width / height; + } + + fn depth_calculation(&self) -> DepthCalculation { + DepthCalculation::ZDifference + } +} + +impl Default for ScaledOrthographicProjection { + fn default() -> Self { + ScaledOrthographicProjection { + aspect_ratio: 1.0, + near: 0.0, + far: 1000.0, + window_origin: WindowOrigin::Center, + } + } +} diff --git a/crates/bevy_render/src/lib.rs b/crates/bevy_render/src/lib.rs index 39ca67dc2b627..e51a191401e5d 100644 --- a/crates/bevy_render/src/lib.rs +++ b/crates/bevy_render/src/lib.rs @@ -35,7 +35,8 @@ use base::Msaa; use bevy_app::prelude::*; use bevy_asset::AddAsset; use camera::{ - ActiveCameras, Camera, OrthographicProjection, PerspectiveProjection, VisibleEntities, + ActiveCameras, Camera, VisibleEntities, + OrthographicProjection, PerspectiveProjection, ScaledOrthographicProjection, }; use pipeline::{ IndexFormat, PipelineCompiler, PipelineDescriptor, PipelineSpecialization, PrimitiveTopology, @@ -146,6 +147,10 @@ impl Plugin for RenderPlugin { bevy_app::stage::POST_UPDATE, camera::camera_system::.system(), ) + .add_system_to_stage( + bevy_app::stage::POST_UPDATE, + camera::camera_system::.system(), + ) .add_system_to_stage( bevy_app::stage::POST_UPDATE, camera::camera_system::.system(), From 2558b35c22784deede65db0093bae50db7ae2b62 Mon Sep 17 00:00:00 2001 From: Jasen Borisov Date: Thu, 21 Jan 2021 18:19:21 +0100 Subject: [PATCH 02/18] custom scale for ScaledOrthographicProjection --- crates/bevy_render/src/camera/projection.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/crates/bevy_render/src/camera/projection.rs b/crates/bevy_render/src/camera/projection.rs index ed835df2f0503..dd02fc01c670a 100644 --- a/crates/bevy_render/src/camera/projection.rs +++ b/crates/bevy_render/src/camera/projection.rs @@ -116,6 +116,7 @@ impl Default for OrthographicProjection { #[derive(Debug, Clone, Reflect)] #[reflect(Component)] pub struct ScaledOrthographicProjection { + pub scale: f32, pub aspect_ratio: f32, pub near: f32, pub far: f32, @@ -127,10 +128,10 @@ impl CameraProjection for ScaledOrthographicProjection { match self.window_origin { WindowOrigin::Center => { Mat4::orthographic_rh( - -self.aspect_ratio, - self.aspect_ratio, - -1.0, - 1.0, + -self.aspect_ratio * self.scale, + self.aspect_ratio * self.scale, + -self.scale, + self.scale, self.near, self.far, ) @@ -138,9 +139,9 @@ impl CameraProjection for ScaledOrthographicProjection { WindowOrigin::BottomLeft => { Mat4::orthographic_rh( 0.0, - self.aspect_ratio, + self.aspect_ratio * self.scale, 0.0, - 1.0, + self.scale, self.near, self.far, ) @@ -160,6 +161,7 @@ impl CameraProjection for ScaledOrthographicProjection { impl Default for ScaledOrthographicProjection { fn default() -> Self { ScaledOrthographicProjection { + scale: 1.0, aspect_ratio: 1.0, near: 0.0, far: 1000.0, From 9af00aabf9ea5790f4f13ab76323fbac0494fe90 Mon Sep 17 00:00:00 2001 From: Jasen Borisov Date: Thu, 21 Jan 2021 18:42:09 +0100 Subject: [PATCH 03/18] allow choosing base axis for ScaledOrthographicProjection --- crates/bevy_render/src/camera/projection.rs | 40 ++++++++++++++++++--- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/crates/bevy_render/src/camera/projection.rs b/crates/bevy_render/src/camera/projection.rs index dd02fc01c670a..2d518200dbada 100644 --- a/crates/bevy_render/src/camera/projection.rs +++ b/crates/bevy_render/src/camera/projection.rs @@ -113,6 +113,13 @@ impl Default for OrthographicProjection { } } +#[derive(Debug, Clone, Reflect, Serialize, Deserialize)] +#[reflect_value(Serialize, Deserialize)] +pub enum BaseAxis { + Vertical, + Horizontal, +} + #[derive(Debug, Clone, Reflect)] #[reflect(Component)] pub struct ScaledOrthographicProjection { @@ -121,12 +128,13 @@ pub struct ScaledOrthographicProjection { pub near: f32, pub far: f32, pub window_origin: WindowOrigin, + pub base_axis: BaseAxis, } impl CameraProjection for ScaledOrthographicProjection { fn get_projection_matrix(&self) -> Mat4 { - match self.window_origin { - WindowOrigin::Center => { + match (&self.window_origin, &self.base_axis) { + (WindowOrigin::Center, BaseAxis::Vertical) => { Mat4::orthographic_rh( -self.aspect_ratio * self.scale, self.aspect_ratio * self.scale, @@ -136,7 +144,7 @@ impl CameraProjection for ScaledOrthographicProjection { self.far, ) } - WindowOrigin::BottomLeft => { + (WindowOrigin::BottomLeft, BaseAxis::Vertical) => { Mat4::orthographic_rh( 0.0, self.aspect_ratio * self.scale, @@ -146,11 +154,34 @@ impl CameraProjection for ScaledOrthographicProjection { self.far, ) } + (WindowOrigin::Center, BaseAxis::Horizontal) => { + Mat4::orthographic_rh( + -self.scale, + self.scale, + -self.aspect_ratio * self.scale, + self.aspect_ratio * self.scale, + self.near, + self.far, + ) + } + (WindowOrigin::BottomLeft, BaseAxis::Horizontal) => { + Mat4::orthographic_rh( + 0.0, + self.scale, + 0.0, + self.aspect_ratio * self.scale, + self.near, + self.far, + ) + } } } fn update(&mut self, width: f32, height: f32) { - self.aspect_ratio = width / height; + self.aspect_ratio = match self.base_axis { + BaseAxis::Vertical => width / height, + BaseAxis::Horizontal => height / width, + } } fn depth_calculation(&self) -> DepthCalculation { @@ -166,6 +197,7 @@ impl Default for ScaledOrthographicProjection { near: 0.0, far: 1000.0, window_origin: WindowOrigin::Center, + base_axis: BaseAxis::Vertical, } } } From 857b61f12860044e58432f9f66e717d699ffc9d5 Mon Sep 17 00:00:00 2001 From: Jasen Borisov Date: Thu, 21 Jan 2021 18:46:23 +0100 Subject: [PATCH 04/18] cargo fmt --- crates/bevy_render/src/camera/projection.rs | 72 +++++++++------------ crates/bevy_render/src/lib.rs | 4 +- 2 files changed, 34 insertions(+), 42 deletions(-) diff --git a/crates/bevy_render/src/camera/projection.rs b/crates/bevy_render/src/camera/projection.rs index 2d518200dbada..109f7e87bcc76 100644 --- a/crates/bevy_render/src/camera/projection.rs +++ b/crates/bevy_render/src/camera/projection.rs @@ -134,46 +134,38 @@ pub struct ScaledOrthographicProjection { impl CameraProjection for ScaledOrthographicProjection { fn get_projection_matrix(&self) -> Mat4 { match (&self.window_origin, &self.base_axis) { - (WindowOrigin::Center, BaseAxis::Vertical) => { - Mat4::orthographic_rh( - -self.aspect_ratio * self.scale, - self.aspect_ratio * self.scale, - -self.scale, - self.scale, - self.near, - self.far, - ) - } - (WindowOrigin::BottomLeft, BaseAxis::Vertical) => { - Mat4::orthographic_rh( - 0.0, - self.aspect_ratio * self.scale, - 0.0, - self.scale, - self.near, - self.far, - ) - } - (WindowOrigin::Center, BaseAxis::Horizontal) => { - Mat4::orthographic_rh( - -self.scale, - self.scale, - -self.aspect_ratio * self.scale, - self.aspect_ratio * self.scale, - self.near, - self.far, - ) - } - (WindowOrigin::BottomLeft, BaseAxis::Horizontal) => { - Mat4::orthographic_rh( - 0.0, - self.scale, - 0.0, - self.aspect_ratio * self.scale, - self.near, - self.far, - ) - } + (WindowOrigin::Center, BaseAxis::Vertical) => Mat4::orthographic_rh( + -self.aspect_ratio * self.scale, + self.aspect_ratio * self.scale, + -self.scale, + self.scale, + self.near, + self.far, + ), + (WindowOrigin::BottomLeft, BaseAxis::Vertical) => Mat4::orthographic_rh( + 0.0, + self.aspect_ratio * self.scale, + 0.0, + self.scale, + self.near, + self.far, + ), + (WindowOrigin::Center, BaseAxis::Horizontal) => Mat4::orthographic_rh( + -self.scale, + self.scale, + -self.aspect_ratio * self.scale, + self.aspect_ratio * self.scale, + self.near, + self.far, + ), + (WindowOrigin::BottomLeft, BaseAxis::Horizontal) => Mat4::orthographic_rh( + 0.0, + self.scale, + 0.0, + self.aspect_ratio * self.scale, + self.near, + self.far, + ), } } diff --git a/crates/bevy_render/src/lib.rs b/crates/bevy_render/src/lib.rs index e51a191401e5d..ed097df6bbdea 100644 --- a/crates/bevy_render/src/lib.rs +++ b/crates/bevy_render/src/lib.rs @@ -35,8 +35,8 @@ use base::Msaa; use bevy_app::prelude::*; use bevy_asset::AddAsset; use camera::{ - ActiveCameras, Camera, VisibleEntities, - OrthographicProjection, PerspectiveProjection, ScaledOrthographicProjection, + ActiveCameras, Camera, OrthographicProjection, PerspectiveProjection, + ScaledOrthographicProjection, VisibleEntities, }; use pipeline::{ IndexFormat, PipelineCompiler, PipelineDescriptor, PipelineSpecialization, PrimitiveTopology, From b0ea4fabf97e5a2233bf6f4bcab7e7e87bf077fa Mon Sep 17 00:00:00 2001 From: Jasen Borisov Date: Thu, 21 Jan 2021 19:03:15 +0100 Subject: [PATCH 05/18] add general (scaled) orthographic camera bundle FIXME: does the same "far" trick from Camera2DBundle make any sense here? --- crates/bevy_render/src/entity.rs | 48 +++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/crates/bevy_render/src/entity.rs b/crates/bevy_render/src/entity.rs index a87aa88896044..6f77842623c94 100644 --- a/crates/bevy_render/src/entity.rs +++ b/crates/bevy_render/src/entity.rs @@ -1,5 +1,8 @@ use crate::{ - camera::{Camera, OrthographicProjection, PerspectiveProjection, VisibleEntities}, + camera::{ + Camera, OrthographicProjection, PerspectiveProjection, ScaledOrthographicProjection, + VisibleEntities, + }, pipeline::RenderPipelines, prelude::Visible, render_graph::base, @@ -23,6 +26,8 @@ pub struct MeshBundle { } /// A component bundle for "3d camera" entities +/// +/// Uses a perspective projection. #[derive(Bundle)] pub struct Camera3dBundle { pub camera: Camera, @@ -48,6 +53,10 @@ impl Default for Camera3dBundle { } /// A component bundle for "2d camera" entities +/// +/// Uses an orthographic projection mapped to window pixels. +/// +/// Use this for pixel-art / sprite-based 2D games. #[derive(Bundle)] pub struct Camera2dBundle { pub camera: Camera, @@ -77,3 +86,40 @@ impl Default for Camera2dBundle { } } } + +/// A component bundle for "orthographic camera" entities +/// +/// Uses a normalized orthographic projection. +/// +/// Use this for CAD-like 3D views or non-pixel-oriented 2D games. +#[derive(Bundle)] +pub struct CameraOrthoBundle { + pub camera: Camera, + pub orthographic_projection: ScaledOrthographicProjection, + pub visible_entities: VisibleEntities, + pub transform: Transform, + pub global_transform: GlobalTransform, +} + +impl Default for CameraOrthoBundle { + fn default() -> Self { + // FIXME does this same far trick from `Camera2DBundle` make any sense here? + + // 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; + CameraOrthoBundle { + camera: Camera { + name: Some(base::camera::CAMERA_2D.to_string()), + ..Default::default() + }, + orthographic_projection: ScaledOrthographicProjection { + far, + ..Default::default() + }, + visible_entities: Default::default(), + transform: Transform::from_xyz(0.0, 0.0, far - 0.1), + global_transform: Default::default(), + } + } +} From 8603eb8f8e191410d3be83b3c3724212a9ccf6e1 Mon Sep 17 00:00:00 2001 From: Jasen Borisov Date: Fri, 22 Jan 2021 23:35:49 +0100 Subject: [PATCH 06/18] fixes --- crates/bevy_render/src/camera/projection.rs | 16 ++++++++-------- crates/bevy_render/src/entity.rs | 17 +++++------------ 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/crates/bevy_render/src/camera/projection.rs b/crates/bevy_render/src/camera/projection.rs index 109f7e87bcc76..fa9745b81e967 100644 --- a/crates/bevy_render/src/camera/projection.rs +++ b/crates/bevy_render/src/camera/projection.rs @@ -142,14 +142,6 @@ impl CameraProjection for ScaledOrthographicProjection { self.near, self.far, ), - (WindowOrigin::BottomLeft, BaseAxis::Vertical) => Mat4::orthographic_rh( - 0.0, - self.aspect_ratio * self.scale, - 0.0, - self.scale, - self.near, - self.far, - ), (WindowOrigin::Center, BaseAxis::Horizontal) => Mat4::orthographic_rh( -self.scale, self.scale, @@ -158,6 +150,14 @@ impl CameraProjection for ScaledOrthographicProjection { self.near, self.far, ), + (WindowOrigin::BottomLeft, BaseAxis::Vertical) => Mat4::orthographic_rh( + 0.0, + self.aspect_ratio * self.scale, + 0.0, + self.scale, + self.near, + self.far, + ), (WindowOrigin::BottomLeft, BaseAxis::Horizontal) => Mat4::orthographic_rh( 0.0, self.scale, diff --git a/crates/bevy_render/src/entity.rs b/crates/bevy_render/src/entity.rs index 6f77842623c94..c5306abb36475 100644 --- a/crates/bevy_render/src/entity.rs +++ b/crates/bevy_render/src/entity.rs @@ -91,7 +91,8 @@ impl Default for Camera2dBundle { /// /// Uses a normalized orthographic projection. /// -/// Use this for CAD-like 3D views or non-pixel-oriented 2D games. +/// Use this for CAD-like 3D views, isometric games, +/// or 2D games that should scale with the window. #[derive(Bundle)] pub struct CameraOrthoBundle { pub camera: Camera, @@ -103,22 +104,14 @@ pub struct CameraOrthoBundle { impl Default for CameraOrthoBundle { fn default() -> Self { - // FIXME does this same far trick from `Camera2DBundle` make any sense here? - - // 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; CameraOrthoBundle { camera: Camera { - name: Some(base::camera::CAMERA_2D.to_string()), - ..Default::default() - }, - orthographic_projection: ScaledOrthographicProjection { - far, + name: Some(base::camera::CAMERA_3D.to_string()), ..Default::default() }, + orthographic_projection: ScaledOrthographicProjection::default(), visible_entities: Default::default(), - transform: Transform::from_xyz(0.0, 0.0, far - 0.1), + transform: Default::default(), global_transform: Default::default(), } } From 88805e0a9d7bfb72977da458bc0a88bde43eb579 Mon Sep 17 00:00:00 2001 From: Jasen Borisov Date: Tue, 26 Jan 2021 18:26:32 +0100 Subject: [PATCH 07/18] camera bundles: rename and new ortho constructors --- crates/bevy_render/src/entity.rs | 60 ++++++++++++++------------------ 1 file changed, 27 insertions(+), 33 deletions(-) diff --git a/crates/bevy_render/src/entity.rs b/crates/bevy_render/src/entity.rs index c5306abb36475..930badcd64889 100644 --- a/crates/bevy_render/src/entity.rs +++ b/crates/bevy_render/src/entity.rs @@ -25,11 +25,11 @@ pub struct MeshBundle { pub global_transform: GlobalTransform, } -/// A component bundle for "3d camera" entities +/// Component bundle for camera entities with perspective projection /// -/// Uses a perspective projection. +/// Use this for 3D rendering. #[derive(Bundle)] -pub struct Camera3dBundle { +pub struct PerspectiveCameraBundle { pub camera: Camera, pub perspective_projection: PerspectiveProjection, pub visible_entities: VisibleEntities, @@ -37,9 +37,9 @@ pub struct Camera3dBundle { pub global_transform: GlobalTransform, } -impl Default for Camera3dBundle { +impl Default for PerspectiveCameraBundle { fn default() -> Self { - Camera3dBundle { + PerspectiveCameraBundle { camera: Camera { name: Some(base::camera::CAMERA_3D.to_string()), ..Default::default() @@ -52,13 +52,11 @@ impl Default for Camera3dBundle { } } -/// A component bundle for "2d camera" entities +/// Component bundle for camera entities with orthographic projection /// -/// Uses an orthographic projection mapped to window pixels. -/// -/// Use this for pixel-art / sprite-based 2D games. +/// Use this for 2D games, isometric games, CAD-like 3D views. #[derive(Bundle)] -pub struct Camera2dBundle { +pub struct OrthographicCameraBundle { pub camera: Camera, pub orthographic_projection: OrthographicProjection, pub visible_entities: VisibleEntities, @@ -66,12 +64,12 @@ pub struct Camera2dBundle { pub global_transform: GlobalTransform, } -impl Default for Camera2dBundle { - fn default() -> Self { +impl OrthographicCameraBundle { + pub fn new_2d() -> 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; - Camera2dBundle { + OrthographicCameraBundle { camera: Camera { name: Some(base::camera::CAMERA_2D.to_string()), ..Default::default() @@ -85,31 +83,27 @@ impl Default for Camera2dBundle { global_transform: Default::default(), } } -} - -/// A component bundle for "orthographic camera" entities -/// -/// Uses a normalized orthographic projection. -/// -/// Use this for CAD-like 3D views, isometric games, -/// or 2D games that should scale with the window. -#[derive(Bundle)] -pub struct CameraOrthoBundle { - pub camera: Camera, - pub orthographic_projection: ScaledOrthographicProjection, - pub visible_entities: VisibleEntities, - pub transform: Transform, - pub global_transform: GlobalTransform, -} -impl Default for CameraOrthoBundle { - fn default() -> Self { - CameraOrthoBundle { + pub fn new_3d() -> Self { + OrthographicCameraBundle { camera: Camera { name: Some(base::camera::CAMERA_3D.to_string()), ..Default::default() }, - orthographic_projection: ScaledOrthographicProjection::default(), + orthographic_projection: Default::default(), + visible_entities: Default::default(), + transform: Default::default(), + global_transform: Default::default(), + } + } + + pub fn with_name(name: &str) -> Self { + OrthographicCameraBundle { + camera: Camera { + name: Some(name.to_string()), + ..Default::default() + }, + orthographic_projection: Default::default(), visible_entities: Default::default(), transform: Default::default(), global_transform: Default::default(), From 373392ebefc7998c50c01f34bf239c69abbc1d94 Mon Sep 17 00:00:00 2001 From: Jasen Borisov Date: Tue, 26 Jan 2021 18:49:40 +0100 Subject: [PATCH 08/18] unify orthographic projections --- crates/bevy_render/src/camera/projection.rs | 141 ++++++++------------ crates/bevy_render/src/entity.rs | 5 +- crates/bevy_render/src/lib.rs | 7 +- 3 files changed, 56 insertions(+), 97 deletions(-) diff --git a/crates/bevy_render/src/camera/projection.rs b/crates/bevy_render/src/camera/projection.rs index fa9745b81e967..888b16664b9b6 100644 --- a/crates/bevy_render/src/camera/projection.rs +++ b/crates/bevy_render/src/camera/projection.rs @@ -51,6 +51,17 @@ pub enum WindowOrigin { BottomLeft, } +#[derive(Debug, Clone, Reflect, Serialize, Deserialize)] +#[reflect_value(Serialize, Deserialize)] +pub enum ScalingMode { + // Match the window size. 1 world unit = 1 pixel. + WindowSize, + // Keep vertical axis constant; resize horizontal with aspect ratio. + FixedVertical, + // Keep horizontal axis constant; resize vertical with aspect ratio. + FixedHorizontal, +} + #[derive(Debug, Clone, Reflect)] #[reflect(Component)] pub struct OrthographicProjection { @@ -61,36 +72,71 @@ pub struct OrthographicProjection { pub near: f32, pub far: f32, pub window_origin: WindowOrigin, + pub scaling_mode: ScalingMode, + pub scale: f32, } impl CameraProjection for OrthographicProjection { fn get_projection_matrix(&self) -> Mat4 { Mat4::orthographic_rh( - self.left, - self.right, - self.bottom, - self.top, + self.left * self.scale, + self.right * self.scale, + self.bottom * self.scale, + self.top * self.scale, self.near, self.far, ) } fn update(&mut self, width: f32, height: f32) { - match self.window_origin { - WindowOrigin::Center => { + match (&self.scaling_mode, &self.window_origin) { + (ScalingMode::WindowSize, WindowOrigin::Center) => { let half_width = width / 2.0; let half_height = height / 2.0; + self.left = -half_width; self.right = half_width; self.top = half_height; self.bottom = -half_height; } - WindowOrigin::BottomLeft => { + (ScalingMode::WindowSize, WindowOrigin::BottomLeft) => { self.left = 0.0; self.right = width; self.top = height; self.bottom = 0.0; } + (ScalingMode::FixedVertical, WindowOrigin::Center) => { + let aspect_ratio = width / height; + + self.left = -aspect_ratio; + self.right = aspect_ratio; + self.top = 1.0; + self.bottom = -1.0; + } + (ScalingMode::FixedVertical, WindowOrigin::BottomLeft) => { + let aspect_ratio = width / height; + + self.left = 0.0; + self.right = aspect_ratio; + self.top = 1.0; + self.bottom = 0.0; + } + (ScalingMode::FixedHorizontal, WindowOrigin::Center) => { + let aspect_ratio = height / width; + + self.left = -1.0; + self.right = 1.0; + self.top = aspect_ratio; + self.bottom = -aspect_ratio; + } + (ScalingMode::FixedHorizontal, WindowOrigin::BottomLeft) => { + let aspect_ratio = height / width; + + self.left = 0.0; + self.right = 1.0; + self.top = aspect_ratio; + self.bottom = 0.0; + } } } @@ -109,87 +155,8 @@ impl Default for OrthographicProjection { near: 0.0, far: 1000.0, window_origin: WindowOrigin::Center, - } - } -} - -#[derive(Debug, Clone, Reflect, Serialize, Deserialize)] -#[reflect_value(Serialize, Deserialize)] -pub enum BaseAxis { - Vertical, - Horizontal, -} - -#[derive(Debug, Clone, Reflect)] -#[reflect(Component)] -pub struct ScaledOrthographicProjection { - pub scale: f32, - pub aspect_ratio: f32, - pub near: f32, - pub far: f32, - pub window_origin: WindowOrigin, - pub base_axis: BaseAxis, -} - -impl CameraProjection for ScaledOrthographicProjection { - fn get_projection_matrix(&self) -> Mat4 { - match (&self.window_origin, &self.base_axis) { - (WindowOrigin::Center, BaseAxis::Vertical) => Mat4::orthographic_rh( - -self.aspect_ratio * self.scale, - self.aspect_ratio * self.scale, - -self.scale, - self.scale, - self.near, - self.far, - ), - (WindowOrigin::Center, BaseAxis::Horizontal) => Mat4::orthographic_rh( - -self.scale, - self.scale, - -self.aspect_ratio * self.scale, - self.aspect_ratio * self.scale, - self.near, - self.far, - ), - (WindowOrigin::BottomLeft, BaseAxis::Vertical) => Mat4::orthographic_rh( - 0.0, - self.aspect_ratio * self.scale, - 0.0, - self.scale, - self.near, - self.far, - ), - (WindowOrigin::BottomLeft, BaseAxis::Horizontal) => Mat4::orthographic_rh( - 0.0, - self.scale, - 0.0, - self.aspect_ratio * self.scale, - self.near, - self.far, - ), - } - } - - fn update(&mut self, width: f32, height: f32) { - self.aspect_ratio = match self.base_axis { - BaseAxis::Vertical => width / height, - BaseAxis::Horizontal => height / width, - } - } - - fn depth_calculation(&self) -> DepthCalculation { - DepthCalculation::ZDifference - } -} - -impl Default for ScaledOrthographicProjection { - fn default() -> Self { - ScaledOrthographicProjection { + scaling_mode: ScalingMode::WindowSize, scale: 1.0, - aspect_ratio: 1.0, - near: 0.0, - far: 1000.0, - window_origin: WindowOrigin::Center, - base_axis: BaseAxis::Vertical, } } } diff --git a/crates/bevy_render/src/entity.rs b/crates/bevy_render/src/entity.rs index 930badcd64889..b3b0e34d12ae1 100644 --- a/crates/bevy_render/src/entity.rs +++ b/crates/bevy_render/src/entity.rs @@ -1,8 +1,5 @@ use crate::{ - camera::{ - Camera, OrthographicProjection, PerspectiveProjection, ScaledOrthographicProjection, - VisibleEntities, - }, + camera::{Camera, OrthographicProjection, PerspectiveProjection, VisibleEntities}, pipeline::RenderPipelines, prelude::Visible, render_graph::base, diff --git a/crates/bevy_render/src/lib.rs b/crates/bevy_render/src/lib.rs index ed097df6bbdea..39ca67dc2b627 100644 --- a/crates/bevy_render/src/lib.rs +++ b/crates/bevy_render/src/lib.rs @@ -35,8 +35,7 @@ use base::Msaa; use bevy_app::prelude::*; use bevy_asset::AddAsset; use camera::{ - ActiveCameras, Camera, OrthographicProjection, PerspectiveProjection, - ScaledOrthographicProjection, VisibleEntities, + ActiveCameras, Camera, OrthographicProjection, PerspectiveProjection, VisibleEntities, }; use pipeline::{ IndexFormat, PipelineCompiler, PipelineDescriptor, PipelineSpecialization, PrimitiveTopology, @@ -147,10 +146,6 @@ impl Plugin for RenderPlugin { bevy_app::stage::POST_UPDATE, camera::camera_system::.system(), ) - .add_system_to_stage( - bevy_app::stage::POST_UPDATE, - camera::camera_system::.system(), - ) .add_system_to_stage( bevy_app::stage::POST_UPDATE, camera::camera_system::.system(), From 8ec9d8966f4d92142fc3712438b92683594cfad6 Mon Sep 17 00:00:00 2001 From: Jasen Borisov Date: Tue, 26 Jan 2021 18:55:43 +0100 Subject: [PATCH 09/18] give PerspectiveCameraBundle constructors like those of OrthographicCameraBundle --- crates/bevy_render/src/entity.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/crates/bevy_render/src/entity.rs b/crates/bevy_render/src/entity.rs index b3b0e34d12ae1..72ebe7d4d1f83 100644 --- a/crates/bevy_render/src/entity.rs +++ b/crates/bevy_render/src/entity.rs @@ -34,6 +34,25 @@ pub struct PerspectiveCameraBundle { pub global_transform: GlobalTransform, } +impl PerspectiveCameraBundle { + pub fn new_3d() -> Self { + Default::default() + } + + pub fn with_name(name: &str) -> Self { + PerspectiveCameraBundle { + camera: Camera { + name: Some(name.to_string()), + ..Default::default() + }, + perspective_projection: Default::default(), + visible_entities: Default::default(), + transform: Default::default(), + global_transform: Default::default(), + } + } +} + impl Default for PerspectiveCameraBundle { fn default() -> Self { PerspectiveCameraBundle { From 3f2e859c96edea8c6dbe4ba6f07bdea79ee12196 Mon Sep 17 00:00:00 2001 From: Jasen Borisov Date: Tue, 26 Jan 2021 19:05:15 +0100 Subject: [PATCH 10/18] update examples with new camera bundle syntax --- examples/2d/contributors.rs | 2 +- examples/2d/sprite.rs | 2 +- examples/2d/sprite_sheet.rs | 2 +- examples/2d/text2d.rs | 2 +- examples/2d/texture_atlas.rs | 2 +- examples/3d/3d_scene.rs | 2 +- examples/3d/load_gltf.rs | 2 +- examples/3d/msaa.rs | 2 +- examples/3d/parenting.rs | 2 +- examples/3d/spawner.rs | 2 +- examples/3d/texture.rs | 2 +- examples/3d/update_gltf_scene.rs | 2 +- examples/3d/z_sort_debug.rs | 2 +- examples/android/android.rs | 2 +- examples/asset/asset_loading.rs | 2 +- examples/asset/custom_asset_io.rs | 2 +- examples/asset/hot_asset_reloading.rs | 2 +- examples/ecs/hierarchy.rs | 2 +- examples/ecs/parallel_query.rs | 2 +- examples/ecs/removal_detection.rs | 2 +- examples/ecs/state.rs | 2 +- examples/game/breakout.rs | 2 +- examples/shader/array_texture.rs | 2 +- examples/shader/hot_shader_reloading.rs | 2 +- examples/shader/mesh_custom_attribute.rs | 2 +- examples/shader/shader_custom_material.rs | 2 +- examples/shader/shader_defs.rs | 2 +- examples/tools/bevymark.rs | 2 +- examples/window/multiple_windows.rs | 4 ++-- 29 files changed, 30 insertions(+), 30 deletions(-) diff --git a/examples/2d/contributors.rs b/examples/2d/contributors.rs index 851dac3d2b0e8..c34ea4e3e8c14 100644 --- a/examples/2d/contributors.rs +++ b/examples/2d/contributors.rs @@ -55,7 +55,7 @@ fn setup( let texture_handle = asset_server.load("branding/icon.png"); commands - .spawn(Camera2dBundle::default()) + .spawn(OrthographicCameraBundle::new_2d()) .spawn(CameraUiBundle::default()); let mut sel = ContributorSelection { diff --git a/examples/2d/sprite.rs b/examples/2d/sprite.rs index 2d8f298c3e1da..6392ce606d69d 100644 --- a/examples/2d/sprite.rs +++ b/examples/2d/sprite.rs @@ -14,7 +14,7 @@ fn setup( ) { let texture_handle = asset_server.load("branding/icon.png"); commands - .spawn(Camera2dBundle::default()) + .spawn(OrthographicCameraBundle::new_2d()) .spawn(SpriteBundle { material: materials.add(texture_handle.into()), ..Default::default() diff --git a/examples/2d/sprite_sheet.rs b/examples/2d/sprite_sheet.rs index e8c92c45df346..155401cc120d7 100644 --- a/examples/2d/sprite_sheet.rs +++ b/examples/2d/sprite_sheet.rs @@ -31,7 +31,7 @@ fn setup( let texture_atlas = TextureAtlas::from_grid(texture_handle, Vec2::new(24.0, 24.0), 7, 1); let texture_atlas_handle = texture_atlases.add(texture_atlas); commands - .spawn(Camera2dBundle::default()) + .spawn(OrthographicCameraBundle::new_2d()) .spawn(SpriteSheetBundle { texture_atlas: texture_atlas_handle, transform: Transform::from_scale(Vec3::splat(6.0)), diff --git a/examples/2d/text2d.rs b/examples/2d/text2d.rs index 4b3b6ab4f64ac..f5d91c8a5172f 100644 --- a/examples/2d/text2d.rs +++ b/examples/2d/text2d.rs @@ -11,7 +11,7 @@ fn main() { fn setup(commands: &mut Commands, asset_server: Res) { commands // 2d camera - .spawn(Camera2dBundle::default()) + .spawn(OrthographicCameraBundle::new_2d()) .spawn(Text2dBundle { text: Text::with_section( "This text is in the 2D scene.", diff --git a/examples/2d/texture_atlas.rs b/examples/2d/texture_atlas.rs index c643d5e931615..f1267be1649e6 100644 --- a/examples/2d/texture_atlas.rs +++ b/examples/2d/texture_atlas.rs @@ -64,7 +64,7 @@ fn setup( // set up a scene to display our texture atlas commands - .spawn(Camera2dBundle::default()) + .spawn(OrthographicCameraBundle::new_2d()) // draw a sprite from the atlas .spawn(SpriteSheetBundle { transform: Transform { diff --git a/examples/3d/3d_scene.rs b/examples/3d/3d_scene.rs index dadb559a86b83..a66db90191f52 100644 --- a/examples/3d/3d_scene.rs +++ b/examples/3d/3d_scene.rs @@ -35,7 +35,7 @@ fn setup( ..Default::default() }) // camera - .spawn(Camera3dBundle { + .spawn(PerspectiveCameraBundle { transform: Transform::from_xyz(-2.0, 2.5, 5.0) .looking_at(Vec3::default(), Vec3::unit_y()), ..Default::default() diff --git a/examples/3d/load_gltf.rs b/examples/3d/load_gltf.rs index c3340c6e0d027..02005a727a9d7 100644 --- a/examples/3d/load_gltf.rs +++ b/examples/3d/load_gltf.rs @@ -15,7 +15,7 @@ fn setup(commands: &mut Commands, asset_server: Res) { transform: Transform::from_xyz(4.0, 5.0, 4.0), ..Default::default() }) - .spawn(Camera3dBundle { + .spawn(PerspectiveCameraBundle { transform: Transform::from_xyz(0.7, 0.7, 1.0) .looking_at(Vec3::new(0.0, 0.3, 0.0), Vec3::unit_y()), ..Default::default() diff --git a/examples/3d/msaa.rs b/examples/3d/msaa.rs index 1fe5688fd03a1..ed5a920737fbf 100644 --- a/examples/3d/msaa.rs +++ b/examples/3d/msaa.rs @@ -31,7 +31,7 @@ fn setup( ..Default::default() }) // camera - .spawn(Camera3dBundle { + .spawn(PerspectiveCameraBundle { transform: Transform::from_xyz(-3.0, 3.0, 5.0) .looking_at(Vec3::default(), Vec3::unit_y()), ..Default::default() diff --git a/examples/3d/parenting.rs b/examples/3d/parenting.rs index ff8c2e9c274b8..81e4b3d9d4330 100644 --- a/examples/3d/parenting.rs +++ b/examples/3d/parenting.rs @@ -57,7 +57,7 @@ fn setup( ..Default::default() }) // camera - .spawn(Camera3dBundle { + .spawn(PerspectiveCameraBundle { transform: Transform::from_xyz(5.0, 10.0, 10.0) .looking_at(Vec3::default(), Vec3::unit_y()), ..Default::default() diff --git a/examples/3d/spawner.rs b/examples/3d/spawner.rs index 09a88c7d55641..978aaec3663c5 100644 --- a/examples/3d/spawner.rs +++ b/examples/3d/spawner.rs @@ -43,7 +43,7 @@ fn setup( ..Default::default() }) // camera - .spawn(Camera3dBundle { + .spawn(PerspectiveCameraBundle { transform: Transform::from_xyz(0.0, 15.0, 150.0) .looking_at(Vec3::default(), Vec3::unit_y()), ..Default::default() diff --git a/examples/3d/texture.rs b/examples/3d/texture.rs index db47465500641..705979879b7e6 100644 --- a/examples/3d/texture.rs +++ b/examples/3d/texture.rs @@ -95,7 +95,7 @@ fn setup( ..Default::default() }) // camera - .spawn(Camera3dBundle { + .spawn(PerspectiveCameraBundle { transform: Transform::from_xyz(3.0, 5.0, 8.0) .looking_at(Vec3::default(), Vec3::unit_y()), ..Default::default() diff --git a/examples/3d/update_gltf_scene.rs b/examples/3d/update_gltf_scene.rs index a5140e8098b99..e5b2d5eedcbac 100644 --- a/examples/3d/update_gltf_scene.rs +++ b/examples/3d/update_gltf_scene.rs @@ -29,7 +29,7 @@ fn setup( transform: Transform::from_xyz(4.0, 5.0, 4.0), ..Default::default() }) - .spawn(Camera3dBundle { + .spawn(PerspectiveCameraBundle { transform: Transform::from_xyz(1.05, 0.9, 1.5) .looking_at(Vec3::new(0.0, 0.3, 0.0), Vec3::unit_y()), ..Default::default() diff --git a/examples/3d/z_sort_debug.rs b/examples/3d/z_sort_debug.rs index d7a69e1b0f6ca..337608401c8da 100644 --- a/examples/3d/z_sort_debug.rs +++ b/examples/3d/z_sort_debug.rs @@ -82,7 +82,7 @@ fn setup( }); }) // camera - .spawn(Camera3dBundle { + .spawn(PerspectiveCameraBundle { transform: Transform::from_xyz(5.0, 10.0, 10.0) .looking_at(Vec3::default(), Vec3::unit_y()), ..Default::default() diff --git a/examples/android/android.rs b/examples/android/android.rs index ce8a9d616c452..1a2f25116dc0c 100644 --- a/examples/android/android.rs +++ b/examples/android/android.rs @@ -37,7 +37,7 @@ fn setup( ..Default::default() }) // camera - .spawn(Camera3dBundle { + .spawn(PerspectiveCameraBundle { transform: Transform::from_xyz(-2.0, 2.5, 5.0) .looking_at(Vec3::default(), Vec3::unit_y()), ..Default::default() diff --git a/examples/asset/asset_loading.rs b/examples/asset/asset_loading.rs index a471bc91e1022..bf4d17863ce90 100644 --- a/examples/asset/asset_loading.rs +++ b/examples/asset/asset_loading.rs @@ -70,7 +70,7 @@ fn setup( ..Default::default() }) // camera - .spawn(Camera3dBundle { + .spawn(PerspectiveCameraBundle { transform: Transform::from_xyz(0.0, 3.0, 10.0) .looking_at(Vec3::default(), Vec3::unit_y()), ..Default::default() diff --git a/examples/asset/custom_asset_io.rs b/examples/asset/custom_asset_io.rs index 7e986644e4be4..f6694080543fa 100644 --- a/examples/asset/custom_asset_io.rs +++ b/examples/asset/custom_asset_io.rs @@ -96,7 +96,7 @@ fn setup( ) { let texture_handle = asset_server.load("branding/icon.png"); commands - .spawn(Camera2dBundle::default()) + .spawn(OrthographicCameraBundle::new_2d()) .spawn(SpriteBundle { material: materials.add(texture_handle.into()), ..Default::default() diff --git a/examples/asset/hot_asset_reloading.rs b/examples/asset/hot_asset_reloading.rs index 62578443e5d7f..b27ba6de82106 100644 --- a/examples/asset/hot_asset_reloading.rs +++ b/examples/asset/hot_asset_reloading.rs @@ -30,7 +30,7 @@ fn setup(commands: &mut Commands, asset_server: Res) { ..Default::default() }) // camera - .spawn(Camera3dBundle { + .spawn(PerspectiveCameraBundle { transform: Transform::from_xyz(2.0, 2.0, 6.0) .looking_at(Vec3::default(), Vec3::unit_y()), ..Default::default() diff --git a/examples/ecs/hierarchy.rs b/examples/ecs/hierarchy.rs index 5d0f49a03388a..875bd7a9cd32d 100644 --- a/examples/ecs/hierarchy.rs +++ b/examples/ecs/hierarchy.rs @@ -13,7 +13,7 @@ fn setup( asset_server: Res, mut materials: ResMut>, ) { - commands.spawn(Camera2dBundle::default()); + commands.spawn(OrthographicCameraBundle::new_2d()); let texture = asset_server.load("branding/icon.png"); // Spawn a root entity with no parent diff --git a/examples/ecs/parallel_query.rs b/examples/ecs/parallel_query.rs index b590a2c0460a8..17296707cd871 100644 --- a/examples/ecs/parallel_query.rs +++ b/examples/ecs/parallel_query.rs @@ -8,7 +8,7 @@ fn spawn_system( asset_server: Res, mut materials: ResMut>, ) { - commands.spawn(Camera2dBundle::default()); + commands.spawn(OrthographicCameraBundle::new_2d()); let texture_handle = asset_server.load("branding/icon.png"); let material = materials.add(texture_handle.into()); for _ in 0..128 { diff --git a/examples/ecs/removal_detection.rs b/examples/ecs/removal_detection.rs index 6709f940477e3..80c430ff833d4 100644 --- a/examples/ecs/removal_detection.rs +++ b/examples/ecs/removal_detection.rs @@ -33,7 +33,7 @@ fn setup( let texture = asset_server.load("branding/icon.png"); commands - .spawn(Camera2dBundle::default()) + .spawn(OrthographicCameraBundle::new_2d()) .spawn(SpriteBundle { material: materials.add(texture.into()), ..Default::default() diff --git a/examples/ecs/state.rs b/examples/ecs/state.rs index 770157aa19ec2..26db86aecf49e 100644 --- a/examples/ecs/state.rs +++ b/examples/ecs/state.rs @@ -104,7 +104,7 @@ fn setup_game( ) { let texture_handle = asset_server.load("branding/icon.png"); commands - .spawn(Camera2dBundle::default()) + .spawn(OrthographicCameraBundle::new_2d()) .spawn(SpriteBundle { material: materials.add(texture_handle.into()), ..Default::default() diff --git a/examples/game/breakout.rs b/examples/game/breakout.rs index 16ec1f67a0d42..7ab26c39dfb6a 100644 --- a/examples/game/breakout.rs +++ b/examples/game/breakout.rs @@ -44,7 +44,7 @@ fn setup( // Add the game's entities to our world commands // cameras - .spawn(Camera2dBundle::default()) + .spawn(OrthographicCameraBundle::new_2d()) .spawn(CameraUiBundle::default()) // paddle .spawn(SpriteBundle { diff --git a/examples/shader/array_texture.rs b/examples/shader/array_texture.rs index 368831f7d3ae9..43912ab0853fb 100644 --- a/examples/shader/array_texture.rs +++ b/examples/shader/array_texture.rs @@ -109,7 +109,7 @@ fn setup( .add_node_edge("my_array_texture", base::node::MAIN_PASS) .unwrap(); - commands.spawn(Camera3dBundle { + commands.spawn(PerspectiveCameraBundle { transform: Transform::from_xyz(2.0, 2.0, 2.0).looking_at(Vec3::default(), Vec3::unit_y()), ..Default::default() }); diff --git a/examples/shader/hot_shader_reloading.rs b/examples/shader/hot_shader_reloading.rs index e64bfc0d00781..6f675224a4a9e 100644 --- a/examples/shader/hot_shader_reloading.rs +++ b/examples/shader/hot_shader_reloading.rs @@ -72,7 +72,7 @@ fn setup( }) .with(material) // camera - .spawn(Camera3dBundle { + .spawn(PerspectiveCameraBundle { transform: Transform::from_xyz(3.0, 5.0, -8.0) .looking_at(Vec3::default(), Vec3::unit_y()), ..Default::default() diff --git a/examples/shader/mesh_custom_attribute.rs b/examples/shader/mesh_custom_attribute.rs index 03858f4a595e0..6d0d2ca09e295 100644 --- a/examples/shader/mesh_custom_attribute.rs +++ b/examples/shader/mesh_custom_attribute.rs @@ -137,7 +137,7 @@ fn setup( }) .with(material) // camera - .spawn(Camera3dBundle { + .spawn(PerspectiveCameraBundle { transform: Transform::from_xyz(3.0, 5.0, -8.0) .looking_at(Vec3::default(), Vec3::unit_y()), ..Default::default() diff --git a/examples/shader/shader_custom_material.rs b/examples/shader/shader_custom_material.rs index ca74cdee0bfae..dc02029f37709 100644 --- a/examples/shader/shader_custom_material.rs +++ b/examples/shader/shader_custom_material.rs @@ -93,7 +93,7 @@ fn setup( }) .with(material) // camera - .spawn(Camera3dBundle { + .spawn(PerspectiveCameraBundle { transform: Transform::from_xyz(3.0, 5.0, -8.0) .looking_at(Vec3::default(), Vec3::unit_y()), ..Default::default() diff --git a/examples/shader/shader_defs.rs b/examples/shader/shader_defs.rs index 487e5705201d7..552db2f9b9c54 100644 --- a/examples/shader/shader_defs.rs +++ b/examples/shader/shader_defs.rs @@ -124,7 +124,7 @@ fn setup( }) .with(blue_material) // camera - .spawn(Camera3dBundle { + .spawn(PerspectiveCameraBundle { transform: Transform::from_xyz(3.0, 5.0, -8.0) .looking_at(Vec3::default(), Vec3::unit_y()), ..Default::default() diff --git a/examples/tools/bevymark.rs b/examples/tools/bevymark.rs index 91054be6d4d99..4e6dfdb72bcda 100644 --- a/examples/tools/bevymark.rs +++ b/examples/tools/bevymark.rs @@ -50,7 +50,7 @@ fn main() { fn setup(commands: &mut Commands, asset_server: Res) { commands - .spawn(Camera2dBundle::default()) + .spawn(OrthographicCameraBundle::new_2d()) .spawn(CameraUiBundle::default()) .spawn(TextBundle { text: Text { diff --git a/examples/window/multiple_windows.rs b/examples/window/multiple_windows.rs index b1929e525d37c..44db637e0a05b 100644 --- a/examples/window/multiple_windows.rs +++ b/examples/window/multiple_windows.rs @@ -192,13 +192,13 @@ fn setup_pipeline( ..Default::default() }) // main camera - .spawn(Camera3dBundle { + .spawn(PerspectiveCameraBundle { transform: Transform::from_xyz(0.0, 0.0, 6.0) .looking_at(Vec3::default(), Vec3::unit_y()), ..Default::default() }) // second window camera - .spawn(Camera3dBundle { + .spawn(PerspectiveCameraBundle { camera: Camera { name: Some("Secondary".to_string()), window: window_id, From b24bb8d000f0240311e5a9a83c6bc96ab805dad3 Mon Sep 17 00:00:00 2001 From: Jasen Borisov Date: Tue, 26 Jan 2021 19:08:26 +0100 Subject: [PATCH 11/18] rename CameraUiBundle to UiCameraBundle --- crates/bevy_ui/src/entity.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/bevy_ui/src/entity.rs b/crates/bevy_ui/src/entity.rs index 64fb748e175e0..28f0faf21ffad 100644 --- a/crates/bevy_ui/src/entity.rs +++ b/crates/bevy_ui/src/entity.rs @@ -164,7 +164,7 @@ impl Default for ButtonBundle { } #[derive(Bundle, Debug)] -pub struct CameraUiBundle { +pub struct UiCameraBundle { pub camera: Camera, pub orthographic_projection: OrthographicProjection, pub visible_entities: VisibleEntities, @@ -172,12 +172,12 @@ pub struct CameraUiBundle { pub global_transform: GlobalTransform, } -impl Default for CameraUiBundle { +impl Default for UiCameraBundle { fn default() -> 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; - CameraUiBundle { + UiCameraBundle { camera: Camera { name: Some(crate::camera::CAMERA_UI.to_string()), ..Default::default() From 6b6513d5da1d47e0b1d813961cd4161314759e5d Mon Sep 17 00:00:00 2001 From: Jasen Borisov Date: Tue, 26 Jan 2021 19:08:42 +0100 Subject: [PATCH 12/18] update examples --- examples/2d/contributors.rs | 2 +- examples/ecs/state.rs | 2 +- examples/game/breakout.rs | 2 +- examples/scene/scene.rs | 2 +- examples/tools/bevymark.rs | 2 +- examples/ui/button.rs | 2 +- examples/ui/font_atlas_debug.rs | 2 +- examples/ui/text.rs | 2 +- examples/ui/text_debug.rs | 2 +- examples/ui/ui.rs | 2 +- examples/window/scale_factor_override.rs | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/examples/2d/contributors.rs b/examples/2d/contributors.rs index c34ea4e3e8c14..821196b9c1c8b 100644 --- a/examples/2d/contributors.rs +++ b/examples/2d/contributors.rs @@ -56,7 +56,7 @@ fn setup( commands .spawn(OrthographicCameraBundle::new_2d()) - .spawn(CameraUiBundle::default()); + .spawn(UiCameraBundle::default()); let mut sel = ContributorSelection { order: vec![], diff --git a/examples/ecs/state.rs b/examples/ecs/state.rs index 26db86aecf49e..95e8f82763138 100644 --- a/examples/ecs/state.rs +++ b/examples/ecs/state.rs @@ -35,7 +35,7 @@ fn setup_menu( ) { commands // ui camera - .spawn(CameraUiBundle::default()) + .spawn(UiCameraBundle::default()) .spawn(ButtonBundle { style: Style { size: Size::new(Val::Px(150.0), Val::Px(65.0)), diff --git a/examples/game/breakout.rs b/examples/game/breakout.rs index 7ab26c39dfb6a..750635024a07e 100644 --- a/examples/game/breakout.rs +++ b/examples/game/breakout.rs @@ -45,7 +45,7 @@ fn setup( commands // cameras .spawn(OrthographicCameraBundle::new_2d()) - .spawn(CameraUiBundle::default()) + .spawn(UiCameraBundle::default()) // paddle .spawn(SpriteBundle { material: materials.add(Color::rgb(0.5, 0.5, 1.0).into()), diff --git a/examples/scene/scene.rs b/examples/scene/scene.rs index 23b3262ce2fd5..a1c1b6009c251 100644 --- a/examples/scene/scene.rs +++ b/examples/scene/scene.rs @@ -97,7 +97,7 @@ fn save_scene_system(_world: &mut World, resources: &mut Resources) { // This is only necessary for the info message in the UI. See examples/ui/text.rs for a standalone text example. fn infotext_system(commands: &mut Commands, asset_server: Res) { - commands.spawn(CameraUiBundle::default()).spawn(TextBundle { + commands.spawn(UiCameraBundle::default()).spawn(TextBundle { style: Style { align_self: AlignSelf::FlexEnd, ..Default::default() diff --git a/examples/tools/bevymark.rs b/examples/tools/bevymark.rs index 4e6dfdb72bcda..a24203a211730 100644 --- a/examples/tools/bevymark.rs +++ b/examples/tools/bevymark.rs @@ -51,7 +51,7 @@ fn main() { fn setup(commands: &mut Commands, asset_server: Res) { commands .spawn(OrthographicCameraBundle::new_2d()) - .spawn(CameraUiBundle::default()) + .spawn(UiCameraBundle::default()) .spawn(TextBundle { text: Text { sections: vec![ diff --git a/examples/ui/button.rs b/examples/ui/button.rs index dc831caed5abc..119234a5cf464 100644 --- a/examples/ui/button.rs +++ b/examples/ui/button.rs @@ -61,7 +61,7 @@ fn setup( ) { commands // ui camera - .spawn(CameraUiBundle::default()) + .spawn(UiCameraBundle::default()) .spawn(ButtonBundle { style: Style { size: Size::new(Val::Px(150.0), Val::Px(65.0)), diff --git a/examples/ui/font_atlas_debug.rs b/examples/ui/font_atlas_debug.rs index 3ef3a0c47428d..bbd3884305dab 100644 --- a/examples/ui/font_atlas_debug.rs +++ b/examples/ui/font_atlas_debug.rs @@ -79,7 +79,7 @@ fn text_update_system(mut state: ResMut, time: Res