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
impl Camera
sourcepub fn new_orthographic(
viewport: Viewport,
position: Vec3,
target: Vec3,
up: Vec3,
height: f32,
z_near: f32,
z_far: f32
) -> Self
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.
sourcepub 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
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.
sourcepub fn new_2d(viewport: Viewport) -> Self
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.
sourcepub fn disable_tone_and_color_mapping(&mut self)
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.
sourcepub fn set_default_tone_and_color_mapping(&mut self)
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>§
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: impl Into<PixelPoint>) -> Vector3<f32>
pub fn position_at_pixel(&self, pixel: impl Into<PixelPoint>) -> Vector3<f32>
Returns the 3D position at the given pixel coordinate.
sourcepub fn position_at_uv_coordinates(
&self,
coords: impl Into<UvCoordinate>
) -> Vector3<f32>
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.
sourcepub fn view_direction_at_pixel(
&self,
pixel: impl Into<PixelPoint>
) -> Vector3<f32>
pub fn view_direction_at_pixel( &self, pixel: impl Into<PixelPoint> ) -> Vector3<f32>
Returns the 3D view direction at the given pixel coordinate.
sourcepub fn view_direction_at_uv_coordinates(
&self,
coords: impl Into<UvCoordinate>
) -> Vector3<f32>
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.
sourcepub fn uv_coordinates_at_pixel(
&self,
pixel: impl Into<PixelPoint>
) -> UvCoordinate
pub fn uv_coordinates_at_pixel( &self, pixel: impl Into<PixelPoint> ) -> UvCoordinate
Returns the uv coordinate for the given pixel coordinate.
sourcepub fn uv_coordinates_at_position(&self, position: Vector3<f32>) -> UvCoordinate
pub fn uv_coordinates_at_position(&self, position: Vector3<f32>) -> UvCoordinate
Returns the uv coordinate for the given world position.
sourcepub fn pixel_at_uv_coordinates(
&self,
coords: impl Into<UvCoordinate>
) -> PixelPoint
pub fn pixel_at_uv_coordinates( &self, coords: impl Into<UvCoordinate> ) -> PixelPoint
Returns the pixel coordinate for the given uv coordinate.
sourcepub fn pixel_at_position(&self, position: Vector3<f32>) -> PixelPoint
pub fn pixel_at_position(&self, position: Vector3<f32>) -> PixelPoint
Returns the pixel coordinate for the given world position.
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.