Struct three_d::CameraControl[][src]

pub struct CameraControl { /* fields omitted */ }
Expand description

3D controls for a camera. Use this to add additional control functionality to a camera.

Implementations

impl CameraControl[src]

pub fn new(camera: Camera) -> Self[src]

Extends the given camera with additional functionality for camera control.

pub fn translate(&mut self, change: &Vec3) -> Result<(), Error>[src]

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

pub fn rotate_around(
    &mut self,
    point: &Vec3,
    x: f32,
    y: f32
) -> Result<(), Error>
[src]

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.

pub fn rotate_around_with_fixed_up(
    &mut self,
    point: &Vec3,
    x: f32,
    y: f32
) -> Result<(), Error>
[src]

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.

pub fn pan(&mut self, x: f32, y: f32) -> Result<(), Error>[src]

Moves the camera in the plane orthogonal to the current view direction, which means the view and up directions will stay the same. The input x specifies the amount of translation in the left direction and y specifies the amount of translation in the up direction.

pub fn zoom_towards(
    &mut self,
    point: &Vec3,
    delta: f32,
    minimum_distance: f32,
    maximum_distance: f32
) -> Result<(), Error>
[src]

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

Methods from Deref<Target = Camera>

pub fn set_perspective_projection(
    &mut self,
    field_of_view_y: Degrees,
    aspect: f32,
    z_near: f32,
    z_far: f32
) -> Result<(), Error>
[src]

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

pub fn set_orthographic_projection(
    &mut self,
    width: f32,
    height: f32,
    depth: f32
) -> Result<(), Error>
[src]

Specify the camera to use orthographic projection with the given width, height and depth. The view frustum width is +/- width/2, height is +/- height/2 and depth is 0 to depth.

pub fn set_aspect(&mut self, value: f32) -> Result<bool, Error>[src]

Change the current projection to abide to the given aspect ratio.

pub fn set_view(
    &mut self,
    position: Vec3,
    target: Vec3,
    up: Vec3
) -> Result<(), Error>
[src]

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.

pub fn mirror_in_xz_plane(&mut self) -> Result<(), Error>[src]

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

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

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.

pub fn pick(
    &self,
    screen_coordinates: (f32, f32),
    max_depth: f32,
    objects: &[&dyn Geometry]
) -> Result<Option<Vec3>, Error>
[src]

Finds the closest intersection between a ray from this camera in the direction of the given screen coordinates and the given geometries. Returns None if no geometry was hit before the given maximum depth.

pub fn position_at(&self, screen_coordinates: (f32, f32)) -> Vec3[src]

Returns the 3D position at the given screen/image plane coordinates. The coordinates must be between 0 and 1, where (0, 0) indicate the top left corner of the screen and (1, 1) indicate the bottom right corner.

pub fn view_direction_at(&self, screen_coordinates: (f32, f32)) -> Vec3[src]

Returns the 3D view direction at the given screen/image plane coordinates. The coordinates must be between 0 and 1, where (0, 0) indicate the top left corner of the screen and (1, 1) indicate the bottom right corner.

pub fn view(&self) -> &Mat4[src]

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).

pub fn projection(&self) -> &Mat4[src]

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

pub fn position(&self) -> &Vec3[src]

Returns the position of this camera.

pub fn target(&self) -> &Vec3[src]

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

pub fn up(&self) -> &Vec3[src]

Returns the up direction of this camera.

pub fn view_direction(&self) -> Vec3[src]

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

pub fn right_direction(&self) -> Vec3[src]

Returns the right direction of this camera.

pub fn uniform_buffer(&self) -> &UniformBuffer[src]

Returns an uniform buffer containing camera information which makes it easy to transfer all necessary camera information to a shader.

Use this buffer in your Program like this program.use_uniform_block(camera.uniform_buffer(), "Camera"); and add the following to your shader code:

layout (std140) uniform Camera
{
    mat4 viewProjection;
    mat4 view;
    mat4 projection;
    vec3 position;
    float padding;
} camera;

Trait Implementations

impl Deref for CameraControl[src]

type Target = Camera

The resulting type after dereferencing.

fn deref(&self) -> &Self::Target[src]

Dereferences the value.

impl DerefMut for CameraControl[src]

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

Mutably dereferences the value.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.