added constexpr support for radar

This commit is contained in:
2026-07-05 05:53:28 +03:00
parent 9299ea8960
commit b4f4917aec
2 changed files with 16 additions and 3 deletions
+13 -2
View File
@@ -10,14 +10,25 @@ namespace omath::algorithm
template<class Camera, class FloatingType>
requires std::is_floating_point_v<FloatingType>
[[nodiscard]]
Vector2<float> world_to_radar(const Camera& camera, const Vector3<FloatingType>& position, const FloatingType scale)
constexpr Vector2<float> world_to_radar(const Camera& camera, const Vector3<FloatingType>& position, const FloatingType scale)
{
const auto look_at_angles = camera.calc_look_at_angles(position);
const auto current_angles = camera.get_view_angles();
if consteval
{
const auto right_yaw = current_angles.yaw
- camera.calc_look_at_angles(camera.get_origin() + camera.get_abs_right()).yaw
- decltype(current_angles.yaw)::from_degrees(90);
const auto sign = right_yaw.cos() < 0 ? -1.f : 1.f;
const auto yaw = current_angles.yaw - look_at_angles.yaw - decltype(current_angles.yaw)::from_degrees(90);
return omath::Vector2<float>(static_cast<float>(yaw.cos()) * sign, static_cast<float>(yaw.sin()))
* (camera.get_origin().distance_to(position) * scale);
}
static const auto sign = [&camera, &current_angles]
{
auto right_yaw = current_angles.yaw
const auto right_yaw = current_angles.yaw
- camera.calc_look_at_angles(camera.get_origin() + camera.get_abs_right()).yaw
- decltype(current_angles.yaw)::from_degrees(90);
return right_yaw.cos() < 0 ? -1.f : 1.f;