mirror of
https://github.com/orange-cpp/omath.git
synced 2026-04-25 12:23:26 +00:00
updated for unreal
This commit is contained in:
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/=CppImplicitDefaultConstructorNotAvailable/@EntryIndexedValue" value="WARNING" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppIncompatiblePointerConversion/@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/=CppIncompleteSwitchStatement/@EntryIndexedValue" value="WARNING" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppInconsistentNaming/@EntryIndexedValue" value="HINT" type="string" />
|
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppInconsistentNaming/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppIntegralToPointerConversion/@EntryIndexedValue" value="WARNING" 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/=CppInvalidLineContinuation/@EntryIndexedValue" value="WARNING" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppJoinDeclarationAndAssignment/@EntryIndexedValue" value="SUGGESTION" 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/=CppStaticDataMemberInUnnamedStruct/@EntryIndexedValue" value="WARNING" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppStaticSpecifierOnAnonymousNamespaceMember/@EntryIndexedValue" value="SUGGESTION" 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/=CppStringLiteralToCharPointerConversion/@EntryIndexedValue" value="WARNING" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTabsAreDisallowed/@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/=CppTemplateArgumentsCanBeDeduced/@EntryIndexedValue" value="HINT" 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/=CppTemplateParameterNeverUsed/@EntryIndexedValue" value="HINT" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTemplateParameterShadowing/@EntryIndexedValue" value="WARNING" 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/=CppUnmatchedPragmaEndRegionDirective/@EntryIndexedValue" value="WARNING" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnmatchedPragmaRegionDirective/@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/=CppUnnamedNamespaceInHeaderFile/@EntryIndexedValue" value="WARNING" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnnecessaryWhitespace/@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/=CppUnsignedZeroComparison/@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/=CppUnusedIncludeDirective/@EntryIndexedValue" value="WARNING" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseAlgorithmWithCount/@EntryIndexedValue" value="SUGGESTION" type="string" />
|
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseAlgorithmWithCount/@EntryIndexedValue" value="SUGGESTION" type="string" />
|
||||||
|
|||||||
@@ -9,5 +9,5 @@
|
|||||||
|
|
||||||
namespace omath::unreal_engine
|
namespace omath::unreal_engine
|
||||||
{
|
{
|
||||||
using Camera = projection::Camera<Mat4X4, ViewAngles, CameraTrait, NDCDepthRange::ZERO_TO_ONE>;
|
using Camera = projection::Camera<Mat4X4, ViewAngles, CameraTrait, NDCDepthRange::ZERO_TO_ONE, {}, double>;
|
||||||
} // namespace omath::unreal_engine
|
} // namespace omath::unreal_engine
|
||||||
@@ -11,16 +11,16 @@
|
|||||||
|
|
||||||
namespace omath::unreal_engine
|
namespace omath::unreal_engine
|
||||||
{
|
{
|
||||||
constexpr Vector3<float> k_abs_up = {0, 0, 1};
|
constexpr Vector3<double> k_abs_up = {0, 0, 1};
|
||||||
constexpr Vector3<float> k_abs_right = {0, 1, 0};
|
constexpr Vector3<double> k_abs_right = {0, 1, 0};
|
||||||
constexpr Vector3<float> k_abs_forward = {1, 0, 0};
|
constexpr Vector3<double> k_abs_forward = {1, 0, 0};
|
||||||
|
|
||||||
using Mat4X4 = Mat<4, 4, float, MatStoreType::ROW_MAJOR>;
|
using Mat4X4 = Mat<4, 4, double, MatStoreType::ROW_MAJOR>;
|
||||||
using Mat3X3 = Mat<4, 4, float, MatStoreType::ROW_MAJOR>;
|
using Mat3X3 = Mat<4, 4, double, MatStoreType::ROW_MAJOR>;
|
||||||
using Mat1X3 = Mat<1, 3, float, MatStoreType::ROW_MAJOR>;
|
using Mat1X3 = Mat<1, 3, double, MatStoreType::ROW_MAJOR>;
|
||||||
using PitchAngle = Angle<float, -90.f, 90.f, AngleFlags::Clamped>;
|
using PitchAngle = Angle<double, -90., 90., AngleFlags::Clamped>;
|
||||||
using YawAngle = Angle<float, -180.f, 180.f, AngleFlags::Normalized>;
|
using YawAngle = Angle<double, -180., 180., AngleFlags::Normalized>;
|
||||||
using RollAngle = Angle<float, -180.f, 180.f, AngleFlags::Normalized>;
|
using RollAngle = Angle<double, -180., 180., AngleFlags::Normalized>;
|
||||||
|
|
||||||
using ViewAngles = omath::ViewAngles<PitchAngle, YawAngle, RollAngle>;
|
using ViewAngles = omath::ViewAngles<PitchAngle, YawAngle, RollAngle>;
|
||||||
} // namespace omath::unreal_engine
|
} // namespace omath::unreal_engine
|
||||||
|
|||||||
@@ -8,21 +8,21 @@
|
|||||||
namespace omath::unreal_engine
|
namespace omath::unreal_engine
|
||||||
{
|
{
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Vector3<float> forward_vector(const ViewAngles& angles) noexcept;
|
Vector3<double> forward_vector(const ViewAngles& angles) noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Vector3<float> right_vector(const ViewAngles& angles) noexcept;
|
Vector3<double> right_vector(const ViewAngles& angles) noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Vector3<float> up_vector(const ViewAngles& angles) noexcept;
|
Vector3<double> up_vector(const ViewAngles& angles) noexcept;
|
||||||
|
|
||||||
[[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept;
|
[[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<double>& cam_origin) noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
|
Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[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;
|
NDCDepthRange ndc_depth_range = NDCDepthRange::NEGATIVE_ONE_TO_ONE) noexcept;
|
||||||
|
|
||||||
template<class FloatingType>
|
template<class FloatingType>
|
||||||
|
|||||||
@@ -12,13 +12,13 @@ namespace omath::unreal_engine
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
static ViewAngles calc_look_at_angle(const Vector3<float>& cam_origin, const Vector3<float>& look_at) noexcept;
|
static ViewAngles calc_look_at_angle(const Vector3<double>& cam_origin, const Vector3<double>& look_at) noexcept;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept;
|
static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<double>& cam_origin) noexcept;
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov, const projection::ViewPort& view_port,
|
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
|
} // namespace omath::unreal_engine
|
||||||
@@ -17,9 +17,11 @@ namespace omath::unreal_engine
|
|||||||
const float time, const float gravity) noexcept
|
const float time, const float gravity) noexcept
|
||||||
{
|
{
|
||||||
const auto launch_pos = projectile.m_origin + projectile.m_launch_offset;
|
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
|
auto current_pos = launch_pos
|
||||||
+ forward_vector({PitchAngle::from_degrees(-pitch), YawAngle::from_degrees(yaw),
|
+ Vector3<float>{static_cast<float>(fwd_d.x), static_cast<float>(fwd_d.y),
|
||||||
RollAngle::from_degrees(0)})
|
static_cast<float>(fwd_d.z)}
|
||||||
* projectile.m_launch_speed * time;
|
* projectile.m_launch_speed * time;
|
||||||
current_pos.y -= (gravity * projectile.m_gravity_scale) * (time * time) * 0.5f;
|
current_pos.y -= (gravity * projectile.m_gravity_scale) * (time * time) * 0.5f;
|
||||||
|
|
||||||
|
|||||||
@@ -714,13 +714,13 @@ namespace omath
|
|||||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR,
|
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR,
|
||||||
NDCDepthRange DepthRange = NDCDepthRange::NEGATIVE_ONE_TO_ONE>
|
NDCDepthRange DepthRange = NDCDepthRange::NEGATIVE_ONE_TO_ONE>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Mat<4, 4, Type, St> mat_perspective_left_handed_horizontal_fov(const float horizontal_fov,
|
Mat<4, 4, Type, St> mat_perspective_left_handed_horizontal_fov(const Type horizontal_fov,
|
||||||
const float aspect_ratio, const float near,
|
const Type aspect_ratio, const Type near,
|
||||||
const float far) noexcept
|
const Type far) noexcept
|
||||||
{
|
{
|
||||||
const float inv_tan_half_hfov = 1.f / std::tan(angles::degrees_to_radians(horizontal_fov) / 2.f);
|
const auto 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 auto x_axis = inv_tan_half_hfov;
|
||||||
const float y_axis = inv_tan_half_hfov * aspect_ratio;
|
const auto y_axis = inv_tan_half_hfov / aspect_ratio;
|
||||||
|
|
||||||
if constexpr (DepthRange == NDCDepthRange::ZERO_TO_ONE)
|
if constexpr (DepthRange == NDCDepthRange::ZERO_TO_ONE)
|
||||||
return {{x_axis, 0.f, 0.f, 0.f},
|
return {{x_axis, 0.f, 0.f, 0.f},
|
||||||
@@ -739,9 +739,9 @@ namespace omath
|
|||||||
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR,
|
template<class Type = float, MatStoreType St = MatStoreType::ROW_MAJOR,
|
||||||
NDCDepthRange DepthRange = NDCDepthRange::NEGATIVE_ONE_TO_ONE>
|
NDCDepthRange DepthRange = NDCDepthRange::NEGATIVE_ONE_TO_ONE>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Mat<4, 4, Type, St> mat_perspective_right_handed_horizontal_fov(const float horizontal_fov,
|
Mat<4, 4, Type, St> mat_perspective_right_handed_horizontal_fov(const Type horizontal_fov,
|
||||||
const float aspect_ratio, const float near,
|
const Type aspect_ratio, const Type near,
|
||||||
const float far) noexcept
|
const Type far) noexcept
|
||||||
{
|
{
|
||||||
const float inv_tan_half_hfov = 1.f / std::tan(angles::degrees_to_radians(horizontal_fov) / 2.f);
|
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 x_axis = inv_tan_half_hfov;
|
||||||
|
|||||||
@@ -45,14 +45,14 @@ namespace omath::projection
|
|||||||
struct CameraAxes
|
struct CameraAxes
|
||||||
{
|
{
|
||||||
bool inverted_forward = false;
|
bool inverted_forward = false;
|
||||||
bool inverted_right = false;
|
bool inverted_right = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class T, class MatType, class ViewAnglesType, class NumericType>
|
template<class T, class MatType, class ViewAnglesType, class NumericType>
|
||||||
concept CameraEngineConcept =
|
concept CameraEngineConcept =
|
||||||
requires(const Vector3<float>& cam_origin, const Vector3<float>& look_at, const ViewAnglesType& angles,
|
requires(const Vector3<NumericType>& cam_origin, const Vector3<NumericType>& look_at,
|
||||||
const FieldOfView& fov, const ViewPort& viewport, float znear, float zfar,
|
const ViewAnglesType& angles, const FieldOfView& fov, const ViewPort& viewport,
|
||||||
NDCDepthRange ndc_depth_range) {
|
NumericType znear, NumericType zfar, NDCDepthRange ndc_depth_range) {
|
||||||
// Presence + return types
|
// Presence + return types
|
||||||
{ T::calc_look_at_angle(cam_origin, look_at) } -> std::same_as<ViewAnglesType>;
|
{ T::calc_look_at_angle(cam_origin, look_at) } -> std::same_as<ViewAnglesType>;
|
||||||
{ T::calc_view_matrix(angles, cam_origin) } -> std::same_as<MatType>;
|
{ T::calc_view_matrix(angles, cam_origin) } -> std::same_as<MatType>;
|
||||||
@@ -65,8 +65,8 @@ namespace omath::projection
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<class Mat4X4Type, class ViewAnglesType, class TraitClass,
|
template<class Mat4X4Type, class ViewAnglesType, class TraitClass,
|
||||||
NDCDepthRange depth_range = NDCDepthRange::NEGATIVE_ONE_TO_ONE,
|
NDCDepthRange depth_range = NDCDepthRange::NEGATIVE_ONE_TO_ONE, CameraAxes axes = {},
|
||||||
CameraAxes axes = {}, class NumericType = float>
|
class NumericType = float>
|
||||||
requires CameraEngineConcept<TraitClass, Mat4X4Type, ViewAnglesType, NumericType>
|
requires CameraEngineConcept<TraitClass, Mat4X4Type, ViewAnglesType, NumericType>
|
||||||
class Camera final
|
class Camera final
|
||||||
{
|
{
|
||||||
@@ -83,17 +83,17 @@ namespace omath::projection
|
|||||||
};
|
};
|
||||||
|
|
||||||
~Camera() = default;
|
~Camera() = default;
|
||||||
Camera(const Vector3<float>& position, const ViewAnglesType& view_angles, const ViewPort& view_port,
|
Camera(const Vector3<NumericType>& position, const ViewAnglesType& view_angles, const ViewPort& view_port,
|
||||||
const FieldOfView& fov, const NumericType near, const NumericType far) noexcept
|
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_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)
|
m_view_angles(view_angles), m_origin(position)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ProjectionParams
|
struct ProjectionParams final
|
||||||
{
|
{
|
||||||
FieldOfView fov;
|
FieldOfView fov;
|
||||||
float aspect_ratio;
|
float aspect_ratio{};
|
||||||
};
|
};
|
||||||
|
|
||||||
// Recovers vertical FOV and aspect ratio from a perspective projection matrix
|
// 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.
|
// The view matrix is R * T(-origin), so the last column stores t = -R * origin.
|
||||||
// Recovering origin: origin = -R^T * t
|
// Recovering origin: origin = -R^T * t
|
||||||
return {
|
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, 0] * view_matrix[0, 3] + view_matrix[1, 0] * view_matrix[1, 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[2, 0] * 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, 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
|
[[nodiscard]] const Mat4X4Type& get_projection_matrix() const noexcept
|
||||||
{
|
{
|
||||||
if (!m_projection_matrix.has_value())
|
if (!m_projection_matrix.has_value())
|
||||||
m_projection_matrix = TraitClass::calc_projection_matrix(m_field_of_view, m_view_port,
|
m_projection_matrix = TraitClass::calc_projection_matrix(
|
||||||
m_near_plane_distance, m_far_plane_distance,
|
m_field_of_view, m_view_port, m_near_plane_distance, m_far_plane_distance, depth_range);
|
||||||
depth_range);
|
|
||||||
|
|
||||||
return m_projection_matrix.value();
|
return m_projection_matrix.value();
|
||||||
}
|
}
|
||||||
@@ -293,7 +295,7 @@ namespace omath::projection
|
|||||||
}
|
}
|
||||||
template<ScreenStart screen_start = ScreenStart::TOP_LEFT_CORNER>
|
template<ScreenStart screen_start = ScreenStart::TOP_LEFT_CORNER>
|
||||||
[[nodiscard]] std::expected<Vector3<NumericType>, Error>
|
[[nodiscard]] std::expected<Vector3<NumericType>, Error>
|
||||||
world_to_screen_unclipped(const Vector3<float>& world_position) const noexcept
|
world_to_screen_unclipped(const Vector3<NumericType>& world_position) const noexcept
|
||||||
{
|
{
|
||||||
const auto normalized_cords = world_to_view_port(world_position, ViewPortClipping::MANUAL);
|
const auto normalized_cords = world_to_view_port(world_position, ViewPortClipping::MANUAL);
|
||||||
|
|
||||||
@@ -332,8 +334,9 @@ namespace omath::projection
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Helper: all three vertices outside the same clip plane
|
// Helper: all three vertices outside the same clip plane
|
||||||
auto all_outside_plane = [](const int axis, const std::array<NumericType, 4>& a, const std::array<NumericType, 4>& b,
|
auto all_outside_plane = [](const int axis, const std::array<NumericType, 4>& a,
|
||||||
const std::array<NumericType, 4>& c, const bool positive_side)
|
const std::array<NumericType, 4>& b, const std::array<NumericType, 4>& c,
|
||||||
|
const bool positive_side)
|
||||||
{
|
{
|
||||||
if (positive_side)
|
if (positive_side)
|
||||||
return a[axis] > a[3] && b[axis] > b[3] && c[axis] > c[3];
|
return a[axis] > a[3] && b[axis] > b[3] && c[axis] > c[3];
|
||||||
@@ -389,16 +392,16 @@ namespace omath::projection
|
|||||||
// Far = r3 - r2
|
// Far = r3 - r2
|
||||||
struct Plane final
|
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
|
const auto extract_plane = [&m](const int sign, const int row) -> Plane
|
||||||
{
|
{
|
||||||
return {
|
return {
|
||||||
m.at(3, 0) + static_cast<float>(sign) * m.at(row, 0),
|
m.at(3, 0) + static_cast<NumericType>(sign) * m.at(row, 0),
|
||||||
m.at(3, 1) + static_cast<float>(sign) * m.at(row, 1),
|
m.at(3, 1) + static_cast<NumericType>(sign) * m.at(row, 1),
|
||||||
m.at(3, 2) + static_cast<float>(sign) * m.at(row, 2),
|
m.at(3, 2) + static_cast<NumericType>(sign) * m.at(row, 2),
|
||||||
m.at(3, 3) + static_cast<float>(sign) * m.at(row, 3),
|
m.at(3, 3) + static_cast<NumericType>(sign) * m.at(row, 3),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -452,12 +455,12 @@ namespace omath::projection
|
|||||||
|
|
||||||
// ReSharper disable once CppTooWideScope
|
// ReSharper disable once CppTooWideScope
|
||||||
constexpr auto z_min = depth_range == NDCDepthRange::ZERO_TO_ONE ? 0.0f : -1.0f;
|
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
|
const auto clipped_manually = clipping == ViewPortClipping::MANUAL
|
||||||
|| projected.at(2, 0) > 1.0f + eps);
|
&& (projected.at(2, 0) < z_min - eps || projected.at(2, 0) > 1.0f + eps);
|
||||||
if (clipped_manually)
|
if (clipped_manually)
|
||||||
return std::unexpected(Error::WORLD_POSITION_IS_OUT_OF_SCREEN_BOUNDS);
|
return std::unexpected(Error::WORLD_POSITION_IS_OUT_OF_SCREEN_BOUNDS);
|
||||||
|
|
||||||
return Vector3<float>{projected.at(0, 0), projected.at(1, 0), projected.at(2, 0)};
|
return Vector3<NumericType>{projected.at(0, 0), projected.at(1, 0), projected.at(2, 0)};
|
||||||
}
|
}
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
std::expected<Vector3<NumericType>, Error> view_port_to_world(const Vector3<NumericType>& ndc) const noexcept
|
std::expected<Vector3<NumericType>, Error> view_port_to_world(const Vector3<NumericType>& ndc) const noexcept
|
||||||
@@ -478,19 +481,21 @@ namespace omath::projection
|
|||||||
inverted_projection /= w;
|
inverted_projection /= w;
|
||||||
|
|
||||||
return Vector3<NumericType>{inverted_projection.at(0, 0), inverted_projection.at(1, 0),
|
return Vector3<NumericType>{inverted_projection.at(0, 0), inverted_projection.at(1, 0),
|
||||||
inverted_projection.at(2, 0)};
|
inverted_projection.at(2, 0)};
|
||||||
}
|
}
|
||||||
|
|
||||||
template<ScreenStart screen_start = ScreenStart::TOP_LEFT_CORNER>
|
template<ScreenStart screen_start = ScreenStart::TOP_LEFT_CORNER>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
std::expected<Vector3<NumericType>, Error> screen_to_world(const Vector3<NumericType>& screen_pos) const noexcept
|
std::expected<Vector3<NumericType>, Error>
|
||||||
|
screen_to_world(const Vector3<NumericType>& screen_pos) const noexcept
|
||||||
{
|
{
|
||||||
return view_port_to_world(screen_to_ndc<screen_start>(screen_pos));
|
return view_port_to_world(screen_to_ndc<screen_start>(screen_pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
template<ScreenStart screen_start = ScreenStart::TOP_LEFT_CORNER>
|
template<ScreenStart screen_start = ScreenStart::TOP_LEFT_CORNER>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
std::expected<Vector3<NumericType>, Error> screen_to_world(const Vector2<NumericType>& screen_pos) const noexcept
|
std::expected<Vector3<NumericType>, Error>
|
||||||
|
screen_to_world(const Vector2<NumericType>& screen_pos) const noexcept
|
||||||
{
|
{
|
||||||
const auto& [x, y] = screen_pos;
|
const auto& [x, y] = screen_pos;
|
||||||
return screen_to_world<screen_start>({x, y, 1.f});
|
return screen_to_world<screen_start>({x, y, 1.f});
|
||||||
@@ -498,13 +503,13 @@ namespace omath::projection
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
ViewPort m_view_port{};
|
ViewPort m_view_port{};
|
||||||
Angle<NumericType, 0.f, 180.f, AngleFlags::Clamped> m_field_of_view;
|
FieldOfView m_field_of_view;
|
||||||
|
|
||||||
mutable std::optional<Mat4X4Type> m_view_projection_matrix;
|
mutable std::optional<Mat4X4Type> m_view_projection_matrix;
|
||||||
mutable std::optional<Mat4X4Type> m_projection_matrix;
|
mutable std::optional<Mat4X4Type> m_projection_matrix;
|
||||||
mutable std::optional<Mat4X4Type> m_view_matrix;
|
mutable std::optional<Mat4X4Type> m_view_matrix;
|
||||||
float m_far_plane_distance;
|
NumericType m_far_plane_distance;
|
||||||
float m_near_plane_distance;
|
NumericType m_near_plane_distance;
|
||||||
|
|
||||||
ViewAnglesType m_view_angles;
|
ViewAnglesType m_view_angles;
|
||||||
Vector3<NumericType> m_origin;
|
Vector3<NumericType> m_origin;
|
||||||
@@ -524,10 +529,10 @@ namespace omath::projection
|
|||||||
return is_ndc_z_value_out_of_bounds(data[2]);
|
return is_ndc_z_value_out_of_bounds(data[2]);
|
||||||
}
|
}
|
||||||
template<class ZType>
|
template<class ZType>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr static bool is_ndc_z_value_out_of_bounds(const ZType& z_ndc) noexcept
|
constexpr static bool is_ndc_z_value_out_of_bounds(const ZType& z_ndc) noexcept
|
||||||
{
|
{
|
||||||
constexpr auto eps = std::numeric_limits<float>::epsilon();
|
constexpr auto eps = std::numeric_limits<NumericType>::epsilon();
|
||||||
if constexpr (depth_range == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
|
if constexpr (depth_range == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
|
||||||
return z_ndc < -1.0f - eps || z_ndc > 1.0f + eps;
|
return z_ndc < -1.0f - eps || z_ndc > 1.0f + eps;
|
||||||
if constexpr (depth_range == NDCDepthRange::ZERO_TO_ONE)
|
if constexpr (depth_range == NDCDepthRange::ZERO_TO_ONE)
|
||||||
@@ -550,8 +555,8 @@ namespace omath::projection
|
|||||||
v
|
v
|
||||||
*/
|
*/
|
||||||
|
|
||||||
[[nodiscard]] Vector3<float>
|
[[nodiscard]] Vector3<NumericType>
|
||||||
ndc_to_screen_position_from_top_left_corner(const Vector3<float>& ndc) const noexcept
|
ndc_to_screen_position_from_top_left_corner(const Vector3<NumericType>& 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};
|
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<float>
|
[[nodiscard]] Vector3<NumericType>
|
||||||
ndc_to_screen_position_from_bottom_left_corner(const Vector3<float>& ndc) const noexcept
|
ndc_to_screen_position_from_bottom_left_corner(const Vector3<NumericType>& ndc) const noexcept
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
^
|
^
|
||||||
@@ -585,7 +590,7 @@ namespace omath::projection
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<ScreenStart screen_start = ScreenStart::TOP_LEFT_CORNER>
|
template<ScreenStart screen_start = ScreenStart::TOP_LEFT_CORNER>
|
||||||
[[nodiscard]] Vector3<float> screen_to_ndc(const Vector3<float>& screen_pos) const noexcept
|
[[nodiscard]] Vector3<NumericType> screen_to_ndc(const Vector3<NumericType>& screen_pos) const noexcept
|
||||||
{
|
{
|
||||||
if constexpr (screen_start == ScreenStart::TOP_LEFT_CORNER)
|
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,
|
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,
|
||||||
|
|||||||
@@ -4,27 +4,27 @@
|
|||||||
#include "omath/engines/unreal_engine/formulas.hpp"
|
#include "omath/engines/unreal_engine/formulas.hpp"
|
||||||
namespace omath::unreal_engine
|
namespace omath::unreal_engine
|
||||||
{
|
{
|
||||||
Vector3<float> forward_vector(const ViewAngles& angles) noexcept
|
Vector3<double> forward_vector(const ViewAngles& angles) noexcept
|
||||||
{
|
{
|
||||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_forward);
|
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)};
|
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
|
||||||
}
|
}
|
||||||
Vector3<float> right_vector(const ViewAngles& angles) noexcept
|
Vector3<double> right_vector(const ViewAngles& angles) noexcept
|
||||||
{
|
{
|
||||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_right);
|
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)};
|
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
|
||||||
}
|
}
|
||||||
Vector3<float> up_vector(const ViewAngles& angles) noexcept
|
Vector3<double> up_vector(const ViewAngles& angles) noexcept
|
||||||
{
|
{
|
||||||
const auto vec = rotation_matrix(angles) * mat_column_from_vector(k_abs_up);
|
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)};
|
return {vec.at(0, 0), vec.at(1, 0), vec.at(2, 0)};
|
||||||
}
|
}
|
||||||
Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
|
Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<double>& cam_origin) noexcept
|
||||||
{
|
{
|
||||||
return mat_camera_view<float, MatStoreType::ROW_MAJOR>(forward_vector(angles), right_vector(angles),
|
return mat_camera_view<double, MatStoreType::ROW_MAJOR>(forward_vector(angles), right_vector(angles),
|
||||||
up_vector(angles), cam_origin);
|
up_vector(angles), cam_origin);
|
||||||
}
|
}
|
||||||
Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
|
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.
|
// frame), which for column-vector composition is Rz·Ry·Rx.
|
||||||
// Pitch and roll axes in omath spin opposite to UE's convention, so
|
// Pitch and roll axes in omath spin opposite to UE's convention, so
|
||||||
// both carry a sign flip.
|
// both carry a sign flip.
|
||||||
return mat_rotation_axis_z<float, MatStoreType::ROW_MAJOR>(angles.yaw)
|
return mat_rotation_axis_z<double, MatStoreType::ROW_MAJOR>(angles.yaw)
|
||||||
* mat_rotation_axis_y<float, MatStoreType::ROW_MAJOR>(-angles.pitch)
|
* mat_rotation_axis_y<double, MatStoreType::ROW_MAJOR>(-angles.pitch)
|
||||||
* mat_rotation_axis_x<float, MatStoreType::ROW_MAJOR>(-angles.roll);
|
* mat_rotation_axis_x<double, MatStoreType::ROW_MAJOR>(-angles.roll);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Mat4X4 calc_perspective_projection_matrix(const float field_of_view, const float aspect_ratio, const float near,
|
Mat4X4 calc_perspective_projection_matrix(const double field_of_view, const double aspect_ratio, const double near,
|
||||||
const float far, const NDCDepthRange ndc_depth_range) noexcept
|
const double far, const NDCDepthRange ndc_depth_range) noexcept
|
||||||
{
|
{
|
||||||
// UE stores horizontal FOV in FMinimalViewInfo — use the left-handed
|
// UE stores horizontal FOV in FMinimalViewInfo — use the left-handed
|
||||||
// horizontal-FOV builder directly.
|
// horizontal-FOV builder directly.
|
||||||
if (ndc_depth_range == NDCDepthRange::ZERO_TO_ONE)
|
if (ndc_depth_range == NDCDepthRange::ZERO_TO_ONE)
|
||||||
return mat_perspective_left_handed_horizontal_fov<
|
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);
|
field_of_view, aspect_ratio, near, far);
|
||||||
if (ndc_depth_range == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
|
if (ndc_depth_range == NDCDepthRange::NEGATIVE_ONE_TO_ONE)
|
||||||
return mat_perspective_left_handed_horizontal_fov<
|
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);
|
field_of_view, aspect_ratio, near, far);
|
||||||
std::unreachable();
|
std::unreachable();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,20 +6,20 @@
|
|||||||
namespace omath::unreal_engine
|
namespace omath::unreal_engine
|
||||||
{
|
{
|
||||||
|
|
||||||
ViewAngles CameraTrait::calc_look_at_angle(const Vector3<float>& cam_origin, const Vector3<float>& look_at) noexcept
|
ViewAngles CameraTrait::calc_look_at_angle(const Vector3<double>& cam_origin, const Vector3<double>& look_at) noexcept
|
||||||
{
|
{
|
||||||
const auto direction = (look_at - cam_origin).normalized();
|
const auto direction = (look_at - cam_origin).normalized();
|
||||||
|
|
||||||
return {PitchAngle::from_radians(std::asin(direction.z)),
|
return {PitchAngle::from_radians(std::asin(direction.z)),
|
||||||
YawAngle::from_radians(std::atan2(direction.y, direction.x)), RollAngle::from_radians(0.f)};
|
YawAngle::from_radians(std::atan2(direction.y, direction.x)), RollAngle::from_radians(0.f)};
|
||||||
}
|
}
|
||||||
Mat4X4 CameraTrait::calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
|
Mat4X4 CameraTrait::calc_view_matrix(const ViewAngles& angles, const Vector3<double>& cam_origin) noexcept
|
||||||
{
|
{
|
||||||
return unreal_engine::calc_view_matrix(angles, cam_origin);
|
return unreal_engine::calc_view_matrix(angles, cam_origin);
|
||||||
}
|
}
|
||||||
Mat4X4 CameraTrait::calc_projection_matrix(const projection::FieldOfView& fov,
|
Mat4X4 CameraTrait::calc_projection_matrix(const projection::FieldOfView& fov,
|
||||||
const projection::ViewPort& view_port, const float near,
|
const projection::ViewPort& view_port, const double near,
|
||||||
const float far, const NDCDepthRange ndc_depth_range) noexcept
|
const double far, const NDCDepthRange ndc_depth_range) noexcept
|
||||||
{
|
{
|
||||||
return calc_perspective_projection_matrix(fov.as_degrees(), view_port.aspect_ratio(), near, far,
|
return calc_perspective_projection_matrix(fov.as_degrees(), view_port.aspect_ratio(), near, far,
|
||||||
ndc_depth_range);
|
ndc_depth_range);
|
||||||
|
|||||||
@@ -499,10 +499,11 @@ TEST(NDCDepthRangeTests, CryEngine_BothDepthRanges)
|
|||||||
// ── Verify Z mapping for ZERO_TO_ONE across all engines ─────────────────────
|
// ── 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
|
// 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<class Type = float, MatStoreType Store = MatStoreType::ROW_MAJOR>
|
||||||
|
static float project_z_lh(const Mat<4, 4, Type, Store>& proj, float z)
|
||||||
{
|
{
|
||||||
auto clip = proj * mat_column_from_vector<float>({0, 0, z});
|
auto clip = proj * mat_column_from_vector<Type, Store>({0, 0, static_cast<Type>(z)});
|
||||||
return clip.at(2, 0) / clip.at(3, 0);
|
return static_cast<float>(clip.at(2, 0) / clip.at(3, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(NDCDepthRangeTests, Source_ZeroToOne_ZRange)
|
TEST(NDCDepthRangeTests, Source_ZeroToOne_ZRange)
|
||||||
|
|||||||
@@ -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);
|
auto cam = omath::unreal_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, {}, 0.01f, 1000.f);
|
||||||
|
|
||||||
EXPECT_EQ(cam.get_origin(), omath::Vector3<float>{});
|
EXPECT_EQ(cam.get_origin(), omath::Vector3<double>{});
|
||||||
cam.set_field_of_view(omath::projection::FieldOfView::from_degrees(50.f));
|
cam.set_field_of_view(omath::projection::FieldOfView::from_degrees(50.f));
|
||||||
|
|
||||||
EXPECT_EQ(cam.get_field_of_view().as_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;
|
std::size_t failed_points = 0;
|
||||||
for (int i = 0; i < 100; i++)
|
for (int i = 0; i < 100; i++)
|
||||||
{
|
{
|
||||||
const auto position_to_look = omath::Vector3<float>{dist(gen), dist(gen), dist(gen)};
|
const auto position_to_look = omath::Vector3<double>{dist(gen), dist(gen), dist(gen)};
|
||||||
|
|
||||||
if (cam.get_origin().distance_to(position_to_look) < 10)
|
if (cam.get_origin().distance_to(position_to_look) < 10)
|
||||||
continue;
|
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)
|
TEST(unit_test_unreal_engine, loook_at_random_x_axis)
|
||||||
{
|
{
|
||||||
std::mt19937 gen(std::random_device{}()); // Seed with a non-deterministic source
|
std::mt19937 gen(std::random_device{}()); // Seed with a non-deterministic source
|
||||||
std::uniform_real_distribution<float> dist(-1000.f, 1000.f);
|
std::uniform_real_distribution<double> dist(-1000.f, 1000.f);
|
||||||
|
|
||||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.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);
|
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;
|
std::size_t failed_points = 0;
|
||||||
for (int i = 0; i < 1000; i++)
|
for (int i = 0; i < 1000; i++)
|
||||||
{
|
{
|
||||||
const auto position_to_look = omath::Vector3<float>{dist(gen), dist(gen), dist(gen)};
|
const auto position_to_look = omath::Vector3<double>{dist(gen), dist(gen), dist(gen)};
|
||||||
|
|
||||||
if (cam.get_origin().distance_to(position_to_look) < 10)
|
if (cam.get_origin().distance_to(position_to_look) < 10)
|
||||||
continue;
|
continue;
|
||||||
@@ -190,7 +190,7 @@ TEST(unit_test_unreal_engine, loook_at_random_y_axis)
|
|||||||
std::size_t failed_points = 0;
|
std::size_t failed_points = 0;
|
||||||
for (int i = 0; i < 1000; i++)
|
for (int i = 0; i < 1000; i++)
|
||||||
{
|
{
|
||||||
const auto position_to_look = omath::Vector3<float>{0.f, dist(gen), 0.f};
|
const auto position_to_look = omath::Vector3<double>{0.f, dist(gen), 0.f};
|
||||||
|
|
||||||
if (cam.get_origin().distance_to(position_to_look) < 10)
|
if (cam.get_origin().distance_to(position_to_look) < 10)
|
||||||
continue;
|
continue;
|
||||||
@@ -221,7 +221,7 @@ TEST(unit_test_unreal_engine, loook_at_random_z_axis)
|
|||||||
std::size_t failed_points = 0;
|
std::size_t failed_points = 0;
|
||||||
for (int i = 0; i < 1000; i++)
|
for (int i = 0; i < 1000; i++)
|
||||||
{
|
{
|
||||||
const auto position_to_look = omath::Vector3<float>{0.f, 0.f, dist(gen)};
|
const auto position_to_look = omath::Vector3<double>{0.f, 0.f, dist(gen)};
|
||||||
|
|
||||||
if (cam.get_origin().distance_to(position_to_look) < 10)
|
if (cam.get_origin().distance_to(position_to_look) < 10)
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
Reference in New Issue
Block a user