pub struct Camera { /* private fields */ }Expand description
Represents a camera used for viewing 3D assets.
Implementations§
source§impl Camera
impl Camera
sourcepub fn new_orthographic(
viewport: Viewport,
position: Vector3<f32>,
target: Vector3<f32>,
up: Vector3<f32>,
height: f32,
z_near: f32,
z_far: f32
) -> Camera
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.
sourcepub 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
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.
sourcepub fn set_perspective_projection(
&mut self,
field_of_view_y: impl Into<Rad<f32>>,
z_near: f32,
z_far: f32
)
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.
sourcepub fn set_orthographic_projection(&mut self, height: f32, z_near: f32, z_far: f32)
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.
sourcepub fn set_viewport(&mut self, viewport: Viewport) -> bool
pub fn set_viewport(&mut self, viewport: Viewport) -> bool
Set the current viewport. Returns whether or not the viewport actually changed.
sourcepub fn set_view(
&mut self,
position: Vector3<f32>,
target: Vector3<f32>,
up: Vector3<f32>
)
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.
sourcepub fn mirror_in_xz_plane(&mut self)
pub fn mirror_in_xz_plane(&mut self)
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)) -> Vector3<f32>
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.
sourcepub fn position_at_uv_coordinates(&self, coords: (f32, f32)) -> Vector3<f32>
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.
sourcepub fn view_direction_at_pixel(&self, pixel: (f32, f32)) -> Vector3<f32>
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.
sourcepub fn view_direction_at_uv_coordinates(
&self,
coords: (f32, f32)
) -> Vector3<f32>
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.
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 is 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: Vector3<f32>) -> (f32, f32)
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.
sourcepub fn pixel_at_uv_coordinates(&self, coords: (f32, f32)) -> (f32, f32)
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.
sourcepub fn pixel_at_position(&self, position: Vector3<f32>) -> (f32, f32)
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.
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) -> &Matrix4<f32>
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).
sourcepub fn projection(&self) -> &Matrix4<f32>
pub fn projection(&self) -> &Matrix4<f32>
Returns the projection matrix, ie. the matrix that projects objects in view space onto this cameras image plane.
sourcepub fn target(&self) -> &Vector3<f32>
pub fn target(&self) -> &Vector3<f32>
Returns the target of this camera, ie the point that this camera looks towards.
sourcepub fn up(&self) -> &Vector3<f32>
pub fn up(&self) -> &Vector3<f32>
Returns the up direction of this camera (might not be orthogonal to the view direction).
sourcepub fn view_direction(&self) -> Vector3<f32>
pub fn view_direction(&self) -> Vector3<f32>
Returns the view direction of this camera, ie. the direction the camera is looking.
sourcepub fn right_direction(&self) -> Vector3<f32>
pub fn right_direction(&self) -> Vector3<f32>
Returns the right direction of this camera.
sourcepub fn translate(&mut self, change: &Vector3<f32>)
pub fn translate(&mut self, change: &Vector3<f32>)
Translate the camera by the given change while keeping the same view and up directions.
sourcepub fn pitch(&mut self, delta: impl Into<Rad<f32>>)
pub fn pitch(&mut self, delta: impl Into<Rad<f32>>)
Rotates the camera by the angle delta around the ‘right’ direction.
sourcepub fn yaw(&mut self, delta: impl Into<Rad<f32>>)
pub fn yaw(&mut self, delta: impl Into<Rad<f32>>)
Rotates the camera by the angle delta around the ‘up’ direction.
sourcepub fn roll(&mut self, delta: impl Into<Rad<f32>>)
pub fn roll(&mut self, delta: impl Into<Rad<f32>>)
Rotates the camera by the angle delta around the ‘view’ direction.
sourcepub fn rotate_around(&mut self, point: &Vector3<f32>, x: f32, y: f32)
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.
sourcepub fn rotate_around_with_fixed_up(&mut self, point: &Vector3<f32>, x: f32, y: f32)
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.