Struct Camera

Source
pub struct Camera {
    pub tone_mapping: ToneMapping,
    pub color_mapping: ColorMapping,
    /* private fields */
}
Expand description

Represents a camera used for viewing 2D and 3D objects.

Fields§

§tone_mapping: ToneMapping

This tone mapping is applied to the final color of renders using this camera.

§color_mapping: ColorMapping

This color mapping is applied to the final color of renders using this camera.

Implementations§

Source§

impl Camera

Source

pub fn new_orthographic( viewport: Viewport, position: Vec3, target: Vec3, up: Vec3, height: f32, z_near: f32, z_far: f32, ) -> Self

New camera which projects the world with an orthographic projection.

Source

pub fn new_perspective( viewport: Viewport, position: Vec3, target: Vec3, up: Vec3, field_of_view_y: impl Into<Radians>, z_near: f32, z_far: f32, ) -> Self

New camera which projects the world with a perspective projection.

Source

pub fn new_2d(viewport: Viewport) -> Self

Returns an orthographic camera for viewing 2D content. The camera is placed at the center of the given viewport. The (0, 0) position is at the bottom left corner and the (viewport.width, viewport.height) position is at the top right corner.

Source

pub fn disable_tone_and_color_mapping(&mut self)

Disables the tone and color mapping so as to be ready for rendering into an intermediate render target with this camera.

Source

pub fn set_default_tone_and_color_mapping(&mut self)

Sets the tone and color mapping to default so as to be ready for rendering into the final render target (usually the screen) with this camera.

Methods from Deref<Target = Camera>§

Source

pub fn set_perspective_projection( &mut self, field_of_view_y: impl Into<Rad<f32>>, z_near: f32, z_far: f32, )

Specify the camera to use perspective projection with the given field of view in the y-direction and near and far plane.

Source

pub fn set_orthographic_projection( &mut self, height: f32, z_near: f32, z_far: f32, )

Specify the camera to use orthographic projection with the given dimensions. The view frustum height is +/- height/2. The view frustum width is calculated as height * viewport.width / viewport.height. The view frustum depth is z_near to z_far. All of the above values are scaled by the zoom factor which is one over the distance between the camera position and target.

Source

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

Set the current viewport. Returns whether or not the viewport actually changed.

Source

pub fn set_view( &mut self, position: Vector3<f32>, target: Vector3<f32>, up: Vector3<f32>, )

Change the view of the camera. The camera is placed at the given position, looking at the given target and with the given up direction.

Source

pub fn frustum(&self) -> Frustum

Returns the Frustum for this camera.

Source

pub fn position_at_pixel(&self, pixel: impl Into<PixelPoint>) -> Vector3<f32>

Returns the 3D position at the given pixel coordinate.

Source

pub fn position_at_uv_coordinates( &self, coords: impl Into<UvCoordinate>, ) -> Vector3<f32>

Returns the 3D position at the given uv coordinate of the viewport.

Source

pub fn view_direction_at_pixel( &self, pixel: impl Into<PixelPoint>, ) -> Vector3<f32>

Returns the 3D view direction at the given pixel coordinate.

Source

pub fn view_direction_at_uv_coordinates( &self, coords: impl Into<UvCoordinate>, ) -> Vector3<f32>

Returns the 3D view direction at the given uv coordinate of the viewport.

Source

pub fn uv_coordinates_at_pixel( &self, pixel: impl Into<PixelPoint>, ) -> UvCoordinate

Returns the uv coordinate for the given pixel coordinate.

Source

pub fn uv_coordinates_at_position(&self, position: Vector3<f32>) -> UvCoordinate

Returns the uv coordinate for the given world position.

Source

pub fn pixel_at_uv_coordinates( &self, coords: impl Into<UvCoordinate>, ) -> PixelPoint

Returns the pixel coordinate for the given uv coordinate.

Source

pub fn pixel_at_position(&self, position: Vector3<f32>) -> PixelPoint

Returns the pixel coordinate for the given world position.

Source

pub fn projection_type(&self) -> &ProjectionType

Returns the type of projection (orthographic or perspective) including parameters.

Source

pub fn view(&self) -> Matrix4<f32>

Returns the view matrix, ie. the matrix that transforms objects from world space (as placed in the world) to view space (as seen from this camera).

Source

pub fn projection(&self) -> Matrix4<f32>

Returns the projection matrix, ie. the matrix that projects objects in view space onto this cameras image plane.

Source

pub fn viewport(&self) -> Viewport

Returns the viewport.

Source

pub fn z_near(&self) -> f32

Returns the distance to the near plane of the camera frustum.

Source

pub fn z_far(&self) -> f32

Returns the distance to the far plane of the camera frustum.

Source

pub fn position(&self) -> Vector3<f32>

Returns the position of this camera.

Source

pub fn target(&self) -> Vector3<f32>

Returns the target of this camera, ie the point that this camera looks towards.

Source

pub fn up(&self) -> Vector3<f32>

Returns the up direction of this camera. This will probably not be orthogonal to the view direction, use up_orthogonal instead if that is needed.

Source

pub fn up_orthogonal(&self) -> Vector3<f32>

Returns the up direction of this camera that is orthogonal to the view direction.

Source

pub fn view_direction(&self) -> Vector3<f32>

Returns the view direction of this camera, ie. the direction the camera is looking.

Source

pub fn right_direction(&self) -> Vector3<f32>

Returns the right direction of this camera.

Source

pub fn translate(&mut self, change: Vector3<f32>)

Translate the camera by the given change while keeping the same view and up directions.

Source

pub fn pitch(&mut self, delta: impl Into<Rad<f32>>)

Rotates the camera by the angle delta around the ‘right’ direction.

Source

pub fn yaw(&mut self, delta: impl Into<Rad<f32>>)

Rotates the camera by the angle delta around the ‘up’ direction.

Source

pub fn roll(&mut self, delta: impl Into<Rad<f32>>)

Rotates the camera by the angle delta around the ‘view’ direction.

Source

pub fn rotate_around(&mut self, point: Vector3<f32>, x: f32, y: f32)

Rotate the camera around the given point while keeping the same distance to the point. The input x specifies the amount of rotation in the left direction and y specifies the amount of rotation in the up direction. If you want the camera up direction to stay fixed, use the rotate_around_with_fixed_up function instead.

Source

pub fn rotate_around_with_fixed_up( &mut self, point: Vector3<f32>, x: f32, y: f32, )

Rotate the camera around the given point while keeping the same distance to the point and the same up direction. The input x specifies the amount of rotation in the left direction and y specifies the amount of rotation in the up direction.

Source

pub fn zoom(&mut self, delta: f32, minimum_distance: f32, maximum_distance: f32)

Moves the camera towards the camera target by the amount delta while keeping the given minimum and maximum distance to the target.

Source

pub fn zoom_towards( &mut self, point: Vector3<f32>, delta: f32, minimum_distance: f32, maximum_distance: f32, )

Moves the camera towards the given point by the amount delta while keeping the given minimum and maximum distance to the camera target. Note that the camera target is also updated so that the view direction is the same.

Source

pub fn set_zoom_factor(&mut self, zoom_factor: f32)

Sets the zoom factor of this camera, ie. the distance to the camera will be 1/zoom_factor.

Source

pub fn zoom_factor(&self) -> f32

The zoom factor for this camera, which is the same as one over the distance between the camera position and target.

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

Source§

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

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

impl Deref for Camera

Source§

type Target = Camera

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for Camera

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl Viewer for Camera

Source§

fn position(&self) -> Vec3

The position of the viewer.
Source§

fn view(&self) -> Mat4

The view matrix which transforms from world space to view space.
Source§

fn projection(&self) -> Mat4

The projection matrix which transforms from view space to clip space (2D position on the screen).
Source§

fn viewport(&self) -> Viewport

The 2D Viewport of the viewer.
Source§

fn z_near(&self) -> f32

Defines the minimum depth in world space.
Source§

fn z_far(&self) -> f32

Defines the maximum depth in world space.
Source§

fn color_mapping(&self) -> ColorMapping

Defines the ColorMapping applied to the final rendered image.
Source§

fn tone_mapping(&self) -> ToneMapping

Defines the ToneMapping applied to the final rendered image.

Auto Trait Implementations§

§

impl Freeze for Camera

§

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> 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> 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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 = 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>,

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> AutoreleaseSafe for T
where T: ?Sized,

Source§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,