mirror of
https://github.com/orange-cpp/omath.git
synced 2026-04-19 11:43:26 +00:00
Compare commits
21 Commits
v5.0.0
...
4567cfa318
| Author | SHA1 | Date | |
|---|---|---|---|
| 4567cfa318 | |||
| 1db9340dbf | |||
| 7b9a181b0e | |||
| 0876af3c14 | |||
| e46a369ddc | |||
| 630ffa69f6 | |||
| 609970cdfe | |||
| e935155022 | |||
| 800082e4b3 | |||
| 02d909f77d | |||
| 49319a1c7c | |||
| d0f3e5059a | |||
| c9874f30d0 | |||
| 3080faeaa9 | |||
| af36c909a4 | |||
| 1041256fac | |||
| 88012e2524 | |||
| 4561dbe0e7 | |||
| b50f759675 | |||
| 85b672fdf3 | |||
| 360734f252 |
4
.idea/editor.xml
generated
4
.idea/editor.xml
generated
@@ -17,7 +17,7 @@
|
|||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBoostFormatTooManyArgs/@EntryIndexedValue" value="WARNING" type="string" />
|
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppBoostFormatTooManyArgs/@EntryIndexedValue" value="WARNING" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppCStyleCast/@EntryIndexedValue" value="SUGGESTION" type="string" />
|
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppCStyleCast/@EntryIndexedValue" value="SUGGESTION" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppCVQualifierCanNotBeAppliedToReference/@EntryIndexedValue" value="WARNING" type="string" />
|
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppCVQualifierCanNotBeAppliedToReference/@EntryIndexedValue" value="WARNING" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassCanBeFinal/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
|
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassCanBeFinal/@EntryIndexedValue" value="WARNING" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassIsIncomplete/@EntryIndexedValue" value="WARNING" type="string" />
|
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassIsIncomplete/@EntryIndexedValue" value="WARNING" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassNeedsConstructorBecauseOfUninitializedMember/@EntryIndexedValue" value="WARNING" type="string" />
|
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassNeedsConstructorBecauseOfUninitializedMember/@EntryIndexedValue" value="WARNING" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassNeverUsed/@EntryIndexedValue" value="WARNING" type="string" />
|
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppClassNeverUsed/@EntryIndexedValue" value="WARNING" type="string" />
|
||||||
@@ -110,7 +110,7 @@
|
|||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLambdaCaptureNeverUsed/@EntryIndexedValue" value="WARNING" type="string" />
|
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLambdaCaptureNeverUsed/@EntryIndexedValue" value="WARNING" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLocalVariableMayBeConst/@EntryIndexedValue" value="HINT" type="string" />
|
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLocalVariableMayBeConst/@EntryIndexedValue" value="HINT" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLocalVariableMightNotBeInitialized/@EntryIndexedValue" value="WARNING" type="string" />
|
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLocalVariableMightNotBeInitialized/@EntryIndexedValue" value="WARNING" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLocalVariableWithNonTrivialDtorIsNeverUsed/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
|
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLocalVariableWithNonTrivialDtorIsNeverUsed/@EntryIndexedValue" value="WARNING" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLongFloat/@EntryIndexedValue" value="WARNING" type="string" />
|
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppLongFloat/@EntryIndexedValue" value="WARNING" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMemberFunctionMayBeConst/@EntryIndexedValue" value="SUGGESTION" type="string" />
|
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMemberFunctionMayBeConst/@EntryIndexedValue" value="SUGGESTION" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMemberFunctionMayBeStatic/@EntryIndexedValue" value="SUGGESTION" type="string" />
|
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppMemberFunctionMayBeStatic/@EntryIndexedValue" value="SUGGESTION" type="string" />
|
||||||
|
|||||||
@@ -80,9 +80,10 @@ if (auto screen = camera.world_to_screen(world_position)) {
|
|||||||
- **Collision Detection**: Production ready code to handle collision detection by using simple interfaces.
|
- **Collision Detection**: Production ready code to handle collision detection by using simple interfaces.
|
||||||
- **No Additional Dependencies**: No additional dependencies need to use OMath except unit test execution
|
- **No Additional Dependencies**: No additional dependencies need to use OMath except unit test execution
|
||||||
- **Ready for meta-programming**: Omath use templates for common types like Vectors, Matrixes etc, to handle all types!
|
- **Ready for meta-programming**: Omath use templates for common types like Vectors, Matrixes etc, to handle all types!
|
||||||
- **Engine support**: Supports coordinate systems of **Source, Unity, Unreal, Frostbite, IWEngine and canonical OpenGL**.
|
- **Engine support**: Supports coordinate systems of **Source, Unity, Unreal, Frostbite, IWEngine, CryEngine and canonical OpenGL**.
|
||||||
- **Cross platform**: Supports Windows, MacOS and Linux.
|
- **Cross platform**: Supports Windows, MacOS and Linux.
|
||||||
- **Algorithms**: Has ability to scan for byte pattern with wildcards in PE files/modules, binary slices, works even with Wine apps.
|
- **Algorithms**: Has ability to scan for byte pattern with wildcards in ELF/Mach-O/PE files/modules, binary slices, works even with Wine apps.
|
||||||
|
- **Battle tested**: It's already used by some big players on the market like wraith.su and bluedream.ltd
|
||||||
<div align = center>
|
<div align = center>
|
||||||
|
|
||||||
# Gallery
|
# Gallery
|
||||||
|
|||||||
@@ -149,10 +149,13 @@ int main()
|
|||||||
// Check if context is valid using standard GL
|
// Check if context is valid using standard GL
|
||||||
const GLubyte* renderer = glGetString(GL_RENDERER);
|
const GLubyte* renderer = glGetString(GL_RENDERER);
|
||||||
const GLubyte* version = glGetString(GL_VERSION);
|
const GLubyte* version = glGetString(GL_VERSION);
|
||||||
if (renderer && version) {
|
if (renderer && version)
|
||||||
|
{
|
||||||
std::cout << "Renderer: " << renderer << "\n";
|
std::cout << "Renderer: " << renderer << "\n";
|
||||||
std::cout << "OpenGL version supported: " << version << "\n";
|
std::cout << "OpenGL version supported: " << version << "\n";
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
std::cerr << "Failed to get GL_RENDERER or GL_VERSION. Context might be invalid.\n";
|
std::cerr << "Failed to get GL_RENDERER or GL_VERSION. Context might be invalid.\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,11 +165,14 @@ int main()
|
|||||||
if (glewErr != GLEW_OK)
|
if (glewErr != GLEW_OK)
|
||||||
{
|
{
|
||||||
// Ignore NO_GLX_DISPLAY if we have a valid context
|
// Ignore NO_GLX_DISPLAY if we have a valid context
|
||||||
if (glewErr == GLEW_ERROR_NO_GLX_DISPLAY && renderer) {
|
if (glewErr == GLEW_ERROR_NO_GLX_DISPLAY && renderer)
|
||||||
std::cerr << "GLEW warning: " << glewGetErrorString(glewErr) << " (Ignored because context seems valid)\n";
|
{
|
||||||
} else {
|
std::cerr << "GLEW warning: " << glewGetErrorString(glewErr) << " (Ignored because context seems valid)\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
std::cerr << "Failed to initialize GLEW: " << reinterpret_cast<const char*>(glewGetErrorString(glewErr))
|
std::cerr << "Failed to initialize GLEW: " << reinterpret_cast<const char*>(glewGetErrorString(glewErr))
|
||||||
<< "\n";
|
<< "\n";
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -300,11 +306,65 @@ int main()
|
|||||||
|
|
||||||
static float old_frame_time = glfwGetTime();
|
static float old_frame_time = glfwGetTime();
|
||||||
|
|
||||||
|
float lastX = 640.0f / 2.0f;
|
||||||
|
float lastY = 480.0f / 2.0f;
|
||||||
|
bool firstMouse = true;
|
||||||
|
bool mouse_capture = false;
|
||||||
|
float mouseSensitivity = 0.1f;
|
||||||
// ---------- Main loop ----------
|
// ---------- Main loop ----------
|
||||||
|
static double old_mouse_time = glfwGetTime();
|
||||||
while (!glfwWindowShouldClose(window))
|
while (!glfwWindowShouldClose(window))
|
||||||
{
|
{
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
omath::Vector3<float> move_dir;
|
||||||
|
if (glfwGetKey(window, GLFW_KEY_W))
|
||||||
|
move_dir += camera.get_forward();
|
||||||
|
|
||||||
|
if (glfwGetKey(window, GLFW_KEY_A))
|
||||||
|
move_dir -= camera.get_right();
|
||||||
|
|
||||||
|
if (glfwGetKey(window, GLFW_KEY_S))
|
||||||
|
move_dir -= camera.get_forward();
|
||||||
|
|
||||||
|
if (glfwGetKey(window, GLFW_KEY_D))
|
||||||
|
move_dir += camera.get_right();
|
||||||
|
|
||||||
|
if (glfwGetKey(window, GLFW_KEY_SPACE))
|
||||||
|
move_dir += camera.get_up();
|
||||||
|
|
||||||
|
if (glfwGetKey(window, GLFW_KEY_LEFT_CONTROL))
|
||||||
|
move_dir -= camera.get_up();
|
||||||
|
|
||||||
|
|
||||||
|
auto delta = glfwGetTime() - old_mouse_time;
|
||||||
|
if (glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) && delta > 0.4)
|
||||||
|
{
|
||||||
|
old_mouse_time = glfwGetTime();
|
||||||
|
mouse_capture = !mouse_capture;
|
||||||
|
|
||||||
|
glfwSetInputMode(window, GLFW_CURSOR, mouse_capture ? GLFW_CURSOR_CAPTURED : GLFW_CURSOR_NORMAL);
|
||||||
|
}
|
||||||
|
if (mouse_capture)
|
||||||
|
{
|
||||||
|
int x, y;
|
||||||
|
glfwGetWindowSize(window, &x, &y);
|
||||||
|
|
||||||
|
camera.set_origin(camera.get_origin() + (move_dir.normalized() * 0.4f));
|
||||||
|
|
||||||
|
double xpos, ypos;
|
||||||
|
glfwGetCursorPos(window, &xpos, &ypos);
|
||||||
|
float xoffset = (float)xpos - x / 2.f;
|
||||||
|
float yoffset = y / 2.f - ypos ; // reversed: y-coordinates go bottom->top for pitch
|
||||||
|
|
||||||
|
xoffset *= mouseSensitivity;
|
||||||
|
yoffset *= mouseSensitivity;
|
||||||
|
|
||||||
|
auto new_angles = camera.get_view_angles();
|
||||||
|
new_angles.pitch += decltype(new_angles.pitch)::from_degrees(yoffset);
|
||||||
|
new_angles.yaw -= decltype(new_angles.yaw)::from_degrees(xoffset);
|
||||||
|
camera.set_view_angles(new_angles);
|
||||||
|
glfwSetCursorPos(window, x / 2., y / 2);
|
||||||
|
}
|
||||||
float currentTime = glfwGetTime();
|
float currentTime = glfwGetTime();
|
||||||
float deltaTime = currentTime - old_frame_time;
|
float deltaTime = currentTime - old_frame_time;
|
||||||
old_frame_time = currentTime;
|
old_frame_time = currentTime;
|
||||||
|
|||||||
@@ -13,11 +13,11 @@
|
|||||||
|
|
||||||
namespace omath::collision
|
namespace omath::collision
|
||||||
{
|
{
|
||||||
template<class V>
|
template<class V, class FloatingType>
|
||||||
concept EpaVector = requires(const V& a, const V& b, float s) {
|
concept EpaVector = requires(const V& a, const V& b, FloatingType s) {
|
||||||
{ a - b } -> std::same_as<V>;
|
{ a - b } -> std::same_as<V>;
|
||||||
{ a.cross(b) } -> std::same_as<V>;
|
{ a.cross(b) } -> std::same_as<V>;
|
||||||
{ a.dot(b) } -> std::same_as<float>;
|
{ a.dot(b) } -> std::same_as<FloatingType>;
|
||||||
{ -a } -> std::same_as<V>;
|
{ -a } -> std::same_as<V>;
|
||||||
{ a * s } -> std::same_as<V>;
|
{ a * s } -> std::same_as<V>;
|
||||||
{ a / s } -> std::same_as<V>;
|
{ a / s } -> std::same_as<V>;
|
||||||
@@ -28,13 +28,18 @@ namespace omath::collision
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using VectorType = ColliderInterfaceType::VectorType;
|
using VectorType = ColliderInterfaceType::VectorType;
|
||||||
static_assert(EpaVector<VectorType>, "VertexType must satisfy EpaVector concept");
|
static_assert(EpaVector<VectorType, typename VectorType::ContainedType>,
|
||||||
|
"VertexType must satisfy EpaVector concept");
|
||||||
|
|
||||||
|
private:
|
||||||
|
using FloatingType = VectorType::ContainedType;
|
||||||
|
|
||||||
|
public:
|
||||||
struct Result final
|
struct Result final
|
||||||
{
|
{
|
||||||
VectorType normal{}; // from A to B
|
VectorType normal{}; // from A to B
|
||||||
VectorType penetration_vector;
|
VectorType penetration_vector;
|
||||||
float depth{0.0f};
|
FloatingType depth{0.0};
|
||||||
int iterations{0};
|
int iterations{0};
|
||||||
int num_vertices{0};
|
int num_vertices{0};
|
||||||
int num_faces{0};
|
int num_faces{0};
|
||||||
@@ -43,7 +48,7 @@ namespace omath::collision
|
|||||||
struct Params final
|
struct Params final
|
||||||
{
|
{
|
||||||
int max_iterations{64};
|
int max_iterations{64};
|
||||||
float tolerance{1e-4f}; // absolute tolerance on distance growth
|
FloatingType tolerance{1e-4}; // absolute tolerance on distance growth
|
||||||
};
|
};
|
||||||
// Precondition: simplex.size()==4 and contains the origin.
|
// Precondition: simplex.size()==4 and contains the origin.
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
@@ -75,13 +80,13 @@ namespace omath::collision
|
|||||||
if (heap.empty())
|
if (heap.empty())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//FIXME: STORE REF VALUE, DO NOT USE
|
// FIXME: STORE REF VALUE, DO NOT USE
|
||||||
// AFTER IF STATEMENT BLOCK
|
// AFTER IF STATEMENT BLOCK
|
||||||
const Face& face = faces[heap.top().idx];
|
const Face& face = faces[heap.top().idx];
|
||||||
|
|
||||||
// Get the furthest point in face normal direction
|
// Get the furthest point in face normal direction
|
||||||
const VectorType p = support_point(a, b, face.n);
|
const VectorType p = support_point(a, b, face.n);
|
||||||
const float p_dist = face.n.dot(p);
|
const auto p_dist = face.n.dot(p);
|
||||||
|
|
||||||
// Converged if we can’t push the face closer than tolerance
|
// Converged if we can’t push the face closer than tolerance
|
||||||
if (p_dist - face.d <= params.tolerance)
|
if (p_dist - face.d <= params.tolerance)
|
||||||
@@ -136,7 +141,7 @@ namespace omath::collision
|
|||||||
{
|
{
|
||||||
int i0, i1, i2;
|
int i0, i1, i2;
|
||||||
VectorType n; // unit outward normal
|
VectorType n; // unit outward normal
|
||||||
float d; // n · v0 (>=0 ideally because origin is inside)
|
FloatingType d; // n · v0 (>=0 ideally because origin is inside)
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Edge final
|
struct Edge final
|
||||||
@@ -146,7 +151,7 @@ namespace omath::collision
|
|||||||
|
|
||||||
struct HeapItem final
|
struct HeapItem final
|
||||||
{
|
{
|
||||||
float d;
|
FloatingType d;
|
||||||
int idx;
|
int idx;
|
||||||
};
|
};
|
||||||
struct HeapCmp final
|
struct HeapCmp final
|
||||||
@@ -178,7 +183,7 @@ namespace omath::collision
|
|||||||
static bool visible_from(const Face& f, const VectorType& p)
|
static bool visible_from(const Face& f, const VectorType& p)
|
||||||
{
|
{
|
||||||
// positive if p is in front of the face
|
// positive if p is in front of the face
|
||||||
return f.n.dot(p) - f.d > 1e-7f;
|
return f.n.dot(p) - f.d > static_cast<FloatingType>(1e-7);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void add_edge_boundary(std::pmr::vector<Edge>& boundary, int a, int b)
|
static void add_edge_boundary(std::pmr::vector<Edge>& boundary, int a, int b)
|
||||||
@@ -198,19 +203,20 @@ namespace omath::collision
|
|||||||
const VectorType& a1 = vertexes[i1];
|
const VectorType& a1 = vertexes[i1];
|
||||||
const VectorType& a2 = vertexes[i2];
|
const VectorType& a2 = vertexes[i2];
|
||||||
VectorType n = (a1 - a0).cross(a2 - a0);
|
VectorType n = (a1 - a0).cross(a2 - a0);
|
||||||
if (n.dot(n) <= 1e-30f)
|
if (n.dot(n) <= static_cast<FloatingType>(1e-30))
|
||||||
{
|
{
|
||||||
n = any_perp_vec(a1 - a0); // degenerate guard
|
n = any_perp_vec(a1 - a0); // degenerate guard
|
||||||
}
|
}
|
||||||
// Ensure normal points outward (away from origin): require n·a0 >= 0
|
// Ensure normal points outward (away from origin): require n·a0 >= 0
|
||||||
if (n.dot(a0) < 0.0f)
|
if (n.dot(a0) < static_cast<FloatingType>(0.0))
|
||||||
{
|
{
|
||||||
std::swap(i1, i2);
|
std::swap(i1, i2);
|
||||||
n = -n;
|
n = -n;
|
||||||
}
|
}
|
||||||
const float inv_len = 1.0f / std::sqrt(std::max(n.dot(n), 1e-30f));
|
const auto inv_len =
|
||||||
|
static_cast<FloatingType>(1.0) / std::sqrt(std::max(n.dot(n), static_cast<FloatingType>(1e-30)));
|
||||||
n = n * inv_len;
|
n = n * inv_len;
|
||||||
const float d = n.dot(a0);
|
const auto d = n.dot(a0);
|
||||||
return {i0, i1, i2, n, d};
|
return {i0, i1, i2, n, d};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,7 +229,7 @@ namespace omath::collision
|
|||||||
|
|
||||||
template<class V>
|
template<class V>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
static constexpr bool near_zero_vec(const V& v, const float eps = 1e-7f)
|
static constexpr bool near_zero_vec(const V& v, const FloatingType eps = 1e-7f)
|
||||||
{
|
{
|
||||||
return v.dot(v) <= eps * eps;
|
return v.dot(v) <= eps * eps;
|
||||||
}
|
}
|
||||||
|
|||||||
13
include/omath/engines/cry_engine/camera.hpp
Normal file
13
include/omath/engines/cry_engine/camera.hpp
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
//
|
||||||
|
// Created by Vlad on 3/22/2025.
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "omath/engines/cry_engine/constants.hpp"
|
||||||
|
#include "omath/projection/camera.hpp"
|
||||||
|
#include "traits/camera_trait.hpp"
|
||||||
|
|
||||||
|
namespace omath::cry_engine
|
||||||
|
{
|
||||||
|
using Camera = projection::Camera<Mat4X4, ViewAngles, CameraTrait>;
|
||||||
|
} // namespace omath::cry_engine
|
||||||
25
include/omath/engines/cry_engine/constants.hpp
Normal file
25
include/omath/engines/cry_engine/constants.hpp
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
//
|
||||||
|
// Created by Vlad on 10/21/2025.
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "omath/linear_algebra/mat.hpp"
|
||||||
|
#include "omath/linear_algebra/vector3.hpp"
|
||||||
|
#include <omath/trigonometry/angle.hpp>
|
||||||
|
#include <omath/trigonometry/view_angles.hpp>
|
||||||
|
|
||||||
|
namespace omath::cry_engine
|
||||||
|
{
|
||||||
|
constexpr Vector3<float> k_abs_up = {0, 0, 1};
|
||||||
|
constexpr Vector3<float> k_abs_right = {1, 0, 0};
|
||||||
|
constexpr Vector3<float> k_abs_forward = {0, 1, 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<float, -90.f, 90.f, AngleFlags::Clamped>;
|
||||||
|
using YawAngle = Angle<float, -180.f, 180.f, AngleFlags::Normalized>;
|
||||||
|
using RollAngle = Angle<float, -180.f, 180.f, AngleFlags::Normalized>;
|
||||||
|
|
||||||
|
using ViewAngles = omath::ViewAngles<PitchAngle, YawAngle, RollAngle>;
|
||||||
|
} // namespace omath::cry_engine
|
||||||
74
include/omath/engines/cry_engine/formulas.hpp
Normal file
74
include/omath/engines/cry_engine/formulas.hpp
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
//
|
||||||
|
// Created by Vlad on 3/22/2025.
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "omath/engines/cry_engine/constants.hpp"
|
||||||
|
|
||||||
|
namespace omath::cry_engine
|
||||||
|
{
|
||||||
|
[[nodiscard]]
|
||||||
|
Vector3<float> forward_vector(const ViewAngles& angles) noexcept;
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
Vector3<float> right_vector(const ViewAngles& angles) noexcept;
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
Vector3<float> up_vector(const ViewAngles& angles) noexcept;
|
||||||
|
|
||||||
|
[[nodiscard]] Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& 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) noexcept;
|
||||||
|
|
||||||
|
template<class FloatingType>
|
||||||
|
requires std::is_floating_point_v<FloatingType>
|
||||||
|
[[nodiscard]]
|
||||||
|
constexpr FloatingType units_to_centimeters(const FloatingType& units)
|
||||||
|
{
|
||||||
|
return units / static_cast<FloatingType>(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class FloatingType>
|
||||||
|
requires std::is_floating_point_v<FloatingType>
|
||||||
|
[[nodiscard]]
|
||||||
|
constexpr FloatingType units_to_meters(const FloatingType& units)
|
||||||
|
{
|
||||||
|
return units;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class FloatingType>
|
||||||
|
requires std::is_floating_point_v<FloatingType>
|
||||||
|
[[nodiscard]]
|
||||||
|
constexpr FloatingType units_to_kilometers(const FloatingType& units)
|
||||||
|
{
|
||||||
|
return units_to_meters(units) / static_cast<FloatingType>(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class FloatingType>
|
||||||
|
requires std::is_floating_point_v<FloatingType>
|
||||||
|
[[nodiscard]]
|
||||||
|
constexpr FloatingType centimeters_to_units(const FloatingType& centimeters)
|
||||||
|
{
|
||||||
|
return centimeters * static_cast<FloatingType>(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class FloatingType>
|
||||||
|
requires std::is_floating_point_v<FloatingType>
|
||||||
|
[[nodiscard]]
|
||||||
|
constexpr FloatingType meters_to_units(const FloatingType& meters)
|
||||||
|
{
|
||||||
|
return meters;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class FloatingType>
|
||||||
|
requires std::is_floating_point_v<FloatingType>
|
||||||
|
[[nodiscard]]
|
||||||
|
constexpr FloatingType kilometers_to_units(const FloatingType& kilometers)
|
||||||
|
{
|
||||||
|
return meters_to_units(kilometers * static_cast<FloatingType>(1000));
|
||||||
|
}
|
||||||
|
} // namespace omath::cry_engine
|
||||||
12
include/omath/engines/cry_engine/mesh.hpp
Normal file
12
include/omath/engines/cry_engine/mesh.hpp
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
//
|
||||||
|
// Created by Vladislav on 09.11.2025.
|
||||||
|
//
|
||||||
|
#pragma once
|
||||||
|
#include "constants.hpp"
|
||||||
|
#include "omath/3d_primitives/mesh.hpp"
|
||||||
|
#include "traits/mesh_trait.hpp"
|
||||||
|
|
||||||
|
namespace omath::cry_engine
|
||||||
|
{
|
||||||
|
using Mesh = primitives::Mesh<Mat4X4, ViewAngles, MeshTrait>;
|
||||||
|
}
|
||||||
24
include/omath/engines/cry_engine/traits/camera_trait.hpp
Normal file
24
include/omath/engines/cry_engine/traits/camera_trait.hpp
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
//
|
||||||
|
// Created by Vlad on 8/10/2025.
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "omath/engines/cry_engine/formulas.hpp"
|
||||||
|
#include "omath/projection/camera.hpp"
|
||||||
|
|
||||||
|
namespace omath::cry_engine
|
||||||
|
{
|
||||||
|
class CameraTrait final
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
[[nodiscard]]
|
||||||
|
static ViewAngles calc_look_at_angle(const Vector3<float>& cam_origin, const Vector3<float>& look_at) noexcept;
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
static Mat4X4 calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept;
|
||||||
|
[[nodiscard]]
|
||||||
|
static Mat4X4 calc_projection_matrix(const projection::FieldOfView& fov, const projection::ViewPort& view_port,
|
||||||
|
float near, float far) noexcept;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace omath::cry_engine
|
||||||
19
include/omath/engines/cry_engine/traits/mesh_trait.hpp
Normal file
19
include/omath/engines/cry_engine/traits/mesh_trait.hpp
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
//
|
||||||
|
// Created by Vladislav on 09.11.2025.
|
||||||
|
//
|
||||||
|
#pragma once
|
||||||
|
#include <omath/engines/cry_engine/constants.hpp>
|
||||||
|
#include <omath/engines/cry_engine/formulas.hpp>
|
||||||
|
|
||||||
|
namespace omath::cry_engine
|
||||||
|
{
|
||||||
|
class MeshTrait final
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
[[nodiscard]]
|
||||||
|
static Mat4X4 rotation_matrix(const ViewAngles& rotation)
|
||||||
|
{
|
||||||
|
return cry_engine::rotation_matrix(rotation);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} // namespace omath::cry_engine
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
//
|
||||||
|
// Created by Vlad on 8/6/2025.
|
||||||
|
//
|
||||||
|
#pragma once
|
||||||
|
#include "omath/engines/cry_engine/formulas.hpp"
|
||||||
|
#include "omath/projectile_prediction/projectile.hpp"
|
||||||
|
#include "omath/projectile_prediction/target.hpp"
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
|
namespace omath::cry_engine
|
||||||
|
{
|
||||||
|
class PredEngineTrait final
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
constexpr static Vector3<float> predict_projectile_position(const projectile_prediction::Projectile& projectile,
|
||||||
|
const float pitch, const float yaw,
|
||||||
|
const float time, const float gravity) noexcept
|
||||||
|
{
|
||||||
|
auto current_pos = projectile.m_origin
|
||||||
|
+ forward_vector({PitchAngle::from_degrees(-pitch), YawAngle::from_degrees(yaw),
|
||||||
|
RollAngle::from_degrees(0)})
|
||||||
|
* projectile.m_launch_speed * time;
|
||||||
|
current_pos.z -= (gravity * projectile.m_gravity_scale) * (time * time) * 0.5f;
|
||||||
|
|
||||||
|
return current_pos;
|
||||||
|
}
|
||||||
|
[[nodiscard]]
|
||||||
|
static constexpr Vector3<float> predict_target_position(const projectile_prediction::Target& target,
|
||||||
|
const float time, const float gravity) noexcept
|
||||||
|
{
|
||||||
|
auto predicted = target.m_origin + target.m_velocity * time;
|
||||||
|
|
||||||
|
if (target.m_is_airborne)
|
||||||
|
predicted.z -= gravity * (time * time) * 0.5f;
|
||||||
|
|
||||||
|
return predicted;
|
||||||
|
}
|
||||||
|
[[nodiscard]]
|
||||||
|
static float calc_vector_2d_distance(const Vector3<float>& delta) noexcept
|
||||||
|
{
|
||||||
|
return std::sqrt(delta.x * delta.x + delta.y * delta.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
constexpr static float get_vector_height_coordinate(const Vector3<float>& vec) noexcept
|
||||||
|
{
|
||||||
|
return vec.z;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
static Vector3<float> calc_viewpoint_from_angles(const projectile_prediction::Projectile& projectile,
|
||||||
|
Vector3<float> predicted_target_position,
|
||||||
|
const std::optional<float> projectile_pitch) noexcept
|
||||||
|
{
|
||||||
|
const auto delta2d = calc_vector_2d_distance(predicted_target_position - projectile.m_origin);
|
||||||
|
const auto height = delta2d * std::tan(angles::degrees_to_radians(projectile_pitch.value()));
|
||||||
|
|
||||||
|
return {predicted_target_position.x, predicted_target_position.y, projectile.m_origin.z + height};
|
||||||
|
}
|
||||||
|
// Due to specification of maybe_calculate_projectile_launch_pitch_angle, pitch angle must be:
|
||||||
|
// 89 look up, -89 look down
|
||||||
|
[[nodiscard]]
|
||||||
|
static float calc_direct_pitch_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept
|
||||||
|
{
|
||||||
|
const auto direction = (view_to - origin).normalized();
|
||||||
|
return angles::radians_to_degrees(std::asin(direction.z));
|
||||||
|
}
|
||||||
|
[[nodiscard]]
|
||||||
|
static float calc_direct_yaw_angle(const Vector3<float>& origin, const Vector3<float>& view_to) noexcept
|
||||||
|
{
|
||||||
|
const auto direction = (view_to - origin).normalized();
|
||||||
|
|
||||||
|
return angles::radians_to_degrees(-std::atan2(direction.x, direction.y));
|
||||||
|
};
|
||||||
|
};
|
||||||
|
} // namespace omath::cry_engine
|
||||||
@@ -55,7 +55,7 @@ namespace omath::frostbite_engine
|
|||||||
const auto delta2d = calc_vector_2d_distance(predicted_target_position - projectile.m_origin);
|
const auto delta2d = calc_vector_2d_distance(predicted_target_position - projectile.m_origin);
|
||||||
const auto height = delta2d * std::tan(angles::degrees_to_radians(projectile_pitch.value()));
|
const auto height = delta2d * std::tan(angles::degrees_to_radians(projectile_pitch.value()));
|
||||||
|
|
||||||
return {predicted_target_position.x, predicted_target_position.y + height, projectile.m_origin.z};
|
return {predicted_target_position.x, projectile.m_origin.y + height, predicted_target_position.z};
|
||||||
}
|
}
|
||||||
// Due to specification of maybe_calculate_projectile_launch_pitch_angle, pitch angle must be:
|
// Due to specification of maybe_calculate_projectile_launch_pitch_angle, pitch angle must be:
|
||||||
// 89 look up, -89 look down
|
// 89 look up, -89 look down
|
||||||
|
|||||||
@@ -8,5 +8,5 @@
|
|||||||
|
|
||||||
namespace omath::opengl_engine
|
namespace omath::opengl_engine
|
||||||
{
|
{
|
||||||
using Camera = projection::Camera<Mat4X4, ViewAngles, CameraTrait>;
|
using Camera = projection::Camera<Mat4X4, ViewAngles, CameraTrait, true>;
|
||||||
} // namespace omath::opengl_engine
|
} // namespace omath::opengl_engine
|
||||||
@@ -55,7 +55,7 @@ namespace omath::opengl_engine
|
|||||||
const auto delta2d = calc_vector_2d_distance(predicted_target_position - projectile.m_origin);
|
const auto delta2d = calc_vector_2d_distance(predicted_target_position - projectile.m_origin);
|
||||||
const auto height = delta2d * std::tan(angles::degrees_to_radians(projectile_pitch.value()));
|
const auto height = delta2d * std::tan(angles::degrees_to_radians(projectile_pitch.value()));
|
||||||
|
|
||||||
return {predicted_target_position.x, predicted_target_position.y + height, projectile.m_origin.z};
|
return {predicted_target_position.x, projectile.m_origin.y + height, predicted_target_position.z};
|
||||||
}
|
}
|
||||||
// Due to specification of maybe_calculate_projectile_launch_pitch_angle, pitch angle must be:
|
// Due to specification of maybe_calculate_projectile_launch_pitch_angle, pitch angle must be:
|
||||||
// 89 look up, -89 look down
|
// 89 look up, -89 look down
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ namespace omath::unity_engine
|
|||||||
const auto delta2d = calc_vector_2d_distance(predicted_target_position - projectile.m_origin);
|
const auto delta2d = calc_vector_2d_distance(predicted_target_position - projectile.m_origin);
|
||||||
const auto height = delta2d * std::tan(angles::degrees_to_radians(projectile_pitch.value()));
|
const auto height = delta2d * std::tan(angles::degrees_to_radians(projectile_pitch.value()));
|
||||||
|
|
||||||
return {predicted_target_position.x, predicted_target_position.y + height, projectile.m_origin.z};
|
return {predicted_target_position.x, projectile.m_origin.y + height, predicted_target_position.z};
|
||||||
}
|
}
|
||||||
// Due to specification of maybe_calculate_projectile_launch_pitch_angle, pitch angle must be:
|
// Due to specification of maybe_calculate_projectile_launch_pitch_angle, pitch angle must be:
|
||||||
// 89 look up, -89 look down
|
// 89 look up, -89 look down
|
||||||
|
|||||||
@@ -220,6 +220,12 @@ namespace omath
|
|||||||
{
|
{
|
||||||
return std::make_tuple(x, y);
|
return std::make_tuple(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
constexpr std::array<Type, 2> as_array() const noexcept
|
||||||
|
{
|
||||||
|
return {x, y};
|
||||||
|
}
|
||||||
#ifdef OMATH_IMGUI_INTEGRATION
|
#ifdef OMATH_IMGUI_INTEGRATION
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr ImVec2 to_im_vec2() const noexcept
|
constexpr ImVec2 to_im_vec2() const noexcept
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "omath/trigonometry/angle.hpp"
|
|
||||||
#include "omath/linear_algebra/vector2.hpp"
|
#include "omath/linear_algebra/vector2.hpp"
|
||||||
|
#include "omath/trigonometry/angle.hpp"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <expected>
|
#include <expected>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
@@ -233,7 +233,8 @@ namespace omath
|
|||||||
return Angle<float, 0.f, 180.f, AngleFlags::Clamped>::from_radians(std::acos(dot(other) / bottom));
|
return Angle<float, 0.f, 180.f, AngleFlags::Clamped>::from_radians(std::acos(dot(other) / bottom));
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] bool is_perpendicular(const Vector3& other, Type epsilon = static_cast<Type>(0.0001)) const noexcept
|
[[nodiscard]] bool is_perpendicular(const Vector3& other,
|
||||||
|
Type epsilon = static_cast<Type>(0.0001)) const noexcept
|
||||||
{
|
{
|
||||||
if (const auto angle = angle_between(other))
|
if (const auto angle = angle_between(other))
|
||||||
return std::abs(angle->as_degrees() - static_cast<Type>(90)) <= epsilon;
|
return std::abs(angle->as_degrees() - static_cast<Type>(90)) <= epsilon;
|
||||||
@@ -274,6 +275,12 @@ namespace omath
|
|||||||
{
|
{
|
||||||
return length() >= other.length();
|
return length() >= other.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
constexpr std::array<Type, 3> as_array() const noexcept
|
||||||
|
{
|
||||||
|
return {this->x, this->y, z};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
} // namespace omath
|
} // namespace omath
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
//
|
//
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include "omath/linear_algebra/vector3.hpp"
|
#include "omath/linear_algebra/vector3.hpp"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
namespace omath
|
namespace omath
|
||||||
{
|
{
|
||||||
@@ -183,6 +183,12 @@ namespace omath
|
|||||||
return length() >= other.length();
|
return length() >= other.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
constexpr std::array<Type, 4> as_array() const noexcept
|
||||||
|
{
|
||||||
|
return {this->x, this->y, this->z, w};
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef OMATH_IMGUI_INTEGRATION
|
#ifdef OMATH_IMGUI_INTEGRATION
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
constexpr ImVec4 to_im_vec4() const noexcept
|
constexpr ImVec4 to_im_vec4() const noexcept
|
||||||
@@ -200,7 +206,7 @@ namespace omath
|
|||||||
return {static_cast<Type>(other.x), static_cast<Type>(other.y), static_cast<Type>(other.z)};
|
return {static_cast<Type>(other.x), static_cast<Type>(other.y), static_cast<Type>(other.z)};
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
} // namespace omath
|
} // namespace omath
|
||||||
|
|
||||||
template<> struct std::hash<omath::Vector4<float>>
|
template<> struct std::hash<omath::Vector4<float>>
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ namespace omath::projection
|
|||||||
requires noexcept(T::calc_projection_matrix(fov, viewport, znear, zfar));
|
requires noexcept(T::calc_projection_matrix(fov, viewport, znear, zfar));
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class Mat4X4Type, class ViewAnglesType, class TraitClass>
|
template<class Mat4X4Type, class ViewAnglesType, class TraitClass, bool inverted_z = false>
|
||||||
requires CameraEngineConcept<TraitClass, Mat4X4Type, ViewAnglesType>
|
requires CameraEngineConcept<TraitClass, Mat4X4Type, ViewAnglesType>
|
||||||
class Camera final
|
class Camera final
|
||||||
{
|
{
|
||||||
@@ -80,59 +80,96 @@ namespace omath::projection
|
|||||||
{
|
{
|
||||||
m_view_angles = TraitClass::calc_look_at_angle(m_origin, target);
|
m_view_angles = TraitClass::calc_look_at_angle(m_origin, target);
|
||||||
m_view_projection_matrix = std::nullopt;
|
m_view_projection_matrix = std::nullopt;
|
||||||
|
m_view_matrix = std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
[[nodiscard]]
|
||||||
[[nodiscard]] Mat4X4Type calc_view_projection_matrix() const noexcept
|
Vector3<float> get_forward() const noexcept
|
||||||
{
|
{
|
||||||
return TraitClass::calc_projection_matrix(m_field_of_view, m_view_port, m_near_plane_distance,
|
const auto& view_matrix = get_view_matrix();
|
||||||
m_far_plane_distance)
|
|
||||||
* TraitClass::calc_view_matrix(m_view_angles, m_origin);
|
if constexpr (inverted_z)
|
||||||
|
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]};
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
Vector3<float> get_right() const noexcept
|
||||||
|
{
|
||||||
|
const auto& view_matrix = get_view_matrix();
|
||||||
|
return {view_matrix[0, 0], view_matrix[0, 1], view_matrix[0, 2]};
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
Vector3<float> get_up() const noexcept
|
||||||
|
{
|
||||||
|
const auto& view_matrix = get_view_matrix();
|
||||||
|
return {view_matrix[1, 0], view_matrix[1, 1], view_matrix[1, 2]};
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
|
||||||
[[nodiscard]] const Mat4X4Type& get_view_projection_matrix() const noexcept
|
[[nodiscard]] const Mat4X4Type& get_view_projection_matrix() const noexcept
|
||||||
{
|
{
|
||||||
if (!m_view_projection_matrix.has_value())
|
if (!m_view_projection_matrix.has_value())
|
||||||
m_view_projection_matrix = calc_view_projection_matrix();
|
m_view_projection_matrix = get_projection_matrix() * get_view_matrix();
|
||||||
|
|
||||||
return m_view_projection_matrix.value();
|
return m_view_projection_matrix.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] const Mat4X4Type& get_view_matrix() const noexcept
|
||||||
|
{
|
||||||
|
if (!m_view_matrix.has_value())
|
||||||
|
m_view_matrix = TraitClass::calc_view_matrix(m_view_angles, m_origin);
|
||||||
|
|
||||||
|
return m_view_matrix.value();
|
||||||
|
}
|
||||||
|
[[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);
|
||||||
|
|
||||||
|
return m_projection_matrix.value();
|
||||||
|
}
|
||||||
|
|
||||||
void set_field_of_view(const FieldOfView& fov) noexcept
|
void set_field_of_view(const FieldOfView& fov) noexcept
|
||||||
{
|
{
|
||||||
m_field_of_view = fov;
|
m_field_of_view = fov;
|
||||||
m_view_projection_matrix = std::nullopt;
|
m_view_projection_matrix = std::nullopt;
|
||||||
|
m_projection_matrix = std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_near_plane(const float near) noexcept
|
void set_near_plane(const float near) noexcept
|
||||||
{
|
{
|
||||||
m_near_plane_distance = near;
|
m_near_plane_distance = near;
|
||||||
m_view_projection_matrix = std::nullopt;
|
m_view_projection_matrix = std::nullopt;
|
||||||
|
m_projection_matrix = std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_far_plane(const float far) noexcept
|
void set_far_plane(const float far) noexcept
|
||||||
{
|
{
|
||||||
m_far_plane_distance = far;
|
m_far_plane_distance = far;
|
||||||
m_view_projection_matrix = std::nullopt;
|
m_view_projection_matrix = std::nullopt;
|
||||||
|
m_projection_matrix = std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_view_angles(const ViewAnglesType& view_angles) noexcept
|
void set_view_angles(const ViewAnglesType& view_angles) noexcept
|
||||||
{
|
{
|
||||||
m_view_angles = view_angles;
|
m_view_angles = view_angles;
|
||||||
m_view_projection_matrix = std::nullopt;
|
m_view_projection_matrix = std::nullopt;
|
||||||
|
m_view_matrix = std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_origin(const Vector3<float>& origin) noexcept
|
void set_origin(const Vector3<float>& origin) noexcept
|
||||||
{
|
{
|
||||||
m_origin = origin;
|
m_origin = origin;
|
||||||
m_view_projection_matrix = std::nullopt;
|
m_view_projection_matrix = std::nullopt;
|
||||||
|
m_view_matrix = std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_view_port(const ViewPort& view_port) noexcept
|
void set_view_port(const ViewPort& view_port) noexcept
|
||||||
{
|
{
|
||||||
m_view_port = view_port;
|
m_view_port = view_port;
|
||||||
m_view_projection_matrix = std::nullopt;
|
m_view_projection_matrix = std::nullopt;
|
||||||
|
m_projection_matrix = std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] const FieldOfView& get_field_of_view() const noexcept
|
[[nodiscard]] const FieldOfView& get_field_of_view() const noexcept
|
||||||
@@ -283,7 +320,8 @@ namespace omath::projection
|
|||||||
Angle<float, 0.f, 180.f, AngleFlags::Clamped> m_field_of_view;
|
Angle<float, 0.f, 180.f, AngleFlags::Clamped> 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_view_matrix;
|
||||||
float m_far_plane_distance;
|
float m_far_plane_distance;
|
||||||
float m_near_plane_distance;
|
float m_near_plane_distance;
|
||||||
|
|
||||||
|
|||||||
26
source/engines/cry_engine/camera_trait.cpp
Normal file
26
source/engines/cry_engine/camera_trait.cpp
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
//
|
||||||
|
// Created by Vlad on 8/11/2025.
|
||||||
|
//
|
||||||
|
#include "omath/engines/cry_engine/traits/camera_trait.hpp"
|
||||||
|
|
||||||
|
namespace omath::cry_engine
|
||||||
|
{
|
||||||
|
|
||||||
|
ViewAngles CameraTrait::calc_look_at_angle(const Vector3<float>& cam_origin, const Vector3<float>& 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.x, direction.y)), RollAngle::from_radians(0.f)};
|
||||||
|
}
|
||||||
|
Mat4X4 CameraTrait::calc_view_matrix(const ViewAngles& angles, const Vector3<float>& cam_origin) noexcept
|
||||||
|
{
|
||||||
|
return cry_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) noexcept
|
||||||
|
{
|
||||||
|
return calc_perspective_projection_matrix(fov.as_degrees(), view_port.aspect_ratio(), near, far);
|
||||||
|
}
|
||||||
|
} // namespace omath::unity_engine
|
||||||
42
source/engines/cry_engine/formulas.cpp
Normal file
42
source/engines/cry_engine/formulas.cpp
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
//
|
||||||
|
// Created by Vlad on 3/22/2025.
|
||||||
|
//
|
||||||
|
#include "omath/engines/cry_engine/formulas.hpp"
|
||||||
|
|
||||||
|
namespace omath::cry_engine
|
||||||
|
{
|
||||||
|
Vector3<float> 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
|
||||||
|
{
|
||||||
|
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
|
||||||
|
{
|
||||||
|
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
|
||||||
|
{
|
||||||
|
return mat_camera_view<float, MatStoreType::ROW_MAJOR>(forward_vector(angles), right_vector(angles),
|
||||||
|
up_vector(angles), cam_origin);
|
||||||
|
}
|
||||||
|
Mat4X4 rotation_matrix(const ViewAngles& angles) noexcept
|
||||||
|
{
|
||||||
|
return mat_rotation_axis_z<float, MatStoreType::ROW_MAJOR>(angles.yaw)
|
||||||
|
* mat_rotation_axis_y<float, MatStoreType::ROW_MAJOR>(angles.roll)
|
||||||
|
* mat_rotation_axis_x<float, MatStoreType::ROW_MAJOR>(angles.pitch);
|
||||||
|
}
|
||||||
|
Mat4X4 calc_perspective_projection_matrix(const float field_of_view, const float aspect_ratio, const float near,
|
||||||
|
const float far) noexcept
|
||||||
|
{
|
||||||
|
return mat_perspective_left_handed(field_of_view, aspect_ratio, near, far);
|
||||||
|
}
|
||||||
|
} // namespace omath::unity_engine
|
||||||
240
tests/engines/unit_test_cry_engine.cpp
Normal file
240
tests/engines/unit_test_cry_engine.cpp
Normal file
@@ -0,0 +1,240 @@
|
|||||||
|
//
|
||||||
|
// Created by Vladislav on 19.02.2026.
|
||||||
|
//
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <omath/engines/cry_engine/camera.hpp>
|
||||||
|
#include <omath/engines/cry_engine/constants.hpp>
|
||||||
|
#include <omath/engines/cry_engine/formulas.hpp>
|
||||||
|
#include <random>
|
||||||
|
#include <ranges>
|
||||||
|
|
||||||
|
using namespace omath;
|
||||||
|
TEST(unit_test_cry_engine, look_at_forward)
|
||||||
|
{
|
||||||
|
const auto angles = cry_engine::CameraTrait::calc_look_at_angle({}, cry_engine::k_abs_forward);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = cry_engine::forward_vector(angles);
|
||||||
|
for (const auto& [result, etalon] : std::views::zip(dir_vector.as_array(), cry_engine::k_abs_forward.as_array()))
|
||||||
|
EXPECT_NEAR(result, etalon, 0.0001f);
|
||||||
|
}
|
||||||
|
TEST(unit_test_cry_engine, look_at_right)
|
||||||
|
{
|
||||||
|
const auto angles = cry_engine::CameraTrait::calc_look_at_angle({}, cry_engine::k_abs_right);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = cry_engine::forward_vector(angles);
|
||||||
|
for (const auto& [result, etalon] : std::views::zip(dir_vector.as_array(), cry_engine::k_abs_right.as_array()))
|
||||||
|
EXPECT_NEAR(result, etalon, 0.0001f);
|
||||||
|
}
|
||||||
|
TEST(unit_test_cry_engine, look_at_up)
|
||||||
|
{
|
||||||
|
const auto angles = cry_engine::CameraTrait::calc_look_at_angle({}, cry_engine::k_abs_right);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = cry_engine::forward_vector(angles);
|
||||||
|
for (const auto& [result, etalon] : std::views::zip(dir_vector.as_array(), cry_engine::k_abs_right.as_array()))
|
||||||
|
EXPECT_NEAR(result, etalon, 0.0001f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(unit_test_cry_engine, look_at_back)
|
||||||
|
{
|
||||||
|
const auto angles = cry_engine::CameraTrait::calc_look_at_angle({}, -cry_engine::k_abs_forward);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = cry_engine::forward_vector(angles);
|
||||||
|
for (const auto& [result, etalon] : std::views::zip(dir_vector.as_array(), (-cry_engine::k_abs_forward).as_array()))
|
||||||
|
EXPECT_NEAR(result, etalon, 0.0001f);
|
||||||
|
}
|
||||||
|
TEST(unit_test_cry_engine, look_at_left)
|
||||||
|
{
|
||||||
|
const auto angles = cry_engine::CameraTrait::calc_look_at_angle({}, -cry_engine::k_abs_right);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = cry_engine::forward_vector(angles);
|
||||||
|
for (const auto& [result, etalon] : std::views::zip(dir_vector.as_array(), (-cry_engine::k_abs_right).as_array()))
|
||||||
|
EXPECT_NEAR(result, etalon, 0.0001f);
|
||||||
|
}
|
||||||
|
TEST(unit_test_cry_engine, look_at_down)
|
||||||
|
{
|
||||||
|
const auto angles = cry_engine::CameraTrait::calc_look_at_angle({}, -cry_engine::k_abs_up);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = cry_engine::forward_vector(angles);
|
||||||
|
for (const auto& [result, etalon] : std::views::zip(dir_vector.as_array(), (-cry_engine::k_abs_up).as_array()))
|
||||||
|
EXPECT_NEAR(result, etalon, 0.0001f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(unit_test_cry_engine, RightVector)
|
||||||
|
{
|
||||||
|
const auto right = omath::cry_engine::right_vector({});
|
||||||
|
|
||||||
|
EXPECT_EQ(right, omath::cry_engine::k_abs_right);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(unit_test_cry_engine, UpVector)
|
||||||
|
{
|
||||||
|
const auto up = omath::cry_engine::up_vector({});
|
||||||
|
EXPECT_EQ(up, omath::cry_engine::k_abs_up);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(unit_test_cry_engine, ProjectTargetMovedFromCamera)
|
||||||
|
{
|
||||||
|
constexpr auto fov = omath::projection::FieldOfView::from_degrees(60.f);
|
||||||
|
const auto cam = omath::cry_engine::Camera({0, 0, 0}, {}, {1280.f, 720.f}, fov, 0.01f, 1000.f);
|
||||||
|
|
||||||
|
for (float distance = 0.02f; distance < 100.f; distance += 0.01f)
|
||||||
|
{
|
||||||
|
const auto projected = cam.world_to_screen({0, distance, 0});
|
||||||
|
|
||||||
|
EXPECT_TRUE(projected.has_value());
|
||||||
|
|
||||||
|
if (!projected.has_value())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
EXPECT_NEAR(projected->x, 640, 0.00001f);
|
||||||
|
EXPECT_NEAR(projected->y, 360, 0.00001f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(unit_test_cry_engine, CameraSetAndGetFov)
|
||||||
|
{
|
||||||
|
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||||
|
auto cam = omath::cry_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.01f, 1000.f);
|
||||||
|
|
||||||
|
EXPECT_EQ(cam.get_field_of_view().as_degrees(), 90.f);
|
||||||
|
cam.set_field_of_view(omath::projection::FieldOfView::from_degrees(50.f));
|
||||||
|
|
||||||
|
EXPECT_EQ(cam.get_field_of_view().as_degrees(), 50.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(unit_test_cry_engine, CameraSetAndGetOrigin)
|
||||||
|
{
|
||||||
|
auto cam = omath::cry_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, {}, 0.01f, 1000.f);
|
||||||
|
|
||||||
|
EXPECT_EQ(cam.get_origin(), omath::Vector3<float>{});
|
||||||
|
cam.set_field_of_view(omath::projection::FieldOfView::from_degrees(50.f));
|
||||||
|
|
||||||
|
EXPECT_EQ(cam.get_field_of_view().as_degrees(), 50.f);
|
||||||
|
}
|
||||||
|
TEST(unit_test_cry_engine, loook_at_random_all_axis)
|
||||||
|
{
|
||||||
|
std::mt19937 gen(std::random_device{}()); // Seed with a non-deterministic source
|
||||||
|
std::uniform_real_distribution<float> dist(-1000.f, 1000.f);
|
||||||
|
|
||||||
|
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||||
|
auto cam = omath::cry_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.001f, 10000.f);
|
||||||
|
|
||||||
|
std::size_t failed_points = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < 1000; i++)
|
||||||
|
{
|
||||||
|
const auto position_to_look = omath::Vector3<float>{dist(gen), dist(gen), dist(gen)};
|
||||||
|
|
||||||
|
if (cam.get_origin().distance_to(position_to_look) < 10)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
cam.look_at(position_to_look);
|
||||||
|
|
||||||
|
auto projected_pos = cam.world_to_view_port(position_to_look);
|
||||||
|
|
||||||
|
EXPECT_TRUE(projected_pos.has_value());
|
||||||
|
|
||||||
|
if (!projected_pos)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (std::abs(projected_pos->x - 0.f) >= 0.0001f || std::abs(projected_pos->y - 0.f) >= 0.0001f)
|
||||||
|
failed_points++;
|
||||||
|
}
|
||||||
|
EXPECT_LE(failed_points, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(unit_test_cry_engine, loook_at_random_x_axis)
|
||||||
|
{
|
||||||
|
std::mt19937 gen(std::random_device{}()); // Seed with a non-deterministic source
|
||||||
|
std::uniform_real_distribution<float> dist(-1000.f, 1000.f);
|
||||||
|
|
||||||
|
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||||
|
auto cam = omath::cry_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.001f, 10000.f);
|
||||||
|
|
||||||
|
std::size_t failed_points = 0;
|
||||||
|
for (int i = 0; i < 1000; i++)
|
||||||
|
{
|
||||||
|
const auto position_to_look = omath::Vector3<float>{dist(gen), 0.f, 0.f};
|
||||||
|
if (cam.get_origin().distance_to(position_to_look) < 10)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
cam.look_at(position_to_look);
|
||||||
|
|
||||||
|
auto projected_pos = cam.world_to_view_port(position_to_look);
|
||||||
|
|
||||||
|
EXPECT_TRUE(projected_pos.has_value());
|
||||||
|
|
||||||
|
if (!projected_pos)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (std::abs(projected_pos->x - 0.f) >= 0.001f || std::abs(projected_pos->y - 0.f) >= 0.001f)
|
||||||
|
failed_points++;
|
||||||
|
}
|
||||||
|
EXPECT_LE(failed_points, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(unit_test_cry_engine, loook_at_random_y_axis)
|
||||||
|
{
|
||||||
|
std::mt19937 gen(std::random_device{}()); // Seed with a non-deterministic source
|
||||||
|
std::uniform_real_distribution<float> dist(-1000.f, 1000.f);
|
||||||
|
|
||||||
|
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||||
|
auto cam = omath::cry_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.001f, 10000.f);
|
||||||
|
|
||||||
|
std::size_t failed_points = 0;
|
||||||
|
for (int i = 0; i < 1000; i++)
|
||||||
|
{
|
||||||
|
const auto position_to_look = omath::Vector3<float>{0.f, dist(gen), 0.f};
|
||||||
|
if (cam.get_origin().distance_to(position_to_look) < 10)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
cam.look_at(position_to_look);
|
||||||
|
|
||||||
|
auto projected_pos = cam.world_to_view_port(position_to_look);
|
||||||
|
|
||||||
|
EXPECT_TRUE(projected_pos.has_value());
|
||||||
|
|
||||||
|
if (!projected_pos)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (std::abs(projected_pos->x - 0.f) >= 0.01f || std::abs(projected_pos->y - 0.f) >= 0.01f)
|
||||||
|
failed_points++;
|
||||||
|
}
|
||||||
|
EXPECT_LE(failed_points, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(unit_test_cry_engine, loook_at_random_z_axis)
|
||||||
|
{
|
||||||
|
std::mt19937 gen(std::random_device{}()); // Seed with a non-deterministic source
|
||||||
|
std::uniform_real_distribution<float> dist(-1000.f, 1000.f);
|
||||||
|
|
||||||
|
constexpr auto fov = omath::projection::FieldOfView::from_degrees(90.f);
|
||||||
|
auto cam = omath::cry_engine::Camera({0, 0, 0}, {}, {1920.f, 1080.f}, fov, 0.001f, 10000.f);
|
||||||
|
|
||||||
|
std::size_t failed_points = 0;
|
||||||
|
for (int i = 0; i < 1000; i++)
|
||||||
|
{
|
||||||
|
const auto position_to_look = omath::Vector3<float>{0.f, 0.f, dist(gen)};
|
||||||
|
if (cam.get_origin().distance_to(position_to_look) < 10)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
cam.look_at(position_to_look);
|
||||||
|
|
||||||
|
auto projected_pos = cam.world_to_view_port(position_to_look);
|
||||||
|
|
||||||
|
EXPECT_TRUE(projected_pos.has_value());
|
||||||
|
|
||||||
|
if (!projected_pos)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (std::abs(projected_pos->x - 0.f) >= 0.01f || std::abs(projected_pos->y - 0.f) >= 0.01f)
|
||||||
|
failed_points++;
|
||||||
|
}
|
||||||
|
EXPECT_LE(failed_points, 100);
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
#include <omath/engines/frostbite_engine/formulas.hpp>
|
#include <omath/engines/frostbite_engine/formulas.hpp>
|
||||||
#include <print>
|
#include <print>
|
||||||
#include <random>
|
#include <random>
|
||||||
|
#include <ranges>
|
||||||
|
|
||||||
TEST(unit_test_frostbite_engine, UnitsToCentimeters_BasicValues)
|
TEST(unit_test_frostbite_engine, UnitsToCentimeters_BasicValues)
|
||||||
{
|
{
|
||||||
@@ -352,4 +353,55 @@ TEST(unit_test_frostbite_engine, loook_at_random_z_axis)
|
|||||||
failed_points++;
|
failed_points++;
|
||||||
}
|
}
|
||||||
EXPECT_LE(failed_points, 100);
|
EXPECT_LE(failed_points, 100);
|
||||||
}
|
}
|
||||||
|
TEST(unit_test_frostbite_engine, look_at_right)
|
||||||
|
{
|
||||||
|
const auto angles = omath::frostbite_engine::CameraTrait::calc_look_at_angle({}, omath::frostbite_engine::k_abs_right);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = omath::frostbite_engine::forward_vector(angles);
|
||||||
|
for (const auto& [result, etalon] :
|
||||||
|
std::views::zip(dir_vector.as_array(), omath::frostbite_engine::k_abs_right.as_array()))
|
||||||
|
EXPECT_NEAR(result, etalon, 0.0001f);
|
||||||
|
}
|
||||||
|
TEST(unit_test_frostbite_engine, look_at_up)
|
||||||
|
{
|
||||||
|
const auto angles = omath::frostbite_engine::CameraTrait::calc_look_at_angle({}, omath::frostbite_engine::k_abs_right);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = omath::frostbite_engine::forward_vector(angles);
|
||||||
|
for (const auto& [result, etalon] :
|
||||||
|
std::views::zip(dir_vector.as_array(), omath::frostbite_engine::k_abs_right.as_array()))
|
||||||
|
EXPECT_NEAR(result, etalon, 0.0001f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(unit_test_frostbite_engine, look_at_back)
|
||||||
|
{
|
||||||
|
const auto angles = omath::frostbite_engine::CameraTrait::calc_look_at_angle({}, -omath::frostbite_engine::k_abs_forward);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = omath::frostbite_engine::forward_vector(angles);
|
||||||
|
for (const auto& [result, etalon] :
|
||||||
|
std::views::zip(dir_vector.as_array(), (-omath::frostbite_engine::k_abs_forward).as_array()))
|
||||||
|
EXPECT_NEAR(result, etalon, 0.0001f);
|
||||||
|
}
|
||||||
|
TEST(unit_test_frostbite_engine, look_at_left)
|
||||||
|
{
|
||||||
|
const auto angles = omath::frostbite_engine::CameraTrait::calc_look_at_angle({}, -omath::frostbite_engine::k_abs_right);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = omath::frostbite_engine::forward_vector(angles);
|
||||||
|
for (const auto& [result, etalon] :
|
||||||
|
std::views::zip(dir_vector.as_array(), (-omath::frostbite_engine::k_abs_right).as_array()))
|
||||||
|
EXPECT_NEAR(result, etalon, 0.0001f);
|
||||||
|
}
|
||||||
|
TEST(unit_test_frostbite_engine, look_at_down)
|
||||||
|
{
|
||||||
|
const auto angles = omath::frostbite_engine::CameraTrait::calc_look_at_angle({}, -omath::frostbite_engine::k_abs_up);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = omath::frostbite_engine::forward_vector(angles);
|
||||||
|
for (const auto& [result, etalon] :
|
||||||
|
std::views::zip(dir_vector.as_array(), (-omath::frostbite_engine::k_abs_up).as_array()))
|
||||||
|
EXPECT_NEAR(result, etalon, 0.0001f);
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <omath/engines/iw_engine/constants.hpp>
|
#include <omath/engines/iw_engine/constants.hpp>
|
||||||
#include <omath/engines/iw_engine/formulas.hpp>
|
#include <omath/engines/iw_engine/formulas.hpp>
|
||||||
#include <random>
|
#include <random>
|
||||||
|
#include <ranges>
|
||||||
|
|
||||||
TEST(unit_test_iw_engine, ForwardVector)
|
TEST(unit_test_iw_engine, ForwardVector)
|
||||||
{
|
{
|
||||||
@@ -223,4 +224,60 @@ TEST(unit_test_iw_engine, loook_at_random_z_axis)
|
|||||||
failed_points++;
|
failed_points++;
|
||||||
}
|
}
|
||||||
EXPECT_LE(failed_points, 100);
|
EXPECT_LE(failed_points, 100);
|
||||||
|
}
|
||||||
|
TEST(unit_test_iw_engine, look_at_forward)
|
||||||
|
{
|
||||||
|
const auto angles = omath::iw_engine::CameraTrait::calc_look_at_angle({}, omath::iw_engine::k_abs_forward);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = omath::iw_engine::forward_vector(angles);
|
||||||
|
for (const auto& [result, etalon] : std::views::zip(dir_vector.as_array(), omath::iw_engine::k_abs_forward.as_array()))
|
||||||
|
EXPECT_NEAR(result, etalon, 0.0001f);
|
||||||
|
}
|
||||||
|
TEST(unit_test_iw_engine, look_at_right)
|
||||||
|
{
|
||||||
|
const auto angles = omath::iw_engine::CameraTrait::calc_look_at_angle({}, omath::iw_engine::k_abs_right);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = omath::iw_engine::forward_vector(angles);
|
||||||
|
for (const auto& [result, etalon] : std::views::zip(dir_vector.as_array(), omath::iw_engine::k_abs_right.as_array()))
|
||||||
|
EXPECT_NEAR(result, etalon, 0.0001f);
|
||||||
|
}
|
||||||
|
TEST(unit_test_iw_engine, look_at_up)
|
||||||
|
{
|
||||||
|
const auto angles = omath::iw_engine::CameraTrait::calc_look_at_angle({}, omath::iw_engine::k_abs_right);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = omath::iw_engine::forward_vector(angles);
|
||||||
|
for (const auto& [result, etalon] : std::views::zip(dir_vector.as_array(), omath::iw_engine::k_abs_right.as_array()))
|
||||||
|
EXPECT_NEAR(result, etalon, 0.0001f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(unit_test_iw_engine, look_at_back)
|
||||||
|
{
|
||||||
|
const auto angles = omath::iw_engine::CameraTrait::calc_look_at_angle({}, -omath::iw_engine::k_abs_forward);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = omath::iw_engine::forward_vector(angles);
|
||||||
|
for (const auto& [result, etalon] : std::views::zip(dir_vector.as_array(), (-omath::iw_engine::k_abs_forward).as_array()))
|
||||||
|
EXPECT_NEAR(result, etalon, 0.0001f);
|
||||||
|
}
|
||||||
|
TEST(unit_test_iw_engine, look_at_left)
|
||||||
|
{
|
||||||
|
const auto angles = omath::iw_engine::CameraTrait::calc_look_at_angle({}, -omath::iw_engine::k_abs_right);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = omath::iw_engine::forward_vector(angles);
|
||||||
|
for (const auto& [result, etalon] : std::views::zip(dir_vector.as_array(), (-omath::iw_engine::k_abs_right).as_array()))
|
||||||
|
EXPECT_NEAR(result, etalon, 0.0001f);
|
||||||
|
}
|
||||||
|
TEST(unit_test_iw_engine, look_at_down)
|
||||||
|
{
|
||||||
|
const auto angles = omath::iw_engine::CameraTrait::calc_look_at_angle({}, -omath::iw_engine::k_abs_up);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = omath::iw_engine::forward_vector(angles);
|
||||||
|
EXPECT_NEAR(dir_vector.z, -0.99984f, 0.0001f);
|
||||||
|
EXPECT_NEAR(dir_vector.x,- 0.017f, 0.01f);
|
||||||
|
EXPECT_NEAR(dir_vector.y, 0.f, 0.001f);
|
||||||
}
|
}
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <omath/engines/opengl_engine/constants.hpp>
|
#include <omath/engines/opengl_engine/constants.hpp>
|
||||||
#include <omath/engines/opengl_engine/formulas.hpp>
|
#include <omath/engines/opengl_engine/formulas.hpp>
|
||||||
#include <random>
|
#include <random>
|
||||||
|
#include <ranges>
|
||||||
|
|
||||||
TEST(unit_test_opengl, UnitsToCentimeters_BasicValues)
|
TEST(unit_test_opengl, UnitsToCentimeters_BasicValues)
|
||||||
{
|
{
|
||||||
@@ -337,4 +338,60 @@ TEST(unit_test_opengl_engine, loook_at_random_z_axis)
|
|||||||
failed_points++;
|
failed_points++;
|
||||||
}
|
}
|
||||||
EXPECT_LE(failed_points, 100);
|
EXPECT_LE(failed_points, 100);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(unit_test_opengl_engine, look_at_forward)
|
||||||
|
{
|
||||||
|
const auto angles = omath::opengl_engine::CameraTrait::calc_look_at_angle({}, omath::opengl_engine::k_abs_forward);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = omath::opengl_engine::forward_vector(angles);
|
||||||
|
for (const auto& [result, etalon] : std::views::zip(dir_vector.as_array(), omath::opengl_engine::k_abs_forward.as_array()))
|
||||||
|
EXPECT_NEAR(result, etalon, 0.0001f);
|
||||||
|
}
|
||||||
|
TEST(unit_test_opengl_engine, look_at_right)
|
||||||
|
{
|
||||||
|
const auto angles = omath::opengl_engine::CameraTrait::calc_look_at_angle({}, omath::opengl_engine::k_abs_right);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = omath::opengl_engine::forward_vector(angles);
|
||||||
|
for (const auto& [result, etalon] : std::views::zip(dir_vector.as_array(), omath::opengl_engine::k_abs_right.as_array()))
|
||||||
|
EXPECT_NEAR(result, etalon, 0.0001f);
|
||||||
|
}
|
||||||
|
TEST(unit_test_opengl_engine, look_at_up)
|
||||||
|
{
|
||||||
|
const auto angles = omath::opengl_engine::CameraTrait::calc_look_at_angle({}, omath::opengl_engine::k_abs_right);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = omath::opengl_engine::forward_vector(angles);
|
||||||
|
for (const auto& [result, etalon] : std::views::zip(dir_vector.as_array(), omath::opengl_engine::k_abs_right.as_array()))
|
||||||
|
EXPECT_NEAR(result, etalon, 0.0001f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(unit_test_opengl_engine, look_at_back)
|
||||||
|
{
|
||||||
|
const auto angles = omath::opengl_engine::CameraTrait::calc_look_at_angle({}, -omath::opengl_engine::k_abs_forward);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = omath::opengl_engine::forward_vector(angles);
|
||||||
|
for (const auto& [result, etalon] : std::views::zip(dir_vector.as_array(), (-omath::opengl_engine::k_abs_forward).as_array()))
|
||||||
|
EXPECT_NEAR(result, etalon, 0.0001f);
|
||||||
|
}
|
||||||
|
TEST(unit_test_opengl_engine, look_at_left)
|
||||||
|
{
|
||||||
|
const auto angles = omath::opengl_engine::CameraTrait::calc_look_at_angle({}, -omath::opengl_engine::k_abs_right);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = omath::opengl_engine::forward_vector(angles);
|
||||||
|
for (const auto& [result, etalon] : std::views::zip(dir_vector.as_array(), (-omath::opengl_engine::k_abs_right).as_array()))
|
||||||
|
EXPECT_NEAR(result, etalon, 0.0001f);
|
||||||
|
}
|
||||||
|
TEST(unit_test_opengl_engine, look_at_down)
|
||||||
|
{
|
||||||
|
const auto angles = omath::opengl_engine::CameraTrait::calc_look_at_angle({}, -omath::opengl_engine::k_abs_up);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = omath::opengl_engine::forward_vector(angles);
|
||||||
|
for (const auto& [result, etalon] : std::views::zip(dir_vector.as_array(), (-omath::opengl_engine::k_abs_up).as_array()))
|
||||||
|
EXPECT_NEAR(result, etalon, 0.0001f);
|
||||||
}
|
}
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <omath/engines/source_engine/constants.hpp>
|
#include <omath/engines/source_engine/constants.hpp>
|
||||||
#include <omath/engines/source_engine/formulas.hpp>
|
#include <omath/engines/source_engine/formulas.hpp>
|
||||||
#include <random>
|
#include <random>
|
||||||
|
#include <ranges>
|
||||||
|
|
||||||
TEST(unit_test_source_engine_units, HammerUnitsToCentimeters_BasicValues)
|
TEST(unit_test_source_engine_units, HammerUnitsToCentimeters_BasicValues)
|
||||||
{
|
{
|
||||||
@@ -365,4 +366,60 @@ TEST(unit_test_source_engine, loook_at_random_z_axis)
|
|||||||
failed_points++;
|
failed_points++;
|
||||||
}
|
}
|
||||||
EXPECT_LE(failed_points, 100);
|
EXPECT_LE(failed_points, 100);
|
||||||
|
}
|
||||||
|
TEST(unit_test_source_engine, look_at_forward)
|
||||||
|
{
|
||||||
|
const auto angles = omath::source_engine::CameraTrait::calc_look_at_angle({}, omath::source_engine::k_abs_forward);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = omath::source_engine::forward_vector(angles);
|
||||||
|
for (const auto& [result, etalon] : std::views::zip(dir_vector.as_array(), omath::source_engine::k_abs_forward.as_array()))
|
||||||
|
EXPECT_NEAR(result, etalon, 0.0001f);
|
||||||
|
}
|
||||||
|
TEST(unit_test_source_engine, look_at_right)
|
||||||
|
{
|
||||||
|
const auto angles = omath::source_engine::CameraTrait::calc_look_at_angle({}, omath::source_engine::k_abs_right);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = omath::source_engine::forward_vector(angles);
|
||||||
|
for (const auto& [result, etalon] : std::views::zip(dir_vector.as_array(), omath::source_engine::k_abs_right.as_array()))
|
||||||
|
EXPECT_NEAR(result, etalon, 0.0001f);
|
||||||
|
}
|
||||||
|
TEST(unit_test_source_engine, look_at_up)
|
||||||
|
{
|
||||||
|
const auto angles = omath::source_engine::CameraTrait::calc_look_at_angle({}, omath::source_engine::k_abs_right);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = omath::source_engine::forward_vector(angles);
|
||||||
|
for (const auto& [result, etalon] : std::views::zip(dir_vector.as_array(), omath::source_engine::k_abs_right.as_array()))
|
||||||
|
EXPECT_NEAR(result, etalon, 0.0001f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(unit_test_source_engine, look_at_back)
|
||||||
|
{
|
||||||
|
const auto angles = omath::source_engine::CameraTrait::calc_look_at_angle({}, -omath::source_engine::k_abs_forward);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = omath::source_engine::forward_vector(angles);
|
||||||
|
for (const auto& [result, etalon] : std::views::zip(dir_vector.as_array(), (-omath::source_engine::k_abs_forward).as_array()))
|
||||||
|
EXPECT_NEAR(result, etalon, 0.0001f);
|
||||||
|
}
|
||||||
|
TEST(unit_test_source_engine, look_at_left)
|
||||||
|
{
|
||||||
|
const auto angles = omath::source_engine::CameraTrait::calc_look_at_angle({}, -omath::source_engine::k_abs_right);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = omath::source_engine::forward_vector(angles);
|
||||||
|
for (const auto& [result, etalon] : std::views::zip(dir_vector.as_array(), (-omath::source_engine::k_abs_right).as_array()))
|
||||||
|
EXPECT_NEAR(result, etalon, 0.0001f);
|
||||||
|
}
|
||||||
|
TEST(unit_test_source_engine, look_at_down)
|
||||||
|
{
|
||||||
|
const auto angles = omath::source_engine::CameraTrait::calc_look_at_angle({}, -omath::source_engine::k_abs_up);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = omath::source_engine::forward_vector(angles);
|
||||||
|
EXPECT_NEAR(dir_vector.z, -0.99984f, 0.0001f);
|
||||||
|
EXPECT_NEAR(dir_vector.x,- 0.017f, 0.01f);
|
||||||
|
EXPECT_NEAR(dir_vector.y, 0.f, 0.001f);
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
#include <omath/engines/unity_engine/formulas.hpp>
|
#include <omath/engines/unity_engine/formulas.hpp>
|
||||||
#include <print>
|
#include <print>
|
||||||
#include <random>
|
#include <random>
|
||||||
|
#include <ranges>
|
||||||
|
|
||||||
TEST(unit_test_unity_engine, UnitsToCentimeters_BasicValues)
|
TEST(unit_test_unity_engine, UnitsToCentimeters_BasicValues)
|
||||||
{
|
{
|
||||||
@@ -207,7 +208,8 @@ TEST(unit_test_unity_engine, Project)
|
|||||||
constexpr auto fov = omath::projection::FieldOfView::from_degrees(60.f);
|
constexpr auto fov = omath::projection::FieldOfView::from_degrees(60.f);
|
||||||
|
|
||||||
const auto cam = omath::unity_engine::Camera({0, 0, 0}, {}, {1280.f, 720.f}, fov, 0.03f, 1000.f);
|
const auto cam = omath::unity_engine::Camera({0, 0, 0}, {}, {1280.f, 720.f}, fov, 0.03f, 1000.f);
|
||||||
const auto proj = cam.world_to_screen<omath::unity_engine::Camera::ScreenStart::BOTTOM_LEFT_CORNER>({10.f, 3, 10.f});
|
const auto proj =
|
||||||
|
cam.world_to_screen<omath::unity_engine::Camera::ScreenStart::BOTTOM_LEFT_CORNER>({10.f, 3, 10.f});
|
||||||
|
|
||||||
EXPECT_NEAR(proj->x, 1263.538, 0.001f);
|
EXPECT_NEAR(proj->x, 1263.538, 0.001f);
|
||||||
EXPECT_NEAR(proj->y, 547.061f, 0.001f);
|
EXPECT_NEAR(proj->y, 547.061f, 0.001f);
|
||||||
@@ -353,4 +355,65 @@ TEST(unit_test_unity_engine, loook_at_random_z_axis)
|
|||||||
failed_points++;
|
failed_points++;
|
||||||
}
|
}
|
||||||
EXPECT_LE(failed_points, 100);
|
EXPECT_LE(failed_points, 100);
|
||||||
}
|
}
|
||||||
|
TEST(unit_test_unity_engine, look_at_forward)
|
||||||
|
{
|
||||||
|
const auto angles = omath::unity_engine::CameraTrait::calc_look_at_angle({}, omath::unity_engine::k_abs_forward);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = omath::unity_engine::forward_vector(angles);
|
||||||
|
for (const auto& [result, etalon] :
|
||||||
|
std::views::zip(dir_vector.as_array(), omath::unity_engine::k_abs_forward.as_array()))
|
||||||
|
EXPECT_NEAR(result, etalon, 0.0001f);
|
||||||
|
}
|
||||||
|
TEST(unit_test_unity_engine, look_at_right)
|
||||||
|
{
|
||||||
|
const auto angles = omath::unity_engine::CameraTrait::calc_look_at_angle({}, omath::unity_engine::k_abs_right);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = omath::unity_engine::forward_vector(angles);
|
||||||
|
for (const auto& [result, etalon] :
|
||||||
|
std::views::zip(dir_vector.as_array(), omath::unity_engine::k_abs_right.as_array()))
|
||||||
|
EXPECT_NEAR(result, etalon, 0.0001f);
|
||||||
|
}
|
||||||
|
TEST(unit_test_unity_engine, look_at_up)
|
||||||
|
{
|
||||||
|
const auto angles = omath::unity_engine::CameraTrait::calc_look_at_angle({}, omath::unity_engine::k_abs_right);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = omath::unity_engine::forward_vector(angles);
|
||||||
|
for (const auto& [result, etalon] :
|
||||||
|
std::views::zip(dir_vector.as_array(), omath::unity_engine::k_abs_right.as_array()))
|
||||||
|
EXPECT_NEAR(result, etalon, 0.0001f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(unit_test_unity_engine, look_at_back)
|
||||||
|
{
|
||||||
|
const auto angles = omath::unity_engine::CameraTrait::calc_look_at_angle({}, -omath::unity_engine::k_abs_forward);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = omath::unity_engine::forward_vector(angles);
|
||||||
|
for (const auto& [result, etalon] :
|
||||||
|
std::views::zip(dir_vector.as_array(), (-omath::unity_engine::k_abs_forward).as_array()))
|
||||||
|
EXPECT_NEAR(result, etalon, 0.0001f);
|
||||||
|
}
|
||||||
|
TEST(unit_test_unity_engine, look_at_left)
|
||||||
|
{
|
||||||
|
const auto angles = omath::unity_engine::CameraTrait::calc_look_at_angle({}, -omath::unity_engine::k_abs_right);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = omath::unity_engine::forward_vector(angles);
|
||||||
|
for (const auto& [result, etalon] :
|
||||||
|
std::views::zip(dir_vector.as_array(), (-omath::unity_engine::k_abs_right).as_array()))
|
||||||
|
EXPECT_NEAR(result, etalon, 0.0001f);
|
||||||
|
}
|
||||||
|
TEST(unit_test_unity_engine, look_at_down)
|
||||||
|
{
|
||||||
|
const auto angles = omath::unity_engine::CameraTrait::calc_look_at_angle({}, -omath::unity_engine::k_abs_up);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = omath::unity_engine::forward_vector(angles);
|
||||||
|
for (const auto& [result, etalon] :
|
||||||
|
std::views::zip(dir_vector.as_array(), (-omath::unity_engine::k_abs_up).as_array()))
|
||||||
|
EXPECT_NEAR(result, etalon, 0.0001f);
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include <omath/engines/unreal_engine/formulas.hpp>
|
#include <omath/engines/unreal_engine/formulas.hpp>
|
||||||
#include <print>
|
#include <print>
|
||||||
#include <random>
|
#include <random>
|
||||||
|
#include <ranges>
|
||||||
|
|
||||||
TEST(unit_test_unreal_engine, ForwardVector)
|
TEST(unit_test_unreal_engine, ForwardVector)
|
||||||
{
|
{
|
||||||
@@ -361,4 +362,59 @@ TEST(unit_test_unreal_engine, ConstexprConversions)
|
|||||||
static_assert(cm == 100000.0, "units_to_centimeters constexpr failed");
|
static_assert(cm == 100000.0, "units_to_centimeters constexpr failed");
|
||||||
static_assert(m == 1000.0, "units_to_meters constexpr failed");
|
static_assert(m == 1000.0, "units_to_meters constexpr failed");
|
||||||
static_assert(km == 1.0, "units_to_kilometers constexpr failed");
|
static_assert(km == 1.0, "units_to_kilometers constexpr failed");
|
||||||
|
}
|
||||||
|
TEST(unit_test_unreal_engine, look_at_forward)
|
||||||
|
{
|
||||||
|
const auto angles = omath::unreal_engine::CameraTrait::calc_look_at_angle({}, omath::unreal_engine::k_abs_forward);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = omath::unreal_engine::forward_vector(angles);
|
||||||
|
for (const auto& [result, etalon] : std::views::zip(dir_vector.as_array(), omath::unreal_engine::k_abs_forward.as_array()))
|
||||||
|
EXPECT_NEAR(result, etalon, 0.0001f);
|
||||||
|
}
|
||||||
|
TEST(unit_test_unreal_engine, look_at_right)
|
||||||
|
{
|
||||||
|
const auto angles = omath::unreal_engine::CameraTrait::calc_look_at_angle({}, omath::unreal_engine::k_abs_right);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = omath::unreal_engine::forward_vector(angles);
|
||||||
|
for (const auto& [result, etalon] : std::views::zip(dir_vector.as_array(), omath::unreal_engine::k_abs_right.as_array()))
|
||||||
|
EXPECT_NEAR(result, etalon, 0.0001f);
|
||||||
|
}
|
||||||
|
TEST(unit_test_unreal_engine, look_at_up)
|
||||||
|
{
|
||||||
|
const auto angles = omath::unreal_engine::CameraTrait::calc_look_at_angle({}, omath::unreal_engine::k_abs_right);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = omath::unreal_engine::forward_vector(angles);
|
||||||
|
for (const auto& [result, etalon] : std::views::zip(dir_vector.as_array(), omath::unreal_engine::k_abs_right.as_array()))
|
||||||
|
EXPECT_NEAR(result, etalon, 0.0001f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(unit_test_unreal_engine, look_at_back)
|
||||||
|
{
|
||||||
|
const auto angles = omath::unreal_engine::CameraTrait::calc_look_at_angle({}, -omath::unreal_engine::k_abs_forward);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = omath::unreal_engine::forward_vector(angles);
|
||||||
|
for (const auto& [result, etalon] : std::views::zip(dir_vector.as_array(), (-omath::unreal_engine::k_abs_forward).as_array()))
|
||||||
|
EXPECT_NEAR(result, etalon, 0.0001f);
|
||||||
|
}
|
||||||
|
TEST(unit_test_unreal_engine, look_at_left)
|
||||||
|
{
|
||||||
|
const auto angles = omath::unreal_engine::CameraTrait::calc_look_at_angle({}, -omath::unreal_engine::k_abs_right);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = omath::unreal_engine::forward_vector(angles);
|
||||||
|
for (const auto& [result, etalon] : std::views::zip(dir_vector.as_array(), (-omath::unreal_engine::k_abs_right).as_array()))
|
||||||
|
EXPECT_NEAR(result, etalon, 0.0001f);
|
||||||
|
}
|
||||||
|
TEST(unit_test_unreal_engine, look_at_down)
|
||||||
|
{
|
||||||
|
const auto angles = omath::unreal_engine::CameraTrait::calc_look_at_angle({}, -omath::unreal_engine::k_abs_up);
|
||||||
|
|
||||||
|
// ReSharper disable once CppTooWideScopeInitStatement
|
||||||
|
const auto dir_vector = omath::unreal_engine::forward_vector(angles);
|
||||||
|
for (const auto& [result, etalon] : std::views::zip(dir_vector.as_array(), (-omath::unreal_engine::k_abs_up).as_array()))
|
||||||
|
EXPECT_NEAR(result, etalon, 0.0001f);
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user