mirror of
https://github.com/orange-cpp/omath.git
synced 2026-06-15 11:44:34 +00:00
removed gcem as dep
This commit is contained in:
@@ -10,7 +10,6 @@
|
||||
|
||||
using namespace omath;
|
||||
|
||||
#ifdef OMATH_USE_GCEM
|
||||
namespace
|
||||
{
|
||||
constexpr bool close_to(const float actual, const float expected, const float epsilon)
|
||||
@@ -41,7 +40,7 @@ static_assert(
|
||||
&& close_to(rotation.at(1, 1), 1.0f, 1e-5f) && close_to(rotation.at(2, 2), 1.0f, 1e-5f)
|
||||
&& close_to(rotation.at(3, 3), 1.0f, 1e-5f);
|
||||
}(),
|
||||
"CryEngine basis vectors should be constexpr with gcem");
|
||||
"CryEngine basis vectors should be constexpr with embedded constexpr math");
|
||||
|
||||
static_assert(
|
||||
[]
|
||||
@@ -50,7 +49,7 @@ static_assert(
|
||||
return close_to(view.at(0, 0), 1.0f, 1e-5f) && close_to(view.at(1, 2), 1.0f, 1e-5f)
|
||||
&& close_to(view.at(2, 1), 1.0f, 1e-5f) && close_to(view.at(3, 3), 1.0f, 1e-5f);
|
||||
}(),
|
||||
"CryEngine view matrix should be constexpr with gcem");
|
||||
"CryEngine view matrix should be constexpr with embedded constexpr math");
|
||||
|
||||
static_assert(
|
||||
[]
|
||||
@@ -62,7 +61,7 @@ static_assert(
|
||||
|
||||
return vec_close_to(origin, {1.0f, 2.0f, 3.0f}, 1e-5f) && vec_close_to(scale, {2.0f, 3.0f, 4.0f}, 1e-5f);
|
||||
}(),
|
||||
"CryEngine transform extraction should be constexpr with gcem");
|
||||
"CryEngine transform extraction should be constexpr with embedded constexpr math");
|
||||
|
||||
static_assert(
|
||||
[]
|
||||
@@ -73,7 +72,7 @@ static_assert(
|
||||
&& close_to(projection.at(2, 2), 1.1f, 1e-5f) && close_to(projection.at(2, 3), -1.1f, 1e-5f)
|
||||
&& close_to(projection.at(3, 2), 1.0f, 1e-5f);
|
||||
}(),
|
||||
"CryEngine projection matrix should be constexpr with gcem");
|
||||
"CryEngine projection matrix should be constexpr with embedded constexpr math");
|
||||
|
||||
static_assert(
|
||||
[]
|
||||
@@ -91,7 +90,7 @@ static_assert(
|
||||
&& close_to(projection.at(1, 1), 1.0f, 1e-5f) && close_to(projection.at(2, 2), 1.1f, 1e-5f)
|
||||
&& close_to(projection.at(2, 3), -1.1f, 1e-5f) && close_to(projection.at(3, 2), 1.0f, 1e-5f);
|
||||
}(),
|
||||
"CryEngine CameraTrait should be constexpr with gcem");
|
||||
"CryEngine CameraTrait should be constexpr with embedded constexpr math");
|
||||
|
||||
static_assert(omath::cry_engine::units_to_centimeters(100.0f) == 1.0f);
|
||||
static_assert(omath::cry_engine::units_to_meters(2.0f) == 2.0f);
|
||||
@@ -99,7 +98,6 @@ static_assert(omath::cry_engine::units_to_kilometers(2000.0f) == 2.0f);
|
||||
static_assert(omath::cry_engine::centimeters_to_units(1.0f) == 100.0f);
|
||||
static_assert(omath::cry_engine::meters_to_units(2.0f) == 2.0f);
|
||||
static_assert(omath::cry_engine::kilometers_to_units(2.0f) == 2000.0f);
|
||||
#endif
|
||||
|
||||
TEST(unit_test_cry_engine, look_at_forward)
|
||||
{
|
||||
|
||||
@@ -1,40 +1,32 @@
|
||||
// Tests for engine trait headers to improve header coverage
|
||||
#include <gtest/gtest.h>
|
||||
#include <omath/engines/frostbite_engine/camera.hpp>
|
||||
#include <omath/engines/frostbite_engine/traits/pred_engine_trait.hpp>
|
||||
#include <omath/engines/frostbite_engine/traits/mesh_trait.hpp>
|
||||
#include <omath/engines/frostbite_engine/traits/camera_trait.hpp>
|
||||
|
||||
#include <omath/engines/iw_engine/camera.hpp>
|
||||
#include <omath/engines/iw_engine/traits/pred_engine_trait.hpp>
|
||||
#include <omath/engines/iw_engine/traits/mesh_trait.hpp>
|
||||
#include <omath/engines/iw_engine/traits/camera_trait.hpp>
|
||||
|
||||
#include <omath/engines/opengl_engine/camera.hpp>
|
||||
#include <omath/engines/opengl_engine/traits/pred_engine_trait.hpp>
|
||||
#include <omath/engines/opengl_engine/traits/mesh_trait.hpp>
|
||||
#include <omath/engines/opengl_engine/traits/camera_trait.hpp>
|
||||
|
||||
#include <omath/engines/unity_engine/camera.hpp>
|
||||
#include <omath/engines/unity_engine/traits/pred_engine_trait.hpp>
|
||||
#include <omath/engines/unity_engine/traits/mesh_trait.hpp>
|
||||
#include <omath/engines/unity_engine/traits/camera_trait.hpp>
|
||||
|
||||
#include <omath/engines/unreal_engine/camera.hpp>
|
||||
#include <omath/engines/unreal_engine/traits/pred_engine_trait.hpp>
|
||||
#include <omath/engines/unreal_engine/traits/mesh_trait.hpp>
|
||||
#include <omath/engines/unreal_engine/traits/camera_trait.hpp>
|
||||
|
||||
#include <omath/engines/source_engine/camera.hpp>
|
||||
#include <omath/engines/source_engine/traits/pred_engine_trait.hpp>
|
||||
#include <omath/engines/source_engine/traits/camera_trait.hpp>
|
||||
|
||||
#include <omath/engines/cry_engine/camera.hpp>
|
||||
#include <omath/engines/cry_engine/traits/camera_trait.hpp>
|
||||
|
||||
#include <omath/engines/frostbite_engine/camera.hpp>
|
||||
#include <omath/engines/frostbite_engine/traits/camera_trait.hpp>
|
||||
#include <omath/engines/frostbite_engine/traits/mesh_trait.hpp>
|
||||
#include <omath/engines/frostbite_engine/traits/pred_engine_trait.hpp>
|
||||
#include <omath/engines/iw_engine/camera.hpp>
|
||||
#include <omath/engines/iw_engine/traits/camera_trait.hpp>
|
||||
#include <omath/engines/iw_engine/traits/mesh_trait.hpp>
|
||||
#include <omath/engines/iw_engine/traits/pred_engine_trait.hpp>
|
||||
#include <omath/engines/opengl_engine/camera.hpp>
|
||||
#include <omath/engines/opengl_engine/traits/camera_trait.hpp>
|
||||
#include <omath/engines/opengl_engine/traits/mesh_trait.hpp>
|
||||
#include <omath/engines/opengl_engine/traits/pred_engine_trait.hpp>
|
||||
#include <omath/engines/rage_engine/camera.hpp>
|
||||
#include <omath/engines/rage_engine/traits/camera_trait.hpp>
|
||||
|
||||
#include <omath/engines/source_engine/camera.hpp>
|
||||
#include <omath/engines/source_engine/traits/camera_trait.hpp>
|
||||
#include <omath/engines/source_engine/traits/pred_engine_trait.hpp>
|
||||
#include <omath/engines/unity_engine/camera.hpp>
|
||||
#include <omath/engines/unity_engine/traits/camera_trait.hpp>
|
||||
#include <omath/engines/unity_engine/traits/mesh_trait.hpp>
|
||||
#include <omath/engines/unity_engine/traits/pred_engine_trait.hpp>
|
||||
#include <omath/engines/unreal_engine/camera.hpp>
|
||||
#include <omath/engines/unreal_engine/traits/camera_trait.hpp>
|
||||
#include <omath/engines/unreal_engine/traits/mesh_trait.hpp>
|
||||
#include <omath/engines/unreal_engine/traits/pred_engine_trait.hpp>
|
||||
#include <omath/projectile_prediction/projectile.hpp>
|
||||
#include <omath/projectile_prediction/target.hpp>
|
||||
#include <optional>
|
||||
@@ -51,7 +43,6 @@ static void expect_matrix_near(const MatT& a, const MatT& b, float eps = 1e-5f)
|
||||
}
|
||||
|
||||
// ── Launch offset tests for all engines ──────────────────────────────────────
|
||||
#ifdef OMATH_USE_GCEM
|
||||
template<class MatType, class NumericType>
|
||||
constexpr bool matrix_has_non_zero_element(const MatType& mat)
|
||||
{
|
||||
@@ -86,7 +77,6 @@ static_assert(camera_can_calculate_matrices_at_compile_time<unity_engine::Camera
|
||||
static_assert(camera_can_calculate_matrices_at_compile_time<cry_engine::Camera, float>());
|
||||
static_assert(camera_can_calculate_matrices_at_compile_time<rage_engine::Camera, float>());
|
||||
static_assert(camera_can_calculate_matrices_at_compile_time<unreal_engine::Camera, double>());
|
||||
#endif
|
||||
|
||||
#include <omath/engines/cry_engine/traits/pred_engine_trait.hpp>
|
||||
|
||||
@@ -121,8 +111,10 @@ static void verify_zero_offset_matches_default()
|
||||
p2.m_launch_speed = static_cast<AT>(50);
|
||||
p2.m_gravity_scale = static_cast<AT>(1);
|
||||
|
||||
const auto pos1 = Trait::predict_projectile_position(p, static_cast<AT>(15), static_cast<AT>(30), static_cast<AT>(1), static_cast<AT>(9.81));
|
||||
const auto pos2 = Trait::predict_projectile_position(p2, static_cast<AT>(15), static_cast<AT>(30), static_cast<AT>(1), static_cast<AT>(9.81));
|
||||
const auto pos1 = Trait::predict_projectile_position(p, static_cast<AT>(15), static_cast<AT>(30),
|
||||
static_cast<AT>(1), static_cast<AT>(9.81));
|
||||
const auto pos2 = Trait::predict_projectile_position(p2, static_cast<AT>(15), static_cast<AT>(30),
|
||||
static_cast<AT>(1), static_cast<AT>(9.81));
|
||||
#if defined(__x86_64__) || defined(_M_X64) || defined(__aarch64__) || defined(_M_ARM64)
|
||||
constexpr double tol = 1e-6;
|
||||
#else
|
||||
@@ -205,7 +197,8 @@ TEST(LaunchOffsetTests, OffsetShiftsTrajectory)
|
||||
p_with_offset.m_gravity_scale = 1.f;
|
||||
|
||||
const auto pos1 = source_engine::PredEngineTrait::predict_projectile_position(p_no_offset, 20.f, 45.f, 2.f, 9.81f);
|
||||
const auto pos2 = source_engine::PredEngineTrait::predict_projectile_position(p_with_offset, 20.f, 45.f, 2.f, 9.81f);
|
||||
const auto pos2 =
|
||||
source_engine::PredEngineTrait::predict_projectile_position(p_with_offset, 20.f, 45.f, 2.f, 9.81f);
|
||||
|
||||
// The difference should be exactly the launch offset
|
||||
EXPECT_NEAR(pos2.x - pos1.x, 10.f, 1e-4f);
|
||||
@@ -268,12 +261,16 @@ TEST(TraitTests, Frostbite_Pred_And_Mesh_And_Camera)
|
||||
// CameraTrait look at should be callable
|
||||
const auto angles = e::CameraTrait::calc_look_at_angle({0, 0, 0}, {0, 1, 1});
|
||||
(void)angles;
|
||||
const auto proj = e::CameraTrait::calc_projection_matrix(projection::FieldOfView::from_degrees(60.f), {1280.f, 720.f}, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto proj =
|
||||
e::CameraTrait::calc_projection_matrix(projection::FieldOfView::from_degrees(60.f), {1280.f, 720.f}, 0.1f,
|
||||
1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto expected = e::calc_perspective_projection_matrix(60.f, 1280.f / 720.f, 0.1f, 1000.f);
|
||||
expect_matrix_near(proj, expected);
|
||||
|
||||
const auto proj_zo = e::CameraTrait::calc_projection_matrix(projection::FieldOfView::from_degrees(60.f), {1280.f, 720.f}, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
const auto expected_zo = e::calc_perspective_projection_matrix(60.f, 1280.f / 720.f, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
const auto proj_zo = e::CameraTrait::calc_projection_matrix(
|
||||
projection::FieldOfView::from_degrees(60.f), {1280.f, 720.f}, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
const auto expected_zo =
|
||||
e::calc_perspective_projection_matrix(60.f, 1280.f / 720.f, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
expect_matrix_near(proj_zo, expected_zo);
|
||||
EXPECT_NE(proj, proj_zo);
|
||||
}
|
||||
@@ -319,12 +316,16 @@ TEST(TraitTests, IW_Pred_And_Mesh_And_Camera)
|
||||
e::ViewAngles va;
|
||||
expect_matrix_near(e::MeshTrait::rotation_matrix(va), e::rotation_matrix(va));
|
||||
|
||||
const auto proj = e::CameraTrait::calc_projection_matrix(projection::FieldOfView::from_degrees(45.f), {1920.f, 1080.f}, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto proj =
|
||||
e::CameraTrait::calc_projection_matrix(projection::FieldOfView::from_degrees(45.f), {1920.f, 1080.f}, 0.1f,
|
||||
1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto expected = e::calc_perspective_projection_matrix(45.f, 1920.f / 1080.f, 0.1f, 1000.f);
|
||||
expect_matrix_near(proj, expected);
|
||||
|
||||
const auto proj_zo = e::CameraTrait::calc_projection_matrix(projection::FieldOfView::from_degrees(45.f), {1920.f, 1080.f}, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
const auto expected_zo = e::calc_perspective_projection_matrix(45.f, 1920.f / 1080.f, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
const auto proj_zo = e::CameraTrait::calc_projection_matrix(
|
||||
projection::FieldOfView::from_degrees(45.f), {1920.f, 1080.f}, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
const auto expected_zo =
|
||||
e::calc_perspective_projection_matrix(45.f, 1920.f / 1080.f, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
expect_matrix_near(proj_zo, expected_zo);
|
||||
EXPECT_NE(proj, proj_zo);
|
||||
|
||||
@@ -374,12 +375,16 @@ TEST(TraitTests, OpenGL_Pred_And_Mesh_And_Camera)
|
||||
e::ViewAngles va;
|
||||
expect_matrix_near(e::MeshTrait::rotation_matrix(va), e::rotation_matrix(va));
|
||||
|
||||
const auto proj = e::CameraTrait::calc_projection_matrix(projection::FieldOfView::from_degrees(60.f), {1280.f, 720.f}, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto proj =
|
||||
e::CameraTrait::calc_projection_matrix(projection::FieldOfView::from_degrees(60.f), {1280.f, 720.f}, 0.1f,
|
||||
1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto expected = e::calc_perspective_projection_matrix(60.f, 1280.f / 720.f, 0.1f, 1000.f);
|
||||
expect_matrix_near(proj, expected);
|
||||
|
||||
const auto proj_zo = e::CameraTrait::calc_projection_matrix(projection::FieldOfView::from_degrees(60.f), {1280.f, 720.f}, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
const auto expected_zo = e::calc_perspective_projection_matrix(60.f, 1280.f / 720.f, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
const auto proj_zo = e::CameraTrait::calc_projection_matrix(
|
||||
projection::FieldOfView::from_degrees(60.f), {1280.f, 720.f}, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
const auto expected_zo =
|
||||
e::calc_perspective_projection_matrix(60.f, 1280.f / 720.f, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
expect_matrix_near(proj_zo, expected_zo);
|
||||
EXPECT_NE(proj, proj_zo);
|
||||
|
||||
@@ -429,12 +434,16 @@ TEST(TraitTests, Unity_Pred_And_Mesh_And_Camera)
|
||||
e::ViewAngles va;
|
||||
expect_matrix_near(e::MeshTrait::rotation_matrix(va), e::rotation_matrix(va));
|
||||
|
||||
const auto proj = e::CameraTrait::calc_projection_matrix(projection::FieldOfView::from_degrees(60.f), {1280.f, 720.f}, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto proj =
|
||||
e::CameraTrait::calc_projection_matrix(projection::FieldOfView::from_degrees(60.f), {1280.f, 720.f}, 0.1f,
|
||||
1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto expected = e::calc_perspective_projection_matrix(60.f, 1280.f / 720.f, 0.1f, 1000.f);
|
||||
expect_matrix_near(proj, expected);
|
||||
|
||||
const auto proj_zo = e::CameraTrait::calc_projection_matrix(projection::FieldOfView::from_degrees(60.f), {1280.f, 720.f}, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
const auto expected_zo = e::calc_perspective_projection_matrix(60.f, 1280.f / 720.f, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
const auto proj_zo = e::CameraTrait::calc_projection_matrix(
|
||||
projection::FieldOfView::from_degrees(60.f), {1280.f, 720.f}, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
const auto expected_zo =
|
||||
e::calc_perspective_projection_matrix(60.f, 1280.f / 720.f, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
expect_matrix_near(proj_zo, expected_zo);
|
||||
EXPECT_NE(proj, proj_zo);
|
||||
|
||||
@@ -484,12 +493,16 @@ TEST(TraitTests, Unreal_Pred_And_Mesh_And_Camera)
|
||||
e::ViewAngles va;
|
||||
expect_matrix_near(e::MeshTrait::rotation_matrix(va), e::rotation_matrix(va));
|
||||
|
||||
const auto proj = e::CameraTrait::calc_projection_matrix(projection::FieldOfView::from_degrees(60.f), {1280.f, 720.f}, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto proj =
|
||||
e::CameraTrait::calc_projection_matrix(projection::FieldOfView::from_degrees(60.f), {1280.f, 720.f}, 0.1f,
|
||||
1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto expected = e::calc_perspective_projection_matrix(60.f, 1280.f / 720.f, 0.1f, 1000.f);
|
||||
expect_matrix_near(proj, expected);
|
||||
|
||||
const auto proj_zo = e::CameraTrait::calc_projection_matrix(projection::FieldOfView::from_degrees(60.f), {1280.f, 720.f}, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
const auto expected_zo = e::calc_perspective_projection_matrix(60.f, 1280.f / 720.f, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
const auto proj_zo = e::CameraTrait::calc_projection_matrix(
|
||||
projection::FieldOfView::from_degrees(60.f), {1280.f, 720.f}, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
const auto expected_zo =
|
||||
e::calc_perspective_projection_matrix(60.f, 1280.f / 720.f, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
expect_matrix_near(proj_zo, expected_zo);
|
||||
EXPECT_NE(proj, proj_zo);
|
||||
|
||||
@@ -505,18 +518,17 @@ TEST(NDCDepthRangeTests, Source_BothDepthRanges)
|
||||
{
|
||||
namespace e = omath::source_engine;
|
||||
|
||||
const auto proj_no = e::CameraTrait::calc_projection_matrix(
|
||||
projection::FieldOfView::from_degrees(90.f), {1920.f, 1080.f}, 0.1f, 1000.f,
|
||||
NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto expected_no = e::calc_perspective_projection_matrix(
|
||||
90.f, 1920.f / 1080.f, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto proj_no =
|
||||
e::CameraTrait::calc_projection_matrix(projection::FieldOfView::from_degrees(90.f), {1920.f, 1080.f}, 0.1f,
|
||||
1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto expected_no = e::calc_perspective_projection_matrix(90.f, 1920.f / 1080.f, 0.1f, 1000.f,
|
||||
NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
expect_matrix_near(proj_no, expected_no);
|
||||
|
||||
const auto proj_zo = e::CameraTrait::calc_projection_matrix(
|
||||
projection::FieldOfView::from_degrees(90.f), {1920.f, 1080.f}, 0.1f, 1000.f,
|
||||
NDCDepthRange::ZERO_TO_ONE);
|
||||
const auto expected_zo = e::calc_perspective_projection_matrix(
|
||||
90.f, 1920.f / 1080.f, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
projection::FieldOfView::from_degrees(90.f), {1920.f, 1080.f}, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
const auto expected_zo =
|
||||
e::calc_perspective_projection_matrix(90.f, 1920.f / 1080.f, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
expect_matrix_near(proj_zo, expected_zo);
|
||||
|
||||
EXPECT_NE(proj_no, proj_zo);
|
||||
@@ -526,18 +538,17 @@ TEST(NDCDepthRangeTests, CryEngine_BothDepthRanges)
|
||||
{
|
||||
namespace e = omath::cry_engine;
|
||||
|
||||
const auto proj_no = e::CameraTrait::calc_projection_matrix(
|
||||
projection::FieldOfView::from_degrees(90.f), {1920.f, 1080.f}, 0.1f, 1000.f,
|
||||
NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto expected_no = e::calc_perspective_projection_matrix(
|
||||
90.f, 1920.f / 1080.f, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto proj_no =
|
||||
e::CameraTrait::calc_projection_matrix(projection::FieldOfView::from_degrees(90.f), {1920.f, 1080.f}, 0.1f,
|
||||
1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto expected_no = e::calc_perspective_projection_matrix(90.f, 1920.f / 1080.f, 0.1f, 1000.f,
|
||||
NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
expect_matrix_near(proj_no, expected_no);
|
||||
|
||||
const auto proj_zo = e::CameraTrait::calc_projection_matrix(
|
||||
projection::FieldOfView::from_degrees(90.f), {1920.f, 1080.f}, 0.1f, 1000.f,
|
||||
NDCDepthRange::ZERO_TO_ONE);
|
||||
const auto expected_zo = e::calc_perspective_projection_matrix(
|
||||
90.f, 1920.f / 1080.f, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
projection::FieldOfView::from_degrees(90.f), {1920.f, 1080.f}, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
const auto expected_zo =
|
||||
e::calc_perspective_projection_matrix(90.f, 1920.f / 1080.f, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
expect_matrix_near(proj_zo, expected_zo);
|
||||
|
||||
EXPECT_NE(proj_no, proj_zo);
|
||||
@@ -584,7 +595,8 @@ TEST(NDCDepthRangeTests, OpenGL_ZeroToOne_ZRange)
|
||||
const auto proj = e::calc_perspective_projection_matrix(90.f, 16.f / 9.f, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
|
||||
// OpenGL engine uses column-major matrices, project manually
|
||||
auto proj_z = [&](float z) {
|
||||
auto proj_z = [&](float z)
|
||||
{
|
||||
auto clip = proj * mat_column_from_vector<float, MatStoreType::COLUMN_MAJOR>({0, 0, z});
|
||||
return clip.at(2, 0) / clip.at(3, 0);
|
||||
};
|
||||
@@ -612,7 +624,8 @@ TEST(NDCDepthRangeTests, Unity_ZeroToOne_ZRange)
|
||||
// Unity is right-handed, row-major
|
||||
const auto proj = e::calc_perspective_projection_matrix(90.f, 16.f / 9.f, 0.1f, 1000.f, NDCDepthRange::ZERO_TO_ONE);
|
||||
|
||||
auto proj_z = [&](float z) {
|
||||
auto proj_z = [&](float z)
|
||||
{
|
||||
auto clip = proj * mat_column_from_vector<float>({0, 0, z});
|
||||
return clip.at(2, 0) / clip.at(3, 0);
|
||||
};
|
||||
@@ -650,7 +663,8 @@ TEST(NDCDepthRangeTests, CryEngine_ZeroToOne_ZRange)
|
||||
TEST(NDCDepthRangeTests, Source_NegativeOneToOne_ZRange)
|
||||
{
|
||||
namespace e = omath::source_engine;
|
||||
const auto proj = e::calc_perspective_projection_matrix(90.f, 16.f / 9.f, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto proj =
|
||||
e::calc_perspective_projection_matrix(90.f, 16.f / 9.f, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
|
||||
EXPECT_NEAR(project_z_lh(proj, 0.1f), -1.0f, 1e-3f);
|
||||
EXPECT_NEAR(project_z_lh(proj, 1000.f), 1.0f, 1e-3f);
|
||||
@@ -659,7 +673,8 @@ TEST(NDCDepthRangeTests, Source_NegativeOneToOne_ZRange)
|
||||
TEST(NDCDepthRangeTests, IW_NegativeOneToOne_ZRange)
|
||||
{
|
||||
namespace e = omath::iw_engine;
|
||||
const auto proj = e::calc_perspective_projection_matrix(90.f, 16.f / 9.f, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto proj =
|
||||
e::calc_perspective_projection_matrix(90.f, 16.f / 9.f, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
|
||||
EXPECT_NEAR(project_z_lh(proj, 0.1f), -1.0f, 1e-3f);
|
||||
EXPECT_NEAR(project_z_lh(proj, 1000.f), 1.0f, 1e-3f);
|
||||
@@ -668,7 +683,8 @@ TEST(NDCDepthRangeTests, IW_NegativeOneToOne_ZRange)
|
||||
TEST(NDCDepthRangeTests, Frostbite_NegativeOneToOne_ZRange)
|
||||
{
|
||||
namespace e = omath::frostbite_engine;
|
||||
const auto proj = e::calc_perspective_projection_matrix(90.f, 16.f / 9.f, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto proj =
|
||||
e::calc_perspective_projection_matrix(90.f, 16.f / 9.f, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
|
||||
EXPECT_NEAR(project_z_lh(proj, 0.1f), -1.0f, 1e-3f);
|
||||
EXPECT_NEAR(project_z_lh(proj, 1000.f), 1.0f, 1e-3f);
|
||||
@@ -677,7 +693,8 @@ TEST(NDCDepthRangeTests, Frostbite_NegativeOneToOne_ZRange)
|
||||
TEST(NDCDepthRangeTests, Unreal_NegativeOneToOne_ZRange)
|
||||
{
|
||||
namespace e = omath::unreal_engine;
|
||||
const auto proj = e::calc_perspective_projection_matrix(90.f, 16.f / 9.f, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto proj =
|
||||
e::calc_perspective_projection_matrix(90.f, 16.f / 9.f, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
|
||||
EXPECT_NEAR(project_z_lh(proj, 0.1f), -1.0f, 1e-3f);
|
||||
EXPECT_NEAR(project_z_lh(proj, 1000.f), 1.0f, 1e-3f);
|
||||
@@ -686,7 +703,8 @@ TEST(NDCDepthRangeTests, Unreal_NegativeOneToOne_ZRange)
|
||||
TEST(NDCDepthRangeTests, CryEngine_NegativeOneToOne_ZRange)
|
||||
{
|
||||
namespace e = omath::cry_engine;
|
||||
const auto proj = e::calc_perspective_projection_matrix(90.f, 16.f / 9.f, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto proj =
|
||||
e::calc_perspective_projection_matrix(90.f, 16.f / 9.f, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
|
||||
EXPECT_NEAR(project_z_lh(proj, 0.1f), -1.0f, 1e-3f);
|
||||
EXPECT_NEAR(project_z_lh(proj, 1000.f), 1.0f, 1e-3f);
|
||||
@@ -695,9 +713,11 @@ TEST(NDCDepthRangeTests, CryEngine_NegativeOneToOne_ZRange)
|
||||
TEST(NDCDepthRangeTests, OpenGL_NegativeOneToOne_ZRange)
|
||||
{
|
||||
namespace e = omath::opengl_engine;
|
||||
const auto proj = e::calc_perspective_projection_matrix(90.f, 16.f / 9.f, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto proj =
|
||||
e::calc_perspective_projection_matrix(90.f, 16.f / 9.f, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
|
||||
auto proj_z = [&](float z) {
|
||||
auto proj_z = [&](float z)
|
||||
{
|
||||
auto clip = proj * mat_column_from_vector<float, MatStoreType::COLUMN_MAJOR>({0, 0, z});
|
||||
return clip.at(2, 0) / clip.at(3, 0);
|
||||
};
|
||||
@@ -709,9 +729,11 @@ TEST(NDCDepthRangeTests, OpenGL_NegativeOneToOne_ZRange)
|
||||
TEST(NDCDepthRangeTests, Unity_NegativeOneToOne_ZRange)
|
||||
{
|
||||
namespace e = omath::unity_engine;
|
||||
const auto proj = e::calc_perspective_projection_matrix(90.f, 16.f / 9.f, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
const auto proj =
|
||||
e::calc_perspective_projection_matrix(90.f, 16.f / 9.f, 0.1f, 1000.f, NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
|
||||
auto proj_z = [&](float z) {
|
||||
auto proj_z = [&](float z)
|
||||
{
|
||||
auto clip = proj * mat_column_from_vector<float>({0, 0, z});
|
||||
return clip.at(2, 0) / clip.at(3, 0);
|
||||
};
|
||||
|
||||
@@ -19,13 +19,11 @@ namespace
|
||||
|
||||
constexpr float k_eps = 1e-5f;
|
||||
|
||||
#ifdef OMATH_USE_GCEM
|
||||
constexpr bool close_to(const float actual, const float expected, const float epsilon)
|
||||
{
|
||||
const float diff = actual - expected;
|
||||
return (diff < 0.0f ? -diff : diff) <= epsilon;
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -199,10 +197,13 @@ TEST(UnitTestAngle, BinaryMinus_ReturnsWrappedDiff)
|
||||
EXPECT_FLOAT_EQ(c.as_degrees(), 340.0f);
|
||||
}
|
||||
|
||||
#ifdef OMATH_USE_GCEM
|
||||
static_assert(close_to(Pitch::from_degrees(0.0f).sin(), 0.0f, k_eps), "Sin should be constexpr with gcem");
|
||||
static_assert(close_to(Pitch::from_degrees(0.0f).cos(), 1.0f, k_eps), "Cos should be constexpr with gcem");
|
||||
static_assert(close_to(Pitch::from_degrees(45.0f).tan(), 1.0f, 1e-4f), "Tan should be constexpr with gcem");
|
||||
static_assert(close_to(Pitch::from_degrees(45.0f).cot(), 1.0f, 1e-4f), "Cot should be constexpr with gcem");
|
||||
static_assert(close_to(Pitch::from_degrees(45.0f).atan(), 0.66577375f, 1e-6f), "Atan should be constexpr with gcem");
|
||||
#endif
|
||||
static_assert(close_to(Pitch::from_degrees(0.0f).sin(), 0.0f, k_eps),
|
||||
"Sin should be constexpr with embedded constexpr math");
|
||||
static_assert(close_to(Pitch::from_degrees(0.0f).cos(), 1.0f, k_eps),
|
||||
"Cos should be constexpr with embedded constexpr math");
|
||||
static_assert(close_to(Pitch::from_degrees(45.0f).tan(), 1.0f, 1e-4f),
|
||||
"Tan should be constexpr with embedded constexpr math");
|
||||
static_assert(close_to(Pitch::from_degrees(45.0f).cot(), 1.0f, 1e-4f),
|
||||
"Cot should be constexpr with embedded constexpr math");
|
||||
static_assert(close_to(Pitch::from_degrees(45.0f).atan(), 0.66577375f, 1e-6f),
|
||||
"Atan should be constexpr with embedded constexpr math");
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
using namespace omath;
|
||||
|
||||
#ifdef OMATH_USE_GCEM
|
||||
namespace
|
||||
{
|
||||
using Pitch = Angle<float, static_cast<float>(-90), static_cast<float>(90), AngleFlags::Clamped>;
|
||||
@@ -18,7 +17,6 @@ namespace
|
||||
return (diff < 0.0f ? -diff : diff) <= epsilon;
|
||||
}
|
||||
} // namespace
|
||||
#endif
|
||||
|
||||
class UnitTestMat : public ::testing::Test
|
||||
{
|
||||
@@ -177,7 +175,6 @@ TEST_F(UnitTestMat, StaticMethod_ToScreenMat)
|
||||
EXPECT_FLOAT_EQ(screen_mat.at(3, 3), 1.0f);
|
||||
}
|
||||
|
||||
|
||||
// Test exception handling in At() method
|
||||
TEST_F(UnitTestMat, Method_At_OutOfRange)
|
||||
{
|
||||
@@ -225,7 +222,7 @@ TEST(UnitTestMatStandalone, Transpose_NonSquare)
|
||||
TEST(UnitTestMatStandalone, Enverse)
|
||||
{
|
||||
constexpr Mat<2, 2> m{{1.0f, 3.0f}, {2.0f, 5.0f}};
|
||||
constexpr Mat<2,2> mv{{-5.0f, 3.0f}, {2.0f, -1.0f}};
|
||||
constexpr Mat<2, 2> mv{{-5.0f, 3.0f}, {2.0f, -1.0f}};
|
||||
|
||||
EXPECT_EQ(mv, m.inverted());
|
||||
}
|
||||
@@ -248,9 +245,8 @@ TEST(UnitTestMatStandalone, Equanity)
|
||||
}
|
||||
TEST(UnitTestMatStandalone, MatPerspectiveLeftHanded)
|
||||
{
|
||||
const auto perspective_proj = mat_perspective_left_handed_vertical_fov(90.f, 16.f/9.f, 0.1f, 1000.f);
|
||||
auto projected = perspective_proj
|
||||
* mat_column_from_vector<float>({0, 0, 0.1001});
|
||||
const auto perspective_proj = mat_perspective_left_handed_vertical_fov(90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
auto projected = perspective_proj * mat_column_from_vector<float>({0, 0, 0.1001});
|
||||
|
||||
projected /= projected.at(3, 0);
|
||||
|
||||
@@ -259,8 +255,9 @@ TEST(UnitTestMatStandalone, MatPerspectiveLeftHanded)
|
||||
|
||||
TEST(UnitTestMatStandalone, MatPerspectiveLeftHandedZeroToOne)
|
||||
{
|
||||
const auto proj = mat_perspective_left_handed_vertical_fov<float, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
|
||||
90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
const auto proj =
|
||||
mat_perspective_left_handed_vertical_fov<float, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
|
||||
90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
|
||||
// Near plane point should map to z ~ 0
|
||||
auto near_pt = proj * mat_column_from_vector<float>({0, 0, 0.1f});
|
||||
@@ -281,8 +278,9 @@ TEST(UnitTestMatStandalone, MatPerspectiveLeftHandedZeroToOne)
|
||||
|
||||
TEST(UnitTestMatStandalone, MatPerspectiveRightHandedZeroToOne)
|
||||
{
|
||||
const auto proj = mat_perspective_right_handed_vertical_fov<float, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
|
||||
90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
const auto proj =
|
||||
mat_perspective_right_handed_vertical_fov<float, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
|
||||
90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
|
||||
// Near plane point (negative z for right-handed) should map to z ~ 0
|
||||
auto near_pt = proj * mat_column_from_vector<float>({0, 0, -0.1f});
|
||||
@@ -306,7 +304,8 @@ TEST(UnitTestMatStandalone, MatPerspectiveNegativeOneToOneRange)
|
||||
// Verify existing [-1, 1] behavior with explicit template arg matches default
|
||||
const auto proj_default = mat_perspective_left_handed_vertical_fov(90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
const auto proj_explicit = mat_perspective_left_handed_vertical_fov<float, MatStoreType::ROW_MAJOR,
|
||||
NDCDepthRange::NEGATIVE_ONE_TO_ONE>(90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
NDCDepthRange::NEGATIVE_ONE_TO_ONE>(
|
||||
90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
|
||||
EXPECT_EQ(proj_default, proj_explicit);
|
||||
|
||||
@@ -324,7 +323,8 @@ TEST(UnitTestMatStandalone, MatPerspectiveNegativeOneToOneRange)
|
||||
TEST(UnitTestMatStandalone, MatPerspectiveRightHandedNegOneToOne)
|
||||
{
|
||||
const auto proj = mat_perspective_right_handed_vertical_fov<float, MatStoreType::ROW_MAJOR,
|
||||
NDCDepthRange::NEGATIVE_ONE_TO_ONE>(90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
NDCDepthRange::NEGATIVE_ONE_TO_ONE>(90.f, 16.f / 9.f,
|
||||
0.1f, 1000.f);
|
||||
|
||||
// Near plane (negative z for RH) should map to z ~ -1
|
||||
auto near_pt = proj * mat_column_from_vector<float>({0, 0, -0.1f});
|
||||
@@ -340,14 +340,15 @@ TEST(UnitTestMatStandalone, MatPerspectiveRightHandedNegOneToOne)
|
||||
auto mid_pt = proj * mat_column_from_vector<float>({0, 0, -500.f});
|
||||
mid_pt /= mid_pt.at(3, 0);
|
||||
EXPECT_GT(mid_pt.at(2, 0), -1.0f);
|
||||
EXPECT_LT(mid_pt.at(2, 0), 1.0f);
|
||||
EXPECT_LT(mid_pt.at(2, 0), 1.0f);
|
||||
}
|
||||
|
||||
TEST(UnitTestMatStandalone, MatPerspectiveLeftHandedHorizontalFovZeroToOne)
|
||||
{
|
||||
// hfov=90 deg, aspect=16/9 => tan(hfov/2)=1, so x_axis=1 and y_axis=aspect
|
||||
const auto proj = mat_perspective_left_handed_horizontal_fov<float, MatStoreType::ROW_MAJOR,
|
||||
NDCDepthRange::ZERO_TO_ONE>(90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
const auto proj =
|
||||
mat_perspective_left_handed_horizontal_fov<float, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
|
||||
90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
|
||||
// Near plane should map to z ~ 0
|
||||
auto near_pt = proj * mat_column_from_vector<float>({0, 0, 0.1f});
|
||||
@@ -368,7 +369,8 @@ TEST(UnitTestMatStandalone, MatPerspectiveLeftHandedHorizontalFovZeroToOne)
|
||||
TEST(UnitTestMatStandalone, MatPerspectiveLeftHandedHorizontalFovNegOneToOne)
|
||||
{
|
||||
const auto proj = mat_perspective_left_handed_horizontal_fov<float, MatStoreType::ROW_MAJOR,
|
||||
NDCDepthRange::NEGATIVE_ONE_TO_ONE>(90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
NDCDepthRange::NEGATIVE_ONE_TO_ONE>(90.f, 16.f / 9.f,
|
||||
0.1f, 1000.f);
|
||||
|
||||
auto near_pt = proj * mat_column_from_vector<float>({0, 0, 0.1f});
|
||||
near_pt /= near_pt.at(3, 0);
|
||||
@@ -385,8 +387,9 @@ TEST(UnitTestMatStandalone, MatPerspectiveLeftHandedHorizontalFovNegOneToOne)
|
||||
|
||||
TEST(UnitTestMatStandalone, MatPerspectiveRightHandedHorizontalFovZeroToOne)
|
||||
{
|
||||
const auto proj = mat_perspective_right_handed_horizontal_fov<float, MatStoreType::ROW_MAJOR,
|
||||
NDCDepthRange::ZERO_TO_ONE>(90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
const auto proj =
|
||||
mat_perspective_right_handed_horizontal_fov<float, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
|
||||
90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
|
||||
auto near_pt = proj * mat_column_from_vector<float>({0, 0, -0.1f});
|
||||
near_pt /= near_pt.at(3, 0);
|
||||
@@ -404,7 +407,8 @@ TEST(UnitTestMatStandalone, MatPerspectiveRightHandedHorizontalFovZeroToOne)
|
||||
TEST(UnitTestMatStandalone, MatPerspectiveRightHandedHorizontalFovNegOneToOne)
|
||||
{
|
||||
const auto proj = mat_perspective_right_handed_horizontal_fov<float, MatStoreType::ROW_MAJOR,
|
||||
NDCDepthRange::NEGATIVE_ONE_TO_ONE>(90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
NDCDepthRange::NEGATIVE_ONE_TO_ONE>(90.f, 16.f / 9.f,
|
||||
0.1f, 1000.f);
|
||||
|
||||
auto near_pt = proj * mat_column_from_vector<float>({0, 0, -0.1f});
|
||||
near_pt /= near_pt.at(3, 0);
|
||||
@@ -422,7 +426,7 @@ TEST(UnitTestMatStandalone, MatPerspectiveRightHandedHorizontalFovNegOneToOne)
|
||||
TEST(UnitTestMatStandalone, MatPerspectiveHorizontalVsVerticalFovEquivalence)
|
||||
{
|
||||
constexpr float hfov_deg = 90.f;
|
||||
constexpr float aspect = 16.f / 9.f;
|
||||
constexpr float aspect = 16.f / 9.f;
|
||||
const float vfov_deg = angles::horizontal_fov_to_vertical(hfov_deg, aspect);
|
||||
|
||||
const auto proj_h = mat_perspective_left_handed_horizontal_fov(hfov_deg, aspect, 0.1f, 1000.f);
|
||||
@@ -440,11 +444,11 @@ TEST(UnitTestMatStandalone, MatPerspectiveLeftHandedVerticalFovHandedness)
|
||||
{
|
||||
const auto proj = mat_perspective_left_handed_vertical_fov(90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
|
||||
const auto in_front = proj * mat_column_from_vector<float>({0, 0, 1.f});
|
||||
const auto behind = proj * mat_column_from_vector<float>({0, 0, -1.f});
|
||||
const auto in_front = proj * mat_column_from_vector<float>({0, 0, 1.f});
|
||||
const auto behind = proj * mat_column_from_vector<float>({0, 0, -1.f});
|
||||
|
||||
EXPECT_GT(in_front.at(3, 0), 0.0f);
|
||||
EXPECT_LT(behind.at(3, 0), 0.0f);
|
||||
EXPECT_LT(behind.at(3, 0), 0.0f);
|
||||
}
|
||||
|
||||
TEST(UnitTestMatStandalone, MatPerspectiveRightHandedVerticalFovHandedness)
|
||||
@@ -452,21 +456,21 @@ TEST(UnitTestMatStandalone, MatPerspectiveRightHandedVerticalFovHandedness)
|
||||
const auto proj = mat_perspective_right_handed_vertical_fov(90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
|
||||
const auto in_front = proj * mat_column_from_vector<float>({0, 0, -1.f});
|
||||
const auto behind = proj * mat_column_from_vector<float>({0, 0, 1.f});
|
||||
const auto behind = proj * mat_column_from_vector<float>({0, 0, 1.f});
|
||||
|
||||
EXPECT_GT(in_front.at(3, 0), 0.0f);
|
||||
EXPECT_LT(behind.at(3, 0), 0.0f);
|
||||
EXPECT_LT(behind.at(3, 0), 0.0f);
|
||||
}
|
||||
|
||||
TEST(UnitTestMatStandalone, MatPerspectiveLeftHandedHorizontalFovHandedness)
|
||||
{
|
||||
const auto proj = mat_perspective_left_handed_horizontal_fov(90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
|
||||
const auto in_front = proj * mat_column_from_vector<float>({0, 0, 1.f});
|
||||
const auto behind = proj * mat_column_from_vector<float>({0, 0, -1.f});
|
||||
const auto in_front = proj * mat_column_from_vector<float>({0, 0, 1.f});
|
||||
const auto behind = proj * mat_column_from_vector<float>({0, 0, -1.f});
|
||||
|
||||
EXPECT_GT(in_front.at(3, 0), 0.0f);
|
||||
EXPECT_LT(behind.at(3, 0), 0.0f);
|
||||
EXPECT_LT(behind.at(3, 0), 0.0f);
|
||||
}
|
||||
|
||||
TEST(UnitTestMatStandalone, MatPerspectiveRightHandedHorizontalFovHandedness)
|
||||
@@ -474,10 +478,10 @@ TEST(UnitTestMatStandalone, MatPerspectiveRightHandedHorizontalFovHandedness)
|
||||
const auto proj = mat_perspective_right_handed_horizontal_fov(90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
|
||||
const auto in_front = proj * mat_column_from_vector<float>({0, 0, -1.f});
|
||||
const auto behind = proj * mat_column_from_vector<float>({0, 0, 1.f});
|
||||
const auto behind = proj * mat_column_from_vector<float>({0, 0, 1.f});
|
||||
|
||||
EXPECT_GT(in_front.at(3, 0), 0.0f);
|
||||
EXPECT_LT(behind.at(3, 0), 0.0f);
|
||||
EXPECT_LT(behind.at(3, 0), 0.0f);
|
||||
}
|
||||
|
||||
TEST(UnitTestMatStandalone, MatPerspectiveZeroToOneEquanity)
|
||||
@@ -486,10 +490,12 @@ TEST(UnitTestMatStandalone, MatPerspectiveZeroToOneEquanity)
|
||||
constexpr omath::Vector3<float> left_handed = {0, 2, 10};
|
||||
constexpr omath::Vector3<float> right_handed = {0, 2, -10};
|
||||
|
||||
const auto proj_lh = mat_perspective_left_handed_vertical_fov<float, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
|
||||
90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
const auto proj_rh = mat_perspective_right_handed_vertical_fov<float, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
|
||||
90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
const auto proj_lh =
|
||||
mat_perspective_left_handed_vertical_fov<float, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
|
||||
90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
const auto proj_rh =
|
||||
mat_perspective_right_handed_vertical_fov<float, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
|
||||
90.f, 16.f / 9.f, 0.1f, 1000.f);
|
||||
|
||||
auto ndc_lh = proj_lh * mat_column_from_vector(left_handed);
|
||||
auto ndc_rh = proj_rh * mat_column_from_vector(right_handed);
|
||||
@@ -532,20 +538,20 @@ TEST(UnitTestMatStandalone, MatOrthoNegativeOneToOneDefault)
|
||||
{
|
||||
// Verify explicit [-1, 1] matches default
|
||||
const auto ortho_default = mat_ortho_left_handed(-1.f, 1.f, -1.f, 1.f, 0.1f, 100.f);
|
||||
const auto ortho_explicit = mat_ortho_left_handed<float, MatStoreType::ROW_MAJOR,
|
||||
NDCDepthRange::NEGATIVE_ONE_TO_ONE>(-1.f, 1.f, -1.f, 1.f, 0.1f, 100.f);
|
||||
const auto ortho_explicit =
|
||||
mat_ortho_left_handed<float, MatStoreType::ROW_MAJOR, NDCDepthRange::NEGATIVE_ONE_TO_ONE>(-1.f, 1.f, -1.f,
|
||||
1.f, 0.1f, 100.f);
|
||||
|
||||
EXPECT_EQ(ortho_default, ortho_explicit);
|
||||
}
|
||||
|
||||
#ifdef OMATH_USE_GCEM
|
||||
static_assert(
|
||||
[]
|
||||
{
|
||||
constexpr auto scale = mat_extract_scale(mat_scale(Vector3{2.0f, 3.0f, 4.0f}));
|
||||
return close_to(scale.x, 2.0f, 1e-5f) && close_to(scale.y, 3.0f, 1e-5f) && close_to(scale.z, 4.0f, 1e-5f);
|
||||
}(),
|
||||
"Mat scale extraction should be constexpr with gcem");
|
||||
"Mat scale extraction should be constexpr with embedded constexpr math");
|
||||
|
||||
static_assert(
|
||||
[]
|
||||
@@ -555,7 +561,7 @@ static_assert(
|
||||
&& close_to(rotation.at(1, 0), 1.0f, 1e-5f) && close_to(rotation.at(1, 1), 0.0f, 1e-5f)
|
||||
&& close_to(rotation.at(2, 2), 1.0f, 1e-5f) && close_to(rotation.at(3, 3), 1.0f, 1e-5f);
|
||||
}(),
|
||||
"Mat rotation should be constexpr with gcem");
|
||||
"Mat rotation should be constexpr with embedded constexpr math");
|
||||
|
||||
static_assert(
|
||||
[]
|
||||
@@ -567,7 +573,7 @@ static_assert(
|
||||
&& close_to(projection.at(2, 2), 1.1f, 1e-5f) && close_to(projection.at(2, 3), -1.1f, 1e-5f)
|
||||
&& close_to(projection.at(3, 2), 1.0f, 1e-5f);
|
||||
}(),
|
||||
"Mat vertical-FOV perspective should be constexpr with gcem");
|
||||
"Mat vertical-FOV perspective should be constexpr with embedded constexpr math");
|
||||
|
||||
static_assert(
|
||||
[]
|
||||
@@ -579,5 +585,4 @@ static_assert(
|
||||
&& close_to(projection.at(2, 2), -1.1f, 1e-5f) && close_to(projection.at(2, 3), -1.1f, 1e-5f)
|
||||
&& close_to(projection.at(3, 2), -1.0f, 1e-5f);
|
||||
}(),
|
||||
"Mat horizontal-FOV perspective should be constexpr with gcem");
|
||||
#endif
|
||||
"Mat horizontal-FOV perspective should be constexpr with embedded constexpr math");
|
||||
|
||||
@@ -60,7 +60,6 @@ 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);
|
||||
@@ -74,23 +73,21 @@ constexpr bool source_camera_constexpr_projection_round_trip()
|
||||
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->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)
|
||||
{
|
||||
OMATH_CONSTEXPR auto fov = omath::Angle<float, 0.f, 180.f, omath::AngleFlags::Clamped>::from_degrees(90.f);
|
||||
OMATH_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 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);
|
||||
|
||||
OMATH_CONSTEXPR auto projected = cam.world_to_screen({1000.f, 0, 50.f});
|
||||
OMATH_CONSTEXPR auto result = cam.screen_to_world(projected.value());
|
||||
OMATH_CONSTEXPR 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()));
|
||||
@@ -587,11 +584,9 @@ TEST(UnitTestProjection, CalcViewAnglesFromViewMatrix_LookingForward)
|
||||
{
|
||||
constexpr float k_eps = 1e-4f;
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
const omath::source_engine::ViewAngles angles{
|
||||
omath::source_engine::PitchAngle::from_degrees(0.f),
|
||||
omath::source_engine::YawAngle::from_degrees(0.f),
|
||||
omath::source_engine::RollAngle::from_degrees(0.f)
|
||||
};
|
||||
const omath::source_engine::ViewAngles angles{omath::source_engine::PitchAngle::from_degrees(0.f),
|
||||
omath::source_engine::YawAngle::from_degrees(0.f),
|
||||
omath::source_engine::RollAngle::from_degrees(0.f)};
|
||||
const auto cam = omath::source_engine::Camera({0, 0, 0}, angles, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||
|
||||
const auto result = omath::source_engine::Camera::calc_view_angles_from_view_matrix(cam.get_view_matrix());
|
||||
@@ -604,11 +599,9 @@ TEST(UnitTestProjection, CalcViewAnglesFromViewMatrix_PositivePitchAndYaw)
|
||||
{
|
||||
constexpr float k_eps = 1e-4f;
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
const omath::source_engine::ViewAngles angles{
|
||||
omath::source_engine::PitchAngle::from_degrees(30.f),
|
||||
omath::source_engine::YawAngle::from_degrees(45.f),
|
||||
omath::source_engine::RollAngle::from_degrees(0.f)
|
||||
};
|
||||
const omath::source_engine::ViewAngles angles{omath::source_engine::PitchAngle::from_degrees(30.f),
|
||||
omath::source_engine::YawAngle::from_degrees(45.f),
|
||||
omath::source_engine::RollAngle::from_degrees(0.f)};
|
||||
const auto cam = omath::source_engine::Camera({0, 0, 0}, angles, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||
|
||||
const auto result = omath::source_engine::Camera::calc_view_angles_from_view_matrix(cam.get_view_matrix());
|
||||
@@ -621,11 +614,9 @@ TEST(UnitTestProjection, CalcViewAnglesFromViewMatrix_NegativePitchAndYaw)
|
||||
{
|
||||
constexpr float k_eps = 1e-4f;
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
const omath::source_engine::ViewAngles angles{
|
||||
omath::source_engine::PitchAngle::from_degrees(-45.f),
|
||||
omath::source_engine::YawAngle::from_degrees(-90.f),
|
||||
omath::source_engine::RollAngle::from_degrees(0.f)
|
||||
};
|
||||
const omath::source_engine::ViewAngles angles{omath::source_engine::PitchAngle::from_degrees(-45.f),
|
||||
omath::source_engine::YawAngle::from_degrees(-90.f),
|
||||
omath::source_engine::RollAngle::from_degrees(0.f)};
|
||||
const auto cam = omath::source_engine::Camera({0, 0, 0}, angles, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||
|
||||
const auto result = omath::source_engine::Camera::calc_view_angles_from_view_matrix(cam.get_view_matrix());
|
||||
@@ -640,11 +631,9 @@ TEST(UnitTestProjection, CalcViewAnglesFromViewMatrix_OffOriginCameraIgnored)
|
||||
// so the same angles should be recovered regardless of position.
|
||||
constexpr float k_eps = 1e-4f;
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
const omath::source_engine::ViewAngles angles{
|
||||
omath::source_engine::PitchAngle::from_degrees(20.f),
|
||||
omath::source_engine::YawAngle::from_degrees(60.f),
|
||||
omath::source_engine::RollAngle::from_degrees(0.f)
|
||||
};
|
||||
const omath::source_engine::ViewAngles angles{omath::source_engine::PitchAngle::from_degrees(20.f),
|
||||
omath::source_engine::YawAngle::from_degrees(60.f),
|
||||
omath::source_engine::RollAngle::from_degrees(0.f)};
|
||||
const auto cam = omath::source_engine::Camera({100.f, 200.f, -50.f}, angles, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||
|
||||
const auto result = omath::source_engine::Camera::calc_view_angles_from_view_matrix(cam.get_view_matrix());
|
||||
@@ -657,11 +646,9 @@ TEST(UnitTestProjection, CalcViewAnglesFromViewMatrix_RollAlwaysZero)
|
||||
{
|
||||
// Roll cannot be encoded in the forward vector, so it is always 0 in the result.
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
const omath::source_engine::ViewAngles angles{
|
||||
omath::source_engine::PitchAngle::from_degrees(10.f),
|
||||
omath::source_engine::YawAngle::from_degrees(30.f),
|
||||
omath::source_engine::RollAngle::from_degrees(15.f)
|
||||
};
|
||||
const omath::source_engine::ViewAngles angles{omath::source_engine::PitchAngle::from_degrees(10.f),
|
||||
omath::source_engine::YawAngle::from_degrees(30.f),
|
||||
omath::source_engine::RollAngle::from_degrees(15.f)};
|
||||
const auto cam = omath::source_engine::Camera({0, 0, 0}, angles, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||
|
||||
const auto result = omath::source_engine::Camera::calc_view_angles_from_view_matrix(cam.get_view_matrix());
|
||||
@@ -686,11 +673,9 @@ TEST(UnitTestProjection, CalcOriginFromViewMatrix_ArbitraryPosition)
|
||||
{
|
||||
constexpr float k_eps = 1e-3f;
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
const omath::source_engine::ViewAngles angles{
|
||||
omath::source_engine::PitchAngle::from_degrees(0.f),
|
||||
omath::source_engine::YawAngle::from_degrees(0.f),
|
||||
omath::source_engine::RollAngle::from_degrees(0.f)
|
||||
};
|
||||
const omath::source_engine::ViewAngles angles{omath::source_engine::PitchAngle::from_degrees(0.f),
|
||||
omath::source_engine::YawAngle::from_degrees(0.f),
|
||||
omath::source_engine::RollAngle::from_degrees(0.f)};
|
||||
const auto cam = omath::source_engine::Camera({100.f, 200.f, -50.f}, angles, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||
|
||||
const auto origin = omath::source_engine::Camera::calc_origin_from_view_matrix(cam.get_view_matrix());
|
||||
@@ -705,11 +690,9 @@ TEST(UnitTestProjection, CalcOriginFromViewMatrix_WithRotation)
|
||||
// Origin recovery must work even when the camera is rotated.
|
||||
constexpr float k_eps = 1e-3f;
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
const omath::source_engine::ViewAngles angles{
|
||||
omath::source_engine::PitchAngle::from_degrees(30.f),
|
||||
omath::source_engine::YawAngle::from_degrees(45.f),
|
||||
omath::source_engine::RollAngle::from_degrees(0.f)
|
||||
};
|
||||
const omath::source_engine::ViewAngles angles{omath::source_engine::PitchAngle::from_degrees(30.f),
|
||||
omath::source_engine::YawAngle::from_degrees(45.f),
|
||||
omath::source_engine::RollAngle::from_degrees(0.f)};
|
||||
const auto cam = omath::source_engine::Camera({300.f, -100.f, 75.f}, angles, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||
|
||||
const auto origin = omath::source_engine::Camera::calc_origin_from_view_matrix(cam.get_view_matrix());
|
||||
@@ -726,16 +709,12 @@ TEST(UnitTestProjection, CalcOriginFromViewMatrix_IndependentOfAngles)
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
constexpr omath::Vector3<float> expected_origin{50.f, 50.f, 50.f};
|
||||
|
||||
const omath::source_engine::ViewAngles angles_a{
|
||||
omath::source_engine::PitchAngle::from_degrees(0.f),
|
||||
omath::source_engine::YawAngle::from_degrees(0.f),
|
||||
omath::source_engine::RollAngle::from_degrees(0.f)
|
||||
};
|
||||
const omath::source_engine::ViewAngles angles_b{
|
||||
omath::source_engine::PitchAngle::from_degrees(-60.f),
|
||||
omath::source_engine::YawAngle::from_degrees(135.f),
|
||||
omath::source_engine::RollAngle::from_degrees(0.f)
|
||||
};
|
||||
const omath::source_engine::ViewAngles angles_a{omath::source_engine::PitchAngle::from_degrees(0.f),
|
||||
omath::source_engine::YawAngle::from_degrees(0.f),
|
||||
omath::source_engine::RollAngle::from_degrees(0.f)};
|
||||
const omath::source_engine::ViewAngles angles_b{omath::source_engine::PitchAngle::from_degrees(-60.f),
|
||||
omath::source_engine::YawAngle::from_degrees(135.f),
|
||||
omath::source_engine::RollAngle::from_degrees(0.f)};
|
||||
|
||||
const auto cam_a = omath::source_engine::Camera(expected_origin, angles_a, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||
const auto cam_b = omath::source_engine::Camera(expected_origin, angles_b, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||
@@ -758,11 +737,9 @@ TEST(UnitTestProjection, Unity_CalcViewAnglesFromViewMatrix_LookingForward)
|
||||
{
|
||||
constexpr float k_eps = 1e-4f;
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(60.f);
|
||||
const omath::unity_engine::ViewAngles angles{
|
||||
omath::unity_engine::PitchAngle::from_degrees(0.f),
|
||||
omath::unity_engine::YawAngle::from_degrees(0.f),
|
||||
omath::unity_engine::RollAngle::from_degrees(0.f)
|
||||
};
|
||||
const omath::unity_engine::ViewAngles angles{omath::unity_engine::PitchAngle::from_degrees(0.f),
|
||||
omath::unity_engine::YawAngle::from_degrees(0.f),
|
||||
omath::unity_engine::RollAngle::from_degrees(0.f)};
|
||||
const auto cam = omath::unity_engine::Camera({0, 0, 0}, angles, {1280.f, 720.f}, fov, 0.03f, 1000.f);
|
||||
|
||||
const auto result = omath::unity_engine::Camera::calc_view_angles_from_view_matrix(cam.get_view_matrix());
|
||||
@@ -775,11 +752,9 @@ TEST(UnitTestProjection, Unity_CalcViewAnglesFromViewMatrix_PositivePitchAndYaw)
|
||||
{
|
||||
constexpr float k_eps = 1e-4f;
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(60.f);
|
||||
const omath::unity_engine::ViewAngles angles{
|
||||
omath::unity_engine::PitchAngle::from_degrees(30.f),
|
||||
omath::unity_engine::YawAngle::from_degrees(45.f),
|
||||
omath::unity_engine::RollAngle::from_degrees(0.f)
|
||||
};
|
||||
const omath::unity_engine::ViewAngles angles{omath::unity_engine::PitchAngle::from_degrees(30.f),
|
||||
omath::unity_engine::YawAngle::from_degrees(45.f),
|
||||
omath::unity_engine::RollAngle::from_degrees(0.f)};
|
||||
const auto cam = omath::unity_engine::Camera({0, 0, 0}, angles, {1280.f, 720.f}, fov, 0.03f, 1000.f);
|
||||
|
||||
const auto result = omath::unity_engine::Camera::calc_view_angles_from_view_matrix(cam.get_view_matrix());
|
||||
@@ -792,11 +767,9 @@ TEST(UnitTestProjection, Unity_CalcViewAnglesFromViewMatrix_NegativePitchAndYaw)
|
||||
{
|
||||
constexpr float k_eps = 1e-4f;
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(60.f);
|
||||
const omath::unity_engine::ViewAngles angles{
|
||||
omath::unity_engine::PitchAngle::from_degrees(-45.f),
|
||||
omath::unity_engine::YawAngle::from_degrees(-90.f),
|
||||
omath::unity_engine::RollAngle::from_degrees(0.f)
|
||||
};
|
||||
const omath::unity_engine::ViewAngles angles{omath::unity_engine::PitchAngle::from_degrees(-45.f),
|
||||
omath::unity_engine::YawAngle::from_degrees(-90.f),
|
||||
omath::unity_engine::RollAngle::from_degrees(0.f)};
|
||||
const auto cam = omath::unity_engine::Camera({0, 0, 0}, angles, {1280.f, 720.f}, fov, 0.03f, 1000.f);
|
||||
|
||||
const auto result = omath::unity_engine::Camera::calc_view_angles_from_view_matrix(cam.get_view_matrix());
|
||||
@@ -822,11 +795,9 @@ TEST(UnitTestProjection, Unity_CalcOriginFromViewMatrix_ArbitraryPosition)
|
||||
{
|
||||
constexpr float k_eps = 1e-3f;
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(60.f);
|
||||
const omath::unity_engine::ViewAngles angles{
|
||||
omath::unity_engine::PitchAngle::from_degrees(0.f),
|
||||
omath::unity_engine::YawAngle::from_degrees(0.f),
|
||||
omath::unity_engine::RollAngle::from_degrees(0.f)
|
||||
};
|
||||
const omath::unity_engine::ViewAngles angles{omath::unity_engine::PitchAngle::from_degrees(0.f),
|
||||
omath::unity_engine::YawAngle::from_degrees(0.f),
|
||||
omath::unity_engine::RollAngle::from_degrees(0.f)};
|
||||
const auto cam = omath::unity_engine::Camera({100.f, 200.f, -50.f}, angles, {1280.f, 720.f}, fov, 0.03f, 1000.f);
|
||||
|
||||
const auto origin = omath::unity_engine::Camera::calc_origin_from_view_matrix(cam.get_view_matrix());
|
||||
@@ -840,11 +811,9 @@ TEST(UnitTestProjection, Unity_CalcOriginFromViewMatrix_WithRotation)
|
||||
{
|
||||
constexpr float k_eps = 1e-3f;
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(60.f);
|
||||
const omath::unity_engine::ViewAngles angles{
|
||||
omath::unity_engine::PitchAngle::from_degrees(30.f),
|
||||
omath::unity_engine::YawAngle::from_degrees(45.f),
|
||||
omath::unity_engine::RollAngle::from_degrees(0.f)
|
||||
};
|
||||
const omath::unity_engine::ViewAngles angles{omath::unity_engine::PitchAngle::from_degrees(30.f),
|
||||
omath::unity_engine::YawAngle::from_degrees(45.f),
|
||||
omath::unity_engine::RollAngle::from_degrees(0.f)};
|
||||
const auto cam = omath::unity_engine::Camera({300.f, -100.f, 75.f}, angles, {1280.f, 720.f}, fov, 0.03f, 1000.f);
|
||||
|
||||
const auto origin = omath::unity_engine::Camera::calc_origin_from_view_matrix(cam.get_view_matrix());
|
||||
@@ -860,21 +829,21 @@ TEST(UnitTestProjection, SourceEngine_ZeroAngles_BasisVectors)
|
||||
constexpr float k_eps = 1e-5f;
|
||||
const auto cam = omath::source_engine::Camera({}, {}, {1920.f, 1080.f},
|
||||
omath::projection::FieldOfView::from_degrees(90.f), 0.01f, 1000.f);
|
||||
const auto fwd = cam.get_abs_forward();
|
||||
const auto fwd = cam.get_abs_forward();
|
||||
const auto right = cam.get_abs_right();
|
||||
const auto up = cam.get_abs_up();
|
||||
const auto up = cam.get_abs_up();
|
||||
|
||||
EXPECT_NEAR(fwd.x, omath::source_engine::k_abs_forward.x, k_eps);
|
||||
EXPECT_NEAR(fwd.y, omath::source_engine::k_abs_forward.y, k_eps);
|
||||
EXPECT_NEAR(fwd.z, omath::source_engine::k_abs_forward.z, k_eps);
|
||||
EXPECT_NEAR(fwd.x, omath::source_engine::k_abs_forward.x, k_eps);
|
||||
EXPECT_NEAR(fwd.y, omath::source_engine::k_abs_forward.y, k_eps);
|
||||
EXPECT_NEAR(fwd.z, omath::source_engine::k_abs_forward.z, k_eps);
|
||||
|
||||
EXPECT_NEAR(right.x, omath::source_engine::k_abs_right.x, k_eps);
|
||||
EXPECT_NEAR(right.y, omath::source_engine::k_abs_right.y, k_eps);
|
||||
EXPECT_NEAR(right.z, omath::source_engine::k_abs_right.z, k_eps);
|
||||
|
||||
EXPECT_NEAR(up.x, omath::source_engine::k_abs_up.x, k_eps);
|
||||
EXPECT_NEAR(up.y, omath::source_engine::k_abs_up.y, k_eps);
|
||||
EXPECT_NEAR(up.z, omath::source_engine::k_abs_up.z, k_eps);
|
||||
EXPECT_NEAR(up.x, omath::source_engine::k_abs_up.x, k_eps);
|
||||
EXPECT_NEAR(up.y, omath::source_engine::k_abs_up.y, k_eps);
|
||||
EXPECT_NEAR(up.z, omath::source_engine::k_abs_up.z, k_eps);
|
||||
}
|
||||
|
||||
TEST(UnitTestProjection, UnityEngine_ZeroAngles_BasisVectors)
|
||||
@@ -882,21 +851,21 @@ TEST(UnitTestProjection, UnityEngine_ZeroAngles_BasisVectors)
|
||||
constexpr float k_eps = 1e-5f;
|
||||
const auto cam = omath::unity_engine::Camera({}, {}, {1280.f, 720.f},
|
||||
omath::projection::FieldOfView::from_degrees(60.f), 0.03f, 1000.f);
|
||||
const auto fwd = cam.get_abs_forward();
|
||||
const auto fwd = cam.get_abs_forward();
|
||||
const auto right = cam.get_abs_right();
|
||||
const auto up = cam.get_abs_up();
|
||||
const auto up = cam.get_abs_up();
|
||||
|
||||
EXPECT_NEAR(fwd.x, omath::unity_engine::k_abs_forward.x, k_eps);
|
||||
EXPECT_NEAR(fwd.y, omath::unity_engine::k_abs_forward.y, k_eps);
|
||||
EXPECT_NEAR(fwd.z, omath::unity_engine::k_abs_forward.z, k_eps);
|
||||
EXPECT_NEAR(fwd.x, omath::unity_engine::k_abs_forward.x, k_eps);
|
||||
EXPECT_NEAR(fwd.y, omath::unity_engine::k_abs_forward.y, k_eps);
|
||||
EXPECT_NEAR(fwd.z, omath::unity_engine::k_abs_forward.z, k_eps);
|
||||
|
||||
EXPECT_NEAR(right.x, omath::unity_engine::k_abs_right.x, k_eps);
|
||||
EXPECT_NEAR(right.y, omath::unity_engine::k_abs_right.y, k_eps);
|
||||
EXPECT_NEAR(right.z, omath::unity_engine::k_abs_right.z, k_eps);
|
||||
|
||||
EXPECT_NEAR(up.x, omath::unity_engine::k_abs_up.x, k_eps);
|
||||
EXPECT_NEAR(up.y, omath::unity_engine::k_abs_up.y, k_eps);
|
||||
EXPECT_NEAR(up.z, omath::unity_engine::k_abs_up.z, k_eps);
|
||||
EXPECT_NEAR(up.x, omath::unity_engine::k_abs_up.x, k_eps);
|
||||
EXPECT_NEAR(up.y, omath::unity_engine::k_abs_up.y, k_eps);
|
||||
EXPECT_NEAR(up.z, omath::unity_engine::k_abs_up.z, k_eps);
|
||||
}
|
||||
|
||||
TEST(UnitTestProjection, OpenGLEngine_ZeroAngles_BasisVectors)
|
||||
@@ -904,21 +873,21 @@ TEST(UnitTestProjection, OpenGLEngine_ZeroAngles_BasisVectors)
|
||||
constexpr float k_eps = 1e-5f;
|
||||
const auto cam = omath::opengl_engine::Camera({}, {}, {1920.f, 1080.f},
|
||||
omath::projection::FieldOfView::from_degrees(90.f), 0.01f, 1000.f);
|
||||
const auto fwd = cam.get_abs_forward();
|
||||
const auto fwd = cam.get_abs_forward();
|
||||
const auto right = cam.get_abs_right();
|
||||
const auto up = cam.get_abs_up();
|
||||
const auto up = cam.get_abs_up();
|
||||
|
||||
EXPECT_NEAR(fwd.x, omath::opengl_engine::k_abs_forward.x, k_eps);
|
||||
EXPECT_NEAR(fwd.y, omath::opengl_engine::k_abs_forward.y, k_eps);
|
||||
EXPECT_NEAR(fwd.z, omath::opengl_engine::k_abs_forward.z, k_eps);
|
||||
EXPECT_NEAR(fwd.x, omath::opengl_engine::k_abs_forward.x, k_eps);
|
||||
EXPECT_NEAR(fwd.y, omath::opengl_engine::k_abs_forward.y, k_eps);
|
||||
EXPECT_NEAR(fwd.z, omath::opengl_engine::k_abs_forward.z, k_eps);
|
||||
|
||||
EXPECT_NEAR(right.x, omath::opengl_engine::k_abs_right.x, k_eps);
|
||||
EXPECT_NEAR(right.y, omath::opengl_engine::k_abs_right.y, k_eps);
|
||||
EXPECT_NEAR(right.z, omath::opengl_engine::k_abs_right.z, k_eps);
|
||||
|
||||
EXPECT_NEAR(up.x, omath::opengl_engine::k_abs_up.x, k_eps);
|
||||
EXPECT_NEAR(up.y, omath::opengl_engine::k_abs_up.y, k_eps);
|
||||
EXPECT_NEAR(up.z, omath::opengl_engine::k_abs_up.z, k_eps);
|
||||
EXPECT_NEAR(up.x, omath::opengl_engine::k_abs_up.x, k_eps);
|
||||
EXPECT_NEAR(up.y, omath::opengl_engine::k_abs_up.y, k_eps);
|
||||
EXPECT_NEAR(up.z, omath::opengl_engine::k_abs_up.z, k_eps);
|
||||
}
|
||||
|
||||
TEST(UnitTestProjection, UnrealEngine_ZeroAngles_BasisVectors)
|
||||
@@ -926,21 +895,21 @@ TEST(UnitTestProjection, UnrealEngine_ZeroAngles_BasisVectors)
|
||||
constexpr float k_eps = 1e-5f;
|
||||
const auto cam = omath::unreal_engine::Camera({}, {}, {1920.f, 1080.f},
|
||||
omath::projection::FieldOfView::from_degrees(90.f), 0.01f, 1000.f);
|
||||
const auto fwd = cam.get_abs_forward();
|
||||
const auto fwd = cam.get_abs_forward();
|
||||
const auto right = cam.get_abs_right();
|
||||
const auto up = cam.get_abs_up();
|
||||
const auto up = cam.get_abs_up();
|
||||
|
||||
EXPECT_NEAR(fwd.x, omath::unreal_engine::k_abs_forward.x, k_eps);
|
||||
EXPECT_NEAR(fwd.y, omath::unreal_engine::k_abs_forward.y, k_eps);
|
||||
EXPECT_NEAR(fwd.z, omath::unreal_engine::k_abs_forward.z, k_eps);
|
||||
EXPECT_NEAR(fwd.x, omath::unreal_engine::k_abs_forward.x, k_eps);
|
||||
EXPECT_NEAR(fwd.y, omath::unreal_engine::k_abs_forward.y, k_eps);
|
||||
EXPECT_NEAR(fwd.z, omath::unreal_engine::k_abs_forward.z, k_eps);
|
||||
|
||||
EXPECT_NEAR(right.x, omath::unreal_engine::k_abs_right.x, k_eps);
|
||||
EXPECT_NEAR(right.y, omath::unreal_engine::k_abs_right.y, k_eps);
|
||||
EXPECT_NEAR(right.z, omath::unreal_engine::k_abs_right.z, k_eps);
|
||||
|
||||
EXPECT_NEAR(up.x, omath::unreal_engine::k_abs_up.x, k_eps);
|
||||
EXPECT_NEAR(up.y, omath::unreal_engine::k_abs_up.y, k_eps);
|
||||
EXPECT_NEAR(up.z, omath::unreal_engine::k_abs_up.z, k_eps);
|
||||
EXPECT_NEAR(up.x, omath::unreal_engine::k_abs_up.x, k_eps);
|
||||
EXPECT_NEAR(up.y, omath::unreal_engine::k_abs_up.y, k_eps);
|
||||
EXPECT_NEAR(up.z, omath::unreal_engine::k_abs_up.z, k_eps);
|
||||
}
|
||||
|
||||
TEST(UnitTestProjection, FrostbiteEngine_ZeroAngles_BasisVectors)
|
||||
@@ -948,21 +917,21 @@ TEST(UnitTestProjection, FrostbiteEngine_ZeroAngles_BasisVectors)
|
||||
constexpr float k_eps = 1e-5f;
|
||||
const auto cam = omath::frostbite_engine::Camera({}, {}, {1920.f, 1080.f},
|
||||
omath::projection::FieldOfView::from_degrees(90.f), 0.01f, 1000.f);
|
||||
const auto fwd = cam.get_abs_forward();
|
||||
const auto fwd = cam.get_abs_forward();
|
||||
const auto right = cam.get_abs_right();
|
||||
const auto up = cam.get_abs_up();
|
||||
const auto up = cam.get_abs_up();
|
||||
|
||||
EXPECT_NEAR(fwd.x, omath::frostbite_engine::k_abs_forward.x, k_eps);
|
||||
EXPECT_NEAR(fwd.y, omath::frostbite_engine::k_abs_forward.y, k_eps);
|
||||
EXPECT_NEAR(fwd.z, omath::frostbite_engine::k_abs_forward.z, k_eps);
|
||||
EXPECT_NEAR(fwd.x, omath::frostbite_engine::k_abs_forward.x, k_eps);
|
||||
EXPECT_NEAR(fwd.y, omath::frostbite_engine::k_abs_forward.y, k_eps);
|
||||
EXPECT_NEAR(fwd.z, omath::frostbite_engine::k_abs_forward.z, k_eps);
|
||||
|
||||
EXPECT_NEAR(right.x, omath::frostbite_engine::k_abs_right.x, k_eps);
|
||||
EXPECT_NEAR(right.y, omath::frostbite_engine::k_abs_right.y, k_eps);
|
||||
EXPECT_NEAR(right.z, omath::frostbite_engine::k_abs_right.z, k_eps);
|
||||
|
||||
EXPECT_NEAR(up.x, omath::frostbite_engine::k_abs_up.x, k_eps);
|
||||
EXPECT_NEAR(up.y, omath::frostbite_engine::k_abs_up.y, k_eps);
|
||||
EXPECT_NEAR(up.z, omath::frostbite_engine::k_abs_up.z, k_eps);
|
||||
EXPECT_NEAR(up.x, omath::frostbite_engine::k_abs_up.x, k_eps);
|
||||
EXPECT_NEAR(up.y, omath::frostbite_engine::k_abs_up.y, k_eps);
|
||||
EXPECT_NEAR(up.z, omath::frostbite_engine::k_abs_up.z, k_eps);
|
||||
}
|
||||
|
||||
TEST(UnitTestProjection, CryEngine_ZeroAngles_BasisVectors)
|
||||
@@ -970,21 +939,21 @@ TEST(UnitTestProjection, CryEngine_ZeroAngles_BasisVectors)
|
||||
constexpr float k_eps = 1e-5f;
|
||||
const auto cam = omath::cry_engine::Camera({}, {}, {1920.f, 1080.f},
|
||||
omath::projection::FieldOfView::from_degrees(90.f), 0.01f, 1000.f);
|
||||
const auto fwd = cam.get_abs_forward();
|
||||
const auto fwd = cam.get_abs_forward();
|
||||
const auto right = cam.get_abs_right();
|
||||
const auto up = cam.get_abs_up();
|
||||
const auto up = cam.get_abs_up();
|
||||
|
||||
EXPECT_NEAR(fwd.x, omath::cry_engine::k_abs_forward.x, k_eps);
|
||||
EXPECT_NEAR(fwd.y, omath::cry_engine::k_abs_forward.y, k_eps);
|
||||
EXPECT_NEAR(fwd.z, omath::cry_engine::k_abs_forward.z, k_eps);
|
||||
EXPECT_NEAR(fwd.x, omath::cry_engine::k_abs_forward.x, k_eps);
|
||||
EXPECT_NEAR(fwd.y, omath::cry_engine::k_abs_forward.y, k_eps);
|
||||
EXPECT_NEAR(fwd.z, omath::cry_engine::k_abs_forward.z, k_eps);
|
||||
|
||||
EXPECT_NEAR(right.x, omath::cry_engine::k_abs_right.x, k_eps);
|
||||
EXPECT_NEAR(right.y, omath::cry_engine::k_abs_right.y, k_eps);
|
||||
EXPECT_NEAR(right.z, omath::cry_engine::k_abs_right.z, k_eps);
|
||||
|
||||
EXPECT_NEAR(up.x, omath::cry_engine::k_abs_up.x, k_eps);
|
||||
EXPECT_NEAR(up.y, omath::cry_engine::k_abs_up.y, k_eps);
|
||||
EXPECT_NEAR(up.z, omath::cry_engine::k_abs_up.z, k_eps);
|
||||
EXPECT_NEAR(up.x, omath::cry_engine::k_abs_up.x, k_eps);
|
||||
EXPECT_NEAR(up.y, omath::cry_engine::k_abs_up.y, k_eps);
|
||||
EXPECT_NEAR(up.z, omath::cry_engine::k_abs_up.z, k_eps);
|
||||
}
|
||||
|
||||
TEST(UnitTestProjection, IWEngine_ZeroAngles_BasisVectors)
|
||||
@@ -992,21 +961,21 @@ TEST(UnitTestProjection, IWEngine_ZeroAngles_BasisVectors)
|
||||
constexpr float k_eps = 1e-5f;
|
||||
const auto cam = omath::iw_engine::Camera({}, {}, {1920.f, 1080.f},
|
||||
omath::projection::FieldOfView::from_degrees(90.f), 0.01f, 1000.f);
|
||||
const auto fwd = cam.get_abs_forward();
|
||||
const auto fwd = cam.get_abs_forward();
|
||||
const auto right = cam.get_abs_right();
|
||||
const auto up = cam.get_abs_up();
|
||||
const auto up = cam.get_abs_up();
|
||||
|
||||
EXPECT_NEAR(fwd.x, omath::iw_engine::k_abs_forward.x, k_eps);
|
||||
EXPECT_NEAR(fwd.y, omath::iw_engine::k_abs_forward.y, k_eps);
|
||||
EXPECT_NEAR(fwd.z, omath::iw_engine::k_abs_forward.z, k_eps);
|
||||
EXPECT_NEAR(fwd.x, omath::iw_engine::k_abs_forward.x, k_eps);
|
||||
EXPECT_NEAR(fwd.y, omath::iw_engine::k_abs_forward.y, k_eps);
|
||||
EXPECT_NEAR(fwd.z, omath::iw_engine::k_abs_forward.z, k_eps);
|
||||
|
||||
EXPECT_NEAR(right.x, omath::iw_engine::k_abs_right.x, k_eps);
|
||||
EXPECT_NEAR(right.y, omath::iw_engine::k_abs_right.y, k_eps);
|
||||
EXPECT_NEAR(right.z, omath::iw_engine::k_abs_right.z, k_eps);
|
||||
|
||||
EXPECT_NEAR(up.x, omath::iw_engine::k_abs_up.x, k_eps);
|
||||
EXPECT_NEAR(up.y, omath::iw_engine::k_abs_up.y, k_eps);
|
||||
EXPECT_NEAR(up.z, omath::iw_engine::k_abs_up.z, k_eps);
|
||||
EXPECT_NEAR(up.x, omath::iw_engine::k_abs_up.x, k_eps);
|
||||
EXPECT_NEAR(up.y, omath::iw_engine::k_abs_up.y, k_eps);
|
||||
EXPECT_NEAR(up.z, omath::iw_engine::k_abs_up.z, k_eps);
|
||||
}
|
||||
|
||||
// ---- extract_projection_params ----
|
||||
@@ -1142,11 +1111,9 @@ TEST(UnitTestProjection, SetViewAngles_InvalidatesViewMatrix)
|
||||
auto cam = omath::source_engine::Camera({}, {}, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||
|
||||
const auto view_before = cam.get_view_matrix();
|
||||
const omath::source_engine::ViewAngles rotated{
|
||||
omath::source_engine::PitchAngle::from_degrees(30.f),
|
||||
omath::source_engine::YawAngle::from_degrees(45.f),
|
||||
omath::source_engine::RollAngle::from_degrees(0.f)
|
||||
};
|
||||
const omath::source_engine::ViewAngles rotated{omath::source_engine::PitchAngle::from_degrees(30.f),
|
||||
omath::source_engine::YawAngle::from_degrees(45.f),
|
||||
omath::source_engine::RollAngle::from_degrees(0.f)};
|
||||
cam.set_view_angles(rotated);
|
||||
const auto view_after = cam.get_view_matrix();
|
||||
|
||||
@@ -1164,7 +1131,7 @@ TEST(UnitTestProjection, CalcLookAtAngles_ForwardTarget)
|
||||
const auto angles = cam.calc_look_at_angles({100.f, 0.f, 0.f});
|
||||
|
||||
EXPECT_NEAR(angles.pitch.as_degrees(), 0.f, 1e-4f);
|
||||
EXPECT_NEAR(angles.yaw.as_degrees(), 0.f, 1e-4f);
|
||||
EXPECT_NEAR(angles.yaw.as_degrees(), 0.f, 1e-4f);
|
||||
}
|
||||
|
||||
TEST(UnitTestProjection, LookAt_ForwardVectorPointsAtTarget)
|
||||
@@ -1237,11 +1204,7 @@ TEST(UnitTestProjection, TriangleInsideFrustumNotCulled)
|
||||
const auto cam = omath::source_engine::Camera({0.f, 0.f, 0.f}, {}, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||
|
||||
// Small triangle directly in front (Source: +X forward)
|
||||
const omath::Triangle<omath::Vector3<float>> tri{
|
||||
{100.f, 0.f, 1.f},
|
||||
{100.f, 1.f, -1.f},
|
||||
{100.f, -1.f, -1.f}
|
||||
};
|
||||
const omath::Triangle<omath::Vector3<float>> tri{{100.f, 0.f, 1.f}, {100.f, 1.f, -1.f}, {100.f, -1.f, -1.f}};
|
||||
EXPECT_FALSE(cam.is_culled_by_frustum(tri));
|
||||
}
|
||||
|
||||
@@ -1251,11 +1214,7 @@ TEST(UnitTestProjection, TriangleBehindCameraCulled)
|
||||
const auto cam = omath::source_engine::Camera({0.f, 0.f, 0.f}, {}, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||
|
||||
// Triangle entirely behind the camera (-X)
|
||||
const omath::Triangle<omath::Vector3<float>> tri{
|
||||
{-100.f, 0.f, 1.f},
|
||||
{-100.f, 1.f, -1.f},
|
||||
{-100.f, -1.f, -1.f}
|
||||
};
|
||||
const omath::Triangle<omath::Vector3<float>> tri{{-100.f, 0.f, 1.f}, {-100.f, 1.f, -1.f}, {-100.f, -1.f, -1.f}};
|
||||
EXPECT_TRUE(cam.is_culled_by_frustum(tri));
|
||||
}
|
||||
|
||||
@@ -1265,11 +1224,7 @@ TEST(UnitTestProjection, TriangleBeyondFarPlaneCulled)
|
||||
const auto cam = omath::source_engine::Camera({0.f, 0.f, 0.f}, {}, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||
|
||||
// Triangle beyond the 1000-unit far plane
|
||||
const omath::Triangle<omath::Vector3<float>> tri{
|
||||
{2000.f, 0.f, 1.f},
|
||||
{2000.f, 1.f, -1.f},
|
||||
{2000.f, -1.f, -1.f}
|
||||
};
|
||||
const omath::Triangle<omath::Vector3<float>> tri{{2000.f, 0.f, 1.f}, {2000.f, 1.f, -1.f}, {2000.f, -1.f, -1.f}};
|
||||
EXPECT_TRUE(cam.is_culled_by_frustum(tri));
|
||||
}
|
||||
|
||||
@@ -1279,11 +1234,7 @@ TEST(UnitTestProjection, TriangleFarToSideCulled)
|
||||
const auto cam = omath::source_engine::Camera({0.f, 0.f, 0.f}, {}, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||
|
||||
// Triangle far outside the side frustum planes
|
||||
const omath::Triangle<omath::Vector3<float>> tri{
|
||||
{100.f, 5000.f, 0.f},
|
||||
{100.f, 5001.f, 1.f},
|
||||
{100.f, 5001.f, -1.f}
|
||||
};
|
||||
const omath::Triangle<omath::Vector3<float>> tri{{100.f, 5000.f, 0.f}, {100.f, 5001.f, 1.f}, {100.f, 5001.f, -1.f}};
|
||||
EXPECT_TRUE(cam.is_culled_by_frustum(tri));
|
||||
}
|
||||
|
||||
@@ -1293,10 +1244,6 @@ TEST(UnitTestProjection, TriangleStraddlingFrustumNotCulled)
|
||||
const auto cam = omath::source_engine::Camera({0.f, 0.f, 0.f}, {}, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||
|
||||
// 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}
|
||||
};
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
using namespace omath;
|
||||
|
||||
#ifdef OMATH_USE_GCEM
|
||||
namespace
|
||||
{
|
||||
constexpr bool close_to(const float actual, const float expected, const float epsilon)
|
||||
@@ -17,7 +16,6 @@ namespace
|
||||
return (diff < 0.0f ? -diff : diff) <= epsilon;
|
||||
}
|
||||
} // namespace
|
||||
#endif
|
||||
|
||||
class UnitTestTriangle : public ::testing::Test
|
||||
{
|
||||
@@ -30,36 +28,21 @@ protected:
|
||||
constexpr void SetUp() override
|
||||
{
|
||||
// Triangle with vertices (0, 0, 0), (1, 0, 0), (0, 1, 0)
|
||||
t1 = Triangle<Vector3<float>>(
|
||||
Vector3(0.0f, 0.0f, 0.0f),
|
||||
Vector3(1.0f, 0.0f, 0.0f),
|
||||
Vector3(0.0f, 1.0f, 0.0f)
|
||||
);
|
||||
t1 = Triangle<Vector3<float>>(Vector3(0.0f, 0.0f, 0.0f), Vector3(1.0f, 0.0f, 0.0f), Vector3(0.0f, 1.0f, 0.0f));
|
||||
|
||||
// Triangle with vertices (1, 2, 3), (4, 5, 6), (7, 8, 9)
|
||||
t2 = Triangle<Vector3<float>>(
|
||||
Vector3(1.0f, 2.0f, 3.0f),
|
||||
Vector3(4.0f, 5.0f, 6.0f),
|
||||
Vector3(7.0f, 8.0f, 9.0f)
|
||||
);
|
||||
t2 = Triangle<Vector3<float>>(Vector3(1.0f, 2.0f, 3.0f), Vector3(4.0f, 5.0f, 6.0f), Vector3(7.0f, 8.0f, 9.0f));
|
||||
|
||||
// An isosceles right triangle
|
||||
t3 = Triangle<Vector3<float>>(
|
||||
Vector3(0.0f, 0.0f, 0.0f),
|
||||
Vector3(2.0f, 0.0f, 0.0f),
|
||||
Vector3(0.0f, 2.0f, 0.0f)
|
||||
);
|
||||
t3 = Triangle<Vector3<float>>(Vector3(0.0f, 0.0f, 0.0f), Vector3(2.0f, 0.0f, 0.0f), Vector3(0.0f, 2.0f, 0.0f));
|
||||
}
|
||||
};
|
||||
|
||||
// Test constructor and vertices
|
||||
TEST_F(UnitTestTriangle, Constructor)
|
||||
{
|
||||
constexpr Triangle<Vector3<float>> t(
|
||||
Vector3(1.0f, 2.0f, 3.0f),
|
||||
Vector3(4.0f, 5.0f, 6.0f),
|
||||
Vector3(7.0f, 8.0f, 9.0f)
|
||||
);
|
||||
constexpr Triangle<Vector3<float>> t(Vector3(1.0f, 2.0f, 3.0f), Vector3(4.0f, 5.0f, 6.0f),
|
||||
Vector3(7.0f, 8.0f, 9.0f));
|
||||
|
||||
EXPECT_FLOAT_EQ(t.m_vertex1.x, 1.0f);
|
||||
EXPECT_FLOAT_EQ(t.m_vertex1.y, 2.0f);
|
||||
@@ -83,7 +66,6 @@ TEST_F(UnitTestTriangle, CalculateNormal)
|
||||
EXPECT_NEAR(std::fabs(normal_t1.z), 1.0f, 1e-5f);
|
||||
EXPECT_NEAR(normal_t1.length(), 1.0f, 1e-5f);
|
||||
|
||||
|
||||
// For t3, we expect the normal to be along +Z as well
|
||||
const Vector3 normal_t3 = t3.calculate_normal();
|
||||
EXPECT_NEAR(std::fabs(normal_t3.z), 1.0f, 1e-5f);
|
||||
@@ -94,7 +76,10 @@ TEST_F(UnitTestTriangle, SideLengths)
|
||||
{
|
||||
// For t1 side lengths
|
||||
EXPECT_FLOAT_EQ(t1.side_a_length(), std::sqrt(1.0f)); // distance between (0,0,0) and (1,0,0)
|
||||
EXPECT_FLOAT_EQ(t1.side_b_length(), std::sqrt(1.0f + 1.0f)); // distance between (4,5,6) & (7,8,9)... but we are testing t1, so let's be accurate:
|
||||
EXPECT_FLOAT_EQ(
|
||||
t1.side_b_length(),
|
||||
std::sqrt(1.0f
|
||||
+ 1.0f)); // distance between (4,5,6) & (7,8,9)... but we are testing t1, so let's be accurate:
|
||||
// Actually, for t1: vertex2=(1,0,0), vertex3=(0,1,0)
|
||||
// Dist between (0,1,0) and (1,0,0) = sqrt((1-0)^2 + (0-1)^2) = sqrt(1 + 1) = sqrt(2)
|
||||
EXPECT_FLOAT_EQ(t1.side_b_length(), std::sqrt(2.0f));
|
||||
@@ -123,7 +108,7 @@ TEST_F(UnitTestTriangle, SideVectors)
|
||||
|
||||
TEST_F(UnitTestTriangle, IsRectangular)
|
||||
{
|
||||
EXPECT_TRUE(Triangle<Vector3<float>>({2,0,0}, {}, {0,2,0}).is_rectangular());
|
||||
EXPECT_TRUE(Triangle<Vector3<float>>({2, 0, 0}, {}, {0, 2, 0}).is_rectangular());
|
||||
}
|
||||
// Test midpoint
|
||||
TEST_F(UnitTestTriangle, MidPoint)
|
||||
@@ -141,7 +126,6 @@ TEST_F(UnitTestTriangle, MidPoint)
|
||||
EXPECT_FLOAT_EQ(mid2.z, (3.0f + 6.0f + 9.0f) / 3.0f);
|
||||
}
|
||||
|
||||
#ifdef OMATH_USE_GCEM
|
||||
static_assert(
|
||||
[]
|
||||
{
|
||||
@@ -155,5 +139,4 @@ static_assert(
|
||||
&& close_to(mid_point.x, 1.0f, 1e-5f) && close_to(mid_point.y, 4.0f / 3.0f, 1e-5f)
|
||||
&& close_to(mid_point.z, 0.0f, 1e-5f);
|
||||
}(),
|
||||
"Triangle helpers should be constexpr with gcem");
|
||||
#endif
|
||||
"Triangle helpers should be constexpr with embedded constexpr math");
|
||||
|
||||
@@ -463,8 +463,7 @@ static_assert(Vector2(1.0f, 2.0f).dot(Vector2(4.0f, 5.0f)) == 14.0f, "Dot produc
|
||||
static_assert(Vector2(4.0f, 5.0f).distance_to_sqr(Vector2(1.0f, 2.0f)) == 18.0f, "DistToSqr should be 18");
|
||||
static_assert(Vector2(-1.0f, -2.0f).abs() == Vector2(1.0f, 2.0f), "Abs should convert negative values to positive");
|
||||
|
||||
#ifdef OMATH_USE_GCEM
|
||||
static_assert(Vector2(3.0f, 4.0f).length() == 5.0f, "Length should be constexpr with gcem");
|
||||
static_assert(Vector2(0.0f, 0.0f).distance_to(Vector2(3.0f, 4.0f)) == 5.0f, "Distance should be constexpr with gcem");
|
||||
static_assert(Vector2(1.0f, 1.0f) < Vector2(3.0f, 4.0f), "Comparison should be constexpr with gcem");
|
||||
#endif
|
||||
static_assert(Vector2(3.0f, 4.0f).length() == 5.0f, "Length should be constexpr with embedded constexpr math");
|
||||
static_assert(Vector2(0.0f, 0.0f).distance_to(Vector2(3.0f, 4.0f)) == 5.0f,
|
||||
"Distance should be constexpr with embedded constexpr math");
|
||||
static_assert(Vector2(1.0f, 1.0f) < Vector2(3.0f, 4.0f), "Comparison should be constexpr with embedded constexpr math");
|
||||
|
||||
@@ -584,16 +584,15 @@ static_assert(Vector3(4.0f, 5.0f, 6.0f).distance_to_sqr(Vector3(1.0f, 2.0f, 3.0f
|
||||
static_assert(Vector3(-1.0f, -2.0f, -3.0f).abs() == Vector3(1.0f, 2.0f, 3.0f),
|
||||
"Abs should convert negative values to positive");
|
||||
|
||||
#ifdef OMATH_USE_GCEM
|
||||
static_assert(Vector3(1.0f, 2.0f, 2.0f).length() == 3.0f, "Length should be constexpr with gcem");
|
||||
static_assert(Vector3(1.0f, 2.0f, 2.0f).length() == 3.0f, "Length should be constexpr with embedded constexpr math");
|
||||
static_assert(Vector3(0.0f, 0.0f, 0.0f).distance_to(Vector3(1.0f, 2.0f, 2.0f)) == 3.0f,
|
||||
"Distance should be constexpr with gcem");
|
||||
static_assert(Vector3(1.0f, 1.0f, 1.0f) < Vector3(3.0f, 4.0f, 5.0f), "Comparison should be constexpr with gcem");
|
||||
"Distance should be constexpr with embedded constexpr math");
|
||||
static_assert(Vector3(1.0f, 1.0f, 1.0f) < Vector3(3.0f, 4.0f, 5.0f),
|
||||
"Comparison should be constexpr with embedded constexpr math");
|
||||
static_assert(
|
||||
[]
|
||||
{
|
||||
constexpr auto angle = Vector3(1.0f, 0.0f, 0.0f).angle_between(Vector3(0.0f, 1.0f, 0.0f));
|
||||
return angle.has_value() && angle->as_degrees() > 89.999f && angle->as_degrees() < 90.001f;
|
||||
}(),
|
||||
"Angle between should be constexpr with gcem");
|
||||
#endif
|
||||
"Angle between should be constexpr with embedded constexpr math");
|
||||
|
||||
Reference in New Issue
Block a user