mirror of
https://github.com/orange-cpp/omath.git
synced 2026-08-07 21:42:05 +00:00
added constexpr support for radar
This commit is contained in:
@@ -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, ¤t_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;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//
|
||||
// Created by Vlad on 27.08.2024.
|
||||
//
|
||||
#include "omath/algorithm/radar.hpp"
|
||||
#include "omath/engines/unity_engine/camera.hpp"
|
||||
#include <complex>
|
||||
#include <gtest/gtest.h>
|
||||
@@ -1283,8 +1284,9 @@ TEST(UnitTestProjection, TriangleFarToSideCulled)
|
||||
TEST(UnitTestProjection, TriangleStraddlingFrustumNotCulled)
|
||||
{
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
const auto cam = omath::source_engine::Camera({0.f, 0.f, 0.f}, {}, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||
constexpr auto cam = omath::source_engine::Camera({0.f, 0.f, 0.f}, {}, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||
|
||||
constexpr auto position = omath::algorithm::world_to_radar(cam, {-1.f, 0.f, 0.f}, 0.1f);
|
||||
// Large triangle with vertices on both sides of the frustum — should not be culled
|
||||
const omath::Triangle<omath::Vector3<float>> tri{{100.f, 0.f, 0.f}, {100.f, 5000.f, 0.f}, {100.f, 0.f, 5000.f}};
|
||||
EXPECT_FALSE(cam.is_culled_by_frustum(tri));
|
||||
|
||||
Reference in New Issue
Block a user