mirror of
https://github.com/orange-cpp/omath.git
synced 2026-04-25 13:43:27 +00:00
updated for unreal
This commit is contained in:
@@ -4,27 +4,27 @@
|
||||
#include "omath/engines/unreal_engine/formulas.hpp"
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
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<float, MatStoreType::ROW_MAJOR>(angles.yaw)
|
||||
* mat_rotation_axis_y<float, MatStoreType::ROW_MAJOR>(-angles.pitch)
|
||||
* mat_rotation_axis_x<float, MatStoreType::ROW_MAJOR>(-angles.roll);
|
||||
return mat_rotation_axis_z<double, MatStoreType::ROW_MAJOR>(angles.yaw)
|
||||
* mat_rotation_axis_y<double, MatStoreType::ROW_MAJOR>(-angles.pitch)
|
||||
* 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,
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -6,20 +6,20 @@
|
||||
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();
|
||||
|
||||
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<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);
|
||||
}
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user