Struct bevy_render::camera::Camera
source · pub struct Camera {
pub viewport: Option<Viewport>,
pub priority: isize,
pub is_active: bool,
pub computed: ComputedCameraValues,
pub target: RenderTarget,
pub hdr: bool,
}
Expand description
The defining component for camera entities, storing information about how and what to render through this camera.
The Camera
component is added to an entity to define the properties of the viewpoint from
which rendering occurs. It defines the position of the view to render, the projection method
to transform the 3D objects into a 2D image, as well as the render target into which that image
is produced.
Adding a camera is typically done by adding a bundle, either the Camera2dBundle
or the
Camera3dBundle
.
Fields
viewport: Option<Viewport>
If set, this camera will render to the given Viewport
rectangle within the configured RenderTarget
.
priority: isize
Cameras with a lower priority will be rendered before cameras with a higher priority.
is_active: bool
If this is set to true
, this camera will be rendered to its specified RenderTarget
. If false
, this
camera will not be rendered.
computed: ComputedCameraValues
Computed values for this camera, such as the projection matrix and the render target size.
target: RenderTarget
The “target” that this camera will render to.
hdr: bool
If this is set to true
, the camera will use an intermediate “high dynamic range” render texture.
Warning: we are still working on this feature. If MSAA is enabled, there will be artifacts in
some cases. When rendering with WebGL, this will crash if MSAA is enabled.
See https://github.com/bevyengine/bevy/pull/3425 for details.
Implementations
sourceimpl Camera
impl Camera
sourcepub fn to_logical(&self, physical_size: UVec2) -> Option<Vec2>
pub fn to_logical(&self, physical_size: UVec2) -> Option<Vec2>
Converts a physical size in this Camera
to a logical size.
sourcepub fn physical_viewport_rect(&self) -> Option<(UVec2, UVec2)>
pub fn physical_viewport_rect(&self) -> Option<(UVec2, UVec2)>
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
.
sourcepub fn logical_viewport_rect(&self) -> Option<(Vec2, Vec2)>
pub fn logical_viewport_rect(&self) -> Option<(Vec2, Vec2)>
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
.
sourcepub fn logical_viewport_size(&self) -> Option<Vec2>
pub fn logical_viewport_size(&self) -> Option<Vec2>
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
.
For logic that requires the full logical size of the
RenderTarget
, prefer Camera::logical_target_size
.
sourcepub fn physical_viewport_size(&self) -> Option<UVec2>
pub fn physical_viewport_size(&self) -> Option<UVec2>
The physical 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 physical size of
the current RenderTarget
.
For logic that requires the full physical size of the RenderTarget
, prefer Camera::physical_target_size
.
sourcepub fn logical_target_size(&self) -> Option<Vec2>
pub fn logical_target_size(&self) -> Option<Vec2>
The full logical size of this camera’s RenderTarget
, ignoring custom viewport
configuration.
Note that if the viewport
field is Some
, this will not represent the size of the rendered area.
For logic that requires the size of the actually rendered area, prefer Camera::logical_viewport_size
.
sourcepub fn physical_target_size(&self) -> Option<UVec2>
pub fn physical_target_size(&self) -> Option<UVec2>
The full physical size of this camera’s RenderTarget
, ignoring custom viewport
configuration.
Note that if the viewport
field is Some
, this will not represent the size of the rendered area.
For logic that requires the size of the actually rendered area, prefer Camera::physical_viewport_size
.
sourcepub fn projection_matrix(&self) -> Mat4
pub fn projection_matrix(&self) -> Mat4
The projection matrix computed using this camera’s CameraProjection
.
sourcepub fn world_to_viewport(
&self,
camera_transform: &GlobalTransform,
world_position: Vec3
) -> Option<Vec2>
pub fn world_to_viewport(
&self,
camera_transform: &GlobalTransform,
world_position: Vec3
) -> Option<Vec2>
Given a position in world space, use the camera to compute the viewport-space coordinates.
To get the coordinates in Normalized Device Coordinates, you should use
world_to_ndc
.
sourcepub fn viewport_to_world(
&self,
camera_transform: &GlobalTransform,
viewport_position: Vec2
) -> Option<Ray>
pub fn viewport_to_world(
&self,
camera_transform: &GlobalTransform,
viewport_position: Vec2
) -> Option<Ray>
Returns a ray originating from the camera, that passes through everything beyond viewport_position
.
The resulting ray starts on the near plane of the camera.
If the camera’s projection is orthographic the direction of the ray is always equal to camera_transform.forward()
.
To get the world space coordinates with Normalized Device Coordinates, you should use
ndc_to_world
.
sourcepub fn world_to_ndc(
&self,
camera_transform: &GlobalTransform,
world_position: Vec3
) -> Option<Vec3>
pub fn world_to_ndc(
&self,
camera_transform: &GlobalTransform,
world_position: Vec3
) -> Option<Vec3>
Given a position in world space, use the camera’s viewport to compute the Normalized Device Coordinates.
When the position is within the viewport the values returned will be between -1.0 and 1.0 on the X and Y axes,
and between 0.0 and 1.0 on the Z axis.
To get the coordinates in the render target’s viewport dimensions, you should use
world_to_viewport
.
sourcepub fn ndc_to_world(
&self,
camera_transform: &GlobalTransform,
ndc: Vec3
) -> Option<Vec3>
pub fn ndc_to_world(
&self,
camera_transform: &GlobalTransform,
ndc: Vec3
) -> Option<Vec3>
Given a position in Normalized Device Coordinates, use the camera’s viewport to compute the world space position.
When the position is within the viewport the values returned will be between -1.0 and 1.0 on the X and Y axes,
and between 0.0 and 1.0 on the Z axis.
To get the world space coordinates with the viewport position, you should use
world_to_viewport
.
Trait Implementations
sourceimpl FromReflect for Camerawhere
Option<Viewport>: FromReflect,
isize: FromReflect,
bool: FromReflect,
bool: FromReflect,
impl FromReflect for Camerawhere
Option<Viewport>: FromReflect,
isize: FromReflect,
bool: FromReflect,
bool: FromReflect,
sourcefn from_reflect(reflect: &dyn Reflect) -> Option<Self>
fn from_reflect(reflect: &dyn Reflect) -> Option<Self>
Self
from a reflected value.sourceimpl GetTypeRegistration for Camera
impl GetTypeRegistration for Camera
sourceimpl Reflect for Camera
impl Reflect for Camera
sourcefn get_type_info(&self) -> &'static TypeInfo
fn get_type_info(&self) -> &'static TypeInfo
sourcefn as_any_mut(&mut self) -> &mut dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
&mut dyn Any
.sourcefn into_reflect(self: Box<Self>) -> Box<dyn Reflect>
fn into_reflect(self: Box<Self>) -> Box<dyn Reflect>
sourcefn as_reflect(&self) -> &dyn Reflect
fn as_reflect(&self) -> &dyn Reflect
sourcefn as_reflect_mut(&mut self) -> &mut dyn Reflect
fn as_reflect_mut(&mut self) -> &mut dyn Reflect
sourcefn clone_value(&self) -> Box<dyn Reflect>
fn clone_value(&self) -> Box<dyn Reflect>
Reflect
trait object. Read moresourcefn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>>
fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>>
sourcefn reflect_ref(&self) -> ReflectRef<'_>
fn reflect_ref(&self) -> ReflectRef<'_>
sourcefn reflect_mut(&mut self) -> ReflectMut<'_>
fn reflect_mut(&mut self) -> ReflectMut<'_>
sourcefn reflect_owned(self: Box<Self>) -> ReflectOwned
fn reflect_owned(self: Box<Self>) -> ReflectOwned
sourcefn reflect_partial_eq(&self, value: &dyn Reflect) -> Option<bool>
fn reflect_partial_eq(&self, value: &dyn Reflect) -> Option<bool>
sourcefn reflect_hash(&self) -> Option<u64>
fn reflect_hash(&self) -> Option<u64>
sourcefn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>
sourcefn serializable(&self) -> Option<Serializable<'_>>
fn serializable(&self) -> Option<Serializable<'_>>
sourceimpl Struct for Camera
impl Struct for Camera
sourcefn field_at_mut(&mut self, index: usize) -> Option<&mut dyn Reflect>
fn field_at_mut(&mut self, index: usize) -> Option<&mut dyn Reflect>
index
as a &mut dyn Reflect
. Read moresourcefn name_at(&self, index: usize) -> Option<&str>
fn name_at(&self, index: usize) -> Option<&str>
index
.sourcefn iter_fields(&self) -> FieldIter<'_>
fn iter_fields(&self) -> FieldIter<'_>
sourcefn clone_dynamic(&self) -> DynamicStruct
fn clone_dynamic(&self) -> DynamicStruct
DynamicStruct
.Auto Trait Implementations
impl RefUnwindSafe for Camera
impl Send for Camera
impl Sync for Camera
impl Unpin for Camera
impl UnwindSafe for Camera
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
sourceimpl<C> Bundle for Cwhere
C: Component,
impl<C> Bundle for Cwhere
C: Component,
fn component_ids(
components: &mut Components,
storages: &mut Storages,
ids: &mut impl FnMut(ComponentId)
)
unsafe fn from_components<T, F>(ctx: &mut T, func: &mut F) -> Cwhere
F: for<'a> FnMut(&'a mut T) -> OwningPtr<'a>,
fn get_components(self, func: &mut impl FnMut(OwningPtr<'_>))
sourceimpl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
sourcefn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
. Read moresourcefn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read moresourcefn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read moresourcefn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read moresourceimpl<T> DowncastSync for Twhere
T: Any + Send + Sync,
impl<T> DowncastSync for Twhere
T: Any + Send + Sync,
sourceimpl<T> FromWorld for Twhere
T: Default,
impl<T> FromWorld for Twhere
T: Default,
sourcefn from_world(_world: &mut World) -> T
fn from_world(_world: &mut World) -> T
Self
using data from the given Worldsourceimpl<S> GetField for Swhere
S: Struct,
impl<S> GetField for Swhere
S: Struct,
sourceimpl<T> GetPath for Twhere
T: Reflect,
impl<T> GetPath for Twhere
T: Reflect,
sourcefn path<'r, 'p>(
&'r self,
path: &'p str
) -> Result<&'r (dyn Reflect + 'static), ReflectPathError<'p>>
fn path<'r, 'p>(
&'r self,
path: &'p str
) -> Result<&'r (dyn Reflect + 'static), ReflectPathError<'p>>
path
. Read moresourcefn path_mut<'r, 'p>(
&'r mut self,
path: &'p str
) -> Result<&'r mut (dyn Reflect + 'static), ReflectPathError<'p>>
fn path_mut<'r, 'p>(
&'r mut self,
path: &'p str
) -> Result<&'r mut (dyn Reflect + 'static), ReflectPathError<'p>>
path
. Read moresourcefn get_path<T, 'r, 'p>(
&'r self,
path: &'p str
) -> Result<&'r T, ReflectPathError<'p>>where
T: Reflect,
fn get_path<T, 'r, 'p>(
&'r self,
path: &'p str
) -> Result<&'r T, ReflectPathError<'p>>where
T: Reflect,
path
.sourcefn get_path_mut<T, 'r, 'p>(
&'r mut self,
path: &'p str
) -> Result<&'r mut T, ReflectPathError<'p>>where
T: Reflect,
fn get_path_mut<T, 'r, 'p>(
&'r mut self,
path: &'p str
) -> Result<&'r mut T, ReflectPathError<'p>>where
T: Reflect,
path
. Read more