Struct three_d::core::Camera

source ·
pub struct Camera { /* private fields */ }
Expand description

Represents a camera used for viewing 3D assets.

Implementations§

source§

impl Camera

source

pub fn new_orthographic( viewport: Viewport, position: Vector3<f32>, target: Vector3<f32>, up: Vector3<f32>, height: f32, z_near: f32, z_far: f32 ) -> Camera

New camera which projects the world with an orthographic projection. See also set_view, set_perspective_projection and set_orthographic_projection.

source

pub fn new_perspective( viewport: Viewport, position: Vector3<f32>, target: Vector3<f32>, up: Vector3<f32>, field_of_view_y: impl Into<Rad<f32>>, z_near: f32, z_far: f32 ) -> Camera

New camera which projects the world with a perspective projection.

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: (f32, f32)) -> Vector3<f32>

Returns the 3D position at the given pixel coordinate. The pixel coordinate must be in physical pixels, where (viewport.x, viewport.y) indicate the bottom left corner of the viewport and (viewport.x + viewport.width, viewport.y + viewport.height) indicate the top right corner.

source

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

Returns the 3D position at the given uv coordinate of the viewport. The uv coordinate must be between (0, 0) indicating the bottom left corner of the viewport and (1, 1) indicating the top right corner.

source

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

Returns the 3D view direction at the given pixel coordinate. The pixel coordinate must be in physical pixels, where (viewport.x, viewport.y) indicate the bottom left corner of the viewport and (viewport.x + viewport.width, viewport.y + viewport.height) indicate the top right corner.

source

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

Returns the 3D view direction at the given uv coordinate of the viewport. The uv coordinate must be between (0, 0) indicating the bottom left corner of the viewport and (1, 1) indicating the top right corner.

source

pub fn uv_coordinates_at_pixel(&self, pixel: (f32, f32)) -> (f32, f32)

Returns the uv coordinate for the given pixel coordinate. The pixel coordinate must be in physical pixels, where (viewport.x, viewport.y) indicate the bottom left corner of the viewport and (viewport.x + viewport.width, viewport.y + viewport.height) indicate the top right corner. The returned uv coordinate is between 0 and 1 where (0,0) indicate the bottom left corner of the viewport and (1,1) indicate the top right corner.

source

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

Returns the uv coordinate for the given world position. The returned uv coordinate are between 0 and 1 where (0,0) indicate a position that maps to the bottom left corner of the viewport and (1,1) indicate a position that maps to the top right corner.

source

pub fn pixel_at_uv_coordinates(&self, coords: (f32, f32)) -> (f32, f32)

Returns the pixel coordinate for the given uv coordinate. The uv coordinate must be between 0 and 1 where (0,0) indicate the bottom left corner of the viewport and (1,1) indicate the top right corner. The returned pixel coordinate is in physical pixels, where (viewport.x, viewport.y) indicate the bottom left corner of the viewport and (viewport.x + viewport.width, viewport.y + viewport.height) indicate the top right corner.

source

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

Returns the pixel coordinate for the given world position. The returned pixel coordinate is in physical pixels, where (viewport.x, viewport.y) indicate the bottom left corner of the viewport and (viewport.x + viewport.width, viewport.y + viewport.height) indicate the top right corner.

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<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

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 Twhere U: From<T>,

const: unstable · 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 Twhere 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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
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<T> SerializableAny for Twhere T: 'static + Any + Clone + Send + Sync,