diff --git a/source/engines/unreal_engine/formulas.cpp b/source/engines/unreal_engine/formulas.cpp index 6f02ae8..e4a0ad9 100644 --- a/source/engines/unreal_engine/formulas.cpp +++ b/source/engines/unreal_engine/formulas.cpp @@ -31,8 +31,8 @@ namespace omath::unreal_engine Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept { return mat_rotation_axis_x(angles.roll) - * mat_rotation_axis_y(angles.pitch) - * mat_rotation_axis_z(angles.yaw); + * mat_rotation_axis_z(angles.yaw) + * mat_rotation_axis_y(angles.pitch); } Mat4X4 calc_perspective_projection_matrix(const float field_of_view, const float aspect_ratio, const float near, const float far) noexcept diff --git a/source/engines/unreal_engine/traits/camera_trait.cpp b/source/engines/unreal_engine/traits/camera_trait.cpp index 5eb8126..9eedce3 100644 --- a/source/engines/unreal_engine/traits/camera_trait.cpp +++ b/source/engines/unreal_engine/traits/camera_trait.cpp @@ -8,11 +8,10 @@ namespace omath::unreal_engine ViewAngles CameraTrait::calc_look_at_angle(const Vector3& cam_origin, const Vector3& look_at) noexcept { - const auto distance = cam_origin.distance_to(look_at); - const auto delta = cam_origin - look_at; + const auto direction = (look_at - cam_origin).normalized(); - return {PitchAngle::from_radians(-std::asin(delta.z / distance)), - YawAngle::from_radians(std::atan2(delta.x, delta.y)), RollAngle::from_radians(0.f)}; + 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 {