diff --git a/crates/bevy_render/src/camera/camera.rs b/crates/bevy_render/src/camera/camera.rs index 8d0d370b4f853b..8033501189336a 100644 --- a/crates/bevy_render/src/camera/camera.rs +++ b/crates/bevy_render/src/camera/camera.rs @@ -238,14 +238,14 @@ impl Camera { let projection_matrix = self .computed .projection_matrix - .ok_or(BadProjectionMatrixError::ProjectionMatrixUndefinedError)?; + .ok_or(BadProjectionMatrixError::ProjectionMatrixUndefined)?; match projection_matrix.is_finite() { - false => Err(BadProjectionMatrixError::BadProjectionMatrixValuesError( + false => Err(BadProjectionMatrixError::BadProjectionMatrixValues( projection_matrix, )), true => { if projection_matrix == Mat4::ZERO { - Err(BadProjectionMatrixError::BadProjectionMatrixValuesError( + Err(BadProjectionMatrixError::BadProjectionMatrixValues( projection_matrix, )) } else { @@ -280,13 +280,13 @@ impl Camera { ) -> Result { let target_size = self .logical_viewport_size() - .map_err(WorldToViewportError::LogicalViewportSizeError)?; + .map_err(WorldToViewportError::LogicalViewportSize)?; let ndc_space_coords = self .world_to_ndc(camera_transform, world_position) - .map_err(WorldToViewportError::WorldToNdcError)?; + .map_err(WorldToViewportError::WorldToNdc)?; // NDC z-values outside of 0 < z < 1 are outside the (implicit) camera frustum and are thus not in viewport-space if ndc_space_coords.z < 0.0 || ndc_space_coords.z > 1.0 { - return Err(WorldToViewportError::NdcCoordsOutsideFrustumError( + return Err(WorldToViewportError::NdcCoordsOutsideFrustum( ndc_space_coords, )); } @@ -315,16 +315,16 @@ impl Camera { ) -> Result { let target_size = self .logical_viewport_size() - .map_err(ViewportToWorldError::LogicalViewportSizeError)?; + .map_err(ViewportToWorldError::LogicalViewportSize)?; // Flip the Y co-ordinate origin from the top to the bottom. viewport_position.y = target_size.y - viewport_position.y; let ndc = viewport_position * 2. / target_size - Vec2::ONE; let camera_transform_matrix = Self::finite_camera_transform_matrix(camera_transform) - .map_err(ViewportToWorldError::CameraTransformNotFiniteError)?; + .map_err(ViewportToWorldError::CameraTransformNotFinite)?; let projection_matrix = self .checked_projection_matrix() - .map_err(ViewportToWorldError::ProjectionMatrixNotFiniteError)?; + .map_err(ViewportToWorldError::ProjectionMatrixNotFinite)?; let ndc_to_world = camera_transform_matrix * projection_matrix.inverse(); let world_near_plane = ndc_to_world.project_point3(ndc.extend(1.)); @@ -332,13 +332,13 @@ impl Camera { let world_far_plane = ndc_to_world.project_point3(ndc.extend(f32::EPSILON)); if !world_near_plane.is_finite() { - return Err(ViewportToWorldError::WorldNearPlaneNotFiniteError( + return Err(ViewportToWorldError::WorldNearPlaneNotFinite( world_near_plane, )); } if world_far_plane.is_nan() { - return Err(ViewportToWorldError::WorldFarPlaneNanError(world_far_plane)); + return Err(ViewportToWorldError::WorldFarPlaneNan(world_far_plane)); } Ok(Ray { @@ -362,14 +362,14 @@ impl Camera { ) -> Result { let target_size = self .logical_viewport_size() - .map_err(ViewportToWorld2DError::LogicalViewportSizeError)?; + .map_err(ViewportToWorld2DError::LogicalViewportSize)?; // Flip the Y co-ordinate origin from the top to the bottom. viewport_position.y = target_size.y - viewport_position.y; let ndc = viewport_position * 2. / target_size - Vec2::ONE; let world_near_plane = self .ndc_to_world(camera_transform, ndc.extend(1.)) - .map_err(ViewportToWorld2DError::NdcToWorldError)?; + .map_err(ViewportToWorld2DError::NdcToWorld)?; Ok(world_near_plane.truncate()) } @@ -388,20 +388,18 @@ impl Camera { world_position: Vec3, ) -> Result { let camera_transform_matrix = Self::finite_camera_transform_matrix(camera_transform) - .map_err(WorldToNdcError::CameraTransformNotFiniteError)?; + .map_err(WorldToNdcError::CameraTransformNotFinite)?; let projection_matrix = self .checked_projection_matrix() - .map_err(WorldToNdcError::ProjectionMatrixNotFiniteError)?; + .map_err(WorldToNdcError::ProjectionMatrixNotFinite)?; // Build a transformation matrix to convert from world space to NDC using camera data let world_to_ndc: Mat4 = projection_matrix * camera_transform_matrix.inverse(); let ndc_space_coords: Vec3 = world_to_ndc.project_point3(world_position); if !ndc_space_coords.is_finite() { - return Err(WorldToNdcError::NdcSpaceCoordsNotFiniteError( - ndc_space_coords, - )); + return Err(WorldToNdcError::NdcSpaceCoordsNotFinite(ndc_space_coords)); } Ok(ndc_space_coords) @@ -422,18 +420,18 @@ impl Camera { ndc: Vec3, ) -> Result { let camera_transform_matrix = Self::finite_camera_transform_matrix(camera_transform) - .map_err(NdcToWorldError::CameraTransformNotFiniteError)?; + .map_err(NdcToWorldError::CameraTransformNotFinite)?; let projection_matrix = self .checked_projection_matrix() - .map_err(NdcToWorldError::ProjectionMatrixNotFiniteError)?; + .map_err(NdcToWorldError::ProjectionMatrixNotFinite)?; // Build a transformation matrix to convert from NDC to world space using camera data let ndc_to_world = camera_transform_matrix * projection_matrix.inverse(); let world_space_coords = ndc_to_world.project_point3(ndc); if !world_space_coords.is_finite() { - return Err(NdcToWorldError::WorldSpaceCoordsNotFiniteError( + return Err(NdcToWorldError::WorldSpaceCoordsNotFinite( world_space_coords, )); } @@ -444,16 +442,16 @@ impl Camera { #[derive(Debug)] pub enum NdcToWorldError { - WorldSpaceCoordsNotFiniteError(Vec3), - CameraTransformNotFiniteError(CameraTransformNotFiniteError), - ProjectionMatrixNotFiniteError(BadProjectionMatrixError), + WorldSpaceCoordsNotFinite(Vec3), + CameraTransformNotFinite(CameraTransformNotFiniteError), + ProjectionMatrixNotFinite(BadProjectionMatrixError), } #[derive(Debug)] pub enum WorldToNdcError { - NdcSpaceCoordsNotFiniteError(Vec3), - CameraTransformNotFiniteError(CameraTransformNotFiniteError), - ProjectionMatrixNotFiniteError(BadProjectionMatrixError), + NdcSpaceCoordsNotFinite(Vec3), + CameraTransformNotFinite(CameraTransformNotFiniteError), + ProjectionMatrixNotFinite(BadProjectionMatrixError), } #[derive(Debug)] @@ -464,30 +462,30 @@ pub struct LogicalViewportSizeError { #[derive(Debug)] pub enum ViewportToWorldError { - LogicalViewportSizeError(LogicalViewportSizeError), - CameraTransformNotFiniteError(CameraTransformNotFiniteError), - ProjectionMatrixNotFiniteError(BadProjectionMatrixError), - WorldNearPlaneNotFiniteError(Vec3), - WorldFarPlaneNanError(Vec3), + LogicalViewportSize(LogicalViewportSizeError), + CameraTransformNotFinite(CameraTransformNotFiniteError), + ProjectionMatrixNotFinite(BadProjectionMatrixError), + WorldNearPlaneNotFinite(Vec3), + WorldFarPlaneNan(Vec3), } #[derive(Debug)] pub enum ViewportToWorld2DError { - NdcToWorldError(NdcToWorldError), - LogicalViewportSizeError(LogicalViewportSizeError), + NdcToWorld(NdcToWorldError), + LogicalViewportSize(LogicalViewportSizeError), } #[derive(Debug)] pub enum WorldToViewportError { - WorldToNdcError(WorldToNdcError), - LogicalViewportSizeError(LogicalViewportSizeError), - NdcCoordsOutsideFrustumError(Vec3), + WorldToNdc(WorldToNdcError), + LogicalViewportSize(LogicalViewportSizeError), + NdcCoordsOutsideFrustum(Vec3), } #[derive(Debug)] pub enum BadProjectionMatrixError { - BadProjectionMatrixValuesError(Mat4), - ProjectionMatrixUndefinedError, + BadProjectionMatrixValues(Mat4), + ProjectionMatrixUndefined, } #[derive(Debug)]