mirror of
https://github.com/orange-cpp/omath.git
synced 2026-04-18 23:03:27 +00:00
fixed unreal bug, improved interface
This commit is contained in:
@@ -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>;
|
||||
using Camera = projection::Camera<Mat4X4, ViewAngles, CameraTrait, NDCDepthRange::ZERO_TO_ONE>;
|
||||
} // namespace omath::unity_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, true, 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
|
||||
{
|
||||
@@ -87,7 +94,7 @@ namespace omath::projection
|
||||
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 (inverted_z)
|
||||
if constexpr (axes.inverted_forward)
|
||||
forward_vector = -forward_vector;
|
||||
return TraitClass::calc_look_at_angle({}, forward_vector);
|
||||
}
|
||||
@@ -121,7 +128,7 @@ namespace omath::projection
|
||||
{
|
||||
const auto& view_matrix = get_view_matrix();
|
||||
|
||||
if constexpr (inverted_z)
|
||||
if constexpr (axes.inverted_forward)
|
||||
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]};
|
||||
}
|
||||
@@ -130,6 +137,8 @@ namespace omath::projection
|
||||
Vector3<float> get_right() const noexcept
|
||||
{
|
||||
const auto& view_matrix = get_view_matrix();
|
||||
if constexpr (axes.inverted_right)
|
||||
return -Vector3<float>{view_matrix[0, 0], view_matrix[0, 1], view_matrix[0, 2]};
|
||||
return {view_matrix[0, 0], view_matrix[0, 1], view_matrix[0, 2]};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user