mirror of
https://github.com/orange-cpp/omath.git
synced 2026-04-26 01:23:27 +00:00
update
This commit is contained in:
@@ -670,18 +670,18 @@ namespace omath
|
|||||||
Mat<4, 4, Type, St> mat_perspective_left_handed(const float field_of_view, const float aspect_ratio,
|
Mat<4, 4, Type, St> mat_perspective_left_handed(const float field_of_view, const float aspect_ratio,
|
||||||
const float near, const float far) noexcept
|
const float near, const float far) noexcept
|
||||||
{
|
{
|
||||||
const float fov_half_tan = std::tan(angles::degrees_to_radians(field_of_view) / 2.f);
|
const auto fov_half_tan = std::tan(angles::degrees_to_radians(field_of_view) / Type{2});
|
||||||
|
|
||||||
if constexpr (DepthRange == NDCDepthRange::ZERO_TO_ONE)
|
if constexpr (DepthRange == NDCDepthRange::ZERO_TO_ONE)
|
||||||
return {{1.f / (aspect_ratio * fov_half_tan), 0.f, 0.f, 0.f},
|
return {{Type{1} / (aspect_ratio * fov_half_tan), Type{0}, Type{0}, Type{0}},
|
||||||
{0.f, 1.f / fov_half_tan, 0.f, 0.f},
|
{Type{0}, Type{1} / fov_half_tan, Type{0}, Type{0}},
|
||||||
{0.f, 0.f, far / (far - near), -(near * far) / (far - near)},
|
{Type{0}, Type{0}, far / (far - near), -(near * far) / (far - near)},
|
||||||
{0.f, 0.f, 1.f, 0.f}};
|
{Type{0}, Type{0}, Type{1}, Type{0}}};
|
||||||
else if constexpr (DepthRange == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
|
else if constexpr (DepthRange == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
|
||||||
return {{1.f / (aspect_ratio * fov_half_tan), 0.f, 0.f, 0.f},
|
return {{Type{1} / (aspect_ratio * fov_half_tan), Type{0}, Type{0}, Type{0}},
|
||||||
{0.f, 1.f / fov_half_tan, 0.f, 0.f},
|
{Type{0}, Type{1} / fov_half_tan, Type{0}, Type{0}},
|
||||||
{0.f, 0.f, (far + near) / (far - near), -(2.f * near * far) / (far - near)},
|
{Type{0}, Type{0}, (far + near) / (far - near), -(Type{2} * near * far) / (far - near)},
|
||||||
{0.f, 0.f, 1.f, 0.f}};
|
{Type{0}, Type{0}, Type{1}, Type{0}}};
|
||||||
else
|
else
|
||||||
std::unreachable();
|
std::unreachable();
|
||||||
}
|
}
|
||||||
@@ -692,18 +692,18 @@ namespace omath
|
|||||||
Mat<4, 4, Type, St> mat_perspective_right_handed(const float field_of_view, const float aspect_ratio,
|
Mat<4, 4, Type, St> mat_perspective_right_handed(const float field_of_view, const float aspect_ratio,
|
||||||
const float near, const float far) noexcept
|
const float near, const float far) noexcept
|
||||||
{
|
{
|
||||||
const float fov_half_tan = std::tan(angles::degrees_to_radians(field_of_view) / 2.f);
|
const auto fov_half_tan = std::tan(angles::degrees_to_radians(field_of_view) / Type{2});
|
||||||
|
|
||||||
if constexpr (DepthRange == NDCDepthRange::ZERO_TO_ONE)
|
if constexpr (DepthRange == NDCDepthRange::ZERO_TO_ONE)
|
||||||
return {{1.f / (aspect_ratio * fov_half_tan), 0.f, 0.f, 0.f},
|
return {{Type{1} / (aspect_ratio * fov_half_tan), Type{0}, Type{0}, Type{0}},
|
||||||
{0.f, 1.f / fov_half_tan, 0.f, 0.f},
|
{Type{0}, Type{1} / fov_half_tan, Type{0}, Type{0}},
|
||||||
{0.f, 0.f, -far / (far - near), -(near * far) / (far - near)},
|
{Type{0}, Type{0}, -far / (far - near), -(near * far) / (far - near)},
|
||||||
{0.f, 0.f, -1.f, 0.f}};
|
{Type{0}, Type{0}, -Type{1}, Type{0}}};
|
||||||
else if constexpr (DepthRange == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
|
else if constexpr (DepthRange == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
|
||||||
return {{1.f / (aspect_ratio * fov_half_tan), 0.f, 0.f, 0.f},
|
return {{Type{1} / (aspect_ratio * fov_half_tan), Type{0}, Type{0}, Type{0}},
|
||||||
{0.f, 1.f / fov_half_tan, 0.f, 0.f},
|
{Type{0}, Type{1} / fov_half_tan, Type{0}, Type{0}},
|
||||||
{0.f, 0.f, -(far + near) / (far - near), -(2.f * near * far) / (far - near)},
|
{Type{0}, Type{0}, -(far + near) / (far - near), -(Type{2} * near * far) / (far - near)},
|
||||||
{0.f, 0.f, -1.f, 0.f}};
|
{Type{0}, Type{0}, -Type{1}, Type{0}}};
|
||||||
else
|
else
|
||||||
std::unreachable();
|
std::unreachable();
|
||||||
}
|
}
|
||||||
@@ -718,20 +718,20 @@ namespace omath
|
|||||||
const Type aspect_ratio, const Type near,
|
const Type aspect_ratio, const Type near,
|
||||||
const Type far) noexcept
|
const Type far) noexcept
|
||||||
{
|
{
|
||||||
const auto inv_tan_half_hfov = 1.f / std::tan(angles::degrees_to_radians(horizontal_fov) / 2.f);
|
const auto inv_tan_half_hfov = Type{1} / std::tan(angles::degrees_to_radians(horizontal_fov) / Type{2});
|
||||||
const auto x_axis = inv_tan_half_hfov;
|
const auto x_axis = inv_tan_half_hfov;
|
||||||
const auto y_axis = inv_tan_half_hfov * aspect_ratio;
|
const auto y_axis = inv_tan_half_hfov * aspect_ratio;
|
||||||
|
|
||||||
if constexpr (DepthRange == NDCDepthRange::ZERO_TO_ONE)
|
if constexpr (DepthRange == NDCDepthRange::ZERO_TO_ONE)
|
||||||
return {{x_axis, 0.f, 0.f, 0.f},
|
return {{x_axis, Type{0}, Type{0}, Type{0}},
|
||||||
{0.f, y_axis, 0.f, 0.f},
|
{Type{0}, y_axis, Type{0}, Type{0}},
|
||||||
{0.f, 0.f, far / (far - near), -(near * far) / (far - near)},
|
{Type{0}, Type{0}, far / (far - near), -(near * far) / (far - near)},
|
||||||
{0.f, 0.f, 1.f, 0.f}};
|
{Type{0}, Type{0}, Type{1}, Type{0}}};
|
||||||
else if constexpr (DepthRange == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
|
else if constexpr (DepthRange == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
|
||||||
return {{x_axis, 0.f, 0.f, 0.f},
|
return {{x_axis, Type{0}, Type{0}, Type{0}},
|
||||||
{0.f, y_axis, 0.f, 0.f},
|
{Type{0}, y_axis, Type{0}, Type{0}},
|
||||||
{0.f, 0.f, (far + near) / (far - near), -(2.f * near * far) / (far - near)},
|
{Type{0}, Type{0}, (far + near) / (far - near), -(2.f * near * far) / (far - near)},
|
||||||
{0.f, 0.f, 1.f, 0.f}};
|
{Type{0}, Type{0}, Type{1}, Type{0}}};
|
||||||
else
|
else
|
||||||
std::unreachable();
|
std::unreachable();
|
||||||
}
|
}
|
||||||
@@ -743,20 +743,20 @@ namespace omath
|
|||||||
const Type aspect_ratio, const Type near,
|
const Type aspect_ratio, const Type near,
|
||||||
const Type far) noexcept
|
const Type far) noexcept
|
||||||
{
|
{
|
||||||
const float inv_tan_half_hfov = 1.f / std::tan(angles::degrees_to_radians(horizontal_fov) / 2.f);
|
const auto inv_tan_half_hfov = Type{1} / std::tan(angles::degrees_to_radians(horizontal_fov) / Type{2});
|
||||||
const float x_axis = inv_tan_half_hfov;
|
const auto x_axis = inv_tan_half_hfov;
|
||||||
const float y_axis = inv_tan_half_hfov * aspect_ratio;
|
const auto y_axis = inv_tan_half_hfov * aspect_ratio;
|
||||||
|
|
||||||
if constexpr (DepthRange == NDCDepthRange::ZERO_TO_ONE)
|
if constexpr (DepthRange == NDCDepthRange::ZERO_TO_ONE)
|
||||||
return {{x_axis, 0.f, 0.f, 0.f},
|
return {{x_axis, Type{0}, Type{0}, Type{0}},
|
||||||
{0.f, y_axis, 0.f, 0.f},
|
{Type{0}, y_axis, Type{0}, Type{0}},
|
||||||
{0.f, 0.f, -far / (far - near), -(near * far) / (far - near)},
|
{Type{0}, Type{0}, -far / (far - near), -(near * far) / (far - near)},
|
||||||
{0.f, 0.f, -1.f, 0.f}};
|
{Type{0}, Type{0}, -Type{1}, Type{0}}};
|
||||||
else if constexpr (DepthRange == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
|
else if constexpr (DepthRange == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
|
||||||
return {{x_axis, 0.f, 0.f, 0.f},
|
return {{x_axis, Type{0}, Type{0}, Type{0}},
|
||||||
{0.f, y_axis, 0.f, 0.f},
|
{Type{0}, y_axis, Type{0}, Type{0}},
|
||||||
{0.f, 0.f, -(far + near) / (far - near), -(2.f * near * far) / (far - near)},
|
{Type{0}, Type{0}, -(far + near) / (far - near), -(2.f * near * far) / (far - near)},
|
||||||
{0.f, 0.f, -1.f, 0.f}};
|
{Type{0}, Type{0}, -Type{1}, Type{0}}};
|
||||||
else
|
else
|
||||||
std::unreachable();
|
std::unreachable();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -498,7 +498,7 @@ namespace omath::projection
|
|||||||
screen_to_world(const Vector2<NumericType>& screen_pos) const noexcept
|
screen_to_world(const Vector2<NumericType>& screen_pos) const noexcept
|
||||||
{
|
{
|
||||||
const auto& [x, y] = screen_pos;
|
const auto& [x, y] = screen_pos;
|
||||||
return screen_to_world<screen_start>({x, y, 1.f});
|
return screen_to_world<screen_start>({x, y, 1});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
Reference in New Issue
Block a user