Skip to content

Commit

Permalink
feat: add custom camera viewport support. (#100)
Browse files Browse the repository at this point in the history
  • Loading branch information
zicklag committed Feb 18, 2023
1 parent 5849caf commit 8751bdb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions crates/bones_bevy_renderer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,13 @@ fn sync_cameras<W: HasBonesWorld>(
}
_ => (),
}
camera.viewport = bones_camera
.viewport
.map(|x| bevy::render::camera::Viewport {
physical_position: x.position,
physical_size: x.size,
depth: x.depth_min..x.depth_max,
});

*transform = bones_transform.into_bevy();
} else {
Expand Down
22 changes: 22 additions & 0 deletions crates/bones_render/src/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,35 @@ pub struct Camera {
pub height: f32,
/// Whether or not the camera is enabled and rendering.
pub active: bool,
/// An optional viewport override, allowing you to specify that the camera should render to only
/// a portion of the window.
///
/// This can be used, for example, for split screen functionality.
pub viewport: Option<Viewport>,
}

/// A custom viewport specification for a [`Camera`].
#[derive(Clone, Copy, Debug)]
#[repr(C)]
pub struct Viewport {
/// The physical position to render this viewport to within the RenderTarget of this Camera.
/// (0,0) corresponds to the top-left corner.
pub position: UVec2,
/// The physical size of the viewport rectangle to render to within the RenderTarget of this
/// Camera. The origin of the rectangle is in the top-left corner.
pub size: UVec2,
/// The minimum depth to render (on a scale from 0.0 to 1.0).
pub depth_min: f32,
/// The maximum depth to render (on a scale from 0.0 to 1.0).
pub depth_max: f32,
}

impl Default for Camera {
fn default() -> Self {
Self {
height: 400.0,
active: true,
viewport: None,
}
}
}
Expand Down

0 comments on commit 8751bdb

Please sign in to comment.