added improvement

This commit is contained in:
2026-05-17 09:08:20 +03:00
parent 7f88bf8b21
commit cebcfc411d
16 changed files with 376 additions and 1 deletions
@@ -21,6 +21,15 @@ namespace omath::cry_engine
[[nodiscard]]
Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
[[nodiscard]]
Vector3<float> extract_origin(const Mat4X4& mat) noexcept;
[[nodiscard]]
Vector3<float> extract_scale(const Mat4X4& mat) noexcept;
[[nodiscard]]
ViewAngles extract_rotation_angles(const Mat4X4& mat) noexcept;
[[nodiscard]]
Mat4X4 calc_perspective_projection_matrix(float field_of_view, float aspect_ratio, float near, float far,
NDCDepthRange ndc_depth_range = NDCDepthRange::ZERO_TO_ONE) noexcept;
@@ -21,6 +21,15 @@ namespace omath::frostbite_engine
[[nodiscard]]
Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
[[nodiscard]]
Vector3<float> extract_origin(const Mat4X4& mat) noexcept;
[[nodiscard]]
Vector3<float> extract_scale(const Mat4X4& mat) noexcept;
[[nodiscard]]
ViewAngles extract_rotation_angles(const Mat4X4& mat) noexcept;
[[nodiscard]]
Mat4X4 calc_perspective_projection_matrix(float field_of_view, float aspect_ratio, float near, float far,
NDCDepthRange ndc_depth_range = NDCDepthRange::NEGATIVE_ONE_TO_ONE) noexcept;
@@ -19,6 +19,15 @@ namespace omath::iw_engine
[[nodiscard]]
Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
[[nodiscard]]
Vector3<float> extract_origin(const Mat4X4& mat) noexcept;
[[nodiscard]]
Vector3<float> extract_scale(const Mat4X4& mat) noexcept;
[[nodiscard]]
ViewAngles extract_rotation_angles(const Mat4X4& mat) noexcept;
[[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept;
[[nodiscard]]
@@ -20,6 +20,15 @@ namespace omath::opengl_engine
[[nodiscard]]
Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
[[nodiscard]]
Vector3<float> extract_origin(const Mat4X4& mat) noexcept;
[[nodiscard]]
Vector3<float> extract_scale(const Mat4X4& mat) noexcept;
[[nodiscard]]
ViewAngles extract_rotation_angles(const Mat4X4& mat) noexcept;
[[nodiscard]]
Mat4X4 calc_perspective_projection_matrix(float field_of_view, float aspect_ratio, float near, float far,
NDCDepthRange ndc_depth_range = NDCDepthRange::NEGATIVE_ONE_TO_ONE) noexcept;
@@ -12,6 +12,15 @@ namespace omath::source_engine
[[nodiscard]]
Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
[[nodiscard]]
Vector3<float> extract_origin(const Mat4X4& mat) noexcept;
[[nodiscard]]
Vector3<float> extract_scale(const Mat4X4& mat) noexcept;
[[nodiscard]]
ViewAngles extract_rotation_angles(const Mat4X4& mat) noexcept;
[[nodiscard]]
Vector3<float> right_vector(const ViewAngles& angles) noexcept;
@@ -21,6 +21,15 @@ namespace omath::unity_engine
[[nodiscard]]
Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
[[nodiscard]]
Vector3<float> extract_origin(const Mat4X4& mat) noexcept;
[[nodiscard]]
Vector3<float> extract_scale(const Mat4X4& mat) noexcept;
[[nodiscard]]
ViewAngles extract_rotation_angles(const Mat4X4& mat) noexcept;
[[nodiscard]]
Mat4X4 calc_perspective_projection_matrix(float field_of_view, float aspect_ratio, float near, float far,
NDCDepthRange ndc_depth_range = NDCDepthRange::NEGATIVE_ONE_TO_ONE) noexcept;
@@ -21,6 +21,15 @@ namespace omath::unreal_engine
[[nodiscard]]
Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
[[nodiscard]]
Vector3<double> extract_origin(const Mat4X4& mat) noexcept;
[[nodiscard]]
Vector3<double> extract_scale(const Mat4X4& mat) noexcept;
[[nodiscard]]
ViewAngles extract_rotation_angles(const Mat4X4& mat) noexcept;
[[nodiscard]]
Mat4X4 calc_perspective_projection_matrix(double field_of_view, double aspect_ratio, double near, double far,
NDCDepthRange ndc_depth_range = NDCDepthRange::NEGATIVE_ONE_TO_ONE) noexcept;
+43 -1
View File
@@ -5,6 +5,7 @@
#include "vector3.hpp"
#include <algorithm>
#include <array>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <sstream>
@@ -612,6 +613,47 @@ namespace omath
};
}
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR>
[[nodiscard]]
constexpr Vector3<Type> mat_extract_origin(const Mat<4, 4, Type, St>& mat) noexcept
{
return {mat.at(0, 3), mat.at(1, 3), mat.at(2, 3)};
}
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR>
[[nodiscard]]
Vector3<Type> mat_extract_scale(const Mat<4, 4, Type, St>& mat) noexcept
{
auto column_length = [](const Type x, const Type y, const Type z) {
return static_cast<Type>(std::sqrt(x * x + y * y + z * z));
};
return {
column_length(mat.at(0, 0), mat.at(1, 0), mat.at(2, 0)),
column_length(mat.at(0, 1), mat.at(1, 1), mat.at(2, 1)),
column_length(mat.at(0, 2), mat.at(1, 2), mat.at(2, 2)),
};
}
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR>
requires std::is_floating_point_v<Type>
[[nodiscard]]
Vector3<Type> mat_extract_rotation_zyx(const Mat<4, 4, Type, St>& mat) noexcept
{
const auto scale = mat_extract_scale(mat);
const auto m00 = mat.at(0, 0) / scale.x;
const auto m10 = mat.at(1, 0) / scale.x;
const auto m20 = mat.at(2, 0) / scale.x;
const auto m21 = mat.at(2, 1) / scale.y;
const auto m22 = mat.at(2, 2) / scale.z;
return {
angles::radians_to_degrees(std::atan2(m21, m22)),
angles::radians_to_degrees(std::asin(std::clamp(-m20, Type{-1}, Type{1}))),
angles::radians_to_degrees(std::atan2(m10, m00)),
};
}
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR, class Angle>
[[nodiscard]]
Mat<4, 4, Type, St> mat_rotation_axis_x(const Angle& angle) noexcept
@@ -854,4 +896,4 @@ struct std::formatter<omath::Mat<Rows, Columns, Type, StoreType>> // NOLINT(*-dc
if constexpr (std::is_same_v<typename FormatContext::char_type, char8_t>)
return std::format_to(ctx.out(), u8"{}", mat.to_u8string());
}
};
};