mirror of
https://github.com/orange-cpp/omath.git
synced 2026-04-18 18:23:26 +00:00
Compare commits
7 Commits
ba80aebfae
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 20930c629a | |||
| 0845a2e863 | |||
| f3f454b02e | |||
| 0419043720 | |||
| 79f64d9679 | |||
| dbe29926dc | |||
| 9d30446c55 |
6
.idea/editor.xml
generated
6
.idea/editor.xml
generated
@@ -103,7 +103,7 @@
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppImplicitDefaultConstructorNotAvailable/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppIncompatiblePointerConversion/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppIncompleteSwitchStatement/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppInconsistentNaming/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppInconsistentNaming/@EntryIndexedValue" value="HINT" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppIntegralToPointerConversion/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppInvalidLineContinuation/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppJoinDeclarationAndAssignment/@EntryIndexedValue" value="SUGGESTION" type="string" />
|
||||
@@ -202,7 +202,7 @@
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppStaticDataMemberInUnnamedStruct/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppStaticSpecifierOnAnonymousNamespaceMember/@EntryIndexedValue" value="SUGGESTION" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppStringLiteralToCharPointerConversion/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTabsAreDisallowed/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTabsAreDisallowed/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTemplateArgumentsCanBeDeduced/@EntryIndexedValue" value="HINT" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTemplateParameterNeverUsed/@EntryIndexedValue" value="HINT" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTemplateParameterShadowing/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
@@ -216,7 +216,7 @@
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnmatchedPragmaEndRegionDirective/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnmatchedPragmaRegionDirective/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnnamedNamespaceInHeaderFile/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnnecessaryWhitespace/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnnecessaryWhitespace/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnsignedZeroComparison/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnusedIncludeDirective/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseAlgorithmWithCount/@EntryIndexedValue" value="SUGGESTION" type="string" />
|
||||
|
||||
@@ -318,22 +318,22 @@ int main()
|
||||
glfwPollEvents();
|
||||
omath::Vector3<float> move_dir;
|
||||
if (glfwGetKey(window, GLFW_KEY_W))
|
||||
move_dir += camera.get_forward();
|
||||
move_dir += camera.get_abs_forward();
|
||||
|
||||
if (glfwGetKey(window, GLFW_KEY_A))
|
||||
move_dir -= camera.get_right();
|
||||
move_dir -= camera.get_abs_right();
|
||||
|
||||
if (glfwGetKey(window, GLFW_KEY_S))
|
||||
move_dir -= camera.get_forward();
|
||||
move_dir -= camera.get_abs_forward();
|
||||
|
||||
if (glfwGetKey(window, GLFW_KEY_D))
|
||||
move_dir += camera.get_right();
|
||||
move_dir += camera.get_abs_right();
|
||||
|
||||
if (glfwGetKey(window, GLFW_KEY_SPACE))
|
||||
move_dir += camera.get_up();
|
||||
move_dir += camera.get_abs_up();
|
||||
|
||||
if (glfwGetKey(window, GLFW_KEY_LEFT_CONTROL))
|
||||
move_dir -= camera.get_up();
|
||||
move_dir -= camera.get_abs_up();
|
||||
|
||||
|
||||
auto delta = glfwGetTime() - old_mouse_time;
|
||||
|
||||
@@ -9,5 +9,5 @@
|
||||
|
||||
namespace omath::cry_engine
|
||||
{
|
||||
using Camera = projection::Camera<Mat4X4, ViewAngles, CameraTrait, false, NDCDepthRange::ZERO_TO_ONE>;
|
||||
using Camera = projection::Camera<Mat4X4, ViewAngles, CameraTrait, NDCDepthRange::ZERO_TO_ONE>;
|
||||
} // namespace omath::cry_engine
|
||||
@@ -9,5 +9,5 @@
|
||||
|
||||
namespace omath::frostbite_engine
|
||||
{
|
||||
using Camera = projection::Camera<Mat4X4, ViewAngles, CameraTrait, false, NDCDepthRange::ZERO_TO_ONE>;
|
||||
} // namespace omath::unity_engine
|
||||
using Camera = projection::Camera<Mat4X4, ViewAngles, CameraTrait, NDCDepthRange::ZERO_TO_ONE>;
|
||||
} // namespace omath::frostbite_engine
|
||||
@@ -9,5 +9,5 @@
|
||||
|
||||
namespace omath::iw_engine
|
||||
{
|
||||
using Camera = projection::Camera<Mat4X4, ViewAngles, CameraTrait, false, NDCDepthRange::ZERO_TO_ONE>;
|
||||
using Camera = projection::Camera<Mat4X4, ViewAngles, CameraTrait, NDCDepthRange::ZERO_TO_ONE>;
|
||||
} // namespace omath::iw_engine
|
||||
@@ -8,5 +8,5 @@
|
||||
|
||||
namespace omath::opengl_engine
|
||||
{
|
||||
using Camera = projection::Camera<Mat4X4, ViewAngles, CameraTrait, true, NDCDepthRange::NEGATIVE_ONE_TO_ONE>;
|
||||
using Camera = projection::Camera<Mat4X4, ViewAngles, CameraTrait, NDCDepthRange::NEGATIVE_ONE_TO_ONE, {.inverted_forward = true}>;
|
||||
} // namespace omath::opengl_engine
|
||||
@@ -7,5 +7,5 @@
|
||||
#include "traits/camera_trait.hpp"
|
||||
namespace omath::source_engine
|
||||
{
|
||||
using Camera = projection::Camera<Mat4X4, ViewAngles, CameraTrait, false, NDCDepthRange::ZERO_TO_ONE>;
|
||||
using Camera = projection::Camera<Mat4X4, ViewAngles, CameraTrait, NDCDepthRange::ZERO_TO_ONE>;
|
||||
} // namespace omath::source_engine
|
||||
@@ -9,5 +9,5 @@
|
||||
|
||||
namespace omath::unity_engine
|
||||
{
|
||||
using Camera = projection::Camera<Mat4X4, ViewAngles, CameraTrait, false, NDCDepthRange::ZERO_TO_ONE>;
|
||||
using Camera = projection::Camera<Mat4X4, ViewAngles, CameraTrait, NDCDepthRange::ZERO_TO_ONE, {.inverted_forward = true}>;
|
||||
} // namespace omath::unity_engine
|
||||
@@ -9,5 +9,5 @@
|
||||
|
||||
namespace omath::unreal_engine
|
||||
{
|
||||
using Camera = projection::Camera<Mat4X4, ViewAngles, CameraTrait, false, NDCDepthRange::ZERO_TO_ONE>;
|
||||
using Camera = projection::Camera<Mat4X4, ViewAngles, CameraTrait, NDCDepthRange::ZERO_TO_ONE, {.inverted_right = true}>;
|
||||
} // namespace omath::unreal_engine
|
||||
@@ -42,6 +42,12 @@ namespace omath::projection
|
||||
AUTO,
|
||||
MANUAL,
|
||||
};
|
||||
struct CameraAxes
|
||||
{
|
||||
bool inverted_forward = false;
|
||||
bool inverted_right = false;
|
||||
};
|
||||
|
||||
template<class T, class MatType, class ViewAnglesType>
|
||||
concept CameraEngineConcept =
|
||||
requires(const Vector3<float>& cam_origin, const Vector3<float>& look_at, const ViewAnglesType& angles,
|
||||
@@ -58,8 +64,9 @@ namespace omath::projection
|
||||
requires noexcept(T::calc_projection_matrix(fov, viewport, znear, zfar, ndc_depth_range));
|
||||
};
|
||||
|
||||
template<class Mat4X4Type, class ViewAnglesType, class TraitClass, bool inverted_z = false,
|
||||
NDCDepthRange depth_range = NDCDepthRange::NEGATIVE_ONE_TO_ONE>
|
||||
template<class Mat4X4Type, class ViewAnglesType, class TraitClass,
|
||||
NDCDepthRange depth_range = NDCDepthRange::NEGATIVE_ONE_TO_ONE,
|
||||
CameraAxes axes = {}>
|
||||
requires CameraEngineConcept<TraitClass, Mat4X4Type, ViewAnglesType>
|
||||
class Camera final
|
||||
{
|
||||
@@ -83,6 +90,46 @@ namespace omath::projection
|
||||
{
|
||||
}
|
||||
|
||||
struct ProjectionParams
|
||||
{
|
||||
FieldOfView fov;
|
||||
float aspect_ratio;
|
||||
};
|
||||
|
||||
// Recovers vertical FOV and aspect ratio from a perspective projection matrix
|
||||
// built by any of the engine traits. Both variants (ZERO_TO_ONE and
|
||||
// NEGATIVE_ONE_TO_ONE) share the same m[0,0]/m[1,1] layout, so this works
|
||||
// regardless of the NDC depth range.
|
||||
[[nodiscard]]
|
||||
static ProjectionParams extract_projection_params(const Mat4X4Type& proj_matrix) noexcept
|
||||
{
|
||||
// m[1,1] == 1 / tan(fov/2) => fov = 2 * atan(1 / m[1,1])
|
||||
const float f = proj_matrix.at(1, 1);
|
||||
// m[0,0] == m[1,1] / aspect_ratio => aspect = m[1,1] / m[0,0]
|
||||
return {FieldOfView::from_radians(2.f * std::atan(1.f / f)), f / proj_matrix.at(0, 0)};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
static ViewAnglesType calc_view_angles_from_view_matrix(const Mat4X4Type& view_matrix) noexcept
|
||||
{
|
||||
Vector3<float> forward_vector = {view_matrix[2, 0], view_matrix[2, 1], view_matrix[2, 2]};
|
||||
if constexpr (axes.inverted_forward)
|
||||
forward_vector = -forward_vector;
|
||||
return TraitClass::calc_look_at_angle({}, forward_vector);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
static Vector3<float> calc_origin_from_view_matrix(const Mat4X4Type& view_matrix) noexcept
|
||||
{
|
||||
// The view matrix is R * T(-origin), so the last column stores t = -R * origin.
|
||||
// Recovering origin: origin = -R^T * t
|
||||
return {
|
||||
-(view_matrix[0, 0] * view_matrix[0, 3] + view_matrix[1, 0] * view_matrix[1, 3] + view_matrix[2, 0] * view_matrix[2, 3]),
|
||||
-(view_matrix[0, 1] * view_matrix[0, 3] + view_matrix[1, 1] * view_matrix[1, 3] + view_matrix[2, 1] * view_matrix[2, 3]),
|
||||
-(view_matrix[0, 2] * view_matrix[0, 3] + view_matrix[1, 2] * view_matrix[1, 3] + view_matrix[2, 2] * view_matrix[2, 3]),
|
||||
};
|
||||
}
|
||||
|
||||
void look_at(const Vector3<float>& target)
|
||||
{
|
||||
m_view_angles = TraitClass::calc_look_at_angle(m_origin, target);
|
||||
@@ -99,9 +146,6 @@ namespace omath::projection
|
||||
Vector3<float> get_forward() const noexcept
|
||||
{
|
||||
const auto& view_matrix = get_view_matrix();
|
||||
|
||||
if constexpr (inverted_z)
|
||||
return -Vector3<float>{view_matrix[2, 0], view_matrix[2, 1], view_matrix[2, 2]};
|
||||
return {view_matrix[2, 0], view_matrix[2, 1], view_matrix[2, 2]};
|
||||
}
|
||||
|
||||
@@ -118,6 +162,27 @@ namespace omath::projection
|
||||
const auto& view_matrix = get_view_matrix();
|
||||
return {view_matrix[1, 0], view_matrix[1, 1], view_matrix[1, 2]};
|
||||
}
|
||||
[[nodiscard]]
|
||||
Vector3<float> get_abs_forward() const noexcept
|
||||
{
|
||||
if constexpr (axes.inverted_forward)
|
||||
return -get_forward();
|
||||
return get_forward();
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
Vector3<float> get_abs_right() const noexcept
|
||||
{
|
||||
if constexpr (axes.inverted_right)
|
||||
return -get_right();
|
||||
return get_right();
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
Vector3<float> get_abs_up() const noexcept
|
||||
{
|
||||
return get_up();
|
||||
}
|
||||
|
||||
[[nodiscard]] const Mat4X4Type& get_view_projection_matrix() const noexcept
|
||||
{
|
||||
|
||||
@@ -453,3 +453,184 @@ TEST(unit_test_frostbite_engine, ViewAnglesAsVector3NormalizedYaw)
|
||||
|
||||
EXPECT_NEAR(vec.y, -90.f, 0.01f);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// extract_projection_params
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// Tolerance: tan/atan round-trip in single precision introduces ~1e-5 rad
|
||||
// error, which is ~5.7e-4 degrees.
|
||||
static constexpr float k_fov_tolerance_deg = 0.001f;
|
||||
static constexpr float k_aspect_tolerance = 1e-5f;
|
||||
|
||||
TEST(unit_test_frostbite_engine, ExtractProjectionParams_BasicRoundTrip)
|
||||
{
|
||||
// Build a matrix with known inputs and verify both outputs are recovered.
|
||||
constexpr float fov_deg = 60.f;
|
||||
constexpr float aspect = 16.f / 9.f;
|
||||
const auto mat = omath::frostbite_engine::calc_perspective_projection_matrix(
|
||||
fov_deg, aspect, 0.1f, 1000.f, omath::NDCDepthRange::ZERO_TO_ONE);
|
||||
|
||||
const auto [fov, ar] = omath::frostbite_engine::Camera::extract_projection_params(mat);
|
||||
|
||||
EXPECT_NEAR(fov.as_degrees(), fov_deg, k_fov_tolerance_deg);
|
||||
EXPECT_NEAR(ar, aspect, k_aspect_tolerance);
|
||||
}
|
||||
|
||||
TEST(unit_test_frostbite_engine, ExtractProjectionParams_NegOneToOneDepthRange)
|
||||
{
|
||||
// The FOV/aspect encoding in rows 0 and 1 is identical for both NDC
|
||||
// depth ranges, so extraction must work the same way.
|
||||
constexpr float fov_deg = 75.f;
|
||||
constexpr float aspect = 4.f / 3.f;
|
||||
const auto mat = omath::frostbite_engine::calc_perspective_projection_matrix(
|
||||
fov_deg, aspect, 0.1f, 500.f, omath::NDCDepthRange::NEGATIVE_ONE_TO_ONE);
|
||||
|
||||
const auto [fov, ar] = omath::frostbite_engine::Camera::extract_projection_params(mat);
|
||||
|
||||
EXPECT_NEAR(fov.as_degrees(), fov_deg, k_fov_tolerance_deg);
|
||||
EXPECT_NEAR(ar, aspect, k_aspect_tolerance);
|
||||
}
|
||||
|
||||
TEST(unit_test_frostbite_engine, ExtractProjectionParams_Fov45)
|
||||
{
|
||||
constexpr float fov_deg = 45.f;
|
||||
constexpr float aspect = 16.f / 9.f;
|
||||
const auto mat = omath::frostbite_engine::calc_perspective_projection_matrix(
|
||||
fov_deg, aspect, 0.01f, 1000.f);
|
||||
|
||||
const auto [fov, ar] = omath::frostbite_engine::Camera::extract_projection_params(mat);
|
||||
|
||||
EXPECT_NEAR(fov.as_degrees(), fov_deg, k_fov_tolerance_deg);
|
||||
EXPECT_NEAR(ar, aspect, k_aspect_tolerance);
|
||||
}
|
||||
|
||||
TEST(unit_test_frostbite_engine, ExtractProjectionParams_Fov90)
|
||||
{
|
||||
constexpr float fov_deg = 90.f;
|
||||
constexpr float aspect = 16.f / 9.f;
|
||||
const auto mat = omath::frostbite_engine::calc_perspective_projection_matrix(
|
||||
fov_deg, aspect, 0.01f, 1000.f);
|
||||
|
||||
const auto [fov, ar] = omath::frostbite_engine::Camera::extract_projection_params(mat);
|
||||
|
||||
EXPECT_NEAR(fov.as_degrees(), fov_deg, k_fov_tolerance_deg);
|
||||
EXPECT_NEAR(ar, aspect, k_aspect_tolerance);
|
||||
}
|
||||
|
||||
TEST(unit_test_frostbite_engine, ExtractProjectionParams_Fov120)
|
||||
{
|
||||
constexpr float fov_deg = 120.f;
|
||||
constexpr float aspect = 16.f / 9.f;
|
||||
const auto mat = omath::frostbite_engine::calc_perspective_projection_matrix(
|
||||
fov_deg, aspect, 0.01f, 1000.f);
|
||||
|
||||
const auto [fov, ar] = omath::frostbite_engine::Camera::extract_projection_params(mat);
|
||||
|
||||
EXPECT_NEAR(fov.as_degrees(), fov_deg, k_fov_tolerance_deg);
|
||||
EXPECT_NEAR(ar, aspect, k_aspect_tolerance);
|
||||
}
|
||||
|
||||
TEST(unit_test_frostbite_engine, ExtractProjectionParams_AspectRatio_4by3)
|
||||
{
|
||||
constexpr float fov_deg = 60.f;
|
||||
constexpr float aspect = 4.f / 3.f;
|
||||
const auto mat = omath::frostbite_engine::calc_perspective_projection_matrix(
|
||||
fov_deg, aspect, 0.1f, 500.f);
|
||||
|
||||
const auto [fov, ar] = omath::frostbite_engine::Camera::extract_projection_params(mat);
|
||||
|
||||
EXPECT_NEAR(fov.as_degrees(), fov_deg, k_fov_tolerance_deg);
|
||||
EXPECT_NEAR(ar, aspect, k_aspect_tolerance);
|
||||
}
|
||||
|
||||
TEST(unit_test_frostbite_engine, ExtractProjectionParams_AspectRatio_Ultrawide)
|
||||
{
|
||||
constexpr float fov_deg = 90.f;
|
||||
constexpr float aspect = 21.f / 9.f;
|
||||
const auto mat = omath::frostbite_engine::calc_perspective_projection_matrix(
|
||||
fov_deg, aspect, 0.1f, 500.f);
|
||||
|
||||
const auto [fov, ar] = omath::frostbite_engine::Camera::extract_projection_params(mat);
|
||||
|
||||
EXPECT_NEAR(fov.as_degrees(), fov_deg, k_fov_tolerance_deg);
|
||||
EXPECT_NEAR(ar, aspect, k_aspect_tolerance);
|
||||
}
|
||||
|
||||
TEST(unit_test_frostbite_engine, ExtractProjectionParams_AspectRatio_Square)
|
||||
{
|
||||
constexpr float fov_deg = 90.f;
|
||||
constexpr float aspect = 1.f;
|
||||
const auto mat = omath::frostbite_engine::calc_perspective_projection_matrix(
|
||||
fov_deg, aspect, 0.1f, 500.f);
|
||||
|
||||
const auto [fov, ar] = omath::frostbite_engine::Camera::extract_projection_params(mat);
|
||||
|
||||
EXPECT_NEAR(fov.as_degrees(), fov_deg, k_fov_tolerance_deg);
|
||||
EXPECT_NEAR(ar, aspect, k_aspect_tolerance);
|
||||
}
|
||||
|
||||
TEST(unit_test_frostbite_engine, ExtractProjectionParams_FovAndAspectAreIndependent)
|
||||
{
|
||||
// Changing only FOV must not affect recovered aspect ratio, and vice versa.
|
||||
constexpr float aspect = 16.f / 9.f;
|
||||
|
||||
for (const float fov_deg : {45.f, 60.f, 90.f, 110.f})
|
||||
{
|
||||
const auto mat = omath::frostbite_engine::calc_perspective_projection_matrix(
|
||||
fov_deg, aspect, 0.1f, 1000.f);
|
||||
const auto [fov, ar] = omath::frostbite_engine::Camera::extract_projection_params(mat);
|
||||
|
||||
EXPECT_NEAR(fov.as_degrees(), fov_deg, k_fov_tolerance_deg);
|
||||
EXPECT_NEAR(ar, aspect, k_aspect_tolerance);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(unit_test_frostbite_engine, ExtractProjectionParams_ViaCamera_RoundTrip)
|
||||
{
|
||||
// End-to-end: construct a Camera, retrieve its projection matrix, then
|
||||
// recover the FOV and aspect ratio and compare against the original inputs.
|
||||
constexpr auto fov_in = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
constexpr float aspect = 1920.f / 1080.f;
|
||||
|
||||
const auto cam = omath::frostbite_engine::Camera(
|
||||
{0.f, 0.f, 0.f}, {}, {1920.f, 1080.f}, fov_in, 0.01f, 1000.f);
|
||||
|
||||
const auto [fov_out, ar_out] =
|
||||
omath::frostbite_engine::Camera::extract_projection_params(cam.get_projection_matrix());
|
||||
|
||||
EXPECT_NEAR(fov_out.as_degrees(), fov_in.as_degrees(), k_fov_tolerance_deg);
|
||||
EXPECT_NEAR(ar_out, aspect, k_aspect_tolerance);
|
||||
}
|
||||
|
||||
TEST(unit_test_frostbite_engine, ExtractProjectionParams_ViaCamera_AfterFovChange)
|
||||
{
|
||||
// Verify that the extracted FOV tracks the camera's FOV after set_field_of_view().
|
||||
auto cam = omath::frostbite_engine::Camera(
|
||||
{0.f, 0.f, 0.f}, {}, {1920.f, 1080.f},
|
||||
omath::projection::FieldOfView::from_degrees(60.f), 0.01f, 1000.f);
|
||||
|
||||
cam.set_field_of_view(omath::projection::FieldOfView::from_degrees(110.f));
|
||||
|
||||
const auto [fov, ar] =
|
||||
omath::frostbite_engine::Camera::extract_projection_params(cam.get_projection_matrix());
|
||||
|
||||
EXPECT_NEAR(fov.as_degrees(), 110.f, k_fov_tolerance_deg);
|
||||
EXPECT_NEAR(ar, 1920.f / 1080.f, k_aspect_tolerance);
|
||||
}
|
||||
|
||||
TEST(unit_test_frostbite_engine, ExtractProjectionParams_ViaCamera_AfterViewportChange)
|
||||
{
|
||||
// Verify that the extracted aspect ratio tracks the viewport after set_view_port().
|
||||
auto cam = omath::frostbite_engine::Camera(
|
||||
{0.f, 0.f, 0.f}, {}, {1920.f, 1080.f},
|
||||
omath::projection::FieldOfView::from_degrees(90.f), 0.01f, 1000.f);
|
||||
|
||||
cam.set_view_port({1280.f, 720.f});
|
||||
|
||||
const auto [fov, ar] =
|
||||
omath::frostbite_engine::Camera::extract_projection_params(cam.get_projection_matrix());
|
||||
|
||||
EXPECT_NEAR(fov.as_degrees(), 90.f, k_fov_tolerance_deg);
|
||||
EXPECT_NEAR(ar, 1280.f / 720.f, k_aspect_tolerance);
|
||||
}
|
||||
|
||||
@@ -5,8 +5,12 @@
|
||||
#include <complex>
|
||||
#include <gtest/gtest.h>
|
||||
#include <omath/3d_primitives/aabb.hpp>
|
||||
#include <omath/engines/cry_engine/camera.hpp>
|
||||
#include <omath/engines/frostbite_engine/camera.hpp>
|
||||
#include <omath/engines/iw_engine/camera.hpp>
|
||||
#include <omath/engines/opengl_engine/camera.hpp>
|
||||
#include <omath/engines/source_engine/camera.hpp>
|
||||
#include <omath/engines/unreal_engine/camera.hpp>
|
||||
#include <omath/projection/camera.hpp>
|
||||
#include <print>
|
||||
#include <random>
|
||||
@@ -510,4 +514,430 @@ TEST(UnitTestProjection, AabbUnityEngineStraddlesNearNotCulled)
|
||||
// Box straddles near plane (Unity: +Z forward)
|
||||
const omath::primitives::Aabb<float> aabb{{-1.f, -1.f, -5.f}, {1.f, 1.f, 5.f}};
|
||||
EXPECT_FALSE(cam.is_aabb_culled_by_frustum(aabb));
|
||||
}
|
||||
}
|
||||
|
||||
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 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());
|
||||
|
||||
EXPECT_NEAR(result.pitch.as_degrees(), 0.f, k_eps);
|
||||
EXPECT_NEAR(result.yaw.as_degrees(), 0.f, k_eps);
|
||||
}
|
||||
|
||||
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 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());
|
||||
|
||||
EXPECT_NEAR(result.pitch.as_degrees(), 30.f, k_eps);
|
||||
EXPECT_NEAR(result.yaw.as_degrees(), 45.f, k_eps);
|
||||
}
|
||||
|
||||
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 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());
|
||||
|
||||
EXPECT_NEAR(result.pitch.as_degrees(), -45.f, k_eps);
|
||||
EXPECT_NEAR(result.yaw.as_degrees(), -90.f, k_eps);
|
||||
}
|
||||
|
||||
TEST(UnitTestProjection, CalcViewAnglesFromViewMatrix_OffOriginCameraIgnored)
|
||||
{
|
||||
// The forward vector from the view matrix does not depend on camera origin,
|
||||
// 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 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());
|
||||
|
||||
EXPECT_NEAR(result.pitch.as_degrees(), 20.f, k_eps);
|
||||
EXPECT_NEAR(result.yaw.as_degrees(), 60.f, k_eps);
|
||||
}
|
||||
|
||||
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 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());
|
||||
|
||||
EXPECT_FLOAT_EQ(result.roll.as_degrees(), 0.f);
|
||||
}
|
||||
|
||||
TEST(UnitTestProjection, CalcOriginFromViewMatrix_AtOrigin)
|
||||
{
|
||||
constexpr float k_eps = 1e-4f;
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||
const auto cam = omath::source_engine::Camera({0, 0, 0}, {}, {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());
|
||||
|
||||
EXPECT_NEAR(origin.x, 0.f, k_eps);
|
||||
EXPECT_NEAR(origin.y, 0.f, k_eps);
|
||||
EXPECT_NEAR(origin.z, 0.f, k_eps);
|
||||
}
|
||||
|
||||
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 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());
|
||||
|
||||
EXPECT_NEAR(origin.x, 100.f, k_eps);
|
||||
EXPECT_NEAR(origin.y, 200.f, k_eps);
|
||||
EXPECT_NEAR(origin.z, -50.f, k_eps);
|
||||
}
|
||||
|
||||
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 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());
|
||||
|
||||
EXPECT_NEAR(origin.x, 300.f, k_eps);
|
||||
EXPECT_NEAR(origin.y, -100.f, k_eps);
|
||||
EXPECT_NEAR(origin.z, 75.f, k_eps);
|
||||
}
|
||||
|
||||
TEST(UnitTestProjection, CalcOriginFromViewMatrix_IndependentOfAngles)
|
||||
{
|
||||
// Same position, different orientations — should always recover the same origin.
|
||||
constexpr float k_eps = 1e-3f;
|
||||
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 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);
|
||||
|
||||
const auto origin_a = omath::source_engine::Camera::calc_origin_from_view_matrix(cam_a.get_view_matrix());
|
||||
const auto origin_b = omath::source_engine::Camera::calc_origin_from_view_matrix(cam_b.get_view_matrix());
|
||||
|
||||
EXPECT_NEAR(origin_a.x, expected_origin.x, k_eps);
|
||||
EXPECT_NEAR(origin_a.y, expected_origin.y, k_eps);
|
||||
EXPECT_NEAR(origin_a.z, expected_origin.z, k_eps);
|
||||
|
||||
EXPECT_NEAR(origin_b.x, expected_origin.x, k_eps);
|
||||
EXPECT_NEAR(origin_b.y, expected_origin.y, k_eps);
|
||||
EXPECT_NEAR(origin_b.z, expected_origin.z, k_eps);
|
||||
}
|
||||
|
||||
// ---- Unity engine camera tests ----
|
||||
|
||||
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 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());
|
||||
|
||||
EXPECT_NEAR(result.pitch.as_degrees(), 0.f, k_eps);
|
||||
EXPECT_NEAR(result.yaw.as_degrees(), 0.f, k_eps);
|
||||
}
|
||||
|
||||
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 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());
|
||||
|
||||
EXPECT_NEAR(result.pitch.as_degrees(), 30.f, k_eps);
|
||||
EXPECT_NEAR(result.yaw.as_degrees(), 45.f, k_eps);
|
||||
}
|
||||
|
||||
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 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());
|
||||
|
||||
EXPECT_NEAR(result.pitch.as_degrees(), -45.f, k_eps);
|
||||
EXPECT_NEAR(result.yaw.as_degrees(), -90.f, k_eps);
|
||||
}
|
||||
|
||||
TEST(UnitTestProjection, Unity_CalcOriginFromViewMatrix_AtOrigin)
|
||||
{
|
||||
constexpr float k_eps = 1e-4f;
|
||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(60.f);
|
||||
const auto cam = omath::unity_engine::Camera({0, 0, 0}, {}, {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());
|
||||
|
||||
EXPECT_NEAR(origin.x, 0.f, k_eps);
|
||||
EXPECT_NEAR(origin.y, 0.f, k_eps);
|
||||
EXPECT_NEAR(origin.z, 0.f, k_eps);
|
||||
}
|
||||
|
||||
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 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());
|
||||
|
||||
EXPECT_NEAR(origin.x, 100.f, k_eps);
|
||||
EXPECT_NEAR(origin.y, 200.f, k_eps);
|
||||
EXPECT_NEAR(origin.z, -50.f, k_eps);
|
||||
}
|
||||
|
||||
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 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());
|
||||
|
||||
EXPECT_NEAR(origin.x, 300.f, k_eps);
|
||||
EXPECT_NEAR(origin.y, -100.f, k_eps);
|
||||
EXPECT_NEAR(origin.z, 75.f, k_eps);
|
||||
}
|
||||
// ---- Camera basis vectors at zero angles ----
|
||||
|
||||
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 right = cam.get_abs_right();
|
||||
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(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);
|
||||
}
|
||||
|
||||
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 right = cam.get_abs_right();
|
||||
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(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);
|
||||
}
|
||||
|
||||
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 right = cam.get_abs_right();
|
||||
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(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);
|
||||
}
|
||||
|
||||
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 right = cam.get_abs_right();
|
||||
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(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);
|
||||
}
|
||||
|
||||
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 right = cam.get_abs_right();
|
||||
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(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);
|
||||
}
|
||||
|
||||
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 right = cam.get_abs_right();
|
||||
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(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);
|
||||
}
|
||||
|
||||
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 right = cam.get_abs_right();
|
||||
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(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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user