mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 15:03:27 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 29795e9906 | |||
| 0328fef4f7 | |||
| 687772f073 | |||
| c66df11754 | |||
| 0450dc3547 | |||
| 0bd9eda48f |
@@ -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,7 +26,23 @@ 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>
|
||||
requires CameraEngineConcept<TraitClass, Mat4X4Type, ViewAnglesType>
|
||||
class Camera final
|
||||
{
|
||||
public:
|
||||
@@ -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};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -226,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)};
|
||||
}
|
||||
|
||||
@@ -198,7 +198,6 @@ namespace omath
|
||||
{
|
||||
return {static_cast<Type>(other.x), static_cast<Type>(other.y), static_cast<Type>(other.z)};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
};
|
||||
} // namespace omath
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// Created by Vlad on 8/11/2025.
|
||||
//
|
||||
#include "omath/engines/iw_engine/traits/camera_trait.hpp"
|
||||
|
||||
#include "omath/engines/iw_engine/formulas.hpp"
|
||||
namespace omath::iw_engine
|
||||
{
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// Created by Vlad on 8/11/2025.
|
||||
//
|
||||
#include "omath/engines/opengl_engine/traits/camera_trait.hpp"
|
||||
|
||||
#include "omath/engines/opengl_engine/formulas.hpp"
|
||||
|
||||
namespace omath::opengl_engine
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// Created by Vlad on 8/11/2025.
|
||||
//
|
||||
#include "omath/engines/source_engine/traits/camera_trait.hpp"
|
||||
|
||||
#include "omath/engines/source_engine/formulas.hpp"
|
||||
namespace omath::source_engine
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user