pub struct Camera { /* private fields */ }Expand description
Used in a render call to define how to view the 3D world.
Implementations
sourceimpl Camera
impl Camera
sourcepub fn new_orthographic(
context: &Context,
viewport: Viewport,
position: Vec3,
target: Vec3,
up: Vec3,
height: f32,
z_near: f32,
z_far: f32
) -> ThreeDResult<Camera>
pub fn new_orthographic(
context: &Context,
viewport: Viewport,
position: Vec3,
target: Vec3,
up: Vec3,
height: f32,
z_near: f32,
z_far: f32
) -> ThreeDResult<Camera>
New camera which projects the world with an orthographic projection. See also set_view, set_perspective_projection and set_orthographic_projection.
sourcepub fn new_perspective(
context: &Context,
viewport: Viewport,
position: Vec3,
target: Vec3,
up: Vec3,
field_of_view_y: impl Into<Radians>,
z_near: f32,
z_far: f32
) -> ThreeDResult<Camera>
pub fn new_perspective(
context: &Context,
viewport: Viewport,
position: Vec3,
target: Vec3,
up: Vec3,
field_of_view_y: impl Into<Radians>,
z_near: f32,
z_far: f32
) -> ThreeDResult<Camera>
New camera which projects the world with a perspective projection.
sourcepub fn set_perspective_projection(
&mut self,
field_of_view_y: impl Into<Radians>,
z_near: f32,
z_far: f32
) -> ThreeDResult<()>
pub fn set_perspective_projection(
&mut self,
field_of_view_y: impl Into<Radians>,
z_near: f32,
z_far: f32
) -> ThreeDResult<()>
Specify the camera to use perspective projection with the given field of view in the y-direction and near and far plane.
sourcepub fn set_orthographic_projection(
&mut self,
height: f32,
z_near: f32,
z_far: f32
) -> ThreeDResult<()>
pub fn set_orthographic_projection(
&mut self,
height: f32,
z_near: f32,
z_far: f32
) -> ThreeDResult<()>
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.
sourcepub fn set_viewport(&mut self, viewport: Viewport) -> ThreeDResult<bool>
pub fn set_viewport(&mut self, viewport: Viewport) -> ThreeDResult<bool>
Set the current viewport. Returns whether or not the viewport actually changed.
sourcepub fn set_view(
&mut self,
position: Vec3,
target: Vec3,
up: Vec3
) -> ThreeDResult<()>
pub fn set_view(
&mut self,
position: Vec3,
target: Vec3,
up: Vec3
) -> ThreeDResult<()>
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.
sourcepub fn mirror_in_xz_plane(&mut self) -> ThreeDResult<()>
pub fn mirror_in_xz_plane(&mut self) -> ThreeDResult<()>
Change the camera view such that it is mirrored in the xz-plane.
sourcepub fn in_frustum(&self, aabb: &AxisAlignedBoundingBox) -> bool
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.
sourcepub fn position_at_pixel(&self, pixel: (f32, f32)) -> Vec3
pub fn position_at_pixel(&self, pixel: (f32, f32)) -> Vec3
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.
sourcepub fn view_direction_at_pixel(&self, pixel: (f32, f32)) -> Vec3
pub fn view_direction_at_pixel(&self, pixel: (f32, f32)) -> Vec3
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.
sourcepub fn uv_coordinates_at_pixel(&self, pixel: (f32, f32)) -> (f32, f32)
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 are between 0 and 1 where (0,0) indicate the bottom left corner of the viewport and (1,1) indicate the top right corner.
sourcepub fn uv_coordinates_at_position(&self, position: Vec3) -> (f32, f32)
pub fn uv_coordinates_at_position(&self, position: Vec3) -> (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 top left corner of the viewport and (1,1) indicate a position that maps to the bottom right corner.
sourcepub fn projection_type(&self) -> &ProjectionType
pub fn projection_type(&self) -> &ProjectionType
Returns the type of projection (orthographic or perspective) including parameters.
sourcepub fn view(&self) -> &Mat4
pub fn view(&self) -> &Mat4
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).
sourcepub fn projection(&self) -> &Mat4
pub fn projection(&self) -> &Mat4
Returns the projection matrix, ie. the matrix that projects objects in view space onto this cameras image plane.
sourcepub fn target(&self) -> &Vec3
pub fn target(&self) -> &Vec3
Returns the target of this camera, ie the point that this camera looks towards.
sourcepub fn up(&self) -> &Vec3
pub fn up(&self) -> &Vec3
Returns the up direction of this camera (might not be orthogonal to the view direction).
sourcepub fn view_direction(&self) -> Vec3
pub fn view_direction(&self) -> Vec3
Returns the view direction of this camera, ie. the direction the camera is looking.
sourcepub fn right_direction(&self) -> Vec3
pub fn right_direction(&self) -> Vec3
Returns the right direction of this camera.
sourcepub fn uniform_buffer(&self) -> &UniformBuffer
pub fn uniform_buffer(&self) -> &UniformBuffer
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;sourcepub fn translate(&mut self, change: &Vec3) -> ThreeDResult<()>
pub fn translate(&mut self, change: &Vec3) -> ThreeDResult<()>
Translate the camera by the given change while keeping the same view and up directions.
sourcepub fn pitch(&mut self, delta: impl Into<Radians>) -> ThreeDResult<()>
pub fn pitch(&mut self, delta: impl Into<Radians>) -> ThreeDResult<()>
Rotates the camera by the angle delta around the ‘right’ direction.
sourcepub fn yaw(&mut self, delta: impl Into<Radians>) -> ThreeDResult<()>
pub fn yaw(&mut self, delta: impl Into<Radians>) -> ThreeDResult<()>
Rotates the camera by the angle delta around the ‘up’ direction.
sourcepub fn roll(&mut self, delta: impl Into<Radians>) -> ThreeDResult<()>
pub fn roll(&mut self, delta: impl Into<Radians>) -> ThreeDResult<()>
Rotates the camera by the angle delta around the ‘view’ direction.
sourcepub fn rotate_around(
&mut self,
point: &Vec3,
x: f32,
y: f32
) -> ThreeDResult<()>
pub fn rotate_around(
&mut self,
point: &Vec3,
x: f32,
y: f32
) -> ThreeDResult<()>
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.
sourcepub fn rotate_around_with_fixed_up(
&mut self,
point: &Vec3,
x: f32,
y: f32
) -> ThreeDResult<()>
pub fn rotate_around_with_fixed_up(
&mut self,
point: &Vec3,
x: f32,
y: f32
) -> ThreeDResult<()>
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.
sourcepub fn zoom_towards(
&mut self,
point: &Vec3,
delta: f32,
minimum_distance: f32,
maximum_distance: f32
) -> ThreeDResult<()>
pub fn zoom_towards(
&mut self,
point: &Vec3,
delta: f32,
minimum_distance: f32,
maximum_distance: f32
) -> ThreeDResult<()>
Moves the camera towards the given point by the amount delta while keeping the given minimum and maximum distance to the point.
Auto Trait Implementations
impl !RefUnwindSafe for Camera
impl !Send for Camera
impl !Sync for Camera
impl Unpin for Camera
impl !UnwindSafe for Camera
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more