diff --git a/.idea/editor.xml b/.idea/editor.xml
index bce786e..9b5acf8 100644
--- a/.idea/editor.xml
+++ b/.idea/editor.xml
@@ -103,7 +103,7 @@
-
+
@@ -202,7 +202,7 @@
-
+
@@ -216,7 +216,7 @@
-
+
diff --git a/include/omath/engines/unreal_engine/camera.hpp b/include/omath/engines/unreal_engine/camera.hpp
index 1f62c3c..b3032a4 100644
--- a/include/omath/engines/unreal_engine/camera.hpp
+++ b/include/omath/engines/unreal_engine/camera.hpp
@@ -9,5 +9,5 @@
namespace omath::unreal_engine
{
- using Camera = projection::Camera;
+ using Camera = projection::Camera;
} // namespace omath::unreal_engine
\ No newline at end of file
diff --git a/include/omath/engines/unreal_engine/constants.hpp b/include/omath/engines/unreal_engine/constants.hpp
index 98ecf04..9b3bb21 100644
--- a/include/omath/engines/unreal_engine/constants.hpp
+++ b/include/omath/engines/unreal_engine/constants.hpp
@@ -11,16 +11,16 @@
namespace omath::unreal_engine
{
- constexpr Vector3 k_abs_up = {0, 0, 1};
- constexpr Vector3 k_abs_right = {0, 1, 0};
- constexpr Vector3 k_abs_forward = {1, 0, 0};
+ constexpr Vector3 k_abs_up = {0, 0, 1};
+ constexpr Vector3 k_abs_right = {0, 1, 0};
+ constexpr Vector3 k_abs_forward = {1, 0, 0};
- using Mat4X4 = Mat<4, 4, float, MatStoreType::ROW_MAJOR>;
- using Mat3X3 = Mat<4, 4, float, MatStoreType::ROW_MAJOR>;
- using Mat1X3 = Mat<1, 3, float, MatStoreType::ROW_MAJOR>;
- using PitchAngle = Angle;
- using YawAngle = Angle;
- using RollAngle = Angle;
+ using Mat4X4 = Mat<4, 4, double, MatStoreType::ROW_MAJOR>;
+ using Mat3X3 = Mat<4, 4, double, MatStoreType::ROW_MAJOR>;
+ using Mat1X3 = Mat<1, 3, double, MatStoreType::ROW_MAJOR>;
+ using PitchAngle = Angle;
+ using YawAngle = Angle;
+ using RollAngle = Angle;
using ViewAngles = omath::ViewAngles;
} // namespace omath::unreal_engine
diff --git a/include/omath/engines/unreal_engine/formulas.hpp b/include/omath/engines/unreal_engine/formulas.hpp
index 650bebd..68a4060 100644
--- a/include/omath/engines/unreal_engine/formulas.hpp
+++ b/include/omath/engines/unreal_engine/formulas.hpp
@@ -8,21 +8,21 @@
namespace omath::unreal_engine
{
[[nodiscard]]
- Vector3 forward_vector(const ViewAngles& angles) noexcept;
+ Vector3 forward_vector(const ViewAngles& angles) noexcept;
[[nodiscard]]
- Vector3 right_vector(const ViewAngles& angles) noexcept;
+ Vector3 right_vector(const ViewAngles& angles) noexcept;
[[nodiscard]]
- Vector3 up_vector(const ViewAngles& angles) noexcept;
+ Vector3 up_vector(const ViewAngles& angles) noexcept;
- [[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept;
+ [[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept;
[[nodiscard]]
Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
[[nodiscard]]
- Mat4X4 calc_perspective_projection_matrix(float field_of_view, float aspect_ratio, float near, float far,
+ Mat4X4 calc_perspective_projection_matrix(double field_of_view, double aspect_ratio, double near, double far,
NDCDepthRange ndc_depth_range = NDCDepthRange::NEGATIVE_ONE_TO_ONE) noexcept;
template
diff --git a/include/omath/engines/unreal_engine/traits/camera_trait.hpp b/include/omath/engines/unreal_engine/traits/camera_trait.hpp
index 952542c..4b0fe77 100644
--- a/include/omath/engines/unreal_engine/traits/camera_trait.hpp
+++ b/include/omath/engines/unreal_engine/traits/camera_trait.hpp
@@ -12,13 +12,13 @@ namespace omath::unreal_engine
{
public:
[[nodiscard]]
- static ViewAngles calc_look_at_angle(const Vector3& cam_origin, const Vector3& look_at) noexcept;
+ static ViewAngles calc_look_at_angle(const Vector3& cam_origin, const Vector3& look_at) noexcept;
[[nodiscard]]
- static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept;
+ static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept;
[[nodiscard]]
static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov, const projection::ViewPort& view_port,
- float near, float far, NDCDepthRange ndc_depth_range) noexcept;
+ double near, double far, NDCDepthRange ndc_depth_range) noexcept;
};
} // namespace omath::unreal_engine
\ No newline at end of file
diff --git a/include/omath/engines/unreal_engine/traits/pred_engine_trait.hpp b/include/omath/engines/unreal_engine/traits/pred_engine_trait.hpp
index f2a2214..99f5818 100644
--- a/include/omath/engines/unreal_engine/traits/pred_engine_trait.hpp
+++ b/include/omath/engines/unreal_engine/traits/pred_engine_trait.hpp
@@ -17,9 +17,11 @@ namespace omath::unreal_engine
const float time, const float gravity) noexcept
{
const auto launch_pos = projectile.m_origin + projectile.m_launch_offset;
+ const auto fwd_d = forward_vector({PitchAngle::from_degrees(-pitch), YawAngle::from_degrees(yaw),
+ RollAngle::from_degrees(0)});
auto current_pos = launch_pos
- + forward_vector({PitchAngle::from_degrees(-pitch), YawAngle::from_degrees(yaw),
- RollAngle::from_degrees(0)})
+ + Vector3{static_cast(fwd_d.x), static_cast(fwd_d.y),
+ static_cast(fwd_d.z)}
* projectile.m_launch_speed * time;
current_pos.y -= (gravity * projectile.m_gravity_scale) * (time * time) * 0.5f;
diff --git a/include/omath/linear_algebra/mat.hpp b/include/omath/linear_algebra/mat.hpp
index a262b69..86d50ed 100644
--- a/include/omath/linear_algebra/mat.hpp
+++ b/include/omath/linear_algebra/mat.hpp
@@ -714,13 +714,13 @@ namespace omath
template
[[nodiscard]]
- Mat<4, 4, Type, St> mat_perspective_left_handed_horizontal_fov(const float horizontal_fov,
- const float aspect_ratio, const float near,
- const float far) noexcept
+ Mat<4, 4, Type, St> mat_perspective_left_handed_horizontal_fov(const Type horizontal_fov,
+ const Type aspect_ratio, const Type near,
+ const Type far) noexcept
{
- const float inv_tan_half_hfov = 1.f / std::tan(angles::degrees_to_radians(horizontal_fov) / 2.f);
- const float x_axis = inv_tan_half_hfov;
- const float y_axis = inv_tan_half_hfov * aspect_ratio;
+ const auto inv_tan_half_hfov = 1.f / std::tan(angles::degrees_to_radians(horizontal_fov) / 2.f);
+ const auto x_axis = inv_tan_half_hfov;
+ const auto y_axis = inv_tan_half_hfov / aspect_ratio;
if constexpr (DepthRange == NDCDepthRange::ZERO_TO_ONE)
return {{x_axis, 0.f, 0.f, 0.f},
@@ -739,9 +739,9 @@ namespace omath
template
[[nodiscard]]
- Mat<4, 4, Type, St> mat_perspective_right_handed_horizontal_fov(const float horizontal_fov,
- const float aspect_ratio, const float near,
- const float far) noexcept
+ Mat<4, 4, Type, St> mat_perspective_right_handed_horizontal_fov(const Type horizontal_fov,
+ const Type aspect_ratio, const Type near,
+ const Type far) noexcept
{
const float inv_tan_half_hfov = 1.f / std::tan(angles::degrees_to_radians(horizontal_fov) / 2.f);
const float x_axis = inv_tan_half_hfov;
diff --git a/include/omath/projection/camera.hpp b/include/omath/projection/camera.hpp
index bce63f1..bcfae29 100644
--- a/include/omath/projection/camera.hpp
+++ b/include/omath/projection/camera.hpp
@@ -45,14 +45,14 @@ namespace omath::projection
struct CameraAxes
{
bool inverted_forward = false;
- bool inverted_right = false;
+ bool inverted_right = false;
};
template
concept CameraEngineConcept =
- requires(const Vector3& cam_origin, const Vector3& look_at, const ViewAnglesType& angles,
- const FieldOfView& fov, const ViewPort& viewport, float znear, float zfar,
- NDCDepthRange ndc_depth_range) {
+ requires(const Vector3& cam_origin, const Vector3& look_at,
+ const ViewAnglesType& angles, const FieldOfView& fov, const ViewPort& viewport,
+ NumericType znear, NumericType zfar, NDCDepthRange ndc_depth_range) {
// Presence + return types
{ T::calc_look_at_angle(cam_origin, look_at) } -> std::same_as;
{ T::calc_view_matrix(angles, cam_origin) } -> std::same_as;
@@ -65,8 +65,8 @@ namespace omath::projection
};
template
+ NDCDepthRange depth_range = NDCDepthRange::NEGATIVE_ONE_TO_ONE, CameraAxes axes = {},
+ class NumericType = float>
requires CameraEngineConcept
class Camera final
{
@@ -83,17 +83,17 @@ namespace omath::projection
};
~Camera() = default;
- Camera(const Vector3& position, const ViewAnglesType& view_angles, const ViewPort& view_port,
+ Camera(const Vector3& position, const ViewAnglesType& view_angles, const ViewPort& view_port,
const FieldOfView& fov, const NumericType near, const NumericType far) noexcept
: m_view_port(view_port), m_field_of_view(fov), m_far_plane_distance(far), m_near_plane_distance(near),
m_view_angles(view_angles), m_origin(position)
{
}
- struct ProjectionParams
+ struct ProjectionParams final
{
FieldOfView fov;
- float aspect_ratio;
+ float aspect_ratio{};
};
// Recovers vertical FOV and aspect ratio from a perspective projection matrix
@@ -124,9 +124,12 @@ namespace omath::projection
// 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]),
+ -(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]),
};
}
@@ -202,9 +205,8 @@ namespace omath::projection
[[nodiscard]] const Mat4X4Type& get_projection_matrix() const noexcept
{
if (!m_projection_matrix.has_value())
- m_projection_matrix = TraitClass::calc_projection_matrix(m_field_of_view, m_view_port,
- m_near_plane_distance, m_far_plane_distance,
- depth_range);
+ m_projection_matrix = TraitClass::calc_projection_matrix(
+ m_field_of_view, m_view_port, m_near_plane_distance, m_far_plane_distance, depth_range);
return m_projection_matrix.value();
}
@@ -293,7 +295,7 @@ namespace omath::projection
}
template
[[nodiscard]] std::expected, Error>
- world_to_screen_unclipped(const Vector3& world_position) const noexcept
+ world_to_screen_unclipped(const Vector3& world_position) const noexcept
{
const auto normalized_cords = world_to_view_port(world_position, ViewPortClipping::MANUAL);
@@ -332,8 +334,9 @@ namespace omath::projection
return true;
// Helper: all three vertices outside the same clip plane
- auto all_outside_plane = [](const int axis, const std::array& a, const std::array& b,
- const std::array& c, const bool positive_side)
+ auto all_outside_plane = [](const int axis, const std::array& a,
+ const std::array& b, const std::array& c,
+ const bool positive_side)
{
if (positive_side)
return a[axis] > a[3] && b[axis] > b[3] && c[axis] > c[3];
@@ -389,16 +392,16 @@ namespace omath::projection
// Far = r3 - r2
struct Plane final
{
- float a, b, c, d;
+ NumericType a, b, c, d;
};
const auto extract_plane = [&m](const int sign, const int row) -> Plane
{
return {
- m.at(3, 0) + static_cast(sign) * m.at(row, 0),
- m.at(3, 1) + static_cast(sign) * m.at(row, 1),
- m.at(3, 2) + static_cast(sign) * m.at(row, 2),
- m.at(3, 3) + static_cast(sign) * m.at(row, 3),
+ m.at(3, 0) + static_cast(sign) * m.at(row, 0),
+ m.at(3, 1) + static_cast(sign) * m.at(row, 1),
+ m.at(3, 2) + static_cast(sign) * m.at(row, 2),
+ m.at(3, 3) + static_cast(sign) * m.at(row, 3),
};
};
@@ -452,12 +455,12 @@ namespace omath::projection
// ReSharper disable once CppTooWideScope
constexpr auto z_min = depth_range == NDCDepthRange::ZERO_TO_ONE ? 0.0f : -1.0f;
- const auto clipped_manually = clipping == ViewPortClipping::MANUAL && (projected.at(2, 0) < z_min - eps
- || projected.at(2, 0) > 1.0f + eps);
+ const auto clipped_manually = clipping == ViewPortClipping::MANUAL
+ && (projected.at(2, 0) < z_min - eps || projected.at(2, 0) > 1.0f + eps);
if (clipped_manually)
return std::unexpected(Error::WORLD_POSITION_IS_OUT_OF_SCREEN_BOUNDS);
- return Vector3{projected.at(0, 0), projected.at(1, 0), projected.at(2, 0)};
+ return Vector3{projected.at(0, 0), projected.at(1, 0), projected.at(2, 0)};
}
[[nodiscard]]
std::expected, Error> view_port_to_world(const Vector3& ndc) const noexcept
@@ -478,19 +481,21 @@ namespace omath::projection
inverted_projection /= w;
return Vector3{inverted_projection.at(0, 0), inverted_projection.at(1, 0),
- inverted_projection.at(2, 0)};
+ inverted_projection.at(2, 0)};
}
template
[[nodiscard]]
- std::expected, Error> screen_to_world(const Vector3& screen_pos) const noexcept
+ std::expected, Error>
+ screen_to_world(const Vector3& screen_pos) const noexcept
{
return view_port_to_world(screen_to_ndc(screen_pos));
}
template
[[nodiscard]]
- std::expected, Error> screen_to_world(const Vector2& screen_pos) const noexcept
+ std::expected, Error>
+ screen_to_world(const Vector2& screen_pos) const noexcept
{
const auto& [x, y] = screen_pos;
return screen_to_world({x, y, 1.f});
@@ -498,13 +503,13 @@ namespace omath::projection
protected:
ViewPort m_view_port{};
- Angle m_field_of_view;
+ FieldOfView m_field_of_view;
mutable std::optional m_view_projection_matrix;
mutable std::optional m_projection_matrix;
mutable std::optional m_view_matrix;
- float m_far_plane_distance;
- float m_near_plane_distance;
+ NumericType m_far_plane_distance;
+ NumericType m_near_plane_distance;
ViewAnglesType m_view_angles;
Vector3 m_origin;
@@ -524,10 +529,10 @@ namespace omath::projection
return is_ndc_z_value_out_of_bounds(data[2]);
}
template
- [[nodiscard]]
+ [[nodiscard]]
constexpr static bool is_ndc_z_value_out_of_bounds(const ZType& z_ndc) noexcept
{
- constexpr auto eps = std::numeric_limits::epsilon();
+ constexpr auto eps = std::numeric_limits::epsilon();
if constexpr (depth_range == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
return z_ndc < -1.0f - eps || z_ndc > 1.0f + eps;
if constexpr (depth_range == NDCDepthRange::ZERO_TO_ONE)
@@ -550,8 +555,8 @@ namespace omath::projection
v
*/
- [[nodiscard]] Vector3
- ndc_to_screen_position_from_top_left_corner(const Vector3& ndc) const noexcept
+ [[nodiscard]] Vector3
+ ndc_to_screen_position_from_top_left_corner(const Vector3& ndc) const noexcept
{
/*
+------------------------>
@@ -567,8 +572,8 @@ namespace omath::projection
return {(ndc.x + 1.f) / 2.f * m_view_port.m_width, (ndc.y / -2.f + 0.5f) * m_view_port.m_height, ndc.z};
}
- [[nodiscard]] Vector3
- ndc_to_screen_position_from_bottom_left_corner(const Vector3& ndc) const noexcept
+ [[nodiscard]] Vector3
+ ndc_to_screen_position_from_bottom_left_corner(const Vector3& ndc) const noexcept
{
/*
^
@@ -585,7 +590,7 @@ namespace omath::projection
}
template
- [[nodiscard]] Vector3 screen_to_ndc(const Vector3& screen_pos) const noexcept
+ [[nodiscard]] Vector3 screen_to_ndc(const Vector3& screen_pos) const noexcept
{
if constexpr (screen_start == ScreenStart::TOP_LEFT_CORNER)
return {screen_pos.x / m_view_port.m_width * 2.f - 1.f, 1.f - screen_pos.y / m_view_port.m_height * 2.f,
diff --git a/source/engines/unreal_engine/formulas.cpp b/source/engines/unreal_engine/formulas.cpp
index 9405824..c311be8 100644
--- a/source/engines/unreal_engine/formulas.cpp
+++ b/source/engines/unreal_engine/formulas.cpp
@@ -4,27 +4,27 @@
#include "omath/engines/unreal_engine/formulas.hpp"
namespace omath::unreal_engine
{
- Vector3 forward_vector(const ViewAngles& angles) noexcept
+ Vector3 forward_vector(const ViewAngles& angles) noexcept
{
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_forward);
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
}
- Vector3 right_vector(const ViewAngles& angles) noexcept
+ Vector3 right_vector(const ViewAngles& angles) noexcept
{
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_right);
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
}
- Vector3 up_vector(const ViewAngles& angles) noexcept
+ Vector3 up_vector(const ViewAngles& angles) noexcept
{
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_up);
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
}
- Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept
+ Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept
{
- return mat_camera_view(forward_vector(angles), right_vector(angles),
+ return mat_camera_view(forward_vector(angles), right_vector(angles),
up_vector(angles), cam_origin);
}
Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
@@ -33,24 +33,24 @@ namespace omath::unreal_engine
// frame), which for column-vector composition is Rz·Ry·Rx.
// Pitch and roll axes in omath spin opposite to UE's convention, so
// both carry a sign flip.
- return mat_rotation_axis_z(angles.yaw)
- * mat_rotation_axis_y(-angles.pitch)
- * mat_rotation_axis_x(-angles.roll);
+ return mat_rotation_axis_z(angles.yaw)
+ * mat_rotation_axis_y(-angles.pitch)
+ * mat_rotation_axis_x(-angles.roll);
}
- Mat4X4 calc_perspective_projection_matrix(const float field_of_view, const float aspect_ratio, const float near,
- const float far, const NDCDepthRange ndc_depth_range) noexcept
+ Mat4X4 calc_perspective_projection_matrix(const double field_of_view, const double aspect_ratio, const double near,
+ const double far, const NDCDepthRange ndc_depth_range) noexcept
{
// UE stores horizontal FOV in FMinimalViewInfo — use the left-handed
// horizontal-FOV builder directly.
if (ndc_depth_range == NDCDepthRange::ZERO_TO_ONE)
return mat_perspective_left_handed_horizontal_fov<
- float, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
+ double, MatStoreType::ROW_MAJOR, NDCDepthRange::ZERO_TO_ONE>(
field_of_view, aspect_ratio, near, far);
if (ndc_depth_range == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
return mat_perspective_left_handed_horizontal_fov<
- float, MatStoreType::ROW_MAJOR, NDCDepthRange::NEGATIVE_ONE_TO_ONE>(
+ double, MatStoreType::ROW_MAJOR, NDCDepthRange::NEGATIVE_ONE_TO_ONE>(
field_of_view, aspect_ratio, near, far);
std::unreachable();
}
diff --git a/source/engines/unreal_engine/traits/camera_trait.cpp b/source/engines/unreal_engine/traits/camera_trait.cpp
index b676449..f652d3e 100644
--- a/source/engines/unreal_engine/traits/camera_trait.cpp
+++ b/source/engines/unreal_engine/traits/camera_trait.cpp
@@ -6,20 +6,20 @@
namespace omath::unreal_engine
{
- ViewAngles CameraTrait::calc_look_at_angle(const Vector3& cam_origin, const Vector3& look_at) noexcept
+ ViewAngles CameraTrait::calc_look_at_angle(const Vector3& cam_origin, const Vector3& look_at) noexcept
{
const auto direction = (look_at - cam_origin).normalized();
return {PitchAngle::from_radians(std::asin(direction.z)),
YawAngle::from_radians(std::atan2(direction.y, direction.x)), RollAngle::from_radians(0.f)};
}
- Mat4X4 CameraTrait::calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept
+ Mat4X4 CameraTrait::calc_view_matrix(const ViewAngles& angles, const Vector3& cam_origin) noexcept
{
return unreal_engine::calc_view_matrix(angles, cam_origin);
}
Mat4X4 CameraTrait::calc_projection_matrix(const projection::FieldOfView& fov,
- const projection::ViewPort& view_port, const float near,
- const float far, const NDCDepthRange ndc_depth_range) noexcept
+ const projection::ViewPort& view_port, const double near,
+ const double far, const NDCDepthRange ndc_depth_range) noexcept
{
return calc_perspective_projection_matrix(fov.as_degrees(), view_port.aspect_ratio(), near, far,
ndc_depth_range);
diff --git a/tests/engines/unit_test_traits_engines.cpp b/tests/engines/unit_test_traits_engines.cpp
index 5c08bb4..8b343fb 100644
--- a/tests/engines/unit_test_traits_engines.cpp
+++ b/tests/engines/unit_test_traits_engines.cpp
@@ -499,10 +499,11 @@ TEST(NDCDepthRangeTests, CryEngine_BothDepthRanges)
// ── Verify Z mapping for ZERO_TO_ONE across all engines ─────────────────────
// Helper: projects a point at given z through a left-handed projection matrix and returns NDC z
-static float project_z_lh(const Mat<4, 4>& proj, float z)
+template
+static float project_z_lh(const Mat<4, 4, Type, Store>& proj, float z)
{
- auto clip = proj * mat_column_from_vector({0, 0, z});
- return clip.at(2, 0) / clip.at(3, 0);
+ auto clip = proj * mat_column_from_vector({0, 0, static_cast(z)});
+ return static_cast(clip.at(2, 0) / clip.at(3, 0));
}
TEST(NDCDepthRangeTests, Source_ZeroToOne_ZRange)
diff --git a/tests/engines/unit_test_unreal_engine.cpp b/tests/engines/unit_test_unreal_engine.cpp
index cb41716..15e907e 100644
--- a/tests/engines/unit_test_unreal_engine.cpp
+++ b/tests/engines/unit_test_unreal_engine.cpp
@@ -111,7 +111,7 @@ TEST(unit_test_unreal_engine, CameraSetAndGetOrigin)
{
auto cam = omath::unreal_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, {}, 0.01f, 1000.f);
- EXPECT_EQ(cam.get_origin(), omath::Vector3{});
+ EXPECT_EQ(cam.get_origin(), omath::Vector3{});
cam.set_field_of_view(omath::projection::FieldOfView::from_degrees(50.f));
EXPECT_EQ(cam.get_field_of_view().as_degrees(), 50.f);
@@ -129,7 +129,7 @@ TEST(unit_test_unreal_engine, loook_at_random_all_axis)
std::size_t failed_points = 0;
for (int i = 0; i < 100; i++)
{
- const auto position_to_look = omath::Vector3{dist(gen), dist(gen), dist(gen)};
+ const auto position_to_look = omath::Vector3{dist(gen), dist(gen), dist(gen)};
if (cam.get_origin().distance_to(position_to_look) < 10)
continue;
@@ -151,7 +151,7 @@ TEST(unit_test_unreal_engine, loook_at_random_all_axis)
TEST(unit_test_unreal_engine, loook_at_random_x_axis)
{
std::mt19937 gen(std::random_device{}()); // Seed with a non-deterministic source
- std::uniform_real_distribution dist(-1000.f, 1000.f);
+ std::uniform_real_distribution dist(-1000.f, 1000.f);
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
auto cam = omath::unreal_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.001f, 10000.f);
@@ -159,7 +159,7 @@ TEST(unit_test_unreal_engine, loook_at_random_x_axis)
std::size_t failed_points = 0;
for (int i = 0; i < 1000; i++)
{
- const auto position_to_look = omath::Vector3{dist(gen), dist(gen), dist(gen)};
+ const auto position_to_look = omath::Vector3{dist(gen), dist(gen), dist(gen)};
if (cam.get_origin().distance_to(position_to_look) < 10)
continue;
@@ -190,7 +190,7 @@ TEST(unit_test_unreal_engine, loook_at_random_y_axis)
std::size_t failed_points = 0;
for (int i = 0; i < 1000; i++)
{
- const auto position_to_look = omath::Vector3{0.f, dist(gen), 0.f};
+ const auto position_to_look = omath::Vector3{0.f, dist(gen), 0.f};
if (cam.get_origin().distance_to(position_to_look) < 10)
continue;
@@ -221,7 +221,7 @@ TEST(unit_test_unreal_engine, loook_at_random_z_axis)
std::size_t failed_points = 0;
for (int i = 0; i < 1000; i++)
{
- const auto position_to_look = omath::Vector3{0.f, 0.f, dist(gen)};
+ const auto position_to_look = omath::Vector3{0.f, 0.f, dist(gen)};
if (cam.get_origin().distance_to(position_to_look) < 10)
continue;