Skip to content

Commit eb1ca60

Browse files
committed
added additional error code
1 parent b528e41 commit eb1ca60

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

include/omath/projection/camera.hpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,12 +294,21 @@ namespace omath::projection
294294
* mat_column_from_vector<float, Mat4X4Type::get_store_ordering()>(world_position);
295295

296296
const auto& w = projected.at(3, 0);
297-
if (w <= std::numeric_limits<float>::epsilon())
298-
return std::unexpected(Error::WORLD_POSITION_IS_OUT_OF_SCREEN_BOUNDS);
297+
constexpr auto eps = std::numeric_limits<float>::epsilon();
298+
if (w <= eps)
299+
return std::unexpected(Error::PERSPECTIVE_DIVIDER_LESS_EQ_ZERO);
299300

300301
projected /= w;
301302

302-
if (clipping == ViewPortClipping::AUTO && is_ndc_out_of_bounds(projected))
303+
// ReSharper disable once CppTooWideScope
304+
const auto clipped_automatically = clipping == ViewPortClipping::AUTO && is_ndc_out_of_bounds(projected);
305+
if (clipped_automatically)
306+
return std::unexpected(Error::WORLD_POSITION_IS_OUT_OF_SCREEN_BOUNDS);
307+
308+
// ReSharper disable once CppTooWideScope
309+
const auto clipped_manually = clipping == ViewPortClipping::MANUAL && (projected.at(2, 0) < 0.0f - eps
310+
|| projected.at(2, 0) > 1.0f + eps);
311+
if (clipped_manually)
303312
return std::unexpected(Error::WORLD_POSITION_IS_OUT_OF_SCREEN_BOUNDS);
304313

305314
return Vector3<float>{projected.at(0, 0), projected.at(1, 0), projected.at(2, 0)};

include/omath/projection/error_codes.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ namespace omath::projection
1111
{
1212
WORLD_POSITION_IS_OUT_OF_SCREEN_BOUNDS,
1313
INV_VIEW_PROJ_MAT_DET_EQ_ZERO,
14+
PERSPECTIVE_DIVIDER_LESS_EQ_ZERO,
1415
};
1516
}

0 commit comments

Comments
 (0)