Skip to main content

Camera

Struct Camera 

Source
pub struct Camera { /* private fields */ }

Implementations§

Source§

impl Camera

Basic creation and mutation.

Source

pub fn new(options: GraphicsOptions, viewport: Viewport) -> Camera

Create a camera which has

  • options and viewport as given,
  • a view transform of ViewTransform::identity(), and
  • an exposure determined based on the graphics options.
Source

pub fn set_options(&mut self, options: GraphicsOptions)

Replace the GraphicsOptions stored in this camera with options.repair().

Source

pub fn options(&self) -> &GraphicsOptions

Returns the GraphicsOptions value last provided to Camera::new() or Camera::set_options() (possibly with adjusted values).

Source

pub fn set_viewport(&mut self, viewport: Viewport)

Sets the contained viewport value, and recalculates matrices to be suitable for the new viewport’s aspect ratio.

Source

pub fn viewport(&self) -> Viewport

Returns the viewport last provided to Camera::new() or Camera::set_viewport().

Source

pub fn set_view_transform( &mut self, eye_to_world_transform: RigidTransform3D<f64, Eye, Cube>, )

Sets the view transform and recalculates matrices appropriately.

Note that this is specified as the eye-to-world transform; that is, the given transform’s translation should be equal to the view point in world coordinates.

Besides controlling rendering, this is used to determine world coordinates for purposes of view_position() and project_ndc_into_world().

Source

pub fn look_at_y_up( &mut self, eye: Point3D<f64, Cube>, target: Point3D<f64, Cube>, )

Sets the view transform like Camera::set_view_transform(), but in “look at” fashion.

Source

pub fn view_transform(&self) -> RigidTransform3D<f64, Eye, Cube>

Returns the last eye-to-world transform set by Camera::set_view_transform().

Source

pub fn set_measured_exposure(&mut self, value: f32)

Sets the exposure value that should have been determined by average scene brightness. This may or may not affect Self::exposure() depending on the current graphics options.

Source§

impl Camera

Values derived from the basic parameters, and functions for applying this camera’s characteristics to points and colors.

Source

pub fn fov_y(&self) -> f64

Returns the field of view, expressed in degrees on the vertical axis (that is, the horizontal field of view depends on the viewport’s aspect ratio).

Source

pub fn view_distance(&self) -> PositiveSign<f64>

Returns the view distance; the far plane of the view frustum, or the distance at which rendering may be truncated.

Source

pub fn near_plane_distance(&self) -> PositiveSign<f64>

Returns the position of the near plane of the view frustum. This is not currently configurable.

Source

pub fn projection_matrix(&self) -> Transform3D<f64, Eye, Ndc>

Returns a perspective projection matrix based on the configured FOV and view distance,

It maps coordinates in “eye” space into the Normalized Device Cooordinate space whose range is from -1 to 1 in X and Y, and 0 to 1 in Z. (This is DirectX and WebGPU style NDC, rather than OpenGL style which has a range of -1 to 1 in Z.)

Source

pub fn view_matrix(&self) -> Transform3D<f64, Cube, Eye>

Returns a matrix which maps coordinates in world space to coordinates in eye space. It is the inverse of the current Camera::view_transform().

Source

pub fn view_position(&self) -> Point3D<f64, Cube>

Returns the eye position in world coordinates, as set by Camera::set_view_transform().

Source

pub fn project_ndc_into_world(&self, ndc: Point2D<f64, Ndc>) -> Ray

Converts a screen position in normalized device coordinates (as produced by Viewport::normalize_nominal_point()) into a ray in world space. Uses the view transformation given by set_view_transform.

The input coordinates should be within the range -1 to 1, inclusive. If they are not, the result may be a ray whose components are NaN.

The ray’s origin’s distance along the view direction axis is equal to Camera::near_plane_distance(). The ray’s Ray::unit_endpoint() along the view direction axis is equal to Camera::view_distance().

Source

pub fn view_direction_mask(&self) -> OctantMask

Returns an OctantMask which includes all directions (in world space) visible in images rendered as specified by this camera.

This information may be used as a fast initial culling step, avoiding iterating over content behind the camera.

Source

pub fn aab_in_view(&self, aab: Aab) -> bool

Determine whether the given Aab is visible in this projection+view.

Source

pub fn exposure(&self) -> PositiveSign<f32>

Returns the current exposure value for scaling luminance.

Renderers should use this value, not the fixed exposure value in the GraphicsOptions. It may or may not be equal to the last set_measured_exposure(), depending on the graphics options.

Source

pub fn post_process_color(&self, color: Rgba) -> Rgba

Apply postprocessing steps determined by this camera to convert a HDR “scene” color into a SDR “image” color. Specifically:

  1. Multiply the input by this camera’s exposure() value.
  2. Apply the tone mapping operator specified in Camera::options().

Trait Implementations§

Source§

impl Clone for Camera

Source§

fn clone(&self) -> Camera

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Camera

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

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

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
Source§

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

Source§

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> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.