Skip to content

Commit 46a27d8

Browse files
authored
Fix world_to_viewport return error codes (#20662)
# Objective - We use infinite reverse Z. The far plane is 0.0, the near plane is 1.0. The errors are wrong. ## Solution - make them right ## Testing
1 parent 8b4d090 commit 46a27d8

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

crates/bevy_camera/src/camera.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -509,10 +509,10 @@ impl Camera {
509509
.ok_or(ViewportConversionError::InvalidData)?;
510510
// NDC z-values outside of 0 < z < 1 are outside the (implicit) camera frustum and are thus not in viewport-space
511511
if ndc_space_coords.z < 0.0 {
512-
return Err(ViewportConversionError::PastNearPlane);
512+
return Err(ViewportConversionError::PastFarPlane);
513513
}
514514
if ndc_space_coords.z > 1.0 {
515-
return Err(ViewportConversionError::PastFarPlane);
515+
return Err(ViewportConversionError::PastNearPlane);
516516
}
517517

518518
// Flip the Y co-ordinate origin from the bottom to the top.
@@ -547,10 +547,10 @@ impl Camera {
547547
.ok_or(ViewportConversionError::InvalidData)?;
548548
// NDC z-values outside of 0 < z < 1 are outside the (implicit) camera frustum and are thus not in viewport-space
549549
if ndc_space_coords.z < 0.0 {
550-
return Err(ViewportConversionError::PastNearPlane);
550+
return Err(ViewportConversionError::PastFarPlane);
551551
}
552552
if ndc_space_coords.z > 1.0 {
553-
return Err(ViewportConversionError::PastFarPlane);
553+
return Err(ViewportConversionError::PastNearPlane);
554554
}
555555

556556
// Stretching ndc depth to value via near plane and negating result to be in positive room again.

0 commit comments

Comments
 (0)