mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 15:03:27 +00:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0328fef4f7 | |||
| 687772f073 | |||
| c66df11754 | |||
| 0450dc3547 | |||
| 0bd9eda48f | |||
| 858314fa0a | |||
| f277b1038c | |||
| 15c055beb7 | |||
| 4d24815f3e | |||
| d96b0cd2f7 |
38
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
38
.github/ISSUE_TEMPLATE/bug_report.md
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Desktop (please complete the following information):**
|
||||
- OS: [e.g. iOS]
|
||||
- Browser [e.g. chrome, safari]
|
||||
- Version [e.g. 22]
|
||||
|
||||
**Smartphone (please complete the following information):**
|
||||
- Device: [e.g. iPhone6]
|
||||
- OS: [e.g. iOS8.1]
|
||||
- Browser [e.g. stock browser, safari]
|
||||
- Version [e.g. 22]
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
10
.github/ISSUE_TEMPLATE/custom.md
vendored
Normal file
10
.github/ISSUE_TEMPLATE/custom.md
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
---
|
||||
name: Custom issue template
|
||||
about: Describe this issue template's purpose here.
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
|
||||
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
@@ -1,6 +1,6 @@
|
||||
cmake_minimum_required(VERSION 3.26)
|
||||
|
||||
project(omath VERSION 3.0.4.1 LANGUAGES CXX)
|
||||
project(omath VERSION 3.2.1 LANGUAGES CXX)
|
||||
|
||||
include(CMakePackageConfigHelpers)
|
||||
|
||||
|
||||
@@ -13,7 +13,32 @@
|
||||
|
||||
namespace omath::projectile_prediction
|
||||
{
|
||||
template<class T>
|
||||
concept PredEngineConcept =
|
||||
requires(const Projectile& projectile, const Target& target, const Vector3<float>& vec_a,
|
||||
const Vector3<float>& vec_b,
|
||||
Vector3<float> v3, // by-value for calc_viewpoint_from_angles
|
||||
float pitch, float yaw, float time, float gravity, std::optional<float> maybe_pitch) {
|
||||
// Presence + return types
|
||||
{ T::predict_projectile_position(projectile, pitch, yaw, time, gravity) } -> std::same_as<Vec3>;
|
||||
{ T::predict_target_position(target, time, gravity) } -> std::same_as<Vec3>;
|
||||
{ T::calc_vector_2d_distance(vec_a) } -> std::same_as<float>;
|
||||
{ T::get_vector_height_coordinate(vec_b) } -> std::same_as<float>;
|
||||
{ T::calc_viewpoint_from_angles(projectile, v3, maybe_pitch) } -> std::same_as<Vec3>;
|
||||
{ T::calc_direct_pitch_angle(vec_a, vec_b) } -> std::same_as<float>;
|
||||
{ T::calc_direct_yaw_angle(vec_a, vec_b) } -> std::same_as<float>;
|
||||
|
||||
// Enforce noexcept as in PredEngineTrait
|
||||
requires noexcept(T::predict_projectile_position(projectile, pitch, yaw, time, gravity));
|
||||
requires noexcept(T::predict_target_position(target, time, gravity));
|
||||
requires noexcept(T::calc_vector_2d_distance(vec_a));
|
||||
requires noexcept(T::get_vector_height_coordinate(vec_b));
|
||||
requires noexcept(T::calc_viewpoint_from_angles(projectile, v3, maybe_pitch));
|
||||
requires noexcept(T::calc_direct_pitch_angle(vec_a, vec_b));
|
||||
requires noexcept(T::calc_direct_yaw_angle(vec_a, vec_b));
|
||||
};
|
||||
template<class EngineTrait = source_engine::PredEngineTrait>
|
||||
requires PredEngineConcept<EngineTrait>
|
||||
class ProjPredEngineLegacy final : public ProjPredEngineInterface
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -26,11 +26,27 @@ namespace omath::projection
|
||||
};
|
||||
using FieldOfView = Angle<float, 0.f, 180.f, AngleFlags::Clamped>;
|
||||
|
||||
template<class T, class MatType, class ViewAnglesType>
|
||||
concept CameraEngineConcept =
|
||||
requires(const Vector3<float>& cam_origin, const Vector3<float>& look_at, const ViewAnglesType& angles,
|
||||
const FieldOfView& fov, const ViewPort& viewport, float znear, float zfar) {
|
||||
// Presence + return types
|
||||
{ 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_projection_matrix(fov, viewport, znear, zfar) } -> std::same_as<MatType>;
|
||||
|
||||
// Enforce noexcept as in the trait declaration
|
||||
requires noexcept(T::calc_look_at_angle(cam_origin, look_at));
|
||||
requires noexcept(T::calc_view_matrix(angles, cam_origin));
|
||||
requires noexcept(T::calc_projection_matrix(fov, viewport, znear, zfar));
|
||||
};
|
||||
|
||||
template<class Mat4X4Type, class ViewAnglesType, class TraitClass>
|
||||
class Camera
|
||||
requires CameraEngineConcept<TraitClass, Mat4X4Type, ViewAnglesType>
|
||||
class Camera final
|
||||
{
|
||||
public:
|
||||
virtual ~Camera() = default;
|
||||
~Camera() = default;
|
||||
Camera(const Vector3<float>& position, const ViewAnglesType& view_angles, const ViewPort& view_port,
|
||||
const FieldOfView& fov, const float near, const float far) noexcept
|
||||
: m_view_port(view_port), m_field_of_view(fov), m_far_plane_distance(far), m_near_plane_distance(near),
|
||||
@@ -170,6 +186,18 @@ namespace omath::projection
|
||||
|
||||
[[nodiscard]] Vector3<float> ndc_to_screen_position(const Vector3<float>& ndc) const noexcept
|
||||
{
|
||||
/*
|
||||
^
|
||||
| y
|
||||
1 |
|
||||
|
|
||||
|
|
||||
-1 ---------0--------- 1 --> x
|
||||
|
|
||||
|
|
||||
-1 |
|
||||
v
|
||||
*/
|
||||
return {(ndc.x + 1.f) / 2.f * m_view_port.m_width, (1.f - ndc.y) / 2.f * m_view_port.m_height, ndc.z};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -190,6 +190,29 @@ namespace omath
|
||||
return x + y;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
bool operator<(const Vector2& other) const noexcept
|
||||
{
|
||||
return length() < other.length();
|
||||
}
|
||||
[[nodiscard]]
|
||||
bool operator>(const Vector2& other) const noexcept
|
||||
{
|
||||
return length() > other.length();
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
bool operator<=(const Vector2& other) const noexcept
|
||||
{
|
||||
return length() <= other.length();
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
bool operator>=(const Vector2& other) const noexcept
|
||||
{
|
||||
return length() >= other.length();
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr std::tuple<Type, Type> as_tuple() const noexcept
|
||||
{
|
||||
@@ -203,7 +226,7 @@ namespace omath
|
||||
return {static_cast<float>(this->x), static_cast<float>(this->y)};
|
||||
}
|
||||
[[nodiscard]]
|
||||
static Vector3<float> from_im_vec2(const ImVec2& other) noexcept
|
||||
static Vector2 from_im_vec2(const ImVec2& other) noexcept
|
||||
{
|
||||
return {static_cast<Type>(other.x), static_cast<Type>(other.y)};
|
||||
}
|
||||
|
||||
@@ -253,6 +253,30 @@ namespace omath
|
||||
return {angles::radians_to_degrees(std::asin(delta.z / distance)),
|
||||
angles::radians_to_degrees(std::atan2(delta.y, delta.x)), 0};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
bool operator<(const Vector3& other) const noexcept
|
||||
{
|
||||
return length() < other.length();
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
bool operator>(const Vector3& other) const noexcept
|
||||
{
|
||||
return length() > other.length();
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
bool operator<=(const Vector3& other) const noexcept
|
||||
{
|
||||
return length() <= other.length();
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
bool operator>=(const Vector3& other) const noexcept
|
||||
{
|
||||
return length() >= other.length();
|
||||
}
|
||||
};
|
||||
} // namespace omath
|
||||
// ReSharper disable once CppRedundantNamespaceDefinition
|
||||
|
||||
@@ -89,7 +89,7 @@ namespace omath
|
||||
return Vector3<Type>::dot(other) + w * other.w;
|
||||
}
|
||||
|
||||
[[nodiscard]] Vector3<Type> length() const noexcept
|
||||
[[nodiscard]] Type length() const noexcept
|
||||
{
|
||||
return std::sqrt(length_sqr());
|
||||
}
|
||||
@@ -158,6 +158,30 @@ namespace omath
|
||||
return Vector3<Type>::sum() + w;
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
bool operator<(const Vector4& other) const noexcept
|
||||
{
|
||||
return length() < other.length();
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
bool operator>(const Vector4& other) const noexcept
|
||||
{
|
||||
return length() > other.length();
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
bool operator<=(const Vector4& other) const noexcept
|
||||
{
|
||||
return length() <= other.length();
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
bool operator>=(const Vector4& other) const noexcept
|
||||
{
|
||||
return length() >= other.length();
|
||||
}
|
||||
|
||||
#ifdef OMATH_IMGUI_INTEGRATION
|
||||
[[nodiscard]]
|
||||
ImVec4 to_im_vec4() const noexcept
|
||||
|
||||
@@ -346,6 +346,28 @@ TEST_F(UnitTestVector2, NegationOperator_ZeroVector)
|
||||
EXPECT_FLOAT_EQ(result.y, -0.0f);
|
||||
}
|
||||
|
||||
TEST_F(UnitTestVector2, LessOperator)
|
||||
{
|
||||
EXPECT_TRUE(v1 < v2);
|
||||
}
|
||||
|
||||
TEST_F(UnitTestVector2, GreaterOperator)
|
||||
{
|
||||
EXPECT_TRUE(v2 > v1);
|
||||
}
|
||||
TEST_F(UnitTestVector2, LessEqualOperator)
|
||||
{
|
||||
EXPECT_TRUE(omath::Vector2<float>{} <= omath::Vector2<float>{});
|
||||
EXPECT_TRUE(omath::Vector2<float>{} <= omath::Vector2(1.f, 1.f));
|
||||
}
|
||||
|
||||
TEST_F(UnitTestVector2, GreaterEqualOperator)
|
||||
{
|
||||
EXPECT_TRUE(omath::Vector2<float>{} >= omath::Vector2<float>{});
|
||||
EXPECT_TRUE(omath::Vector2(1.f, 1.f) >= omath::Vector2<float>{});
|
||||
}
|
||||
|
||||
|
||||
// Static assertions (compile-time checks)
|
||||
static_assert(Vector2(1.0f, 2.0f).length_sqr() == 5.0f, "LengthSqr should be 5");
|
||||
static_assert(Vector2(1.0f, 2.0f).dot(Vector2(4.0f, 5.0f)) == 14.0f, "Dot product should be 14");
|
||||
|
||||
@@ -402,6 +402,27 @@ TEST_F(UnitTestVector3, IsPerpendicular)
|
||||
EXPECT_FALSE(Vector3(0.0f, 0.0f, 0.0f).is_perpendicular({0.0f, 0.0f, 1.0f}));
|
||||
}
|
||||
|
||||
TEST_F(UnitTestVector3, LessOperator)
|
||||
{
|
||||
EXPECT_TRUE(v1 < v2);
|
||||
}
|
||||
|
||||
TEST_F(UnitTestVector3, GreaterOperator)
|
||||
{
|
||||
EXPECT_TRUE(v2 > v1);
|
||||
}
|
||||
TEST_F(UnitTestVector3, LessEqualOperator)
|
||||
{
|
||||
EXPECT_TRUE(omath::Vector3<float>{} <= omath::Vector3<float>{});
|
||||
EXPECT_TRUE(omath::Vector3<float>{} <= omath::Vector3(1.f, 1.f, 1.f));
|
||||
}
|
||||
|
||||
TEST_F(UnitTestVector3, GreaterEqualOperator)
|
||||
{
|
||||
EXPECT_TRUE(omath::Vector3<float>{} >= omath::Vector3<float>{});
|
||||
EXPECT_TRUE(omath::Vector3(1.f, 1.f, 1.f) >= omath::Vector3<float>{});
|
||||
}
|
||||
|
||||
// Static assertions (compile-time checks)
|
||||
static_assert(Vector3(1.0f, 2.0f, 3.0f).length_sqr() == 14.0f, "LengthSqr should be 14");
|
||||
static_assert(Vector3(1.0f, 2.0f, 3.0f).dot(Vector3(4.0f, 5.0f, 6.0f)) == 32.0f, "Dot product should be 32");
|
||||
|
||||
@@ -215,3 +215,23 @@ TEST_F(UnitTestVector4, Clamp)
|
||||
EXPECT_FLOAT_EQ(v3.z, 2.5f);
|
||||
EXPECT_FLOAT_EQ(v3.w, 4.0f); // w is not clamped in this method
|
||||
}
|
||||
TEST_F(UnitTestVector4, LessOperator)
|
||||
{
|
||||
EXPECT_TRUE(v1 < v2);
|
||||
}
|
||||
|
||||
TEST_F(UnitTestVector4, GreaterOperator)
|
||||
{
|
||||
EXPECT_TRUE(v2 > v1);
|
||||
}
|
||||
TEST_F(UnitTestVector4, LessEqualOperator)
|
||||
{
|
||||
EXPECT_TRUE(omath::Vector4<float>{} <= omath::Vector4<float>{});
|
||||
EXPECT_TRUE(omath::Vector4<float>{} <= omath::Vector4(1.f, 1.f, 1.f, 1.f));
|
||||
}
|
||||
|
||||
TEST_F(UnitTestVector4, GreaterEqualOperator)
|
||||
{
|
||||
EXPECT_TRUE(omath::Vector4<float>{} >= omath::Vector4<float>{});
|
||||
EXPECT_TRUE(omath::Vector4(1.f, 1.f, 1.f, 1.f) >= omath::Vector4<float>{});
|
||||
}
|
||||
Reference in New Issue
Block a user