Struct bevy::render::camera::Camera

source ·
pub struct Camera {
    pub viewport: Option<Viewport>,
    pub order: isize,
    pub is_active: bool,
    pub computed: ComputedCameraValues,
    pub target: RenderTarget,
    pub hdr: bool,
    pub output_mode: CameraOutputMode,
    pub msaa_writeback: bool,
    pub clear_color: ClearColorConfig,
}
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.

§order: isize

Cameras with a higher order are rendered later, and thus on top of lower order cameras.

§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. This allows rendering with a wider range of lighting values.

§output_mode: CameraOutputMode

The CameraOutputMode for this camera.

§msaa_writeback: bool

If this is enabled, a previous camera exists that shares this camera’s render target, and this camera has MSAA enabled, then the previous camera’s outputs will be written to the intermediate multi-sampled render target textures for this camera. This enables cameras with MSAA enabled to “write their results on top” of previous camera results, and include them as a part of their render results. This is enabled by default to ensure cameras with MSAA enabled layer their results in the same way as cameras without MSAA enabled by default.

§clear_color: ClearColorConfig

The clear color operation to perform on the render target.

Implementations§

source§

impl Camera

source

pub fn to_logical(&self, physical_size: UVec2) -> Option<Vec2>

Converts a physical size in this Camera to a logical size.

source

pub fn physical_viewport_rect(&self) -> Option<URect>

The rendered physical bounds URect 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.

source

pub fn logical_viewport_rect(&self) -> Option<Rect>

The rendered logical bounds Rect 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.

source

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.

Returns None if either:

  • the function is called just after the Camera is created, before camera_system is executed,
  • the RenderTarget isn’t correctly set:
    • it references the PrimaryWindow when there is none,
    • it references a Window entity that doesn’t exist or doesn’t actually have a Window component,
    • it references an Image that doesn’t exist (invalid handle),
    • it references a TextureView that doesn’t exist (invalid handle).
source

pub fn physical_viewport_size(&self) -> Option<UVec2>

The physical size of this camera’s viewport (in physical pixels). 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.

source

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.

source

pub fn physical_target_size(&self) -> Option<UVec2>

The full physical size of this camera’s RenderTarget (in physical pixels), 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.

source

pub fn target_scaling_factor(&self) -> Option<f32>

source

pub fn projection_matrix(&self) -> Mat4

The projection matrix computed using this camera’s CameraProjection.

source

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.

Returns None if any of these conditions occur:

  • The computed coordinates are beyond the near or far plane
  • The logical viewport size cannot be computed. See logical_viewport_size
  • The world coordinates cannot be mapped to the Normalized Device Coordinates. See world_to_ndc May also panic if glam_assert is enabled. See world_to_ndc.
source

pub fn viewport_to_world( &self, camera_transform: &GlobalTransform, viewport_position: Vec2 ) -> Option<Ray3d>

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.

Returns None if any of these conditions occur:

  • The logical viewport size cannot be computed. See logical_viewport_size
  • The near or far plane cannot be computed. This can happen if the camera_transform, the world_position, or the projection matrix defined by CameraProjection contain NAN. Panics if the projection matrix is null and glam_assert is enabled.
source

pub fn viewport_to_world_2d( &self, camera_transform: &GlobalTransform, viewport_position: Vec2 ) -> Option<Vec2>

Returns a 2D world position computed from a position on this Camera’s viewport.

Useful for 2D cameras and other cameras with an orthographic projection pointing along the Z axis.

To get the world space coordinates with Normalized Device Coordinates, you should use ndc_to_world.

Returns None if any of these conditions occur:

source

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.

Returns None if the camera_transform, the world_position, or the projection matrix defined by CameraProjection contain NAN. Panics if the camera_transform contains NAN and the glam_assert feature is enabled.

source

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.

Returns None if the camera_transform, the world_position, or the projection matrix defined by CameraProjection contain NAN. Panics if the projection matrix is null and glam_assert is enabled.

Trait Implementations§

source§

impl Clone for Camera

source§

fn clone(&self) -> Camera

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Component for Camera
where Camera: Send + Sync + 'static,

§

type Storage = TableStorage

A marker type indicating the storage type used for this component. This must be either TableStorage or SparseStorage.
source§

impl Debug for Camera

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl Default for Camera

source§

fn default() -> Camera

Returns the “default value” for a type. Read more
source§

impl FromReflect for Camera

source§

fn from_reflect(reflect: &(dyn Reflect + 'static)) -> Option<Camera>

Constructs a concrete instance of Self from a reflected value.
source§

fn take_from_reflect( reflect: Box<dyn Reflect> ) -> Result<Self, Box<dyn Reflect>>

Attempts to downcast the given value to Self using, constructing the value using from_reflect if that fails. Read more
source§

impl GetTypeRegistration for Camera

source§

impl Reflect for Camera

source§

fn get_represented_type_info(&self) -> Option<&'static TypeInfo>

Returns the TypeInfo of the type represented by this value. Read more
source§

fn into_any(self: Box<Camera>) -> Box<dyn Any>

Returns the value as a Box<dyn Any>.
source§

fn as_any(&self) -> &(dyn Any + 'static)

Returns the value as a &dyn Any.
source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Returns the value as a &mut dyn Any.
source§

fn into_reflect(self: Box<Camera>) -> Box<dyn Reflect>

Casts this type to a boxed reflected value.
source§

fn as_reflect(&self) -> &(dyn Reflect + 'static)

Casts this type to a reflected value.
source§

fn as_reflect_mut(&mut self) -> &mut (dyn Reflect + 'static)

Casts this type to a mutable reflected value.
source§

fn clone_value(&self) -> Box<dyn Reflect>

Clones the value as a Reflect trait object. Read more
source§

fn set(&mut self, value: Box<dyn Reflect>) -> Result<(), Box<dyn Reflect>>

Performs a type-checked assignment of a reflected value to this value. Read more
source§

fn apply(&mut self, value: &(dyn Reflect + 'static))

Applies a reflected value to this value. Read more
source§

fn reflect_kind(&self) -> ReflectKind

Returns a zero-sized enumeration of “kinds” of type. Read more
source§

fn reflect_ref(&self) -> ReflectRef<'_>

Returns an immutable enumeration of “kinds” of type. Read more
source§

fn reflect_mut(&mut self) -> ReflectMut<'_>

Returns a mutable enumeration of “kinds” of type. Read more
source§

fn reflect_owned(self: Box<Camera>) -> ReflectOwned

Returns an owned enumeration of “kinds” of type. Read more
source§

fn reflect_partial_eq(&self, value: &(dyn Reflect + 'static)) -> Option<bool>

Returns a “partial equality” comparison result. Read more
source§

fn reflect_hash(&self) -> Option<u64>

Returns a hash of the value (which includes the type). Read more
source§

fn debug(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Debug formatter for the value. Read more
source§

fn serializable(&self) -> Option<Serializable<'_>>

Returns a serializable version of the value. Read more
source§

fn is_dynamic(&self) -> bool

Indicates whether or not this type is a dynamic type. Read more
source§

impl Struct for Camera

source§

fn field(&self, name: &str) -> Option<&(dyn Reflect + 'static)>

Returns a reference to the value of the field named name as a &dyn Reflect.
source§

fn field_mut(&mut self, name: &str) -> Option<&mut (dyn Reflect + 'static)>

Returns a mutable reference to the value of the field named name as a &mut dyn Reflect.
source§

fn field_at(&self, index: usize) -> Option<&(dyn Reflect + 'static)>

Returns a reference to the value of the field with index index as a &dyn Reflect.
source§

fn field_at_mut(&mut self, index: usize) -> Option<&mut (dyn Reflect + 'static)>

Returns a mutable reference to the value of the field with index index as a &mut dyn Reflect.
source§

fn name_at(&self, index: usize) -> Option<&str>

Returns the name of the field with index index.
source§

fn field_len(&self) -> usize

Returns the number of fields in the struct.
source§

fn iter_fields(&self) -> FieldIter<'_>

Returns an iterator over the values of the reflectable fields for this struct.
source§

fn clone_dynamic(&self) -> DynamicStruct

Clones the struct into a DynamicStruct.
source§

impl TypePath for Camera
where Camera: Any + Send + Sync,

source§

fn type_path() -> &'static str

Returns the fully qualified path of the underlying type. Read more
source§

fn short_type_path() -> &'static str

Returns a short, pretty-print enabled path to the type. Read more
source§

fn type_ident() -> Option<&'static str>

Returns the name of the type, or None if it is anonymous. Read more
source§

fn crate_name() -> Option<&'static str>

Returns the name of the crate the type is in, or None if it is anonymous. Read more
source§

fn module_path() -> Option<&'static str>

Returns the path to the module the type is in, or None if it is anonymous. Read more
source§

impl Typed for Camera

source§

fn type_info() -> &'static TypeInfo

Returns the compile-time info for the underlying type.

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§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T, U> AsBindGroupShaderType<U> for T
where U: ShaderType, &'a T: for<'a> Into<U>,

source§

fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U

Return the T ShaderType for self. When used in AsBindGroup derives, it is safe to assume that all images in self exist.
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<C> Bundle for C
where C: Component,

source§

fn component_ids( components: &mut Components, storages: &mut Storages, ids: &mut impl FnMut(ComponentId) )

source§

unsafe fn from_components<T, F>(ctx: &mut T, func: &mut F) -> C
where F: for<'a> FnMut(&'a mut T) -> OwningPtr<'a>,

source§

impl<T> Downcast<T> for T

source§

fn downcast(&self) -> &T

source§

impl<T> Downcast for T
where T: Any,

source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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.
source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<C> DynamicBundle for C
where C: Component,

source§

fn get_components(self, func: &mut impl FnMut(StorageType, OwningPtr<'_>))

source§

impl<T> DynamicTypePath for T
where T: TypePath,

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<S> FromSample<S> for S

source§

fn from_sample_(s: S) -> S

source§

impl<T> FromWorld for T
where T: Default,

source§

fn from_world(_world: &mut World) -> T

Creates Self using data from the given World.
source§

impl<S> GetField for S
where S: Struct,

source§

fn get_field<T>(&self, name: &str) -> Option<&T>
where T: Reflect,

Returns a reference to the value of the field named name, downcast to T.
source§

fn get_field_mut<T>(&mut self, name: &str) -> Option<&mut T>
where T: Reflect,

Returns a mutable reference to the value of the field named name, downcast to T.
source§

impl<T> GetPath for T
where T: Reflect + ?Sized,

source§

fn reflect_path<'p>( &self, path: impl ReflectPath<'p> ) -> Result<&(dyn Reflect + 'static), ReflectPathError<'p>>

Returns a reference to the value specified by path. Read more
source§

fn reflect_path_mut<'p>( &mut self, path: impl ReflectPath<'p> ) -> Result<&mut (dyn Reflect + 'static), ReflectPathError<'p>>

Returns a mutable reference to the value specified by path. Read more
source§

fn path<'p, T>( &self, path: impl ReflectPath<'p> ) -> Result<&T, ReflectPathError<'p>>
where T: Reflect,

Returns a statically typed reference to the value specified by path. Read more
source§

fn path_mut<'p, T>( &mut self, path: impl ReflectPath<'p> ) -> Result<&mut T, ReflectPathError<'p>>
where T: Reflect,

Returns a statically typed mutable reference to the value specified by path. Read more
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

source§

fn to_sample_(self) -> U

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> TypeData for T
where T: 'static + Send + Sync + Clone,

source§

impl<T> Upcast<T> for T

source§

fn upcast(&self) -> Option<&T>

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

source§

impl<T> Settings for T
where T: 'static + Send + Sync,

source§

impl<T> WasmNotSend for T
where T: Send,

source§

impl<T> WasmNotSendSync for T

source§

impl<T> WasmNotSync for T
where T: Sync,