This commit is contained in:
2026-06-14 23:17:48 +03:00
parent 91d9335f83
commit 098be538f7
17 changed files with 54 additions and 46 deletions
@@ -70,17 +70,17 @@ namespace omath::cry_engine
}
[[nodiscard]]
inline OMATH_CONSTEXPR Mat4X4 calc_perspective_projection_matrix(
const float field_of_view, const float aspect_ratio, const float near, const float far,
const float field_of_view, const float aspect_ratio, const float near_plane, const float far_plane,
const NDCDepthRange ndc_depth_range = NDCDepthRange::ZERO_TO_ONE) noexcept
{
if (ndc_depth_range == NDCDepthRange::ZERO_TO_ONE)
return mat_perspective_left_handed_vertical_fov<float, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
field_of_view, aspect_ratio, near, far);
field_of_view, aspect_ratio, near_plane, far_plane);
if (ndc_depth_range == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
return mat_perspective_left_handed_vertical_fov<float, MatStoreType::ROW_MAJOR,
NDCDepthRange::NEGATIVE_ONE_TO_ONE>(
field_of_view, aspect_ratio, near, far);
field_of_view, aspect_ratio, near_plane, far_plane);
std::unreachable();
}
@@ -29,9 +29,10 @@ namespace omath::cry_engine
[[nodiscard]]
OMATH_CONSTEXPR static Mat4X4
calc_projection_matrix(const projection::FieldOfView& fov, const projection::ViewPort& view_port,
const float near, const float far, const NDCDepthRange ndc_depth_range) noexcept
const float near_plane, const float far_plane,
const NDCDepthRange ndc_depth_range) noexcept
{
return calc_perspective_projection_matrix(fov.as_degrees(), view_port.aspect_ratio(), near, far,
return calc_perspective_projection_matrix(fov.as_degrees(), view_port.aspect_ratio(), near_plane, far_plane,
ndc_depth_range);
}
};
@@ -75,17 +75,17 @@ namespace omath::frostbite_engine
[[nodiscard]]
inline OMATH_CONSTEXPR Mat4X4 calc_perspective_projection_matrix(
const float field_of_view, const float aspect_ratio, const float near, const float far,
const float field_of_view, const float aspect_ratio, const float near_plane, const float far_plane,
const NDCDepthRange ndc_depth_range = NDCDepthRange::NEGATIVE_ONE_TO_ONE) noexcept
{
if (ndc_depth_range == NDCDepthRange::ZERO_TO_ONE)
return mat_perspective_left_handed_vertical_fov<float, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
field_of_view, aspect_ratio, near, far);
field_of_view, aspect_ratio, near_plane, far_plane);
if (ndc_depth_range == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
return mat_perspective_left_handed_vertical_fov<float, MatStoreType::ROW_MAJOR,
NDCDepthRange::NEGATIVE_ONE_TO_ONE>(
field_of_view, aspect_ratio, near, far);
field_of_view, aspect_ratio, near_plane, far_plane);
std::unreachable();
}
@@ -31,9 +31,10 @@ namespace omath::frostbite_engine
[[nodiscard]]
OMATH_CONSTEXPR static Mat4X4
calc_projection_matrix(const projection::FieldOfView& fov, const projection::ViewPort& view_port,
const float near, const float far, const NDCDepthRange ndc_depth_range) noexcept
const float near_plane, const float far_plane,
const NDCDepthRange ndc_depth_range) noexcept
{
return calc_perspective_projection_matrix(fov.as_degrees(), view_port.aspect_ratio(), near, far,
return calc_perspective_projection_matrix(fov.as_degrees(), view_port.aspect_ratio(), near_plane, far_plane,
ndc_depth_range);
}
};
+3 -3
View File
@@ -72,7 +72,7 @@ namespace omath::iw_engine
[[nodiscard]]
inline OMATH_CONSTEXPR Mat4X4 calc_perspective_projection_matrix(
const float field_of_view, const float aspect_ratio, const float near, const float far,
const float field_of_view, const float aspect_ratio, const float near_plane, const float far_plane,
const NDCDepthRange ndc_depth_range = NDCDepthRange::NEGATIVE_ONE_TO_ONE) noexcept
{
constexpr float k_source_reference_aspect = 4.f / 3.f;
@@ -80,11 +80,11 @@ namespace omath::iw_engine
if (ndc_depth_range == NDCDepthRange::ZERO_TO_ONE)
return mat_perspective_left_handed_vertical_fov<float, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
vertical_fov, aspect_ratio, near, far);
vertical_fov, aspect_ratio, near_plane, far_plane);
if (ndc_depth_range == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
return mat_perspective_left_handed_vertical_fov<float, MatStoreType::ROW_MAJOR,
NDCDepthRange::NEGATIVE_ONE_TO_ONE>(
vertical_fov, aspect_ratio, near, far);
vertical_fov, aspect_ratio, near_plane, far_plane);
std::unreachable();
}
@@ -31,9 +31,10 @@ namespace omath::iw_engine
[[nodiscard]]
OMATH_CONSTEXPR static Mat4X4
calc_projection_matrix(const projection::FieldOfView& fov, const projection::ViewPort& view_port,
const float near, const float far, const NDCDepthRange ndc_depth_range) noexcept
const float near_plane, const float far_plane,
const NDCDepthRange ndc_depth_range) noexcept
{
return calc_perspective_projection_matrix(fov.as_degrees(), view_port.aspect_ratio(), near, far,
return calc_perspective_projection_matrix(fov.as_degrees(), view_port.aspect_ratio(), near_plane, far_plane,
ndc_depth_range);
}
};
@@ -75,18 +75,18 @@ namespace omath::opengl_engine
[[nodiscard]]
inline OMATH_CONSTEXPR Mat4X4 calc_perspective_projection_matrix(
const float field_of_view, const float aspect_ratio, const float near, const float far,
const float field_of_view, const float aspect_ratio, const float near_plane, const float far_plane,
const NDCDepthRange ndc_depth_range = NDCDepthRange::NEGATIVE_ONE_TO_ONE) noexcept
{
if (ndc_depth_range == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
return mat_perspective_right_handed_vertical_fov<
float, MatStoreType::COLUMN_MAJOR, NDCDepthRange::NEGATIVE_ONE_TO_ONE>(
field_of_view, aspect_ratio, near, far);
field_of_view, aspect_ratio, near_plane, far_plane);
if (ndc_depth_range == NDCDepthRange::ZERO_TO_ONE)
return mat_perspective_right_handed_vertical_fov<
float, MatStoreType::COLUMN_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
field_of_view, aspect_ratio, near, far);
field_of_view, aspect_ratio, near_plane, far_plane);
std::unreachable();
}
@@ -32,9 +32,10 @@ namespace omath::opengl_engine
[[nodiscard]]
OMATH_CONSTEXPR static Mat4X4
calc_projection_matrix(const projection::FieldOfView& fov, const projection::ViewPort& view_port,
const float near, const float far, const NDCDepthRange ndc_depth_range) noexcept
const float near_plane, const float far_plane,
const NDCDepthRange ndc_depth_range) noexcept
{
return calc_perspective_projection_matrix(fov.as_degrees(), view_port.aspect_ratio(), near, far,
return calc_perspective_projection_matrix(fov.as_degrees(), view_port.aspect_ratio(), near_plane, far_plane,
ndc_depth_range);
}
};
@@ -76,17 +76,17 @@ namespace omath::rage_engine
[[nodiscard]]
inline OMATH_CONSTEXPR Mat4X4 calc_perspective_projection_matrix(
const float field_of_view, const float aspect_ratio, const float near, const float far,
const float field_of_view, const float aspect_ratio, const float near_plane, const float far_plane,
const NDCDepthRange ndc_depth_range = NDCDepthRange::ZERO_TO_ONE) noexcept
{
if (ndc_depth_range == NDCDepthRange::ZERO_TO_ONE)
return mat_perspective_left_handed_vertical_fov<float, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
field_of_view, aspect_ratio, near, far);
field_of_view, aspect_ratio, near_plane, far_plane);
if (ndc_depth_range == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
return mat_perspective_left_handed_vertical_fov<float, MatStoreType::ROW_MAJOR,
NDCDepthRange::NEGATIVE_ONE_TO_ONE>(
field_of_view, aspect_ratio, near, far);
field_of_view, aspect_ratio, near_plane, far_plane);
std::unreachable();
}
@@ -31,9 +31,10 @@ namespace omath::rage_engine
[[nodiscard]]
OMATH_CONSTEXPR static Mat4X4
calc_projection_matrix(const projection::FieldOfView& fov, const projection::ViewPort& view_port,
const float near, const float far, const NDCDepthRange ndc_depth_range) noexcept
const float near_plane, const float far_plane,
const NDCDepthRange ndc_depth_range) noexcept
{
return calc_perspective_projection_matrix(fov.as_degrees(), view_port.aspect_ratio(), near, far,
return calc_perspective_projection_matrix(fov.as_degrees(), view_port.aspect_ratio(), near_plane, far_plane,
ndc_depth_range);
}
};
@@ -71,7 +71,7 @@ namespace omath::source_engine
[[nodiscard]]
inline OMATH_CONSTEXPR Mat4X4 calc_perspective_projection_matrix(
const float field_of_view, const float aspect_ratio, const float near, const float far,
const float field_of_view, const float aspect_ratio, const float near_plane, const float far_plane,
const NDCDepthRange ndc_depth_range = NDCDepthRange::NEGATIVE_ONE_TO_ONE) noexcept
{
constexpr float k_source_reference_aspect = 4.f / 3.f;
@@ -79,11 +79,11 @@ namespace omath::source_engine
if (ndc_depth_range == NDCDepthRange::ZERO_TO_ONE)
return mat_perspective_left_handed_vertical_fov<float, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
vertical_fov, aspect_ratio, near, far);
vertical_fov, aspect_ratio, near_plane, far_plane);
if (ndc_depth_range == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
return mat_perspective_left_handed_vertical_fov<float, MatStoreType::ROW_MAJOR,
NDCDepthRange::NEGATIVE_ONE_TO_ONE>(
vertical_fov, aspect_ratio, near, far);
vertical_fov, aspect_ratio, near_plane, far_plane);
std::unreachable();
}
@@ -31,9 +31,10 @@ namespace omath::source_engine
[[nodiscard]]
OMATH_CONSTEXPR static Mat4X4
calc_projection_matrix(const projection::FieldOfView& fov, const projection::ViewPort& view_port,
const float near, const float far, const NDCDepthRange ndc_depth_range) noexcept
const float near_plane, const float far_plane,
const NDCDepthRange ndc_depth_range) noexcept
{
return calc_perspective_projection_matrix(fov.as_degrees(), view_port.aspect_ratio(), near, far,
return calc_perspective_projection_matrix(fov.as_degrees(), view_port.aspect_ratio(), near_plane, far_plane,
ndc_depth_range);
}
};
@@ -75,17 +75,17 @@ namespace omath::unity_engine
[[nodiscard]]
inline OMATH_CONSTEXPR Mat4X4 calc_perspective_projection_matrix(
const float field_of_view, const float aspect_ratio, const float near, const float far,
const float field_of_view, const float aspect_ratio, const float near_plane, const float far_plane,
const NDCDepthRange ndc_depth_range = NDCDepthRange::NEGATIVE_ONE_TO_ONE) noexcept
{
if (ndc_depth_range == NDCDepthRange::ZERO_TO_ONE)
return omath::mat_perspective_right_handed_vertical_fov<
float, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
field_of_view, aspect_ratio, near, far);
field_of_view, aspect_ratio, near_plane, far_plane);
if (ndc_depth_range == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
return omath::mat_perspective_right_handed_vertical_fov<
float, MatStoreType::ROW_MAJOR, NDCDepthRange::NEGATIVE_ONE_TO_ONE>(
field_of_view, aspect_ratio, near, far);
field_of_view, aspect_ratio, near_plane, far_plane);
std::unreachable();
}
@@ -31,9 +31,10 @@ namespace omath::unity_engine
[[nodiscard]]
OMATH_CONSTEXPR static Mat4X4
calc_projection_matrix(const projection::FieldOfView& fov, const projection::ViewPort& view_port,
const float near, const float far, const NDCDepthRange ndc_depth_range) noexcept
const float near_plane, const float far_plane,
const NDCDepthRange ndc_depth_range) noexcept
{
return calc_perspective_projection_matrix(fov.as_degrees(), view_port.aspect_ratio(), near, far,
return calc_perspective_projection_matrix(fov.as_degrees(), view_port.aspect_ratio(), near_plane, far_plane,
ndc_depth_range);
}
};
@@ -75,17 +75,17 @@ namespace omath::unreal_engine
[[nodiscard]]
inline OMATH_CONSTEXPR Mat4X4 calc_perspective_projection_matrix(
const double field_of_view, const double aspect_ratio, const double near, const double far,
const double field_of_view, const double aspect_ratio, const double near_plane, const double far_plane,
const NDCDepthRange ndc_depth_range = NDCDepthRange::NEGATIVE_ONE_TO_ONE) noexcept
{
if (ndc_depth_range == NDCDepthRange::ZERO_TO_ONE)
return mat_perspective_left_handed_horizontal_fov<
double, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
field_of_view, aspect_ratio, near, far);
field_of_view, aspect_ratio, near_plane, far_plane);
if (ndc_depth_range == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
return mat_perspective_left_handed_horizontal_fov<
double, MatStoreType::ROW_MAJOR, NDCDepthRange::NEGATIVE_ONE_TO_ONE>(
field_of_view, aspect_ratio, near, far);
field_of_view, aspect_ratio, near_plane, far_plane);
std::unreachable();
}
@@ -31,9 +31,10 @@ namespace omath::unreal_engine
[[nodiscard]]
OMATH_CONSTEXPR static Mat4X4
calc_projection_matrix(const projection::FieldOfView& fov, const projection::ViewPort& view_port,
const double near, const double far, const NDCDepthRange ndc_depth_range) noexcept
const double near_plane, const double far_plane,
const NDCDepthRange ndc_depth_range) noexcept
{
return calc_perspective_projection_matrix(fov.as_degrees(), view_port.aspect_ratio(), near, far,
return calc_perspective_projection_matrix(fov.as_degrees(), view_port.aspect_ratio(), near_plane, far_plane,
ndc_depth_range);
}
};
+6 -6
View File
@@ -84,13 +84,13 @@ static_assert(source_camera_constexpr_projection_round_trip());
TEST(UnitTestProjection, Projection)
{
constexpr auto fov = omath::Angle<float, 0.f, 180.f, omath::AngleFlags::Clamped>::from_degrees(90.f);
constexpr auto cam = omath::source_engine::Camera({0, 0, 0}, omath::source_engine::ViewAngles{}, {1920.f, 1080.f}, fov,
0.01f, 1000.f);
OMATH_CONSTEXPR auto fov = omath::Angle<float, 0.f, 180.f, omath::AngleFlags::Clamped>::from_degrees(90.f);
OMATH_CONSTEXPR auto cam = omath::source_engine::Camera(
{0, 0, 0}, omath::source_engine::ViewAngles{}, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
constexpr auto projected = cam.world_to_screen({1000.f, 0, 50.f});
constexpr auto result = cam.screen_to_world(projected.value());
constexpr auto result2 = cam.world_to_screen(result.value());
OMATH_CONSTEXPR auto projected = cam.world_to_screen({1000.f, 0, 50.f});
OMATH_CONSTEXPR auto result = cam.screen_to_world(projected.value());
OMATH_CONSTEXPR auto result2 = cam.world_to_screen(result.value());
EXPECT_EQ(static_cast<omath::Vector2<float>>(projected.value()),
static_cast<omath::Vector2<float>>(result2.value()));