Struct three_d::renderer::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 height and depth. 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.

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 mirror_in_xz_plane(&mut self)

Change the camera view such that it is mirrored in the xz-plane.

source

pub fn in_frustum(&self, aabb: &AxisAlignedBoundingBox) -> bool

Returns whether or not the given bounding box is within the camera frustum. It returns false if it is fully outside and true if it is inside or intersects.

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 (might not be 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_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 point.

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

§

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.

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

source§

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