Skip to main content

Camera

Struct Camera 

Source
pub struct Camera {
    pub view: Mat4,
    pub focal_length: f32,
}
Expand description

A pinhole camera that shows a 3D scene in a composable’s bounds.

The camera looks along its own z axis with its x to the right and y down. A point at (x, y, z) in the camera’s frame shows at center + (x, y) * focal_length / z, where center is the middle of the bounds.

Fields§

§view: Mat4

Maps scene space into the camera’s frame.

§focal_length: f32

The distance from the eye to the image, in logical pixels: the distance at which one scene unit shows as one pixel.

Implementations§

Source§

impl Camera

Source

pub fn look_at(eye: Vec3, target: Vec3, down: Vec3, focal_length: f32) -> Camera

A camera at eye that looks at target. down is the scene direction that shows as down; it need not be square to the view.

Source

pub fn focal_length_for(height: f32, vertical_fov: f32) -> f32

The focal length that shows vertical_fov radians across height pixels.

Source

pub fn eye(&self) -> Vec3

The eye’s position in scene space.

Source

pub fn near(&self) -> f32

The camera-frame depth below which the camera sees nothing.

Source

pub fn project(&self, point: Vec3, size: Size) -> Option<Point>

Where point shows in bounds of size; None when it lies nearer than Self::near or behind the eye.

Source

pub fn doorway(&self, window: Rect) -> Mat4

The map from the scene this camera sees into the frame in which window, a rect on the frame’s plane, is a doorway into the scene: the camera stands in the doorway’s middle, looking along the frame’s z, with its x and y along the frame’s, a scene unit to a frame unit. What the camera sees lies behind the doorway.

Source

pub fn ray(&self, point: Point, size: Size) -> Option<Ray>

The ray from the eye through point of bounds of size, in scene space, with a direction that reaches depth one in the camera’s frame at distance one.

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 Copy for Camera

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 PartialEq for Camera

Source§

fn eq(&self, other: &Camera) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Camera

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> AnyEq for T
where T: Any + PartialEq,

Source§

fn equals(&self, other: &(dyn Any + 'static)) -> bool

Source§

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

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<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> ErasedDestructor for T
where T: 'static,

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> LayoutData for T
where T: Any + Debug + PartialEq,

Source§

fn same_as(&self, other: &(dyn LayoutData + 'static)) -> bool

Whether other holds the same data, so a parent can keep its last measure.
Source§

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

The data as Any, to read it by its type.
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.