Skip to content

Commit

Permalink
Further cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
aevyrie committed Jun 6, 2022
1 parent f45bb7d commit da269ed
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions crates/bevy_render/src/camera/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`].
Expand All @@ -130,8 +142,7 @@ impl Camera {
pub fn logical_viewport_size(&self) -> Option<Vec2> {
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())
}

Expand Down

0 comments on commit da269ed

Please sign in to comment.