Skip to content

Commit 3dc5cdd

Browse files
committed
try fix mingw32
1 parent aabec57 commit 3dc5cdd

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

include/omath/projection/camera.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,29 @@ namespace omath::projection
263263
const Vector3<float> world_pos{inverted_projection.at(0, 0), inverted_projection.at(1, 0),
264264
inverted_projection.at(2, 0)};
265265

266+
// Validate that the computed world position is reasonable
266267
constexpr float max_reasonable_component = 1e6f;
267268
if (!std::isfinite(world_pos.x) || !std::isfinite(world_pos.y) || !std::isfinite(world_pos.z) ||
268269
std::abs(world_pos.x) > max_reasonable_component || std::abs(world_pos.y) > max_reasonable_component ||
269270
std::abs(world_pos.z) > max_reasonable_component)
270271
return std::unexpected(Error::WORLD_POSITION_IS_OUT_OF_SCREEN_BOUNDS);
271272

273+
const auto verify_ndc = world_to_view_port(world_pos);
274+
if (verify_ndc.has_value())
275+
{
276+
constexpr float ndc_tolerance = 0.01f;
277+
const auto& verify = verify_ndc.value();
278+
if (std::abs(verify.x - ndc.x) > ndc_tolerance || std::abs(verify.y - ndc.y) > ndc_tolerance ||
279+
std::abs(verify.z - ndc.z) > ndc_tolerance)
280+
{
281+
return std::unexpected(Error::WORLD_POSITION_IS_OUT_OF_SCREEN_BOUNDS);
282+
}
283+
}
284+
else
285+
{
286+
return std::unexpected(Error::WORLD_POSITION_IS_OUT_OF_SCREEN_BOUNDS);
287+
}
288+
272289
return world_pos;
273290
}
274291

0 commit comments

Comments
 (0)