added constexpr engine traits

This commit is contained in:
2026-06-14 22:46:24 +03:00
parent 136cd39496
commit 91d9335f83
32 changed files with 879 additions and 859 deletions
+26 -4
View File
@@ -60,15 +60,37 @@ static void verify_random_look_at_targets_project_to_screen_center(const omath::
}
}
#ifdef OMATH_USE_GCEM
constexpr bool source_camera_constexpr_projection_round_trip()
{
constexpr auto fov = omath::Angle<float, 0.f, 180.f, omath::AngleFlags::Clamped>::from_degrees(90.f);
constexpr auto cam = omath::source_engine::Camera({0, 0, 0}, omath::source_engine::ViewAngles{}, {1920.f, 1080.f},
fov, 0.01f, 1000.f);
constexpr auto projected = cam.world_to_screen({1000.f, 0, 50.f});
constexpr auto result = cam.screen_to_world(projected.value());
constexpr auto result2 = cam.world_to_screen(result.value());
return projected.has_value() && result.has_value() && result2.has_value()
&& static_cast<omath::Vector2<float>>(projected.value())
== static_cast<omath::Vector2<float>>(result2.value())
&& omath::internal::abs(projected->x - 960.f) < 0.001f
&& omath::internal::abs(projected->y - 504.f) < 0.001f
&& omath::internal::abs(projected->z - 1.f) < 0.001f;
}
static_assert(source_camera_constexpr_projection_round_trip());
#endif
TEST(UnitTestProjection, Projection)
{
constexpr auto fov = omath::Angle<float, 0.f, 180.f, omath::AngleFlags::Clamped>::from_degrees(90.f);
const auto cam = omath::source_engine::Camera({0, 0, 0}, omath::source_engine::ViewAngles{}, {1920.f, 1080.f}, fov,
constexpr auto cam = omath::source_engine::Camera({0, 0, 0}, omath::source_engine::ViewAngles{}, {1920.f, 1080.f}, fov,
0.01f, 1000.f);
const auto projected = cam.world_to_screen({1000.f, 0, 50.f});
const auto result = cam.screen_to_world(projected.value());
const auto result2 = cam.world_to_screen(result.value());
constexpr auto projected = cam.world_to_screen({1000.f, 0, 50.f});
constexpr auto result = cam.screen_to_world(projected.value());
constexpr auto result2 = cam.world_to_screen(result.value());
EXPECT_EQ(static_cast<omath::Vector2<float>>(projected.value()),
static_cast<omath::Vector2<float>>(result2.value()));