added nodiscard messages

This commit is contained in:
2026-06-15 20:22:35 +03:00
parent e82ec9c8ac
commit 2779bae82f
8 changed files with 137 additions and 137 deletions
+15 -15
View File
@@ -7,7 +7,7 @@
namespace omath::cry_engine namespace omath::cry_engine
{ {
[[nodiscard]] [[nodiscard("rotation matrix result should not be discarded")]]
constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
{ {
return mat_rotation_axis_z<float, MatStoreType::ROW_MAJOR>(angles.yaw) return mat_rotation_axis_z<float, MatStoreType::ROW_MAJOR>(angles.yaw)
@@ -15,7 +15,7 @@ namespace omath::cry_engine
* mat_rotation_axis_x<float, MatStoreType::ROW_MAJOR>(angles.pitch); * mat_rotation_axis_x<float, MatStoreType::ROW_MAJOR>(angles.pitch);
} }
[[nodiscard]] [[nodiscard("forward vector result should not be discarded")]]
constexpr Vector3<float> forward_vector(const ViewAngles& angles) noexcept constexpr Vector3<float> forward_vector(const ViewAngles& angles) noexcept
{ {
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_forward); const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_forward);
@@ -23,7 +23,7 @@ namespace omath::cry_engine
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)}; return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
} }
[[nodiscard]] [[nodiscard("right vector result should not be discarded")]]
constexpr Vector3<float> right_vector(const ViewAngles& angles) noexcept constexpr Vector3<float> right_vector(const ViewAngles& angles) noexcept
{ {
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_right); const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_right);
@@ -31,7 +31,7 @@ namespace omath::cry_engine
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)}; return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
} }
[[nodiscard]] [[nodiscard("up vector result should not be discarded")]]
constexpr Vector3<float> up_vector(const ViewAngles& angles) noexcept constexpr Vector3<float> up_vector(const ViewAngles& angles) noexcept
{ {
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_up); const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_up);
@@ -39,26 +39,26 @@ namespace omath::cry_engine
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)}; return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
} }
[[nodiscard]] [[nodiscard("view matrix result should not be discarded")]]
constexpr Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept constexpr Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
{ {
return mat_camera_view<float, MatStoreType::ROW_MAJOR>(forward_vector(angles), right_vector(angles), return mat_camera_view<float, MatStoreType::ROW_MAJOR>(forward_vector(angles), right_vector(angles),
up_vector(angles), cam_origin); up_vector(angles), cam_origin);
} }
[[nodiscard]] [[nodiscard("origin result should not be discarded")]]
constexpr Vector3<float> extract_origin(const Mat4X4& mat) noexcept constexpr Vector3<float> extract_origin(const Mat4X4& mat) noexcept
{ {
return mat_extract_origin(mat); return mat_extract_origin(mat);
} }
[[nodiscard]] [[nodiscard("scale result should not be discarded")]]
constexpr Vector3<float> extract_scale(const Mat4X4& mat) noexcept constexpr Vector3<float> extract_scale(const Mat4X4& mat) noexcept
{ {
return mat_extract_scale(mat); return mat_extract_scale(mat);
} }
[[nodiscard]] [[nodiscard("rotation angles result should not be discarded")]]
constexpr ViewAngles extract_rotation_angles(const Mat4X4& mat) noexcept constexpr ViewAngles extract_rotation_angles(const Mat4X4& mat) noexcept
{ {
const auto angles = mat_extract_rotation_zyx(mat); const auto angles = mat_extract_rotation_zyx(mat);
@@ -68,7 +68,7 @@ namespace omath::cry_engine
RollAngle::from_degrees(angles.y), RollAngle::from_degrees(angles.y),
}; };
} }
[[nodiscard]] [[nodiscard("perspective projection matrix result should not be discarded")]]
constexpr Mat4X4 constexpr Mat4X4
calc_perspective_projection_matrix(const float field_of_view, const float aspect_ratio, const float near_plane, calc_perspective_projection_matrix(const float field_of_view, const float aspect_ratio, const float near_plane,
const float far_plane, const float far_plane,
@@ -87,7 +87,7 @@ namespace omath::cry_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("centimeters value should not be discarded")]]
constexpr FloatingType units_to_centimeters(const FloatingType& units) constexpr FloatingType units_to_centimeters(const FloatingType& units)
{ {
return units / static_cast<FloatingType>(100); return units / static_cast<FloatingType>(100);
@@ -95,7 +95,7 @@ namespace omath::cry_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("meters value should not be discarded")]]
constexpr FloatingType units_to_meters(const FloatingType& units) constexpr FloatingType units_to_meters(const FloatingType& units)
{ {
return units; return units;
@@ -103,7 +103,7 @@ namespace omath::cry_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("kilometers value should not be discarded")]]
constexpr FloatingType units_to_kilometers(const FloatingType& units) constexpr FloatingType units_to_kilometers(const FloatingType& units)
{ {
return units_to_meters(units) / static_cast<FloatingType>(1000); return units_to_meters(units) / static_cast<FloatingType>(1000);
@@ -111,7 +111,7 @@ namespace omath::cry_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("units value should not be discarded")]]
constexpr FloatingType centimeters_to_units(const FloatingType& centimeters) constexpr FloatingType centimeters_to_units(const FloatingType& centimeters)
{ {
return centimeters * static_cast<FloatingType>(100); return centimeters * static_cast<FloatingType>(100);
@@ -119,7 +119,7 @@ namespace omath::cry_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("units value should not be discarded")]]
constexpr FloatingType meters_to_units(const FloatingType& meters) constexpr FloatingType meters_to_units(const FloatingType& meters)
{ {
return meters; return meters;
@@ -127,7 +127,7 @@ namespace omath::cry_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("units value should not be discarded")]]
constexpr FloatingType kilometers_to_units(const FloatingType& kilometers) constexpr FloatingType kilometers_to_units(const FloatingType& kilometers)
{ {
return meters_to_units(kilometers * static_cast<FloatingType>(1000)); return meters_to_units(kilometers * static_cast<FloatingType>(1000));
@@ -7,10 +7,10 @@
namespace omath::frostbite_engine namespace omath::frostbite_engine
{ {
[[nodiscard]] [[nodiscard("rotation matrix result should not be discarded")]]
constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept; constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
[[nodiscard]] [[nodiscard("forward vector result should not be discarded")]]
constexpr Vector3<float> forward_vector(const ViewAngles& angles) noexcept constexpr Vector3<float> forward_vector(const ViewAngles& angles) noexcept
{ {
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_forward); const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_forward);
@@ -18,7 +18,7 @@ namespace omath::frostbite_engine
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)}; return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
} }
[[nodiscard]] [[nodiscard("right vector result should not be discarded")]]
constexpr Vector3<float> right_vector(const ViewAngles& angles) noexcept constexpr Vector3<float> right_vector(const ViewAngles& angles) noexcept
{ {
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_right); const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_right);
@@ -26,7 +26,7 @@ namespace omath::frostbite_engine
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)}; return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
} }
[[nodiscard]] [[nodiscard("up vector result should not be discarded")]]
constexpr Vector3<float> up_vector(const ViewAngles& angles) noexcept constexpr Vector3<float> up_vector(const ViewAngles& angles) noexcept
{ {
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_up); const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_up);
@@ -34,14 +34,14 @@ namespace omath::frostbite_engine
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)}; return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
} }
[[nodiscard]] [[nodiscard("view matrix result should not be discarded")]]
constexpr Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept constexpr Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
{ {
return mat_camera_view<float, MatStoreType::ROW_MAJOR>(forward_vector(angles), right_vector(angles), return mat_camera_view<float, MatStoreType::ROW_MAJOR>(forward_vector(angles), right_vector(angles),
up_vector(angles), cam_origin); up_vector(angles), cam_origin);
} }
[[nodiscard]] [[nodiscard("rotation matrix result should not be discarded")]]
constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
{ {
return mat_rotation_axis_z<float, MatStoreType::ROW_MAJOR>(angles.roll) return mat_rotation_axis_z<float, MatStoreType::ROW_MAJOR>(angles.roll)
@@ -49,19 +49,19 @@ namespace omath::frostbite_engine
* mat_rotation_axis_x<float, MatStoreType::ROW_MAJOR>(angles.pitch); * mat_rotation_axis_x<float, MatStoreType::ROW_MAJOR>(angles.pitch);
} }
[[nodiscard]] [[nodiscard("origin result should not be discarded")]]
constexpr Vector3<float> extract_origin(const Mat4X4& mat) noexcept constexpr Vector3<float> extract_origin(const Mat4X4& mat) noexcept
{ {
return mat_extract_origin(mat); return mat_extract_origin(mat);
} }
[[nodiscard]] [[nodiscard("scale result should not be discarded")]]
constexpr Vector3<float> extract_scale(const Mat4X4& mat) noexcept constexpr Vector3<float> extract_scale(const Mat4X4& mat) noexcept
{ {
return mat_extract_scale(mat); return mat_extract_scale(mat);
} }
[[nodiscard]] [[nodiscard("rotation angles result should not be discarded")]]
constexpr ViewAngles extract_rotation_angles(const Mat4X4& mat) noexcept constexpr ViewAngles extract_rotation_angles(const Mat4X4& mat) noexcept
{ {
const auto angles = mat_extract_rotation_zyx(mat); const auto angles = mat_extract_rotation_zyx(mat);
@@ -72,7 +72,7 @@ namespace omath::frostbite_engine
}; };
} }
[[nodiscard]] [[nodiscard("perspective projection matrix result should not be discarded")]]
constexpr Mat4X4 calc_perspective_projection_matrix( constexpr Mat4X4 calc_perspective_projection_matrix(
const float field_of_view, const float aspect_ratio, const float near_plane, const float far_plane, 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 const NDCDepthRange ndc_depth_range = NDCDepthRange::NEGATIVE_ONE_TO_ONE) noexcept
@@ -91,7 +91,7 @@ namespace omath::frostbite_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("centimeters value should not be discarded")]]
constexpr FloatingType units_to_centimeters(const FloatingType& units) constexpr FloatingType units_to_centimeters(const FloatingType& units)
{ {
return units / static_cast<FloatingType>(100); return units / static_cast<FloatingType>(100);
@@ -99,7 +99,7 @@ namespace omath::frostbite_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("meters value should not be discarded")]]
constexpr FloatingType units_to_meters(const FloatingType& units) constexpr FloatingType units_to_meters(const FloatingType& units)
{ {
return units; return units;
@@ -107,7 +107,7 @@ namespace omath::frostbite_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("kilometers value should not be discarded")]]
constexpr FloatingType units_to_kilometers(const FloatingType& units) constexpr FloatingType units_to_kilometers(const FloatingType& units)
{ {
return units_to_meters(units) / static_cast<FloatingType>(1000); return units_to_meters(units) / static_cast<FloatingType>(1000);
@@ -115,7 +115,7 @@ namespace omath::frostbite_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("units value should not be discarded")]]
constexpr FloatingType centimeters_to_units(const FloatingType& centimeters) constexpr FloatingType centimeters_to_units(const FloatingType& centimeters)
{ {
return centimeters * static_cast<FloatingType>(100); return centimeters * static_cast<FloatingType>(100);
@@ -123,7 +123,7 @@ namespace omath::frostbite_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("units value should not be discarded")]]
constexpr FloatingType meters_to_units(const FloatingType& meters) constexpr FloatingType meters_to_units(const FloatingType& meters)
{ {
return meters; return meters;
@@ -131,7 +131,7 @@ namespace omath::frostbite_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("units value should not be discarded")]]
constexpr FloatingType kilometers_to_units(const FloatingType& kilometers) constexpr FloatingType kilometers_to_units(const FloatingType& kilometers)
{ {
return meters_to_units(kilometers * static_cast<FloatingType>(1000)); return meters_to_units(kilometers * static_cast<FloatingType>(1000));
+16 -16
View File
@@ -7,10 +7,10 @@
namespace omath::iw_engine namespace omath::iw_engine
{ {
[[nodiscard]] [[nodiscard("rotation matrix result should not be discarded")]]
constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept; constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
[[nodiscard]] [[nodiscard("forward vector result should not be discarded")]]
constexpr Vector3<float> forward_vector(const ViewAngles& angles) noexcept constexpr Vector3<float> forward_vector(const ViewAngles& angles) noexcept
{ {
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_forward); const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_forward);
@@ -18,7 +18,7 @@ namespace omath::iw_engine
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)}; return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
} }
[[nodiscard]] [[nodiscard("right vector result should not be discarded")]]
constexpr Vector3<float> right_vector(const ViewAngles& angles) noexcept constexpr Vector3<float> right_vector(const ViewAngles& angles) noexcept
{ {
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_right); const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_right);
@@ -26,7 +26,7 @@ namespace omath::iw_engine
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)}; return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
} }
[[nodiscard]] [[nodiscard("up vector result should not be discarded")]]
constexpr Vector3<float> up_vector(const ViewAngles& angles) noexcept constexpr Vector3<float> up_vector(const ViewAngles& angles) noexcept
{ {
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_up); const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_up);
@@ -34,25 +34,25 @@ namespace omath::iw_engine
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)}; return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
} }
[[nodiscard]] [[nodiscard("rotation matrix result should not be discarded")]]
constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
{ {
return mat_rotation_axis_z(angles.yaw) * mat_rotation_axis_y(angles.pitch) * mat_rotation_axis_x(angles.roll); return mat_rotation_axis_z(angles.yaw) * mat_rotation_axis_y(angles.pitch) * mat_rotation_axis_x(angles.roll);
} }
[[nodiscard]] [[nodiscard("origin result should not be discarded")]]
constexpr Vector3<float> extract_origin(const Mat4X4& mat) noexcept constexpr Vector3<float> extract_origin(const Mat4X4& mat) noexcept
{ {
return mat_extract_origin(mat); return mat_extract_origin(mat);
} }
[[nodiscard]] [[nodiscard("scale result should not be discarded")]]
constexpr Vector3<float> extract_scale(const Mat4X4& mat) noexcept constexpr Vector3<float> extract_scale(const Mat4X4& mat) noexcept
{ {
return mat_extract_scale(mat); return mat_extract_scale(mat);
} }
[[nodiscard]] [[nodiscard("rotation angles result should not be discarded")]]
constexpr ViewAngles extract_rotation_angles(const Mat4X4& mat) noexcept constexpr ViewAngles extract_rotation_angles(const Mat4X4& mat) noexcept
{ {
const auto angles = mat_extract_rotation_zyx(mat); const auto angles = mat_extract_rotation_zyx(mat);
@@ -63,13 +63,13 @@ namespace omath::iw_engine
}; };
} }
[[nodiscard]] [[nodiscard("view matrix result should not be discarded")]]
constexpr Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept constexpr Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
{ {
return mat_camera_view(forward_vector(angles), right_vector(angles), up_vector(angles), cam_origin); return mat_camera_view(forward_vector(angles), right_vector(angles), up_vector(angles), cam_origin);
} }
[[nodiscard]] [[nodiscard("perspective projection matrix result should not be discarded")]]
constexpr Mat4X4 calc_perspective_projection_matrix( constexpr Mat4X4 calc_perspective_projection_matrix(
const float field_of_view, const float aspect_ratio, const float near_plane, const float far_plane, 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 const NDCDepthRange ndc_depth_range = NDCDepthRange::NEGATIVE_ONE_TO_ONE) noexcept
@@ -89,7 +89,7 @@ namespace omath::iw_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("centimeters value should not be discarded")]]
constexpr FloatingType units_to_centimeters(const FloatingType& units) constexpr FloatingType units_to_centimeters(const FloatingType& units)
{ {
constexpr auto centimeter_in_unit = static_cast<FloatingType>(2.54); constexpr auto centimeter_in_unit = static_cast<FloatingType>(2.54);
@@ -98,7 +98,7 @@ namespace omath::iw_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("meters value should not be discarded")]]
constexpr FloatingType units_to_meters(const FloatingType& units) constexpr FloatingType units_to_meters(const FloatingType& units)
{ {
return units_to_centimeters(units) / static_cast<FloatingType>(100); return units_to_centimeters(units) / static_cast<FloatingType>(100);
@@ -106,7 +106,7 @@ namespace omath::iw_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("kilometers value should not be discarded")]]
constexpr FloatingType units_to_kilometers(const FloatingType& units) constexpr FloatingType units_to_kilometers(const FloatingType& units)
{ {
return units_to_meters(units) / static_cast<FloatingType>(1000); return units_to_meters(units) / static_cast<FloatingType>(1000);
@@ -114,7 +114,7 @@ namespace omath::iw_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("units value should not be discarded")]]
constexpr FloatingType centimeters_to_units(const FloatingType& centimeters) constexpr FloatingType centimeters_to_units(const FloatingType& centimeters)
{ {
constexpr auto centimeter_in_unit = static_cast<FloatingType>(2.54); constexpr auto centimeter_in_unit = static_cast<FloatingType>(2.54);
@@ -123,7 +123,7 @@ namespace omath::iw_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("units value should not be discarded")]]
constexpr FloatingType meters_to_units(const FloatingType& meters) constexpr FloatingType meters_to_units(const FloatingType& meters)
{ {
return centimeters_to_units(meters * static_cast<FloatingType>(100)); return centimeters_to_units(meters * static_cast<FloatingType>(100));
@@ -131,7 +131,7 @@ namespace omath::iw_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("units value should not be discarded")]]
constexpr FloatingType kilometers_to_units(const FloatingType& kilometers) constexpr FloatingType kilometers_to_units(const FloatingType& kilometers)
{ {
return meters_to_units(kilometers * static_cast<FloatingType>(1000)); return meters_to_units(kilometers * static_cast<FloatingType>(1000));
@@ -6,10 +6,10 @@
namespace omath::opengl_engine namespace omath::opengl_engine
{ {
[[nodiscard]] [[nodiscard("rotation matrix result should not be discarded")]]
constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept; constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
[[nodiscard]] [[nodiscard("forward vector result should not be discarded")]]
constexpr Vector3<float> forward_vector(const ViewAngles& angles) noexcept constexpr Vector3<float> forward_vector(const ViewAngles& angles) noexcept
{ {
const auto vec = const auto vec =
@@ -18,7 +18,7 @@ namespace omath::opengl_engine
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)}; return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
} }
[[nodiscard]] [[nodiscard("right vector result should not be discarded")]]
constexpr Vector3<float> right_vector(const ViewAngles& angles) noexcept constexpr Vector3<float> right_vector(const ViewAngles& angles) noexcept
{ {
const auto vec = const auto vec =
@@ -27,7 +27,7 @@ namespace omath::opengl_engine
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)}; return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
} }
[[nodiscard]] [[nodiscard("up vector result should not be discarded")]]
constexpr Vector3<float> up_vector(const ViewAngles& angles) noexcept constexpr Vector3<float> up_vector(const ViewAngles& angles) noexcept
{ {
const auto vec = rotation_matrix(angles) * mat_column_from_vector<float, MatStoreType::COLUMN_MAJOR>(k_abs_up); const auto vec = rotation_matrix(angles) * mat_column_from_vector<float, MatStoreType::COLUMN_MAJOR>(k_abs_up);
@@ -35,13 +35,13 @@ namespace omath::opengl_engine
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)}; return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
} }
[[nodiscard]] [[nodiscard("view matrix result should not be discarded")]]
constexpr Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept constexpr Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
{ {
return mat_look_at_right_handed(cam_origin, cam_origin + forward_vector(angles), up_vector(angles)); return mat_look_at_right_handed(cam_origin, cam_origin + forward_vector(angles), up_vector(angles));
} }
[[nodiscard]] [[nodiscard("rotation matrix result should not be discarded")]]
constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
{ {
return mat_rotation_axis_z<float, MatStoreType::COLUMN_MAJOR>(angles.roll) return mat_rotation_axis_z<float, MatStoreType::COLUMN_MAJOR>(angles.roll)
@@ -49,19 +49,19 @@ namespace omath::opengl_engine
* mat_rotation_axis_x<float, MatStoreType::COLUMN_MAJOR>(angles.pitch); * mat_rotation_axis_x<float, MatStoreType::COLUMN_MAJOR>(angles.pitch);
} }
[[nodiscard]] [[nodiscard("origin result should not be discarded")]]
constexpr Vector3<float> extract_origin(const Mat4X4& mat) noexcept constexpr Vector3<float> extract_origin(const Mat4X4& mat) noexcept
{ {
return mat_extract_origin(mat); return mat_extract_origin(mat);
} }
[[nodiscard]] [[nodiscard("scale result should not be discarded")]]
constexpr Vector3<float> extract_scale(const Mat4X4& mat) noexcept constexpr Vector3<float> extract_scale(const Mat4X4& mat) noexcept
{ {
return mat_extract_scale(mat); return mat_extract_scale(mat);
} }
[[nodiscard]] [[nodiscard("rotation angles result should not be discarded")]]
constexpr ViewAngles extract_rotation_angles(const Mat4X4& mat) noexcept constexpr ViewAngles extract_rotation_angles(const Mat4X4& mat) noexcept
{ {
const auto angles = mat_extract_rotation_zyx(mat); const auto angles = mat_extract_rotation_zyx(mat);
@@ -72,7 +72,7 @@ namespace omath::opengl_engine
}; };
} }
[[nodiscard]] [[nodiscard("perspective projection matrix result should not be discarded")]]
constexpr Mat4X4 calc_perspective_projection_matrix( constexpr Mat4X4 calc_perspective_projection_matrix(
const float field_of_view, const float aspect_ratio, const float near_plane, const float far_plane, 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 const NDCDepthRange ndc_depth_range = NDCDepthRange::NEGATIVE_ONE_TO_ONE) noexcept
@@ -92,7 +92,7 @@ namespace omath::opengl_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("centimeters value should not be discarded")]]
constexpr FloatingType units_to_centimeters(const FloatingType& units) constexpr FloatingType units_to_centimeters(const FloatingType& units)
{ {
return units / static_cast<FloatingType>(100); return units / static_cast<FloatingType>(100);
@@ -100,7 +100,7 @@ namespace omath::opengl_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("meters value should not be discarded")]]
constexpr FloatingType units_to_meters(const FloatingType& units) constexpr FloatingType units_to_meters(const FloatingType& units)
{ {
return units; return units;
@@ -108,7 +108,7 @@ namespace omath::opengl_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("kilometers value should not be discarded")]]
constexpr FloatingType units_to_kilometers(const FloatingType& units) constexpr FloatingType units_to_kilometers(const FloatingType& units)
{ {
return units_to_meters(units) / static_cast<FloatingType>(1000); return units_to_meters(units) / static_cast<FloatingType>(1000);
@@ -116,7 +116,7 @@ namespace omath::opengl_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("units value should not be discarded")]]
constexpr FloatingType centimeters_to_units(const FloatingType& centimeters) constexpr FloatingType centimeters_to_units(const FloatingType& centimeters)
{ {
return centimeters * static_cast<FloatingType>(100); return centimeters * static_cast<FloatingType>(100);
@@ -124,7 +124,7 @@ namespace omath::opengl_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("units value should not be discarded")]]
constexpr FloatingType meters_to_units(const FloatingType& meters) constexpr FloatingType meters_to_units(const FloatingType& meters)
{ {
return meters; return meters;
@@ -132,7 +132,7 @@ namespace omath::opengl_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("units value should not be discarded")]]
constexpr FloatingType kilometers_to_units(const FloatingType& kilometers) constexpr FloatingType kilometers_to_units(const FloatingType& kilometers)
{ {
return meters_to_units(kilometers * static_cast<FloatingType>(1000)); return meters_to_units(kilometers * static_cast<FloatingType>(1000));
+16 -16
View File
@@ -8,10 +8,10 @@
namespace omath::rage_engine namespace omath::rage_engine
{ {
[[nodiscard]] [[nodiscard("rotation matrix result should not be discarded")]]
constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept; constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
[[nodiscard]] [[nodiscard("forward vector result should not be discarded")]]
constexpr Vector3<float> forward_vector(const ViewAngles& angles) noexcept constexpr Vector3<float> forward_vector(const ViewAngles& angles) noexcept
{ {
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_forward); const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_forward);
@@ -19,7 +19,7 @@ namespace omath::rage_engine
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)}; return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
} }
[[nodiscard]] [[nodiscard("right vector result should not be discarded")]]
constexpr Vector3<float> right_vector(const ViewAngles& angles) noexcept constexpr Vector3<float> right_vector(const ViewAngles& angles) noexcept
{ {
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_right); const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_right);
@@ -27,7 +27,7 @@ namespace omath::rage_engine
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)}; return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
} }
[[nodiscard]] [[nodiscard("up vector result should not be discarded")]]
constexpr Vector3<float> up_vector(const ViewAngles& angles) noexcept constexpr Vector3<float> up_vector(const ViewAngles& angles) noexcept
{ {
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_up); const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_up);
@@ -35,14 +35,14 @@ namespace omath::rage_engine
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)}; return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
} }
[[nodiscard]] [[nodiscard("view matrix result should not be discarded")]]
constexpr Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept constexpr Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
{ {
return mat_camera_view<float, MatStoreType::ROW_MAJOR>(forward_vector(angles), right_vector(angles), return mat_camera_view<float, MatStoreType::ROW_MAJOR>(forward_vector(angles), right_vector(angles),
up_vector(angles), cam_origin); up_vector(angles), cam_origin);
} }
[[nodiscard]] [[nodiscard("rotation matrix result should not be discarded")]]
constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
{ {
return mat_rotation_axis_z<float, MatStoreType::ROW_MAJOR>(angles.yaw) return mat_rotation_axis_z<float, MatStoreType::ROW_MAJOR>(angles.yaw)
@@ -50,19 +50,19 @@ namespace omath::rage_engine
* mat_rotation_axis_x<float, MatStoreType::ROW_MAJOR>(angles.pitch); * mat_rotation_axis_x<float, MatStoreType::ROW_MAJOR>(angles.pitch);
} }
[[nodiscard]] [[nodiscard("origin result should not be discarded")]]
constexpr Vector3<float> extract_origin(const Mat4X4& mat) noexcept constexpr Vector3<float> extract_origin(const Mat4X4& mat) noexcept
{ {
return mat_extract_origin(mat); return mat_extract_origin(mat);
} }
[[nodiscard]] [[nodiscard("scale result should not be discarded")]]
constexpr Vector3<float> extract_scale(const Mat4X4& mat) noexcept constexpr Vector3<float> extract_scale(const Mat4X4& mat) noexcept
{ {
return mat_extract_scale(mat); return mat_extract_scale(mat);
} }
[[nodiscard]] [[nodiscard("rotation angles result should not be discarded")]]
constexpr ViewAngles extract_rotation_angles(const Mat4X4& mat) noexcept constexpr ViewAngles extract_rotation_angles(const Mat4X4& mat) noexcept
{ {
const auto angles = mat_extract_rotation_zyx(mat); const auto angles = mat_extract_rotation_zyx(mat);
@@ -73,7 +73,7 @@ namespace omath::rage_engine
}; };
} }
[[nodiscard]] [[nodiscard("perspective projection matrix result should not be discarded")]]
constexpr Mat4X4 constexpr Mat4X4
calc_perspective_projection_matrix(const float field_of_view, const float aspect_ratio, const float near_plane, calc_perspective_projection_matrix(const float field_of_view, const float aspect_ratio, const float near_plane,
const float far_plane, const float far_plane,
@@ -92,7 +92,7 @@ namespace omath::rage_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("centimeters value should not be discarded")]]
constexpr FloatingType units_to_centimeters(const FloatingType& units) constexpr FloatingType units_to_centimeters(const FloatingType& units)
{ {
return units / static_cast<FloatingType>(100); return units / static_cast<FloatingType>(100);
@@ -100,7 +100,7 @@ namespace omath::rage_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("meters value should not be discarded")]]
constexpr FloatingType units_to_meters(const FloatingType& units) constexpr FloatingType units_to_meters(const FloatingType& units)
{ {
return units; return units;
@@ -108,7 +108,7 @@ namespace omath::rage_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("kilometers value should not be discarded")]]
constexpr FloatingType units_to_kilometers(const FloatingType& units) constexpr FloatingType units_to_kilometers(const FloatingType& units)
{ {
return units_to_meters(units) / static_cast<FloatingType>(1000); return units_to_meters(units) / static_cast<FloatingType>(1000);
@@ -116,7 +116,7 @@ namespace omath::rage_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("units value should not be discarded")]]
constexpr FloatingType centimeters_to_units(const FloatingType& centimeters) constexpr FloatingType centimeters_to_units(const FloatingType& centimeters)
{ {
return centimeters * static_cast<FloatingType>(100); return centimeters * static_cast<FloatingType>(100);
@@ -124,7 +124,7 @@ namespace omath::rage_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("units value should not be discarded")]]
constexpr FloatingType meters_to_units(const FloatingType& meters) constexpr FloatingType meters_to_units(const FloatingType& meters)
{ {
return meters; return meters;
@@ -132,7 +132,7 @@ namespace omath::rage_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("units value should not be discarded")]]
constexpr FloatingType kilometers_to_units(const FloatingType& kilometers) constexpr FloatingType kilometers_to_units(const FloatingType& kilometers)
{ {
return meters_to_units(kilometers * static_cast<FloatingType>(1000)); return meters_to_units(kilometers * static_cast<FloatingType>(1000));
@@ -6,10 +6,10 @@
namespace omath::source_engine namespace omath::source_engine
{ {
[[nodiscard]] [[nodiscard("rotation matrix result should not be discarded")]]
constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept; constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
[[nodiscard]] [[nodiscard("forward vector result should not be discarded")]]
constexpr Vector3<float> forward_vector(const ViewAngles& angles) noexcept constexpr Vector3<float> forward_vector(const ViewAngles& angles) noexcept
{ {
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_forward); const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_forward);
@@ -17,25 +17,25 @@ namespace omath::source_engine
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)}; return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
} }
[[nodiscard]] [[nodiscard("rotation matrix result should not be discarded")]]
constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
{ {
return mat_rotation_axis_z(angles.yaw) * mat_rotation_axis_y(angles.pitch) * mat_rotation_axis_x(angles.roll); return mat_rotation_axis_z(angles.yaw) * mat_rotation_axis_y(angles.pitch) * mat_rotation_axis_x(angles.roll);
} }
[[nodiscard]] [[nodiscard("origin result should not be discarded")]]
constexpr Vector3<float> extract_origin(const Mat4X4& mat) noexcept constexpr Vector3<float> extract_origin(const Mat4X4& mat) noexcept
{ {
return mat_extract_origin(mat); return mat_extract_origin(mat);
} }
[[nodiscard]] [[nodiscard("scale result should not be discarded")]]
constexpr Vector3<float> extract_scale(const Mat4X4& mat) noexcept constexpr Vector3<float> extract_scale(const Mat4X4& mat) noexcept
{ {
return mat_extract_scale(mat); return mat_extract_scale(mat);
} }
[[nodiscard]] [[nodiscard("rotation angles result should not be discarded")]]
constexpr ViewAngles extract_rotation_angles(const Mat4X4& mat) noexcept constexpr ViewAngles extract_rotation_angles(const Mat4X4& mat) noexcept
{ {
const auto angles = mat_extract_rotation_zyx(mat); const auto angles = mat_extract_rotation_zyx(mat);
@@ -46,7 +46,7 @@ namespace omath::source_engine
}; };
} }
[[nodiscard]] [[nodiscard("right vector result should not be discarded")]]
constexpr Vector3<float> right_vector(const ViewAngles& angles) noexcept constexpr Vector3<float> right_vector(const ViewAngles& angles) noexcept
{ {
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_right); const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_right);
@@ -54,7 +54,7 @@ namespace omath::source_engine
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)}; return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
} }
[[nodiscard]] [[nodiscard("up vector result should not be discarded")]]
constexpr Vector3<float> up_vector(const ViewAngles& angles) noexcept constexpr Vector3<float> up_vector(const ViewAngles& angles) noexcept
{ {
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_up); const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_up);
@@ -62,13 +62,13 @@ namespace omath::source_engine
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)}; return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
} }
[[nodiscard]] [[nodiscard("view matrix result should not be discarded")]]
constexpr Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept constexpr Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
{ {
return mat_camera_view(forward_vector(angles), right_vector(angles), up_vector(angles), cam_origin); return mat_camera_view(forward_vector(angles), right_vector(angles), up_vector(angles), cam_origin);
} }
[[nodiscard]] [[nodiscard("perspective projection matrix result should not be discarded")]]
constexpr Mat4X4 calc_perspective_projection_matrix( constexpr Mat4X4 calc_perspective_projection_matrix(
const float field_of_view, const float aspect_ratio, const float near_plane, const float far_plane, 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 const NDCDepthRange ndc_depth_range = NDCDepthRange::NEGATIVE_ONE_TO_ONE) noexcept
@@ -88,7 +88,7 @@ namespace omath::source_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("centimeters value should not be discarded")]]
constexpr FloatingType units_to_centimeters(const FloatingType& units) constexpr FloatingType units_to_centimeters(const FloatingType& units)
{ {
constexpr auto centimeter_in_unit = static_cast<FloatingType>(2.54); constexpr auto centimeter_in_unit = static_cast<FloatingType>(2.54);
@@ -97,7 +97,7 @@ namespace omath::source_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("meters value should not be discarded")]]
constexpr FloatingType units_to_meters(const FloatingType& units) constexpr FloatingType units_to_meters(const FloatingType& units)
{ {
return units_to_centimeters(units) / static_cast<FloatingType>(100); return units_to_centimeters(units) / static_cast<FloatingType>(100);
@@ -105,7 +105,7 @@ namespace omath::source_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("kilometers value should not be discarded")]]
constexpr FloatingType units_to_kilometers(const FloatingType& units) constexpr FloatingType units_to_kilometers(const FloatingType& units)
{ {
return units_to_meters(units) / static_cast<FloatingType>(1000); return units_to_meters(units) / static_cast<FloatingType>(1000);
@@ -113,7 +113,7 @@ namespace omath::source_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("units value should not be discarded")]]
constexpr FloatingType centimeters_to_units(const FloatingType& centimeters) constexpr FloatingType centimeters_to_units(const FloatingType& centimeters)
{ {
constexpr auto centimeter_in_unit = static_cast<FloatingType>(2.54); constexpr auto centimeter_in_unit = static_cast<FloatingType>(2.54);
@@ -122,7 +122,7 @@ namespace omath::source_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("units value should not be discarded")]]
constexpr FloatingType meters_to_units(const FloatingType& meters) constexpr FloatingType meters_to_units(const FloatingType& meters)
{ {
return centimeters_to_units(meters * static_cast<FloatingType>(100)); return centimeters_to_units(meters * static_cast<FloatingType>(100));
@@ -130,7 +130,7 @@ namespace omath::source_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("units value should not be discarded")]]
constexpr FloatingType kilometers_to_units(const FloatingType& kilometers) constexpr FloatingType kilometers_to_units(const FloatingType& kilometers)
{ {
return meters_to_units(kilometers * static_cast<FloatingType>(1000)); return meters_to_units(kilometers * static_cast<FloatingType>(1000));
+16 -16
View File
@@ -7,10 +7,10 @@
namespace omath::unity_engine namespace omath::unity_engine
{ {
[[nodiscard]] [[nodiscard("rotation matrix result should not be discarded")]]
constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept; constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
[[nodiscard]] [[nodiscard("forward vector result should not be discarded")]]
constexpr Vector3<float> forward_vector(const ViewAngles& angles) noexcept constexpr Vector3<float> forward_vector(const ViewAngles& angles) noexcept
{ {
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_forward); const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_forward);
@@ -18,7 +18,7 @@ namespace omath::unity_engine
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)}; return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
} }
[[nodiscard]] [[nodiscard("right vector result should not be discarded")]]
constexpr Vector3<float> right_vector(const ViewAngles& angles) noexcept constexpr Vector3<float> right_vector(const ViewAngles& angles) noexcept
{ {
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_right); const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_right);
@@ -26,7 +26,7 @@ namespace omath::unity_engine
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)}; return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
} }
[[nodiscard]] [[nodiscard("up vector result should not be discarded")]]
constexpr Vector3<float> up_vector(const ViewAngles& angles) noexcept constexpr Vector3<float> up_vector(const ViewAngles& angles) noexcept
{ {
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_up); const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_up);
@@ -34,14 +34,14 @@ namespace omath::unity_engine
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)}; return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
} }
[[nodiscard]] [[nodiscard("view matrix result should not be discarded")]]
constexpr Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept constexpr Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
{ {
return mat_camera_view<float, MatStoreType::ROW_MAJOR>(-forward_vector(angles), right_vector(angles), return mat_camera_view<float, MatStoreType::ROW_MAJOR>(-forward_vector(angles), right_vector(angles),
up_vector(angles), cam_origin); up_vector(angles), cam_origin);
} }
[[nodiscard]] [[nodiscard("rotation matrix result should not be discarded")]]
constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
{ {
return mat_rotation_axis_z<float, MatStoreType::ROW_MAJOR>(angles.roll) return mat_rotation_axis_z<float, MatStoreType::ROW_MAJOR>(angles.roll)
@@ -49,19 +49,19 @@ namespace omath::unity_engine
* mat_rotation_axis_x<float, MatStoreType::ROW_MAJOR>(angles.pitch); * mat_rotation_axis_x<float, MatStoreType::ROW_MAJOR>(angles.pitch);
} }
[[nodiscard]] [[nodiscard("origin result should not be discarded")]]
constexpr Vector3<float> extract_origin(const Mat4X4& mat) noexcept constexpr Vector3<float> extract_origin(const Mat4X4& mat) noexcept
{ {
return mat_extract_origin(mat); return mat_extract_origin(mat);
} }
[[nodiscard]] [[nodiscard("scale result should not be discarded")]]
constexpr Vector3<float> extract_scale(const Mat4X4& mat) noexcept constexpr Vector3<float> extract_scale(const Mat4X4& mat) noexcept
{ {
return mat_extract_scale(mat); return mat_extract_scale(mat);
} }
[[nodiscard]] [[nodiscard("rotation angles result should not be discarded")]]
constexpr ViewAngles extract_rotation_angles(const Mat4X4& mat) noexcept constexpr ViewAngles extract_rotation_angles(const Mat4X4& mat) noexcept
{ {
const auto angles = mat_extract_rotation_zyx(mat); const auto angles = mat_extract_rotation_zyx(mat);
@@ -72,7 +72,7 @@ namespace omath::unity_engine
}; };
} }
[[nodiscard]] [[nodiscard("perspective projection matrix result should not be discarded")]]
constexpr Mat4X4 calc_perspective_projection_matrix( constexpr Mat4X4 calc_perspective_projection_matrix(
const float field_of_view, const float aspect_ratio, const float near_plane, const float far_plane, 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 const NDCDepthRange ndc_depth_range = NDCDepthRange::NEGATIVE_ONE_TO_ONE) noexcept
@@ -90,7 +90,7 @@ namespace omath::unity_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("centimeters value should not be discarded")]]
constexpr FloatingType units_to_centimeters(const FloatingType& units) constexpr FloatingType units_to_centimeters(const FloatingType& units)
{ {
return units / static_cast<FloatingType>(100); return units / static_cast<FloatingType>(100);
@@ -98,7 +98,7 @@ namespace omath::unity_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("meters value should not be discarded")]]
constexpr FloatingType units_to_meters(const FloatingType& units) constexpr FloatingType units_to_meters(const FloatingType& units)
{ {
return units; return units;
@@ -106,7 +106,7 @@ namespace omath::unity_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("kilometers value should not be discarded")]]
constexpr FloatingType units_to_kilometers(const FloatingType& units) constexpr FloatingType units_to_kilometers(const FloatingType& units)
{ {
return units_to_meters(units) / static_cast<FloatingType>(1000); return units_to_meters(units) / static_cast<FloatingType>(1000);
@@ -114,7 +114,7 @@ namespace omath::unity_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("units value should not be discarded")]]
constexpr FloatingType centimeters_to_units(const FloatingType& centimeters) constexpr FloatingType centimeters_to_units(const FloatingType& centimeters)
{ {
return centimeters * static_cast<FloatingType>(100); return centimeters * static_cast<FloatingType>(100);
@@ -122,7 +122,7 @@ namespace omath::unity_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("units value should not be discarded")]]
constexpr FloatingType meters_to_units(const FloatingType& meters) constexpr FloatingType meters_to_units(const FloatingType& meters)
{ {
return meters; return meters;
@@ -130,7 +130,7 @@ namespace omath::unity_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("units value should not be discarded")]]
constexpr FloatingType kilometers_to_units(const FloatingType& kilometers) constexpr FloatingType kilometers_to_units(const FloatingType& kilometers)
{ {
return meters_to_units(kilometers * static_cast<FloatingType>(1000)); return meters_to_units(kilometers * static_cast<FloatingType>(1000));
@@ -7,62 +7,62 @@
namespace omath::unreal_engine namespace omath::unreal_engine
{ {
[[nodiscard]] [[nodiscard("rotation matrix result should not be discarded")]]
inline constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept; constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
[[nodiscard]] [[nodiscard("forward vector result should not be discarded")]]
inline constexpr Vector3<double> forward_vector(const ViewAngles& angles) noexcept constexpr Vector3<double> forward_vector(const ViewAngles& angles) noexcept
{ {
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_forward); const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_forward);
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)}; return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
} }
[[nodiscard]] [[nodiscard("right vector result should not be discarded")]]
inline constexpr Vector3<double> right_vector(const ViewAngles& angles) noexcept constexpr Vector3<double> right_vector(const ViewAngles& angles) noexcept
{ {
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_right); const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_right);
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)}; return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
} }
[[nodiscard]] [[nodiscard("up vector result should not be discarded")]]
inline constexpr Vector3<double> up_vector(const ViewAngles& angles) noexcept constexpr Vector3<double> up_vector(const ViewAngles& angles) noexcept
{ {
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_up); const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_up);
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)}; return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
} }
[[nodiscard]] [[nodiscard("view matrix result should not be discarded")]]
inline constexpr Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<double>& cam_origin) noexcept constexpr Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<double>& cam_origin) noexcept
{ {
return mat_camera_view<double, MatStoreType::ROW_MAJOR>(forward_vector(angles), right_vector(angles), return mat_camera_view<double, MatStoreType::ROW_MAJOR>(forward_vector(angles), right_vector(angles),
up_vector(angles), cam_origin); up_vector(angles), cam_origin);
} }
[[nodiscard]] [[nodiscard("rotation matrix result should not be discarded")]]
inline constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept constexpr Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
{ {
return mat_rotation_axis_z<double, MatStoreType::ROW_MAJOR>(angles.yaw) return mat_rotation_axis_z<double, MatStoreType::ROW_MAJOR>(angles.yaw)
* mat_rotation_axis_y<double, MatStoreType::ROW_MAJOR>(-angles.pitch) * mat_rotation_axis_y<double, MatStoreType::ROW_MAJOR>(-angles.pitch)
* mat_rotation_axis_x<double, MatStoreType::ROW_MAJOR>(-angles.roll); * mat_rotation_axis_x<double, MatStoreType::ROW_MAJOR>(-angles.roll);
} }
[[nodiscard]] [[nodiscard("origin result should not be discarded")]]
inline constexpr Vector3<double> extract_origin(const Mat4X4& mat) noexcept constexpr Vector3<double> extract_origin(const Mat4X4& mat) noexcept
{ {
return mat_extract_origin(mat); return mat_extract_origin(mat);
} }
[[nodiscard]] [[nodiscard("scale result should not be discarded")]]
inline constexpr Vector3<double> extract_scale(const Mat4X4& mat) noexcept constexpr Vector3<double> extract_scale(const Mat4X4& mat) noexcept
{ {
return mat_extract_scale(mat); return mat_extract_scale(mat);
} }
[[nodiscard]] [[nodiscard("rotation angles result should not be discarded")]]
inline constexpr ViewAngles extract_rotation_angles(const Mat4X4& mat) noexcept constexpr ViewAngles extract_rotation_angles(const Mat4X4& mat) noexcept
{ {
const auto angles = mat_extract_rotation_zyx(mat); const auto angles = mat_extract_rotation_zyx(mat);
return { return {
@@ -72,8 +72,8 @@ namespace omath::unreal_engine
}; };
} }
[[nodiscard]] [[nodiscard("perspective projection matrix result should not be discarded")]]
inline constexpr Mat4X4 calc_perspective_projection_matrix( constexpr Mat4X4 calc_perspective_projection_matrix(
const double field_of_view, const double aspect_ratio, const double near_plane, const double far_plane, 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 const NDCDepthRange ndc_depth_range = NDCDepthRange::NEGATIVE_ONE_TO_ONE) noexcept
{ {
@@ -90,7 +90,7 @@ namespace omath::unreal_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("centimeters value should not be discarded")]]
constexpr FloatingType units_to_centimeters(const FloatingType& units) constexpr FloatingType units_to_centimeters(const FloatingType& units)
{ {
return units; return units;
@@ -98,7 +98,7 @@ namespace omath::unreal_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("meters value should not be discarded")]]
constexpr FloatingType units_to_meters(const FloatingType& units) constexpr FloatingType units_to_meters(const FloatingType& units)
{ {
return units / static_cast<FloatingType>(100); return units / static_cast<FloatingType>(100);
@@ -106,7 +106,7 @@ namespace omath::unreal_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("kilometers value should not be discarded")]]
constexpr FloatingType units_to_kilometers(const FloatingType& units) constexpr FloatingType units_to_kilometers(const FloatingType& units)
{ {
return units_to_meters(units) / static_cast<FloatingType>(1000); return units_to_meters(units) / static_cast<FloatingType>(1000);
@@ -114,7 +114,7 @@ namespace omath::unreal_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("units value should not be discarded")]]
constexpr FloatingType centimeters_to_units(const FloatingType& centimeters) constexpr FloatingType centimeters_to_units(const FloatingType& centimeters)
{ {
return centimeters; return centimeters;
@@ -122,7 +122,7 @@ namespace omath::unreal_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("units value should not be discarded")]]
constexpr FloatingType meters_to_units(const FloatingType& meters) constexpr FloatingType meters_to_units(const FloatingType& meters)
{ {
return meters * static_cast<FloatingType>(100); return meters * static_cast<FloatingType>(100);
@@ -130,7 +130,7 @@ namespace omath::unreal_engine
template<class FloatingType> template<class FloatingType>
requires std::is_floating_point_v<FloatingType> requires std::is_floating_point_v<FloatingType>
[[nodiscard]] [[nodiscard("units value should not be discarded")]]
constexpr FloatingType kilometers_to_units(const FloatingType& kilometers) constexpr FloatingType kilometers_to_units(const FloatingType& kilometers)
{ {
return meters_to_units(kilometers * static_cast<FloatingType>(1000)); return meters_to_units(kilometers * static_cast<FloatingType>(1000));