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 de28fd0
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 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 All @@ -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.
Expand Down

0 comments on commit de28fd0

Please sign in to comment.