Skip to content

Commit 3dd792c

Browse files
authored
Merge pull request #110 from orange-cpp/feature/bug_fix
fixed bug due to on screen ndc check
2 parents acf36c3 + 584969d commit 3dd792c

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

include/omath/projection/camera.hpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,16 @@ namespace omath::projection
242242
template<class Type>
243243
[[nodiscard]] constexpr static bool is_ndc_out_of_bounds(const Type& ndc) noexcept
244244
{
245-
return std::ranges::any_of(ndc.raw_array(), [](const auto& val) { return val < -1 || val > 1; });
245+
const auto& raw_array = ndc.raw_array();
246+
247+
if (raw_array[2] < 0.f)
248+
return true;
249+
250+
for (std::size_t i = 0; i < 2; i++)
251+
if (raw_array[i] < -1.f || raw_array[i] > 1.f)
252+
return true;
253+
254+
return false;
246255
}
247256

248257
// NDC REPRESENTATION:

source/engines/unreal_engine/formulas.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,6 @@ namespace omath::unreal_engine
3737
Mat4X4 calc_perspective_projection_matrix(const float field_of_view, const float aspect_ratio, const float near,
3838
const float far) noexcept
3939
{
40-
const float fov_half_tan = std::tan(angles::degrees_to_radians(field_of_view) / 2.f);
41-
42-
return {
43-
{1.f / (aspect_ratio * fov_half_tan), 0, 0, 0},
44-
{0, 1.f / (fov_half_tan), 0, 0},
45-
{0, 0, (far + near) / (far - near), -(2.f * far * near) / (far - near)},
46-
{0, 0, -1.f, 0},
47-
};
40+
return mat_perspective_left_handed(field_of_view, aspect_ratio, near, far);
4841
}
4942
} // namespace omath::unreal_engine

0 commit comments

Comments
 (0)