mirror of
https://github.com/orange-cpp/omath.git
synced 2026-04-19 03:43:27 +00:00
updated z range
This commit is contained in:
@@ -36,13 +36,21 @@ namespace omath::source_engine
|
||||
}
|
||||
|
||||
Mat4X4 calc_perspective_projection_matrix(const float field_of_view, const float aspect_ratio, const float near,
|
||||
const float far) noexcept
|
||||
const float far, const NDCDepthRange ndc_depth_range) noexcept
|
||||
{
|
||||
// NOTE: Need magic number to fix fov calculation, since source inherit Quake proj matrix calculation
|
||||
constexpr auto k_multiply_factor = 0.75f;
|
||||
|
||||
const float fov_half_tan = std::tan(angles::degrees_to_radians(field_of_view) / 2.f) * k_multiply_factor;
|
||||
|
||||
if (ndc_depth_range == NDCDepthRange::ZERO_TO_ONE)
|
||||
return {
|
||||
{1.f / (aspect_ratio * fov_half_tan), 0, 0, 0},
|
||||
{0, 1.f / (fov_half_tan), 0, 0},
|
||||
{0, 0, far / (far - near), -(near * far) / (far - near)},
|
||||
{0, 0, 1, 0},
|
||||
};
|
||||
|
||||
return {
|
||||
{1.f / (aspect_ratio * fov_half_tan), 0, 0, 0},
|
||||
{0, 1.f / (fov_half_tan), 0, 0},
|
||||
|
||||
@@ -20,8 +20,9 @@ namespace omath::source_engine
|
||||
}
|
||||
Mat4X4 CameraTrait::calc_projection_matrix(const projection::FieldOfView& fov,
|
||||
const projection::ViewPort& view_port, const float near,
|
||||
const float far) noexcept
|
||||
const float far, 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, far,
|
||||
ndc_depth_range);
|
||||
}
|
||||
} // namespace omath::source_engine
|
||||
Reference in New Issue
Block a user