Compare commits

...

4 Commits

Author SHA1 Message Date
orange 8a591ce769 added nodiscard message 2026-06-15 22:27:12 +03:00
orange b0561c193e fix 2026-06-15 22:22:19 +03:00
orange fee4e4b9e3 added even more missing nodiscard messages 2026-06-15 20:31:57 +03:00
orange 2779bae82f added nodiscard messages 2026-06-15 20:22:35 +03:00
35 changed files with 242 additions and 233 deletions
+1
View File
@@ -6,6 +6,7 @@ Thanks to everyone who made this possible, including:
- Billy O'Neal aka BillyONeal for fixing compilation issues due to C math library compatibility. - Billy O'Neal aka BillyONeal for fixing compilation issues due to C math library compatibility.
- Alex2772 for reference of AUI declarative interface design for omath::hud. - Alex2772 for reference of AUI declarative interface design for omath::hud.
- Keith O'Hara aka kthohr for a C++ generalized constant expression-based math library that was used as reference. - Keith O'Hara aka kthohr for a C++ generalized constant expression-based math library that was used as reference.
And a big hand to everyone else who has contributed over the past! And a big hand to everyone else who has contributed over the past!
THANKS! <3 THANKS! <3
+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));
@@ -11,7 +11,7 @@ namespace omath::cry_engine
class CameraTrait final class CameraTrait final
{ {
public: public:
[[nodiscard]] [[nodiscard("look-at angle result should not be discarded")]]
constexpr static ViewAngles calc_look_at_angle(const Vector3<float>& cam_origin, constexpr static ViewAngles calc_look_at_angle(const Vector3<float>& cam_origin,
const Vector3<float>& look_at) noexcept const Vector3<float>& look_at) noexcept
{ {
@@ -20,12 +20,12 @@ namespace omath::cry_engine
YawAngle::from_radians(-internal::atan2(direction.x, direction.y)), RollAngle::from_radians(0.f)}; YawAngle::from_radians(-internal::atan2(direction.x, direction.y)), RollAngle::from_radians(0.f)};
} }
[[nodiscard]] [[nodiscard("view matrix result should not be discarded")]]
constexpr static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept constexpr static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
{ {
return cry_engine::calc_view_matrix(angles, cam_origin); return cry_engine::calc_view_matrix(angles, cam_origin);
} }
[[nodiscard]] [[nodiscard("projection matrix result should not be discarded")]]
constexpr static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov, constexpr static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov,
const projection::ViewPort& view_port, const float near_plane, const projection::ViewPort& view_port, const float near_plane,
const float far_plane, const float far_plane,
@@ -10,7 +10,7 @@ namespace omath::cry_engine
class MeshTrait final class MeshTrait final
{ {
public: public:
[[nodiscard]] [[nodiscard("rotation matrix result should not be discarded")]]
static Mat4X4 rotation_matrix(const ViewAngles& rotation) static Mat4X4 rotation_matrix(const ViewAngles& rotation)
{ {
return cry_engine::rotation_matrix(rotation); return cry_engine::rotation_matrix(rotation);
@@ -12,6 +12,7 @@ namespace omath::cry_engine
class PredEngineTrait final class PredEngineTrait final
{ {
public: public:
[[nodiscard("projectile position result should not be discarded")]]
constexpr static Vector3<float> predict_projectile_position(const projectile_prediction::Projectile<float>& projectile, constexpr static Vector3<float> predict_projectile_position(const projectile_prediction::Projectile<float>& projectile,
const float pitch, const float yaw, const float pitch, const float yaw,
const float time, const float gravity) noexcept const float time, const float gravity) noexcept
@@ -25,7 +26,7 @@ namespace omath::cry_engine
return current_pos; return current_pos;
} }
[[nodiscard]] [[nodiscard("target position result should not be discarded")]]
static constexpr Vector3<float> predict_target_position(const projectile_prediction::Target<float>& target, static constexpr Vector3<float> predict_target_position(const projectile_prediction::Target<float>& target,
const float time, const float gravity) noexcept const float time, const float gravity) noexcept
{ {
@@ -36,19 +37,19 @@ namespace omath::cry_engine
return predicted; return predicted;
} }
[[nodiscard]] [[nodiscard("2d distance result should not be discarded")]]
static float calc_vector_2d_distance(const Vector3<float>& delta) noexcept static float calc_vector_2d_distance(const Vector3<float>& delta) noexcept
{ {
return std::sqrt(delta.x * delta.x + delta.y * delta.y); return std::sqrt(delta.x * delta.x + delta.y * delta.y);
} }
[[nodiscard]] [[nodiscard("height coordinate result should not be discarded")]]
constexpr static float get_vector_height_coordinate(const Vector3<float>& vec) noexcept constexpr static float get_vector_height_coordinate(const Vector3<float>& vec) noexcept
{ {
return vec.z; return vec.z;
} }
[[nodiscard]] [[nodiscard("viewpoint result should not be discarded")]]
static Vector3<float> calc_viewpoint_from_angles(const projectile_prediction::Projectile<float>& projectile, static Vector3<float> calc_viewpoint_from_angles(const projectile_prediction::Projectile<float>& projectile,
Vector3<float> predicted_target_position, Vector3<float> predicted_target_position,
const std::optional<float> projectile_pitch) noexcept const std::optional<float> projectile_pitch) noexcept
@@ -60,13 +61,13 @@ namespace omath::cry_engine
} }
// Due to specification of maybe_calculate_projectile_launch_pitch_angle, pitch angle must be: // Due to specification of maybe_calculate_projectile_launch_pitch_angle, pitch angle must be:
// 89 look up, -89 look down // 89 look up, -89 look down
[[nodiscard]] [[nodiscard("pitch angle result should not be discarded")]]
static float calc_direct_pitch_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept static float calc_direct_pitch_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept
{ {
const auto direction = (view_to - origin).normalized(); const auto direction = (view_to - origin).normalized();
return angles::radians_to_degrees(std::asin(direction.z)); return angles::radians_to_degrees(std::asin(direction.z));
} }
[[nodiscard]] [[nodiscard("yaw angle result should not be discarded")]]
static float calc_direct_yaw_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept static float calc_direct_yaw_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept
{ {
const auto direction = (view_to - origin).normalized(); const auto direction = (view_to - origin).normalized();
@@ -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));
@@ -12,7 +12,7 @@ namespace omath::frostbite_engine
class CameraTrait final class CameraTrait final
{ {
public: public:
[[nodiscard]] [[nodiscard("look-at angle result should not be discarded")]]
constexpr static ViewAngles calc_look_at_angle(const Vector3<float>& cam_origin, constexpr static ViewAngles calc_look_at_angle(const Vector3<float>& cam_origin,
const Vector3<float>& look_at) noexcept const Vector3<float>& look_at) noexcept
{ {
@@ -22,12 +22,12 @@ namespace omath::frostbite_engine
YawAngle::from_radians(internal::atan2(direction.x, direction.z)), RollAngle::from_radians(0.f)}; YawAngle::from_radians(internal::atan2(direction.x, direction.z)), RollAngle::from_radians(0.f)};
} }
[[nodiscard]] [[nodiscard("view matrix result should not be discarded")]]
constexpr static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept constexpr static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
{ {
return frostbite_engine::calc_view_matrix(angles, cam_origin); return frostbite_engine::calc_view_matrix(angles, cam_origin);
} }
[[nodiscard]] [[nodiscard("projection matrix result should not be discarded")]]
constexpr static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov, constexpr static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov,
const projection::ViewPort& view_port, const float near_plane, const projection::ViewPort& view_port, const float near_plane,
const float far_plane, const float far_plane,
@@ -10,7 +10,7 @@ namespace omath::frostbite_engine
class MeshTrait final class MeshTrait final
{ {
public: public:
[[nodiscard]] [[nodiscard("rotation matrix result should not be discarded")]]
static Mat4X4 rotation_matrix(const ViewAngles& rotation) static Mat4X4 rotation_matrix(const ViewAngles& rotation)
{ {
return frostbite_engine::rotation_matrix(rotation); return frostbite_engine::rotation_matrix(rotation);
@@ -12,6 +12,7 @@ namespace omath::frostbite_engine
class PredEngineTrait final class PredEngineTrait final
{ {
public: public:
[[nodiscard("projectile position result should not be discarded")]]
constexpr static Vector3<float> predict_projectile_position(const projectile_prediction::Projectile<float>& projectile, constexpr static Vector3<float> predict_projectile_position(const projectile_prediction::Projectile<float>& projectile,
const float pitch, const float yaw, const float pitch, const float yaw,
const float time, const float gravity) noexcept const float time, const float gravity) noexcept
@@ -25,7 +26,7 @@ namespace omath::frostbite_engine
return current_pos; return current_pos;
} }
[[nodiscard]] [[nodiscard("target position result should not be discarded")]]
static constexpr Vector3<float> predict_target_position(const projectile_prediction::Target<float>& target, static constexpr Vector3<float> predict_target_position(const projectile_prediction::Target<float>& target,
const float time, const float gravity) noexcept const float time, const float gravity) noexcept
{ {
@@ -36,19 +37,19 @@ namespace omath::frostbite_engine
return predicted; return predicted;
} }
[[nodiscard]] [[nodiscard("2d distance result should not be discarded")]]
static float calc_vector_2d_distance(const Vector3<float>& delta) noexcept static float calc_vector_2d_distance(const Vector3<float>& delta) noexcept
{ {
return std::sqrt(delta.x * delta.x + delta.z * delta.z); return std::sqrt(delta.x * delta.x + delta.z * delta.z);
} }
[[nodiscard]] [[nodiscard("height coordinate result should not be discarded")]]
constexpr static float get_vector_height_coordinate(const Vector3<float>& vec) noexcept constexpr static float get_vector_height_coordinate(const Vector3<float>& vec) noexcept
{ {
return vec.y; return vec.y;
} }
[[nodiscard]] [[nodiscard("viewpoint result should not be discarded")]]
static Vector3<float> calc_viewpoint_from_angles(const projectile_prediction::Projectile<float>& projectile, static Vector3<float> calc_viewpoint_from_angles(const projectile_prediction::Projectile<float>& projectile,
Vector3<float> predicted_target_position, Vector3<float> predicted_target_position,
const std::optional<float> projectile_pitch) noexcept const std::optional<float> projectile_pitch) noexcept
@@ -60,13 +61,13 @@ namespace omath::frostbite_engine
} }
// Due to specification of maybe_calculate_projectile_launch_pitch_angle, pitch angle must be: // Due to specification of maybe_calculate_projectile_launch_pitch_angle, pitch angle must be:
// 89 look up, -89 look down // 89 look up, -89 look down
[[nodiscard]] [[nodiscard("pitch angle result should not be discarded")]]
static float calc_direct_pitch_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept static float calc_direct_pitch_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept
{ {
const auto direction = (view_to - origin).normalized(); const auto direction = (view_to - origin).normalized();
return angles::radians_to_degrees(std::asin(direction.y)); return angles::radians_to_degrees(std::asin(direction.y));
} }
[[nodiscard]] [[nodiscard("yaw angle result should not be discarded")]]
static float calc_direct_yaw_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept static float calc_direct_yaw_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept
{ {
const auto direction = (view_to - origin).normalized(); const auto direction = (view_to - origin).normalized();
+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));
@@ -12,7 +12,7 @@ namespace omath::iw_engine
class CameraTrait final class CameraTrait final
{ {
public: public:
[[nodiscard]] [[nodiscard("look-at angle result should not be discarded")]]
constexpr static ViewAngles calc_look_at_angle(const Vector3<float>& cam_origin, constexpr static ViewAngles calc_look_at_angle(const Vector3<float>& cam_origin,
const Vector3<float>& look_at) noexcept const Vector3<float>& look_at) noexcept
{ {
@@ -22,12 +22,12 @@ namespace omath::iw_engine
YawAngle::from_radians(internal::atan2(direction.y, direction.x)), RollAngle::from_radians(0.f)}; YawAngle::from_radians(internal::atan2(direction.y, direction.x)), RollAngle::from_radians(0.f)};
} }
[[nodiscard]] [[nodiscard("view matrix result should not be discarded")]]
constexpr static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept constexpr static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
{ {
return iw_engine::calc_view_matrix(angles, cam_origin); return iw_engine::calc_view_matrix(angles, cam_origin);
} }
[[nodiscard]] [[nodiscard("projection matrix result should not be discarded")]]
constexpr static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov, constexpr static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov,
const projection::ViewPort& view_port, const float near_plane, const projection::ViewPort& view_port, const float near_plane,
const float far_plane, const float far_plane,
@@ -10,7 +10,7 @@ namespace omath::iw_engine
class MeshTrait final class MeshTrait final
{ {
public: public:
[[nodiscard]] [[nodiscard("rotation matrix result should not be discarded")]]
static Mat4X4 rotation_matrix(const ViewAngles& rotation) static Mat4X4 rotation_matrix(const ViewAngles& rotation)
{ {
return iw_engine::rotation_matrix(rotation); return iw_engine::rotation_matrix(rotation);
@@ -13,6 +13,7 @@ namespace omath::iw_engine
class PredEngineTrait final class PredEngineTrait final
{ {
public: public:
[[nodiscard("projectile position result should not be discarded")]]
constexpr static Vector3<float> predict_projectile_position(const projectile_prediction::Projectile<float>& projectile, constexpr static Vector3<float> predict_projectile_position(const projectile_prediction::Projectile<float>& projectile,
const float pitch, const float yaw, const float pitch, const float yaw,
const float time, const float gravity) noexcept const float time, const float gravity) noexcept
@@ -26,7 +27,7 @@ namespace omath::iw_engine
return current_pos; return current_pos;
} }
[[nodiscard]] [[nodiscard("target position result should not be discarded")]]
static constexpr Vector3<float> predict_target_position(const projectile_prediction::Target<float>& target, static constexpr Vector3<float> predict_target_position(const projectile_prediction::Target<float>& target,
const float time, const float gravity) noexcept const float time, const float gravity) noexcept
{ {
@@ -37,19 +38,19 @@ namespace omath::iw_engine
return predicted; return predicted;
} }
[[nodiscard]] [[nodiscard("2d distance result should not be discarded")]]
static float calc_vector_2d_distance(const Vector3<float>& delta) noexcept static float calc_vector_2d_distance(const Vector3<float>& delta) noexcept
{ {
return std::sqrt(delta.x * delta.x + delta.y * delta.y); return std::sqrt(delta.x * delta.x + delta.y * delta.y);
} }
[[nodiscard]] [[nodiscard("height coordinate result should not be discarded")]]
constexpr static float get_vector_height_coordinate(const Vector3<float>& vec) noexcept constexpr static float get_vector_height_coordinate(const Vector3<float>& vec) noexcept
{ {
return vec.z; return vec.z;
} }
[[nodiscard]] [[nodiscard("viewpoint result should not be discarded")]]
static Vector3<float> calc_viewpoint_from_angles(const projectile_prediction::Projectile<float>& projectile, static Vector3<float> calc_viewpoint_from_angles(const projectile_prediction::Projectile<float>& projectile,
Vector3<float> predicted_target_position, Vector3<float> predicted_target_position,
const std::optional<float> projectile_pitch) noexcept const std::optional<float> projectile_pitch) noexcept
@@ -61,7 +62,7 @@ namespace omath::iw_engine
} }
// Due to specification of maybe_calculate_projectile_launch_pitch_angle, pitch angle must be: // Due to specification of maybe_calculate_projectile_launch_pitch_angle, pitch angle must be:
// 89 look up, -89 look down // 89 look up, -89 look down
[[nodiscard]] [[nodiscard("pitch angle result should not be discarded")]]
static float calc_direct_pitch_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept static float calc_direct_pitch_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept
{ {
const auto distance = origin.distance_to(view_to); const auto distance = origin.distance_to(view_to);
@@ -69,7 +70,7 @@ namespace omath::iw_engine
return angles::radians_to_degrees(std::asin(delta.z / distance)); return angles::radians_to_degrees(std::asin(delta.z / distance));
} }
[[nodiscard]] [[nodiscard("yaw angle result should not be discarded")]]
static float calc_direct_yaw_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept static float calc_direct_yaw_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept
{ {
const auto delta = view_to - origin; const auto delta = view_to - origin;
@@ -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));
@@ -12,7 +12,7 @@ namespace omath::opengl_engine
class CameraTrait final class CameraTrait final
{ {
public: public:
[[nodiscard]] [[nodiscard("look-at angle result should not be discarded")]]
constexpr static ViewAngles calc_look_at_angle(const Vector3<float>& cam_origin, constexpr static ViewAngles calc_look_at_angle(const Vector3<float>& cam_origin,
const Vector3<float>& look_at) noexcept const Vector3<float>& look_at) noexcept
{ {
@@ -22,12 +22,12 @@ namespace omath::opengl_engine
YawAngle::from_radians(-internal::atan2(direction.x, -direction.z)), RollAngle::from_radians(0.f)}; YawAngle::from_radians(-internal::atan2(direction.x, -direction.z)), RollAngle::from_radians(0.f)};
} }
[[nodiscard]] [[nodiscard("view matrix result should not be discarded")]]
constexpr static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept constexpr static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
{ {
return opengl_engine::calc_view_matrix(angles, cam_origin); return opengl_engine::calc_view_matrix(angles, cam_origin);
} }
[[nodiscard]] [[nodiscard("projection matrix result should not be discarded")]]
constexpr static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov, constexpr static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov,
const projection::ViewPort& view_port, const float near_plane, const projection::ViewPort& view_port, const float near_plane,
const float far_plane, const float far_plane,
@@ -10,7 +10,7 @@ namespace omath::opengl_engine
class MeshTrait final class MeshTrait final
{ {
public: public:
[[nodiscard]] [[nodiscard("rotation matrix result should not be discarded")]]
static Mat4X4 rotation_matrix(const ViewAngles& rotation) static Mat4X4 rotation_matrix(const ViewAngles& rotation)
{ {
return opengl_engine::rotation_matrix(rotation); return opengl_engine::rotation_matrix(rotation);
@@ -12,6 +12,7 @@ namespace omath::opengl_engine
class PredEngineTrait final class PredEngineTrait final
{ {
public: public:
[[nodiscard("projectile position result should not be discarded")]]
constexpr static Vector3<float> predict_projectile_position(const projectile_prediction::Projectile<float>& projectile, constexpr static Vector3<float> predict_projectile_position(const projectile_prediction::Projectile<float>& projectile,
const float pitch, const float yaw, const float pitch, const float yaw,
const float time, const float gravity) noexcept const float time, const float gravity) noexcept
@@ -25,7 +26,7 @@ namespace omath::opengl_engine
return current_pos; return current_pos;
} }
[[nodiscard]] [[nodiscard("target position result should not be discarded")]]
static constexpr Vector3<float> predict_target_position(const projectile_prediction::Target<float>& target, static constexpr Vector3<float> predict_target_position(const projectile_prediction::Target<float>& target,
const float time, const float gravity) noexcept const float time, const float gravity) noexcept
{ {
@@ -36,19 +37,19 @@ namespace omath::opengl_engine
return predicted; return predicted;
} }
[[nodiscard]] [[nodiscard("2d distance result should not be discarded")]]
static float calc_vector_2d_distance(const Vector3<float>& delta) noexcept static float calc_vector_2d_distance(const Vector3<float>& delta) noexcept
{ {
return std::sqrt(delta.x * delta.x + delta.z * delta.z); return std::sqrt(delta.x * delta.x + delta.z * delta.z);
} }
[[nodiscard]] [[nodiscard("height coordinate result should not be discarded")]]
constexpr static float get_vector_height_coordinate(const Vector3<float>& vec) noexcept constexpr static float get_vector_height_coordinate(const Vector3<float>& vec) noexcept
{ {
return vec.y; return vec.y;
} }
[[nodiscard]] [[nodiscard("viewpoint result should not be discarded")]]
static Vector3<float> calc_viewpoint_from_angles(const projectile_prediction::Projectile<float>& projectile, static Vector3<float> calc_viewpoint_from_angles(const projectile_prediction::Projectile<float>& projectile,
Vector3<float> predicted_target_position, Vector3<float> predicted_target_position,
const std::optional<float> projectile_pitch) noexcept const std::optional<float> projectile_pitch) noexcept
@@ -60,13 +61,13 @@ namespace omath::opengl_engine
} }
// Due to specification of maybe_calculate_projectile_launch_pitch_angle, pitch angle must be: // Due to specification of maybe_calculate_projectile_launch_pitch_angle, pitch angle must be:
// 89 look up, -89 look down // 89 look up, -89 look down
[[nodiscard]] [[nodiscard("pitch angle result should not be discarded")]]
static float calc_direct_pitch_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept static float calc_direct_pitch_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept
{ {
const auto direction = (view_to - origin).normalized(); const auto direction = (view_to - origin).normalized();
return angles::radians_to_degrees(std::asin(direction.y)); return angles::radians_to_degrees(std::asin(direction.y));
} }
[[nodiscard]] [[nodiscard("yaw angle result should not be discarded")]]
static float calc_direct_yaw_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept static float calc_direct_yaw_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept
{ {
const auto direction = (view_to - origin).normalized(); const auto direction = (view_to - origin).normalized();
+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));
@@ -12,7 +12,7 @@ namespace omath::rage_engine
class CameraTrait final class CameraTrait final
{ {
public: public:
[[nodiscard]] [[nodiscard("look-at angle result should not be discarded")]]
constexpr static ViewAngles calc_look_at_angle(const Vector3<float>& cam_origin, constexpr static ViewAngles calc_look_at_angle(const Vector3<float>& cam_origin,
const Vector3<float>& look_at) noexcept const Vector3<float>& look_at) noexcept
{ {
@@ -22,12 +22,12 @@ namespace omath::rage_engine
YawAngle::from_radians(-internal::atan2(direction.x, direction.y)), RollAngle::from_radians(0.f)}; YawAngle::from_radians(-internal::atan2(direction.x, direction.y)), RollAngle::from_radians(0.f)};
} }
[[nodiscard]] [[nodiscard("view matrix result should not be discarded")]]
constexpr static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept constexpr static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
{ {
return rage_engine::calc_view_matrix(angles, cam_origin); return rage_engine::calc_view_matrix(angles, cam_origin);
} }
[[nodiscard]] [[nodiscard("projection matrix result should not be discarded")]]
constexpr static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov, constexpr static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov,
const projection::ViewPort& view_port, const float near_plane, const projection::ViewPort& view_port, const float near_plane,
const float far_plane, const float far_plane,
@@ -11,7 +11,7 @@ namespace omath::rage_engine
class MeshTrait final class MeshTrait final
{ {
public: public:
[[nodiscard]] [[nodiscard("rotation matrix result should not be discarded")]]
static Mat4X4 rotation_matrix(const ViewAngles& rotation) static Mat4X4 rotation_matrix(const ViewAngles& rotation)
{ {
return rage_engine::rotation_matrix(rotation); return rage_engine::rotation_matrix(rotation);
@@ -13,6 +13,7 @@ namespace omath::rage_engine
class PredEngineTrait final class PredEngineTrait final
{ {
public: public:
[[nodiscard("projectile position result should not be discarded")]]
constexpr static Vector3<float> constexpr static Vector3<float>
predict_projectile_position(const projectile_prediction::Projectile<float>& projectile, const float pitch, predict_projectile_position(const projectile_prediction::Projectile<float>& projectile, const float pitch,
const float yaw, const float time, const float gravity) noexcept const float yaw, const float time, const float gravity) noexcept
@@ -26,7 +27,7 @@ namespace omath::rage_engine
return current_pos; return current_pos;
} }
[[nodiscard]] [[nodiscard("target position result should not be discarded")]]
static constexpr Vector3<float> predict_target_position(const projectile_prediction::Target<float>& target, static constexpr Vector3<float> predict_target_position(const projectile_prediction::Target<float>& target,
const float time, const float gravity) noexcept const float time, const float gravity) noexcept
{ {
@@ -37,19 +38,19 @@ namespace omath::rage_engine
return predicted; return predicted;
} }
[[nodiscard]] [[nodiscard("2d distance result should not be discarded")]]
static float calc_vector_2d_distance(const Vector3<float>& delta) noexcept static float calc_vector_2d_distance(const Vector3<float>& delta) noexcept
{ {
return std::sqrt(delta.x * delta.x + delta.y * delta.y); return std::sqrt(delta.x * delta.x + delta.y * delta.y);
} }
[[nodiscard]] [[nodiscard("height coordinate result should not be discarded")]]
constexpr static float get_vector_height_coordinate(const Vector3<float>& vec) noexcept constexpr static float get_vector_height_coordinate(const Vector3<float>& vec) noexcept
{ {
return vec.z; return vec.z;
} }
[[nodiscard]] [[nodiscard("viewpoint result should not be discarded")]]
static Vector3<float> calc_viewpoint_from_angles(const projectile_prediction::Projectile<float>& projectile, static Vector3<float> calc_viewpoint_from_angles(const projectile_prediction::Projectile<float>& projectile,
Vector3<float> predicted_target_position, Vector3<float> predicted_target_position,
const std::optional<float> projectile_pitch) noexcept const std::optional<float> projectile_pitch) noexcept
@@ -59,13 +60,13 @@ namespace omath::rage_engine
return {predicted_target_position.x, predicted_target_position.y, projectile.m_origin.z + height}; return {predicted_target_position.x, predicted_target_position.y, projectile.m_origin.z + height};
} }
[[nodiscard]] [[nodiscard("pitch angle result should not be discarded")]]
static float calc_direct_pitch_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept static float calc_direct_pitch_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept
{ {
const auto direction = (view_to - origin).normalized(); const auto direction = (view_to - origin).normalized();
return angles::radians_to_degrees(std::asin(direction.z)); return angles::radians_to_degrees(std::asin(direction.z));
} }
[[nodiscard]] [[nodiscard("yaw angle result should not be discarded")]]
static float calc_direct_yaw_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept static float calc_direct_yaw_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept
{ {
const auto direction = (view_to - origin).normalized(); const auto direction = (view_to - origin).normalized();
@@ -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));
@@ -12,7 +12,7 @@ namespace omath::source_engine
class CameraTrait final class CameraTrait final
{ {
public: public:
[[nodiscard]] [[nodiscard("look-at angle result should not be discarded")]]
constexpr static ViewAngles calc_look_at_angle(const Vector3<float>& cam_origin, constexpr static ViewAngles calc_look_at_angle(const Vector3<float>& cam_origin,
const Vector3<float>& look_at) noexcept const Vector3<float>& look_at) noexcept
{ {
@@ -22,12 +22,12 @@ namespace omath::source_engine
YawAngle::from_radians(internal::atan2(direction.y, direction.x)), RollAngle::from_radians(0.f)}; YawAngle::from_radians(internal::atan2(direction.y, direction.x)), RollAngle::from_radians(0.f)};
} }
[[nodiscard]] [[nodiscard("view matrix result should not be discarded")]]
constexpr static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept constexpr static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
{ {
return source_engine::calc_view_matrix(angles, cam_origin); return source_engine::calc_view_matrix(angles, cam_origin);
} }
[[nodiscard]] [[nodiscard("projection matrix result should not be discarded")]]
constexpr static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov, constexpr static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov,
const projection::ViewPort& view_port, const float near_plane, const projection::ViewPort& view_port, const float near_plane,
const float far_plane, const float far_plane,
@@ -10,7 +10,7 @@ namespace omath::source_engine
class MeshTrait final class MeshTrait final
{ {
public: public:
[[nodiscard]] [[nodiscard("rotation matrix result should not be discarded")]]
static Mat4X4 rotation_matrix(const ViewAngles& rotation) static Mat4X4 rotation_matrix(const ViewAngles& rotation)
{ {
return source_engine::rotation_matrix(rotation); return source_engine::rotation_matrix(rotation);
@@ -13,6 +13,7 @@ namespace omath::source_engine
class PredEngineTrait final class PredEngineTrait final
{ {
public: public:
[[nodiscard("projectile position result should not be discarded")]]
constexpr static Vector3<float> predict_projectile_position(const projectile_prediction::Projectile<float>& projectile, constexpr static Vector3<float> predict_projectile_position(const projectile_prediction::Projectile<float>& projectile,
const float pitch, const float yaw, const float pitch, const float yaw,
const float time, const float gravity) noexcept const float time, const float gravity) noexcept
@@ -26,7 +27,7 @@ namespace omath::source_engine
return current_pos; return current_pos;
} }
[[nodiscard]] [[nodiscard("target position result should not be discarded")]]
static constexpr Vector3<float> predict_target_position(const projectile_prediction::Target<float>& target, static constexpr Vector3<float> predict_target_position(const projectile_prediction::Target<float>& target,
const float time, const float gravity) noexcept const float time, const float gravity) noexcept
{ {
@@ -37,19 +38,19 @@ namespace omath::source_engine
return predicted; return predicted;
} }
[[nodiscard]] [[nodiscard("2d distance result should not be discarded")]]
static float calc_vector_2d_distance(const Vector3<float>& delta) noexcept static float calc_vector_2d_distance(const Vector3<float>& delta) noexcept
{ {
return std::sqrt(delta.x * delta.x + delta.y * delta.y); return std::sqrt(delta.x * delta.x + delta.y * delta.y);
} }
[[nodiscard]] [[nodiscard("height coordinate result should not be discarded")]]
constexpr static float get_vector_height_coordinate(const Vector3<float>& vec) noexcept constexpr static float get_vector_height_coordinate(const Vector3<float>& vec) noexcept
{ {
return vec.z; return vec.z;
} }
[[nodiscard]] [[nodiscard("viewpoint result should not be discarded")]]
static Vector3<float> calc_viewpoint_from_angles(const projectile_prediction::Projectile<float>& projectile, static Vector3<float> calc_viewpoint_from_angles(const projectile_prediction::Projectile<float>& projectile,
Vector3<float> predicted_target_position, Vector3<float> predicted_target_position,
const std::optional<float> projectile_pitch) noexcept const std::optional<float> projectile_pitch) noexcept
@@ -61,7 +62,7 @@ namespace omath::source_engine
} }
// Due to specification of maybe_calculate_projectile_launch_pitch_angle, pitch angle must be: // Due to specification of maybe_calculate_projectile_launch_pitch_angle, pitch angle must be:
// 89 look up, -89 look down // 89 look up, -89 look down
[[nodiscard]] [[nodiscard("pitch angle result should not be discarded")]]
static float calc_direct_pitch_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept static float calc_direct_pitch_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept
{ {
const auto distance = origin.distance_to(view_to); const auto distance = origin.distance_to(view_to);
@@ -69,7 +70,7 @@ namespace omath::source_engine
return angles::radians_to_degrees(std::asin(delta.z / distance)); return angles::radians_to_degrees(std::asin(delta.z / distance));
} }
[[nodiscard]] [[nodiscard("yaw angle result should not be discarded")]]
static float calc_direct_yaw_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept static float calc_direct_yaw_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept
{ {
const auto delta = view_to - origin; const auto delta = view_to - origin;
+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));
@@ -12,7 +12,7 @@ namespace omath::unity_engine
class CameraTrait final class CameraTrait final
{ {
public: public:
[[nodiscard]] [[nodiscard("look-at angle result should not be discarded")]]
constexpr static ViewAngles calc_look_at_angle(const Vector3<float>& cam_origin, constexpr static ViewAngles calc_look_at_angle(const Vector3<float>& cam_origin,
const Vector3<float>& look_at) noexcept const Vector3<float>& look_at) noexcept
{ {
@@ -22,12 +22,12 @@ namespace omath::unity_engine
YawAngle::from_radians(internal::atan2(direction.x, direction.z)), RollAngle::from_radians(0.f)}; YawAngle::from_radians(internal::atan2(direction.x, direction.z)), RollAngle::from_radians(0.f)};
} }
[[nodiscard]] [[nodiscard("view matrix result should not be discarded")]]
constexpr static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept constexpr static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
{ {
return unity_engine::calc_view_matrix(angles, cam_origin); return unity_engine::calc_view_matrix(angles, cam_origin);
} }
[[nodiscard]] [[nodiscard("projection matrix result should not be discarded")]]
constexpr static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov, constexpr static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov,
const projection::ViewPort& view_port, const float near_plane, const projection::ViewPort& view_port, const float near_plane,
const float far_plane, const float far_plane,
@@ -10,7 +10,7 @@ namespace omath::unity_engine
class MeshTrait final class MeshTrait final
{ {
public: public:
[[nodiscard]] [[nodiscard("rotation matrix result should not be discarded")]]
static Mat4X4 rotation_matrix(const ViewAngles& rotation) static Mat4X4 rotation_matrix(const ViewAngles& rotation)
{ {
return unity_engine::rotation_matrix(rotation); return unity_engine::rotation_matrix(rotation);
@@ -12,6 +12,7 @@ namespace omath::unity_engine
class PredEngineTrait final class PredEngineTrait final
{ {
public: public:
[[nodiscard("projectile position result should not be discarded")]]
constexpr static Vector3<float> predict_projectile_position(const projectile_prediction::Projectile<float>& projectile, constexpr static Vector3<float> predict_projectile_position(const projectile_prediction::Projectile<float>& projectile,
const float pitch, const float yaw, const float pitch, const float yaw,
const float time, const float gravity) noexcept const float time, const float gravity) noexcept
@@ -25,7 +26,7 @@ namespace omath::unity_engine
return current_pos; return current_pos;
} }
[[nodiscard]] [[nodiscard("target position result should not be discarded")]]
static constexpr Vector3<float> predict_target_position(const projectile_prediction::Target<float>& target, static constexpr Vector3<float> predict_target_position(const projectile_prediction::Target<float>& target,
const float time, const float gravity) noexcept const float time, const float gravity) noexcept
{ {
@@ -36,19 +37,19 @@ namespace omath::unity_engine
return predicted; return predicted;
} }
[[nodiscard]] [[nodiscard("2d distance result should not be discarded")]]
static float calc_vector_2d_distance(const Vector3<float>& delta) noexcept static float calc_vector_2d_distance(const Vector3<float>& delta) noexcept
{ {
return std::sqrt(delta.x * delta.x + delta.z * delta.z); return std::sqrt(delta.x * delta.x + delta.z * delta.z);
} }
[[nodiscard]] [[nodiscard("height coordinate result should not be discarded")]]
constexpr static float get_vector_height_coordinate(const Vector3<float>& vec) noexcept constexpr static float get_vector_height_coordinate(const Vector3<float>& vec) noexcept
{ {
return vec.y; return vec.y;
} }
[[nodiscard]] [[nodiscard("viewpoint result should not be discarded")]]
static Vector3<float> calc_viewpoint_from_angles(const projectile_prediction::Projectile<float>& projectile, static Vector3<float> calc_viewpoint_from_angles(const projectile_prediction::Projectile<float>& projectile,
Vector3<float> predicted_target_position, Vector3<float> predicted_target_position,
const std::optional<float> projectile_pitch) noexcept const std::optional<float> projectile_pitch) noexcept
@@ -60,13 +61,13 @@ namespace omath::unity_engine
} }
// Due to specification of maybe_calculate_projectile_launch_pitch_angle, pitch angle must be: // Due to specification of maybe_calculate_projectile_launch_pitch_angle, pitch angle must be:
// 89 look up, -89 look down // 89 look up, -89 look down
[[nodiscard]] [[nodiscard("pitch angle result should not be discarded")]]
static float calc_direct_pitch_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept static float calc_direct_pitch_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept
{ {
const auto direction = (view_to - origin).normalized(); const auto direction = (view_to - origin).normalized();
return angles::radians_to_degrees(std::asin(direction.y)); return angles::radians_to_degrees(std::asin(direction.y));
} }
[[nodiscard]] [[nodiscard("yaw angle result should not be discarded")]]
static float calc_direct_yaw_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept static float calc_direct_yaw_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept
{ {
const auto direction = (view_to - origin).normalized(); const auto direction = (view_to - origin).normalized();
@@ -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));
@@ -12,7 +12,7 @@ namespace omath::unreal_engine
class CameraTrait final class CameraTrait final
{ {
public: public:
[[nodiscard]] [[nodiscard("look-at angle result should not be discarded")]]
constexpr static ViewAngles calc_look_at_angle(const Vector3<double>& cam_origin, constexpr static ViewAngles calc_look_at_angle(const Vector3<double>& cam_origin,
const Vector3<double>& look_at) noexcept const Vector3<double>& look_at) noexcept
{ {
@@ -22,12 +22,12 @@ namespace omath::unreal_engine
YawAngle::from_radians(internal::atan2(direction.y, direction.x)), RollAngle::from_radians(0.f)}; YawAngle::from_radians(internal::atan2(direction.y, direction.x)), RollAngle::from_radians(0.f)};
} }
[[nodiscard]] [[nodiscard("view matrix result should not be discarded")]]
constexpr static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<double>& cam_origin) noexcept constexpr static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<double>& cam_origin) noexcept
{ {
return unreal_engine::calc_view_matrix(angles, cam_origin); return unreal_engine::calc_view_matrix(angles, cam_origin);
} }
[[nodiscard]] [[nodiscard("projection matrix result should not be discarded")]]
constexpr static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov, constexpr static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov,
const projection::ViewPort& view_port, const double near_plane, const projection::ViewPort& view_port, const double near_plane,
const double far_plane, const double far_plane,
@@ -10,7 +10,7 @@ namespace omath::unreal_engine
class MeshTrait final class MeshTrait final
{ {
public: public:
[[nodiscard]] [[nodiscard("rotation matrix result should not be discarded")]]
static Mat4X4 rotation_matrix(const ViewAngles& rotation) static Mat4X4 rotation_matrix(const ViewAngles& rotation)
{ {
return unreal_engine::rotation_matrix(rotation); return unreal_engine::rotation_matrix(rotation);
@@ -12,6 +12,7 @@ namespace omath::unreal_engine
class PredEngineTrait final class PredEngineTrait final
{ {
public: public:
[[nodiscard("projectile position result should not be discarded")]]
static Vector3<double> predict_projectile_position(const projectile_prediction::Projectile<double>& projectile, static Vector3<double> predict_projectile_position(const projectile_prediction::Projectile<double>& projectile,
const double pitch, const double yaw, const double pitch, const double yaw,
const double time, const double gravity) noexcept const double time, const double gravity) noexcept
@@ -27,7 +28,7 @@ namespace omath::unreal_engine
return current_pos; return current_pos;
} }
[[nodiscard]] [[nodiscard("target position result should not be discarded")]]
static Vector3<double> predict_target_position(const projectile_prediction::Target<double>& target, static Vector3<double> predict_target_position(const projectile_prediction::Target<double>& target,
const double time, const double gravity) noexcept const double time, const double gravity) noexcept
{ {
@@ -39,19 +40,19 @@ namespace omath::unreal_engine
return predicted; return predicted;
} }
[[nodiscard]] [[nodiscard("2d distance result should not be discarded")]]
static double calc_vector_2d_distance(const Vector3<double>& delta) noexcept static double calc_vector_2d_distance(const Vector3<double>& delta) noexcept
{ {
return std::sqrt(delta.x * delta.x + delta.z * delta.z); return std::sqrt(delta.x * delta.x + delta.z * delta.z);
} }
[[nodiscard]] [[nodiscard("height coordinate result should not be discarded")]]
static double get_vector_height_coordinate(const Vector3<double>& vec) noexcept static double get_vector_height_coordinate(const Vector3<double>& vec) noexcept
{ {
return vec.y; return vec.y;
} }
[[nodiscard]] [[nodiscard("viewpoint result should not be discarded")]]
static Vector3<double> calc_viewpoint_from_angles(const projectile_prediction::Projectile<double>& projectile, static Vector3<double> calc_viewpoint_from_angles(const projectile_prediction::Projectile<double>& projectile,
Vector3<double> predicted_target_position, Vector3<double> predicted_target_position,
const std::optional<double> projectile_pitch) noexcept const std::optional<double> projectile_pitch) noexcept
@@ -64,7 +65,7 @@ namespace omath::unreal_engine
// Due to specification of maybe_calculate_projectile_launch_pitch_angle, pitch angle must be: // Due to specification of maybe_calculate_projectile_launch_pitch_angle, pitch angle must be:
// 89 look up, -89 look down // 89 look up, -89 look down
[[nodiscard]] [[nodiscard("pitch angle result should not be discarded")]]
static double calc_direct_pitch_angle(const Vector3<double>& origin, const Vector3<double>& view_to) noexcept static double calc_direct_pitch_angle(const Vector3<double>& origin, const Vector3<double>& view_to) noexcept
{ {
const auto direction = (view_to - origin).normalized(); const auto direction = (view_to - origin).normalized();
@@ -72,7 +73,7 @@ namespace omath::unreal_engine
return angles::radians_to_degrees(std::asin(direction.z)); return angles::radians_to_degrees(std::asin(direction.z));
} }
[[nodiscard]] [[nodiscard("yaw angle result should not be discarded")]]
static double calc_direct_yaw_angle(const Vector3<double>& origin, const Vector3<double>& view_to) noexcept static double calc_direct_yaw_angle(const Vector3<double>& origin, const Vector3<double>& view_to) noexcept
{ {
const auto direction = (view_to - origin).normalized(); const auto direction = (view_to - origin).normalized();
+1 -1
View File
@@ -11,7 +11,7 @@ namespace omath::hud
public: public:
CanvasBox(Vector2<float> top, Vector2<float> bottom, float ratio = 4.f); CanvasBox(Vector2<float> top, Vector2<float> bottom, float ratio = 4.f);
[[nodiscard]] [[nodiscard("You have to use array")]]
std::array<Vector2<float>, 4> as_array() const; std::array<Vector2<float>, 4> as_array() const;
Vector2<float> top_left_corner; Vector2<float> top_left_corner;
+14 -14
View File
@@ -34,13 +34,13 @@ namespace omath
m_value.clamp(0.f, 1.f); m_value.clamp(0.f, 1.f);
} }
constexpr explicit Color() noexcept = default; constexpr explicit Color() noexcept = default;
[[nodiscard]] [[nodiscard("color result should not be discarded")]]
constexpr static Color from_rgba(const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t a) noexcept constexpr static Color from_rgba(const uint8_t r, const uint8_t g, const uint8_t b, const uint8_t a) noexcept
{ {
return Color(Vector4<float>(r, g, b, a) / 255.f); return Color(Vector4<float>(r, g, b, a) / 255.f);
} }
[[nodiscard]] [[nodiscard("color result should not be discarded")]]
constexpr static Color from_hsv(float hue, const float saturation, const float value) noexcept constexpr static Color from_hsv(float hue, const float saturation, const float value) noexcept
{ {
float r{}, g{}, b{}; float r{}, g{}, b{};
@@ -80,13 +80,13 @@ namespace omath
return {r, g, b, 1.f}; return {r, g, b, 1.f};
} }
[[nodiscard]] [[nodiscard("color result should not be discarded")]]
constexpr static Color from_hsv(const Hsv& hsv) noexcept constexpr static Color from_hsv(const Hsv& hsv) noexcept
{ {
return from_hsv(hsv.hue, hsv.saturation, hsv.value); return from_hsv(hsv.hue, hsv.saturation, hsv.value);
} }
[[nodiscard]] [[nodiscard("hsv result should not be discarded")]]
constexpr Hsv to_hsv() const noexcept constexpr Hsv to_hsv() const noexcept
{ {
Hsv hsv_data; Hsv hsv_data;
@@ -141,33 +141,33 @@ namespace omath
*this = from_hsv(hsv); *this = from_hsv(hsv);
} }
[[nodiscard]] [[nodiscard("blended color result should not be discarded")]]
constexpr Color blend(const Color& other, float ratio) const noexcept constexpr Color blend(const Color& other, float ratio) const noexcept
{ {
ratio = std::clamp(ratio, 0.f, 1.f); ratio = std::clamp(ratio, 0.f, 1.f);
return Color(this->m_value * (1.f - ratio) + other.m_value * ratio); return Color(this->m_value * (1.f - ratio) + other.m_value * ratio);
} }
[[nodiscard]] static constexpr Color red() [[nodiscard("color result should not be discarded")]] static constexpr Color red()
{ {
return {1.f, 0.f, 0.f, 1.f}; return {1.f, 0.f, 0.f, 1.f};
} }
[[nodiscard]] static constexpr Color green() [[nodiscard("color result should not be discarded")]] static constexpr Color green()
{ {
return {0.f, 1.f, 0.f, 1.f}; return {0.f, 1.f, 0.f, 1.f};
} }
[[nodiscard]] static constexpr Color blue() [[nodiscard("color result should not be discarded")]] static constexpr Color blue()
{ {
return {0.f, 0.f, 1.f, 1.f}; return {0.f, 0.f, 1.f, 1.f};
} }
#ifdef OMATH_IMGUI_INTEGRATION #ifdef OMATH_IMGUI_INTEGRATION
[[nodiscard]] [[nodiscard("ImColor result should not be discarded")]]
ImColor to_im_color() const noexcept ImColor to_im_color() const noexcept
{ {
return {m_value.to_im_vec4()}; return {m_value.to_im_vec4()};
} }
#endif #endif
[[nodiscard]] std::string to_string() const noexcept [[nodiscard("string result should not be discarded")]] std::string to_string() const noexcept
{ {
return std::format("[r:{}, g:{}, b:{}, a:{}]", return std::format("[r:{}, g:{}, b:{}, a:{}]",
static_cast<int>(m_value.x * 255.f), static_cast<int>(m_value.x * 255.f),
@@ -175,24 +175,24 @@ namespace omath
static_cast<int>(m_value.z * 255.f), static_cast<int>(m_value.z * 255.f),
static_cast<int>(m_value.w * 255.f)); static_cast<int>(m_value.w * 255.f));
} }
[[nodiscard]] std::string to_rgbf_string() const noexcept [[nodiscard("string result should not be discarded")]] std::string to_rgbf_string() const noexcept
{ {
return std::format("[r:{}, g:{}, b:{}, a:{}]", return std::format("[r:{}, g:{}, b:{}, a:{}]",
m_value.x, m_value.y, m_value.z, m_value.w); m_value.x, m_value.y, m_value.z, m_value.w);
} }
[[nodiscard]] std::string to_hsv_string() const noexcept [[nodiscard("string result should not be discarded")]] std::string to_hsv_string() const noexcept
{ {
const auto [hue, saturation, value] = to_hsv(); const auto [hue, saturation, value] = to_hsv();
return std::format("[h:{}, s:{}, v:{}]", hue, saturation, value); return std::format("[h:{}, s:{}, v:{}]", hue, saturation, value);
} }
[[nodiscard]] std::wstring to_wstring() const noexcept [[nodiscard("wide string result should not be discarded")]] std::wstring to_wstring() const noexcept
{ {
const auto ascii_string = to_string(); const auto ascii_string = to_string();
return {ascii_string.cbegin(), ascii_string.cend()}; return {ascii_string.cbegin(), ascii_string.cend()};
} }
// ReSharper disable once CppInconsistentNaming // ReSharper disable once CppInconsistentNaming
[[nodiscard]] std::u8string to_u8string() const noexcept [[nodiscard("UTF-8 string result should not be discarded")]] std::u8string to_u8string() const noexcept
{ {
const auto ascii_string = to_string(); const auto ascii_string = to_string();
return {ascii_string.cbegin(), ascii_string.cend()}; return {ascii_string.cbegin(), ascii_string.cend()};