From de28fd094fba273e4b4494c906cde3cebe4d75bc Mon Sep 17 00:00:00 2001 From: Aevyrie Date: Mon, 6 Jun 2022 09:49:32 -0700 Subject: [PATCH] Further cleanup --- crates/bevy_render/src/camera/camera.rs | 30 ++++++++++++++++--------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/crates/bevy_render/src/camera/camera.rs b/crates/bevy_render/src/camera/camera.rs index 7be37cbf8beac..2de7ef9490bbd 100644 --- a/crates/bevy_render/src/camera/camera.rs +++ b/crates/bevy_render/src/camera/camera.rs @@ -111,16 +111,28 @@ impl Camera { Some((input.as_dvec2() / scale).as_vec2()) } - /// The logical dimensions of the viewport, the (minimum, maximum) points of the viewport, - /// measured from the top-left. + /// The rendered physical bounds (minimum, maximum) of the camera. If the `viewport` field is + /// set to [`Some`], this will be the rect of that custom viewport. Otherwise it will default to + /// the full physical rect of the current [`RenderTarget`]. #[inline] - pub fn logical_viewport_rect(&self) -> Option<(Vec2, Vec2)> { - let vp_position = self.viewport.as_ref()?.physical_position; - let min = self.physical_to_logical(vp_position)?; - let max = self.logical_viewport_size()?; + pub fn physical_viewport_rect(&self) -> Option<(UVec2, UVec2)> { + let min = self.viewport.as_ref()?.physical_position; + let max = min + self.physical_viewport_size()?; Some((min, max)) } + /// The rendered logical bounds (minimum, maximum) of the camera. If the `viewport` field is set + /// to [`Some`], this will be the rect of that custom viewport. Otherwise it will default to the + /// full logical rect of the current [`RenderTarget`]. + #[inline] + pub fn logical_viewport_rect(&self) -> Option<(Vec2, Vec2)> { + let (min, max) = self.physical_viewport_rect()?; + Some(( + self.physical_to_logical(min)?, + self.physical_to_logical(max)?, + )) + } + /// The logical size of this camera's viewport. If the `viewport` field is set to [`Some`], this /// will be the size of that custom viewport. Otherwise it will default to the full logical size /// of the current [`RenderTarget`]. @@ -130,8 +142,7 @@ impl Camera { pub fn logical_viewport_size(&self) -> Option { self.viewport .as_ref() - .map(|v| self.physical_to_logical(v.physical_size)) - .flatten() + .and_then(|v| self.physical_to_logical(v.physical_size)) .or_else(|| self.logical_target_size()) } @@ -155,8 +166,7 @@ impl Camera { self.computed .target_info .as_ref() - .map(|t| self.physical_to_logical(t.physical_size)) - .flatten() + .and_then(|t| self.physical_to_logical(t.physical_size)) } /// The full physical size of this camera's [`RenderTarget`], ignoring custom `viewport` configuration.