mirror of
https://github.com/orange-cpp/omath.git
synced 2026-04-19 06:03:27 +00:00
Compare commits
25 Commits
v5.1.0.rc4
...
v5.1.0.rc5
| Author | SHA1 | Date | |
|---|---|---|---|
| 927508a76b | |||
| f390b386d7 | |||
| 012d837e8b | |||
| 6236c8fd68 | |||
| 06dc36089f | |||
| 91136a61c4 | |||
| 9cdffcbdb1 | |||
| a3e93ac259 | |||
| 59f6d7a361 | |||
| dcf1ef1ea9 | |||
| 89bd879187 | |||
| aa08c7cb65 | |||
| a5c0ca0cbd | |||
| 624683aed6 | |||
| f46672b2c6 | |||
| b8e61f49fa | |||
| 37ea091282 | |||
| 29a2743728 | |||
| 1117eb37f1 | |||
| b6b0d4db13 | |||
| 2e8a74aaaf | |||
| d8632dc74c | |||
| fd531c930c | |||
| a91673216d | |||
| 6487554844 |
@@ -12,6 +12,7 @@ AlignConsecutiveMacros: AcrossEmptyLinesAndComments
|
|||||||
AlignTrailingComments: false
|
AlignTrailingComments: false
|
||||||
AllowShortBlocksOnASingleLine: Never
|
AllowShortBlocksOnASingleLine: Never
|
||||||
AllowShortFunctionsOnASingleLine: None
|
AllowShortFunctionsOnASingleLine: None
|
||||||
|
AllowShortLambdasOnASingleLine: None
|
||||||
AllowShortIfStatementsOnASingleLine: false
|
AllowShortIfStatementsOnASingleLine: false
|
||||||
AllowShortLoopsOnASingleLine: false
|
AllowShortLoopsOnASingleLine: false
|
||||||
BreakTemplateDeclarations: Leave
|
BreakTemplateDeclarations: Leave
|
||||||
|
|||||||
@@ -138,6 +138,43 @@ namespace imgui_desktop::gui
|
|||||||
ImGui::SliderFloat("Thick##skel", &m_skel_thickness, 0.5f, 5.f);
|
ImGui::SliderFloat("Thick##skel", &m_skel_thickness, 0.5f, 5.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ImGui::CollapsingHeader("Progress Ring"))
|
||||||
|
{
|
||||||
|
ImGui::Checkbox("Show##ring", &m_show_ring);
|
||||||
|
ImGui::ColorEdit4("Color##ring", reinterpret_cast<float*>(&m_ring_color), ImGuiColorEditFlags_NoInputs);
|
||||||
|
ImGui::ColorEdit4("BG##ring", reinterpret_cast<float*>(&m_ring_bg), ImGuiColorEditFlags_NoInputs);
|
||||||
|
ImGui::SliderFloat("Radius##ring", &m_ring_radius, 4.f, 30.f);
|
||||||
|
ImGui::SliderFloat("Value##ring", &m_ring_ratio, 0.f, 1.f);
|
||||||
|
ImGui::SliderFloat("Thick##ring", &m_ring_thickness, 0.5f, 6.f);
|
||||||
|
ImGui::SliderFloat("Offset##ring", &m_ring_offset, 0.f, 15.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ImGui::CollapsingHeader("Scan Marker"))
|
||||||
|
{
|
||||||
|
ImGui::Checkbox("Show##scan", &m_show_scan);
|
||||||
|
ImGui::ColorEdit4("Fill##scan", reinterpret_cast<float*>(&m_scan_color), ImGuiColorEditFlags_NoInputs);
|
||||||
|
ImGui::ColorEdit4("Outline##scan", reinterpret_cast<float*>(&m_scan_outline), ImGuiColorEditFlags_NoInputs);
|
||||||
|
ImGui::SliderFloat("Thick##scan", &m_scan_outline_thickness, 0.5f, 5.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ImGui::CollapsingHeader("Aim Dot"))
|
||||||
|
{
|
||||||
|
ImGui::Checkbox("Show##aim", &m_show_aim);
|
||||||
|
ImGui::ColorEdit4("Color##aim", reinterpret_cast<float*>(&m_aim_color), ImGuiColorEditFlags_NoInputs);
|
||||||
|
ImGui::SliderFloat("Radius##aim", &m_aim_radius, 1.f, 10.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ImGui::CollapsingHeader("Projectile Aim"))
|
||||||
|
{
|
||||||
|
ImGui::Checkbox("Show##proj", &m_show_proj);
|
||||||
|
ImGui::ColorEdit4("Color##proj", reinterpret_cast<float*>(&m_proj_color), ImGuiColorEditFlags_NoInputs);
|
||||||
|
ImGui::SliderFloat("Size##proj", &m_proj_size, 1.f, 30.f);
|
||||||
|
ImGui::SliderFloat("Line width##proj", &m_proj_line_width, 0.5f, 5.f);
|
||||||
|
ImGui::SliderFloat("Pos X##proj", &m_proj_pos_x, 0.f, vp->Size.x);
|
||||||
|
ImGui::SliderFloat("Pos Y##proj", &m_proj_pos_y, 0.f, vp->Size.y);
|
||||||
|
ImGui::Combo("Figure##proj", &m_proj_figure, "Circle\0Square\0");
|
||||||
|
}
|
||||||
|
|
||||||
if (ImGui::CollapsingHeader("Snap Line"))
|
if (ImGui::CollapsingHeader("Snap Line"))
|
||||||
{
|
{
|
||||||
ImGui::Checkbox("Show##snap", &m_show_snap);
|
ImGui::Checkbox("Show##snap", &m_show_snap);
|
||||||
@@ -166,9 +203,7 @@ namespace imgui_desktop::gui
|
|||||||
when(m_show_cornered_box, CorneredBox{omath::Color::from_rgba(255, 0, 255, 255), m_box_fill,
|
when(m_show_cornered_box, CorneredBox{omath::Color::from_rgba(255, 0, 255, 255), m_box_fill,
|
||||||
m_corner_ratio, m_box_thickness}),
|
m_corner_ratio, m_box_thickness}),
|
||||||
when(m_show_dashed_box, DashedBox{m_dash_color, m_dash_len, m_dash_gap, m_dash_thickness}),
|
when(m_show_dashed_box, DashedBox{m_dash_color, m_dash_len, m_dash_gap, m_dash_thickness}),
|
||||||
|
RightSide{
|
||||||
RightSide
|
|
||||||
{
|
|
||||||
when(m_show_right_bar, bar),
|
when(m_show_right_bar, bar),
|
||||||
when(m_show_right_dashed_bar, dbar),
|
when(m_show_right_dashed_bar, dbar),
|
||||||
when(m_show_right_labels,
|
when(m_show_right_labels,
|
||||||
@@ -177,9 +212,12 @@ namespace imgui_desktop::gui
|
|||||||
Label{{1.f, 0.f, 0.f, 1.f}, m_label_offset, m_outlined, "Shield: 125/125"}),
|
Label{{1.f, 0.f, 0.f, 1.f}, m_label_offset, m_outlined, "Shield: 125/125"}),
|
||||||
when(m_show_right_labels,
|
when(m_show_right_labels,
|
||||||
Label{{1.f, 0.f, 1.f, 1.f}, m_label_offset, m_outlined, "*LOCKED*"}),
|
Label{{1.f, 0.f, 1.f, 1.f}, m_label_offset, m_outlined, "*LOCKED*"}),
|
||||||
|
|
||||||
|
SpaceVertical{10},
|
||||||
|
when(m_show_ring, ProgressRing{m_ring_color, m_ring_bg, m_ring_radius, m_ring_ratio,
|
||||||
|
m_ring_thickness, m_ring_offset}),
|
||||||
},
|
},
|
||||||
LeftSide
|
LeftSide{
|
||||||
{
|
|
||||||
when(m_show_left_bar, bar),
|
when(m_show_left_bar, bar),
|
||||||
when(m_show_left_dashed_bar, dbar),
|
when(m_show_left_dashed_bar, dbar),
|
||||||
when(m_show_left_labels, Label{omath::Color::from_rgba(255, 128, 0, 255),
|
when(m_show_left_labels, Label{omath::Color::from_rgba(255, 128, 0, 255),
|
||||||
@@ -187,8 +225,7 @@ namespace imgui_desktop::gui
|
|||||||
when(m_show_left_labels, Label{omath::Color::from_rgba(0, 200, 255, 255),
|
when(m_show_left_labels, Label{omath::Color::from_rgba(0, 200, 255, 255),
|
||||||
m_label_offset, m_outlined, "Level: 42"}),
|
m_label_offset, m_outlined, "Level: 42"}),
|
||||||
},
|
},
|
||||||
TopSide
|
TopSide{
|
||||||
{
|
|
||||||
when(m_show_top_bar, bar),
|
when(m_show_top_bar, bar),
|
||||||
when(m_show_top_dashed_bar, dbar),
|
when(m_show_top_dashed_bar, dbar),
|
||||||
when(m_show_centered_top, Centered{Label{omath::Color::from_rgba(0, 255, 255, 255),
|
when(m_show_centered_top, Centered{Label{omath::Color::from_rgba(0, 255, 255, 255),
|
||||||
@@ -198,8 +235,7 @@ namespace imgui_desktop::gui
|
|||||||
when(m_show_top_labels, Label{omath::Color::from_rgba(255, 0, 0, 255), m_label_offset,
|
when(m_show_top_labels, Label{omath::Color::from_rgba(255, 0, 0, 255), m_label_offset,
|
||||||
m_outlined, "*BLEEDING*"}),
|
m_outlined, "*BLEEDING*"}),
|
||||||
},
|
},
|
||||||
BottomSide
|
BottomSide{
|
||||||
{
|
|
||||||
when(m_show_bottom_bar, bar),
|
when(m_show_bottom_bar, bar),
|
||||||
when(m_show_bottom_dashed_bar, dbar),
|
when(m_show_bottom_dashed_bar, dbar),
|
||||||
when(m_show_centered_bottom, Centered{Label{omath::Color::from_rgba(255, 255, 255, 255),
|
when(m_show_centered_bottom, Centered{Label{omath::Color::from_rgba(255, 255, 255, 255),
|
||||||
@@ -207,7 +243,10 @@ namespace imgui_desktop::gui
|
|||||||
when(m_show_bottom_labels, Label{omath::Color::from_rgba(200, 200, 0, 255),
|
when(m_show_bottom_labels, Label{omath::Color::from_rgba(200, 200, 0, 255),
|
||||||
m_label_offset, m_outlined, "42m"}),
|
m_label_offset, m_outlined, "42m"}),
|
||||||
},
|
},
|
||||||
|
when(m_show_aim, AimDot{{m_entity_x, m_entity_top_y+40.f}, m_aim_color, m_aim_radius}),
|
||||||
|
when(m_show_scan, ScanMarker{m_scan_color, m_scan_outline, m_scan_outline_thickness}),
|
||||||
when(m_show_skeleton, Skeleton{m_skel_color, m_skel_thickness}),
|
when(m_show_skeleton, Skeleton{m_skel_color, m_skel_thickness}),
|
||||||
|
when(m_show_proj, ProjectileAim{{m_proj_pos_x, m_proj_pos_y}, m_proj_color, m_proj_size, m_proj_line_width, static_cast<ProjectileAim::Figure>(m_proj_figure)}),
|
||||||
when(m_show_snap, SnapLine{{vp->Size.x / 2.f, vp->Size.y}, m_snap_color, m_snap_width}));
|
when(m_show_snap, SnapLine{{vp->Size.x / 2.f, vp->Size.y}, m_snap_color, m_snap_width}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,9 +61,34 @@ namespace imgui_desktop::gui
|
|||||||
float m_skel_thickness = 1.f;
|
float m_skel_thickness = 1.f;
|
||||||
bool m_show_skeleton = false;
|
bool m_show_skeleton = false;
|
||||||
|
|
||||||
|
// Progress ring
|
||||||
|
omath::Color m_ring_color = omath::Color::from_rgba(0, 200, 255, 255);
|
||||||
|
omath::Color m_ring_bg{0.3f, 0.3f, 0.3f, 0.5f};
|
||||||
|
float m_ring_radius = 10.f, m_ring_ratio = 0.65f, m_ring_thickness = 2.5f, m_ring_offset = 5.f;
|
||||||
|
bool m_show_ring = false;
|
||||||
|
|
||||||
|
// Scan marker
|
||||||
|
omath::Color m_scan_color = omath::Color::from_rgba(255, 200, 0, 150);
|
||||||
|
omath::Color m_scan_outline = omath::Color::from_rgba(255, 200, 0, 255);
|
||||||
|
float m_scan_outline_thickness = 2.f;
|
||||||
|
bool m_show_scan = false;
|
||||||
|
|
||||||
|
// Aim dot
|
||||||
|
omath::Color m_aim_color = omath::Color::from_rgba(255, 0, 0, 255);
|
||||||
|
float m_aim_radius = 3.f;
|
||||||
|
bool m_show_aim = false;
|
||||||
|
|
||||||
// Snap line
|
// Snap line
|
||||||
omath::Color m_snap_color = omath::Color::from_rgba(255, 50, 50, 255);
|
omath::Color m_snap_color = omath::Color::from_rgba(255, 50, 50, 255);
|
||||||
float m_snap_width = 1.5f;
|
float m_snap_width = 1.5f;
|
||||||
bool m_show_snap = true;
|
bool m_show_snap = true;
|
||||||
|
|
||||||
|
// Projectile aim
|
||||||
|
omath::Color m_proj_color = omath::Color::from_rgba(255, 50, 50, 255);
|
||||||
|
float m_proj_size = 10.f;
|
||||||
|
float m_proj_line_width = 1.5f;
|
||||||
|
float m_proj_pos_x = 300.f, m_proj_pos_y = 30.f;
|
||||||
|
int m_proj_figure = 1; // 0=circle, 1=square
|
||||||
|
bool m_show_proj = true;
|
||||||
};
|
};
|
||||||
} // namespace imgui_desktop::gui
|
} // namespace imgui_desktop::gui
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ namespace omath::cry_engine
|
|||||||
const float pitch, const float yaw,
|
const float pitch, const float yaw,
|
||||||
const float time, const float gravity) noexcept
|
const float time, const float gravity) noexcept
|
||||||
{
|
{
|
||||||
auto current_pos = projectile.m_origin
|
const auto launch_pos = projectile.m_origin + projectile.m_launch_offset;
|
||||||
|
auto current_pos = launch_pos
|
||||||
+ forward_vector({PitchAngle::from_degrees(-pitch), YawAngle::from_degrees(yaw),
|
+ forward_vector({PitchAngle::from_degrees(-pitch), YawAngle::from_degrees(yaw),
|
||||||
RollAngle::from_degrees(0)})
|
RollAngle::from_degrees(0)})
|
||||||
* projectile.m_launch_speed * time;
|
* projectile.m_launch_speed * time;
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ namespace omath::frostbite_engine
|
|||||||
const float pitch, const float yaw,
|
const float pitch, const float yaw,
|
||||||
const float time, const float gravity) noexcept
|
const float time, const float gravity) noexcept
|
||||||
{
|
{
|
||||||
auto current_pos = projectile.m_origin
|
const auto launch_pos = projectile.m_origin + projectile.m_launch_offset;
|
||||||
|
auto current_pos = launch_pos
|
||||||
+ forward_vector({PitchAngle::from_degrees(-pitch), YawAngle::from_degrees(yaw),
|
+ forward_vector({PitchAngle::from_degrees(-pitch), YawAngle::from_degrees(yaw),
|
||||||
RollAngle::from_degrees(0)})
|
RollAngle::from_degrees(0)})
|
||||||
* projectile.m_launch_speed * time;
|
* projectile.m_launch_speed * time;
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ namespace omath::iw_engine
|
|||||||
const float pitch, const float yaw,
|
const float pitch, const float yaw,
|
||||||
const float time, const float gravity) noexcept
|
const float time, const float gravity) noexcept
|
||||||
{
|
{
|
||||||
auto current_pos = projectile.m_origin
|
const auto launch_pos = projectile.m_origin + projectile.m_launch_offset;
|
||||||
|
auto current_pos = launch_pos
|
||||||
+ forward_vector({PitchAngle::from_degrees(-pitch), YawAngle::from_degrees(yaw),
|
+ forward_vector({PitchAngle::from_degrees(-pitch), YawAngle::from_degrees(yaw),
|
||||||
RollAngle::from_degrees(0)})
|
RollAngle::from_degrees(0)})
|
||||||
* projectile.m_launch_speed * time;
|
* projectile.m_launch_speed * time;
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ namespace omath::opengl_engine
|
|||||||
const float pitch, const float yaw,
|
const float pitch, const float yaw,
|
||||||
const float time, const float gravity) noexcept
|
const float time, const float gravity) noexcept
|
||||||
{
|
{
|
||||||
auto current_pos = projectile.m_origin
|
const auto launch_pos = projectile.m_origin + projectile.m_launch_offset;
|
||||||
|
auto current_pos = launch_pos
|
||||||
+ forward_vector({PitchAngle::from_degrees(-pitch), YawAngle::from_degrees(yaw),
|
+ forward_vector({PitchAngle::from_degrees(-pitch), YawAngle::from_degrees(yaw),
|
||||||
RollAngle::from_degrees(0)})
|
RollAngle::from_degrees(0)})
|
||||||
* projectile.m_launch_speed * time;
|
* projectile.m_launch_speed * time;
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ namespace omath::source_engine
|
|||||||
const float pitch, const float yaw,
|
const float pitch, const float yaw,
|
||||||
const float time, const float gravity) noexcept
|
const float time, const float gravity) noexcept
|
||||||
{
|
{
|
||||||
auto current_pos = projectile.m_origin
|
const auto launch_pos = projectile.m_origin + projectile.m_launch_offset;
|
||||||
|
auto current_pos = launch_pos
|
||||||
+ forward_vector({PitchAngle::from_degrees(-pitch), YawAngle::from_degrees(yaw),
|
+ forward_vector({PitchAngle::from_degrees(-pitch), YawAngle::from_degrees(yaw),
|
||||||
RollAngle::from_degrees(0)})
|
RollAngle::from_degrees(0)})
|
||||||
* projectile.m_launch_speed * time;
|
* projectile.m_launch_speed * time;
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ namespace omath::unity_engine
|
|||||||
const float pitch, const float yaw,
|
const float pitch, const float yaw,
|
||||||
const float time, const float gravity) noexcept
|
const float time, const float gravity) noexcept
|
||||||
{
|
{
|
||||||
auto current_pos = projectile.m_origin
|
const auto launch_pos = projectile.m_origin + projectile.m_launch_offset;
|
||||||
|
auto current_pos = launch_pos
|
||||||
+ forward_vector({PitchAngle::from_degrees(-pitch), YawAngle::from_degrees(yaw),
|
+ forward_vector({PitchAngle::from_degrees(-pitch), YawAngle::from_degrees(yaw),
|
||||||
RollAngle::from_degrees(0)})
|
RollAngle::from_degrees(0)})
|
||||||
* projectile.m_launch_speed * time;
|
* projectile.m_launch_speed * time;
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ namespace omath::unreal_engine
|
|||||||
const float pitch, const float yaw,
|
const float pitch, const float yaw,
|
||||||
const float time, const float gravity) noexcept
|
const float time, const float gravity) noexcept
|
||||||
{
|
{
|
||||||
auto current_pos = projectile.m_origin
|
const auto launch_pos = projectile.m_origin + projectile.m_launch_offset;
|
||||||
|
auto current_pos = launch_pos
|
||||||
+ forward_vector({PitchAngle::from_degrees(-pitch), YawAngle::from_degrees(yaw),
|
+ forward_vector({PitchAngle::from_degrees(-pitch), YawAngle::from_degrees(yaw),
|
||||||
RollAngle::from_degrees(0)})
|
RollAngle::from_degrees(0)})
|
||||||
* projectile.m_launch_speed * time;
|
* projectile.m_launch_speed * time;
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ namespace omath::hud
|
|||||||
const std::string_view& text);
|
const std::string_view& text);
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
EntityOverlay& add_right_label(const Color& color, float offset, bool outlined, std::format_string<Args...> fmt,
|
EntityOverlay& add_right_label(const Color& color, const float offset, const bool outlined, std::format_string<Args...> fmt,
|
||||||
Args&&... args)
|
Args&&... args)
|
||||||
{
|
{
|
||||||
return add_right_label(color, offset, outlined,
|
return add_right_label(color, offset, outlined,
|
||||||
@@ -79,7 +79,7 @@ namespace omath::hud
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
EntityOverlay& add_left_label(const Color& color, float offset, bool outlined, std::format_string<Args...> fmt,
|
EntityOverlay& add_left_label(const Color& color, const float offset, const bool outlined, std::format_string<Args...> fmt,
|
||||||
Args&&... args)
|
Args&&... args)
|
||||||
{
|
{
|
||||||
return add_left_label(color, offset, outlined,
|
return add_left_label(color, offset, outlined,
|
||||||
@@ -87,7 +87,7 @@ namespace omath::hud
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
EntityOverlay& add_top_label(const Color& color, float offset, bool outlined, std::format_string<Args...> fmt,
|
EntityOverlay& add_top_label(const Color& color, const float offset, const bool outlined, std::format_string<Args...> fmt,
|
||||||
Args&&... args)
|
Args&&... args)
|
||||||
{
|
{
|
||||||
return add_top_label(color, offset, outlined,
|
return add_top_label(color, offset, outlined,
|
||||||
@@ -95,7 +95,7 @@ namespace omath::hud
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
EntityOverlay& add_bottom_label(const Color& color, float offset, bool outlined,
|
EntityOverlay& add_bottom_label(const Color& color, const float offset, const bool outlined,
|
||||||
std::format_string<Args...> fmt, Args&&... args)
|
std::format_string<Args...> fmt, Args&&... args)
|
||||||
{
|
{
|
||||||
return add_bottom_label(color, offset, outlined,
|
return add_bottom_label(color, offset, outlined,
|
||||||
@@ -103,7 +103,7 @@ namespace omath::hud
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
EntityOverlay& add_centered_top_label(const Color& color, float offset, bool outlined,
|
EntityOverlay& add_centered_top_label(const Color& color, const float offset, const bool outlined,
|
||||||
std::format_string<Args...> fmt, Args&&... args)
|
std::format_string<Args...> fmt, Args&&... args)
|
||||||
{
|
{
|
||||||
return add_centered_top_label(color, offset, outlined,
|
return add_centered_top_label(color, offset, outlined,
|
||||||
@@ -111,13 +111,43 @@ namespace omath::hud
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
EntityOverlay& add_centered_bottom_label(const Color& color, float offset, bool outlined,
|
EntityOverlay& add_centered_bottom_label(const Color& color, const float offset, const bool outlined,
|
||||||
std::format_string<Args...> fmt, Args&&... args)
|
std::format_string<Args...> fmt, Args&&... args)
|
||||||
{
|
{
|
||||||
return add_centered_bottom_label(color, offset, outlined,
|
return add_centered_bottom_label(color, offset, outlined,
|
||||||
std::string_view{std::vformat(fmt.get(), std::make_format_args(args...))});
|
std::string_view{std::vformat(fmt.get(), std::make_format_args(args...))});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Spacers ─────────────────────────────────────────────────────
|
||||||
|
EntityOverlay& add_right_space_vertical(float size);
|
||||||
|
EntityOverlay& add_right_space_horizontal(float size);
|
||||||
|
EntityOverlay& add_left_space_vertical(float size);
|
||||||
|
EntityOverlay& add_left_space_horizontal(float size);
|
||||||
|
EntityOverlay& add_top_space_vertical(float size);
|
||||||
|
EntityOverlay& add_top_space_horizontal(float size);
|
||||||
|
EntityOverlay& add_bottom_space_vertical(float size);
|
||||||
|
EntityOverlay& add_bottom_space_horizontal(float size);
|
||||||
|
|
||||||
|
// ── Progress rings ──────────────────────────────────────────────
|
||||||
|
EntityOverlay& add_right_progress_ring(const Color& color, const Color& bg, float radius, float ratio,
|
||||||
|
float thickness = 2.f, float offset = 5.f, int segments = 0);
|
||||||
|
EntityOverlay& add_left_progress_ring(const Color& color, const Color& bg, float radius, float ratio,
|
||||||
|
float thickness = 2.f, float offset = 5.f, int segments = 0);
|
||||||
|
EntityOverlay& add_top_progress_ring(const Color& color, const Color& bg, float radius, float ratio,
|
||||||
|
float thickness = 2.f, float offset = 5.f, int segments = 0);
|
||||||
|
EntityOverlay& add_bottom_progress_ring(const Color& color, const Color& bg, float radius, float ratio,
|
||||||
|
float thickness = 2.f, float offset = 5.f, int segments = 0);
|
||||||
|
|
||||||
|
// ── Icons ────────────────────────────────────────────────────────
|
||||||
|
EntityOverlay& add_right_icon(const std::any& texture_id, float width, float height,
|
||||||
|
const Color& tint = Color{1.f, 1.f, 1.f, 1.f}, float offset = 5.f);
|
||||||
|
EntityOverlay& add_left_icon(const std::any& texture_id, float width, float height,
|
||||||
|
const Color& tint = Color{1.f, 1.f, 1.f, 1.f}, float offset = 5.f);
|
||||||
|
EntityOverlay& add_top_icon(const std::any& texture_id, float width, float height,
|
||||||
|
const Color& tint = Color{1.f, 1.f, 1.f, 1.f}, float offset = 5.f);
|
||||||
|
EntityOverlay& add_bottom_icon(const std::any& texture_id, float width, float height,
|
||||||
|
const Color& tint = Color{1.f, 1.f, 1.f, 1.f}, float offset = 5.f);
|
||||||
|
|
||||||
// ── Misc ─────────────────────────────────────────────────────────
|
// ── Misc ─────────────────────────────────────────────────────────
|
||||||
EntityOverlay& add_snap_line(const Vector2<float>& start_pos, const Color& color, float width);
|
EntityOverlay& add_snap_line(const Vector2<float>& start_pos, const Color& color, float width);
|
||||||
|
|
||||||
@@ -142,15 +172,19 @@ namespace omath::hud
|
|||||||
dispatch(*w);
|
dispatch(*w);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dispatch(const widget::Box& w);
|
void dispatch(const widget::Box& box);
|
||||||
void dispatch(const widget::CorneredBox& w);
|
void dispatch(const widget::CorneredBox& cornered_box);
|
||||||
void dispatch(const widget::DashedBox& w);
|
void dispatch(const widget::DashedBox& dashed_box);
|
||||||
void dispatch(const widget::RightSide& w);
|
void dispatch(const widget::RightSide& right_side);
|
||||||
void dispatch(const widget::LeftSide& w);
|
void dispatch(const widget::LeftSide& left_side);
|
||||||
void dispatch(const widget::TopSide& w);
|
void dispatch(const widget::TopSide& top_side);
|
||||||
void dispatch(const widget::BottomSide& w);
|
void dispatch(const widget::BottomSide& bottom_side);
|
||||||
void dispatch(const widget::Skeleton& w);
|
void dispatch(const widget::Skeleton& skeleton);
|
||||||
void dispatch(const widget::SnapLine& w);
|
void dispatch(const widget::SnapLine& snap_line);
|
||||||
|
void dispatch(const widget::ScanMarker& scan_marker);
|
||||||
|
void dispatch(const widget::AimDot& aim_dot);
|
||||||
|
void dispatch(const widget::ProjectileAim& proj_widget);
|
||||||
|
void draw_progress_ring(const Vector2<float>& center, const widget::ProgressRing& ring);
|
||||||
void draw_outlined_text(const Vector2<float>& position, const Color& color, const std::string_view& text);
|
void draw_outlined_text(const Vector2<float>& position, const Color& color, const std::string_view& text);
|
||||||
void draw_dashed_line(const Vector2<float>& from, const Vector2<float>& to, const Color& color, float dash_len,
|
void draw_dashed_line(const Vector2<float>& from, const Vector2<float>& to, const Color& color, float dash_len,
|
||||||
float gap_len, float thickness) const;
|
float gap_len, float thickness) const;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "omath/linear_algebra/vector2.hpp"
|
#include "omath/linear_algebra/vector2.hpp"
|
||||||
#include "omath/utility/color.hpp"
|
#include "omath/utility/color.hpp"
|
||||||
|
#include <any>
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
@@ -56,6 +57,35 @@ namespace omath::hud::widget
|
|||||||
float width;
|
float width;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ScanMarker
|
||||||
|
{
|
||||||
|
Color color;
|
||||||
|
Color outline{0.f, 0.f, 0.f, 0.f};
|
||||||
|
float outline_thickness = 1.f;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Dot at an absolute screen position.
|
||||||
|
struct AimDot
|
||||||
|
{
|
||||||
|
Vector2<float> position;
|
||||||
|
Color color;
|
||||||
|
float radius = 3.f;
|
||||||
|
};
|
||||||
|
struct ProjectileAim
|
||||||
|
{
|
||||||
|
enum class Figure
|
||||||
|
{
|
||||||
|
CIRCLE,
|
||||||
|
SQUARE,
|
||||||
|
};
|
||||||
|
Vector2<float> position;
|
||||||
|
Color color;
|
||||||
|
float size = 3.f;
|
||||||
|
float line_size = 1.f;
|
||||||
|
Figure figure = Figure::SQUARE;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// ── Side-agnostic widgets (used inside XxxSide containers) ────────────────
|
// ── Side-agnostic widgets (used inside XxxSide containers) ────────────────
|
||||||
|
|
||||||
/// A filled bar. `size` is width for left/right sides, height for top/bottom.
|
/// A filled bar. `size` is width for left/right sides, height for top/bottom.
|
||||||
@@ -84,9 +114,9 @@ namespace omath::hud::widget
|
|||||||
|
|
||||||
struct Label
|
struct Label
|
||||||
{
|
{
|
||||||
Color color;
|
Color color;
|
||||||
float offset;
|
float offset;
|
||||||
bool outlined;
|
bool outlined;
|
||||||
std::string_view text;
|
std::string_view text;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -99,9 +129,44 @@ namespace omath::hud::widget
|
|||||||
template<typename W>
|
template<typename W>
|
||||||
Centered(W) -> Centered<W>;
|
Centered(W) -> Centered<W>;
|
||||||
|
|
||||||
|
/// Empty vertical gap that advances the Y cursor without drawing.
|
||||||
|
struct SpaceVertical
|
||||||
|
{
|
||||||
|
float size;
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Empty horizontal gap that advances the X cursor without drawing.
|
||||||
|
struct SpaceHorizontal
|
||||||
|
{
|
||||||
|
float size;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ProgressRing
|
||||||
|
{
|
||||||
|
Color color;
|
||||||
|
Color bg{0.3f, 0.3f, 0.3f, 0.5f};
|
||||||
|
float radius = 12.f;
|
||||||
|
float ratio;
|
||||||
|
float thickness = 2.f;
|
||||||
|
float offset = 5.f;
|
||||||
|
int segments = 32;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Icon
|
||||||
|
{
|
||||||
|
std::any texture_id;
|
||||||
|
float width;
|
||||||
|
float height;
|
||||||
|
Color tint{1.f, 1.f, 1.f, 1.f};
|
||||||
|
float offset = 5.f;
|
||||||
|
};
|
||||||
|
|
||||||
// ── Side widget variant ───────────────────────────────────────────────────
|
// ── Side widget variant ───────────────────────────────────────────────────
|
||||||
struct None {}; ///< No-op placeholder — used by widget::when for disabled elements.
|
struct None
|
||||||
using SideWidget = std::variant<None, Bar, DashedBar, Label, Centered<Label>>;
|
{
|
||||||
|
}; ///< No-op placeholder — used by widget::when for disabled elements.
|
||||||
|
using SideWidget =
|
||||||
|
std::variant<None, Bar, DashedBar, Label, Centered<Label>, SpaceVertical, SpaceHorizontal, ProgressRing, Icon>;
|
||||||
|
|
||||||
// ── Side containers ───────────────────────────────────────────────────────
|
// ── Side containers ───────────────────────────────────────────────────────
|
||||||
// Storing std::initializer_list<SideWidget> is safe here: the backing array
|
// Storing std::initializer_list<SideWidget> is safe here: the backing array
|
||||||
@@ -109,10 +174,34 @@ namespace omath::hud::widget
|
|||||||
// temporary side-container object, which is consumed within the same
|
// temporary side-container object, which is consumed within the same
|
||||||
// full-expression by EntityOverlay::dispatch. No heap allocation occurs.
|
// full-expression by EntityOverlay::dispatch. No heap allocation occurs.
|
||||||
|
|
||||||
struct RightSide { std::initializer_list<SideWidget> children; RightSide(std::initializer_list<SideWidget> c) : children(c) {} };
|
struct RightSide
|
||||||
struct LeftSide { std::initializer_list<SideWidget> children; LeftSide(std::initializer_list<SideWidget> c) : children(c) {} };
|
{
|
||||||
struct TopSide { std::initializer_list<SideWidget> children; TopSide(std::initializer_list<SideWidget> c) : children(c) {} };
|
std::initializer_list<SideWidget> children;
|
||||||
struct BottomSide { std::initializer_list<SideWidget> children; BottomSide(std::initializer_list<SideWidget> c) : children(c) {} };
|
RightSide(const std::initializer_list<SideWidget> c): children(c)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
struct LeftSide
|
||||||
|
{
|
||||||
|
std::initializer_list<SideWidget> children;
|
||||||
|
LeftSide(const std::initializer_list<SideWidget> c): children(c)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
struct TopSide
|
||||||
|
{
|
||||||
|
std::initializer_list<SideWidget> children;
|
||||||
|
TopSide(const std::initializer_list<SideWidget> c): children(c)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
struct BottomSide
|
||||||
|
{
|
||||||
|
std::initializer_list<SideWidget> children;
|
||||||
|
BottomSide(const std::initializer_list<SideWidget> c): children(c)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace omath::hud::widget
|
} // namespace omath::hud::widget
|
||||||
|
|
||||||
@@ -121,10 +210,11 @@ namespace omath::hud::widget
|
|||||||
/// Inside XxxSide containers: returns the widget as a SideWidget when condition is true,
|
/// Inside XxxSide containers: returns the widget as a SideWidget when condition is true,
|
||||||
/// or None{} otherwise. Preferred over hud::when for types inside the SideWidget variant.
|
/// or None{} otherwise. Preferred over hud::when for types inside the SideWidget variant.
|
||||||
template<typename W>
|
template<typename W>
|
||||||
requires std::constructible_from<SideWidget, W>
|
requires std::constructible_from<SideWidget, W>
|
||||||
SideWidget when(const bool condition, W widget)
|
SideWidget when(const bool condition, W widget)
|
||||||
{
|
{
|
||||||
if (condition) return SideWidget{std::move(widget)};
|
if (condition)
|
||||||
|
return SideWidget{std::move(widget)};
|
||||||
return None{};
|
return None{};
|
||||||
}
|
}
|
||||||
} // namespace omath::hud::widget
|
} // namespace omath::hud::widget
|
||||||
@@ -136,7 +226,8 @@ namespace omath::hud
|
|||||||
template<typename W>
|
template<typename W>
|
||||||
std::optional<W> when(const bool condition, W widget)
|
std::optional<W> when(const bool condition, W widget)
|
||||||
{
|
{
|
||||||
if (condition) return std::move(widget);
|
if (condition)
|
||||||
|
return std::move(widget);
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
} // namespace omath::hud
|
} // namespace omath::hud
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "omath/linear_algebra/vector2.hpp"
|
#include "omath/linear_algebra/vector2.hpp"
|
||||||
#include "omath/utility/color.hpp"
|
#include "omath/utility/color.hpp"
|
||||||
|
#include <any>
|
||||||
#include <span>
|
#include <span>
|
||||||
|
|
||||||
namespace omath::hud
|
namespace omath::hud
|
||||||
@@ -24,6 +25,20 @@ namespace omath::hud
|
|||||||
|
|
||||||
virtual void add_filled_rectangle(const Vector2<float>& min, const Vector2<float>& max, const Color& color) = 0;
|
virtual void add_filled_rectangle(const Vector2<float>& min, const Vector2<float>& max, const Color& color) = 0;
|
||||||
|
|
||||||
|
virtual void add_circle(const Vector2<float>& center, float radius, const Color& color, float thickness,
|
||||||
|
int segments = 0) = 0;
|
||||||
|
|
||||||
|
virtual void add_filled_circle(const Vector2<float>& center, float radius, const Color& color,
|
||||||
|
int segments = 0) = 0;
|
||||||
|
|
||||||
|
/// Draw an arc (partial circle outline). Angles in radians, 0 = right (+X), counter-clockwise.
|
||||||
|
virtual void add_arc(const Vector2<float>& center, float radius, float a_min, float a_max, const Color& color,
|
||||||
|
float thickness, int segments = 0) = 0;
|
||||||
|
|
||||||
|
/// Draw a textured quad. texture_id is renderer-specific (e.g. ImTextureID for ImGui).
|
||||||
|
virtual void add_image(const std::any& texture_id, const Vector2<float>& min, const Vector2<float>& max,
|
||||||
|
const Color& tint = Color{1.f, 1.f, 1.f, 1.f}) = 0;
|
||||||
|
|
||||||
virtual void add_text(const Vector2<float>& position, const Color& color, const std::string_view& text) = 0;
|
virtual void add_text(const Vector2<float>& position, const Color& color, const std::string_view& text) = 0;
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
|
|||||||
@@ -17,6 +17,14 @@ namespace omath::hud
|
|||||||
void add_filled_polyline(const std::span<const Vector2<float>>& vertexes, const Color& color) override;
|
void add_filled_polyline(const std::span<const Vector2<float>>& vertexes, const Color& color) override;
|
||||||
void add_rectangle(const Vector2<float>& min, const Vector2<float>& max, const Color& color) override;
|
void add_rectangle(const Vector2<float>& min, const Vector2<float>& max, const Color& color) override;
|
||||||
void add_filled_rectangle(const Vector2<float>& min, const Vector2<float>& max, const Color& color) override;
|
void add_filled_rectangle(const Vector2<float>& min, const Vector2<float>& max, const Color& color) override;
|
||||||
|
void add_circle(const Vector2<float>& center, float radius, const Color& color, float thickness,
|
||||||
|
int segments = 0) override;
|
||||||
|
void add_filled_circle(const Vector2<float>& center, float radius, const Color& color,
|
||||||
|
int segments = 0) override;
|
||||||
|
void add_arc(const Vector2<float>& center, float radius, float a_min, float a_max, const Color& color,
|
||||||
|
float thickness, int segments = 0) override;
|
||||||
|
void add_image(const std::any& texture_id, const Vector2<float>& min, const Vector2<float>& max,
|
||||||
|
const Color& tint = Color{1.f, 1.f, 1.f, 1.f}) override;
|
||||||
void add_text(const Vector2<float>& position, const Color& color, const std::string_view& text) override;
|
void add_text(const Vector2<float>& position, const Color& color, const std::string_view& text) override;
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
virtual Vector2<float> calc_text_size(const std::string_view& text) override;
|
virtual Vector2<float> calc_text_size(const std::string_view& text) override;
|
||||||
|
|||||||
@@ -8,12 +8,23 @@
|
|||||||
|
|
||||||
namespace omath::projectile_prediction
|
namespace omath::projectile_prediction
|
||||||
{
|
{
|
||||||
|
struct AimAngles
|
||||||
|
{
|
||||||
|
float pitch{};
|
||||||
|
float yaw{};
|
||||||
|
};
|
||||||
|
|
||||||
class ProjPredEngineInterface
|
class ProjPredEngineInterface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
virtual std::optional<Vector3<float>> maybe_calculate_aim_point(const Projectile& projectile,
|
virtual std::optional<Vector3<float>> maybe_calculate_aim_point(const Projectile& projectile,
|
||||||
const Target& target) const = 0;
|
const Target& target) const = 0;
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
virtual std::optional<AimAngles> maybe_calculate_aim_angles(const Projectile& projectile,
|
||||||
|
const Target& target) const = 0;
|
||||||
|
|
||||||
virtual ~ProjPredEngineInterface() = default;
|
virtual ~ProjPredEngineInterface() = default;
|
||||||
};
|
};
|
||||||
} // namespace omath::projectile_prediction
|
} // namespace omath::projectile_prediction
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ namespace omath::projectile_prediction
|
|||||||
[[nodiscard]] std::optional<Vector3<float>>
|
[[nodiscard]] std::optional<Vector3<float>>
|
||||||
maybe_calculate_aim_point(const Projectile& projectile, const Target& target) const override;
|
maybe_calculate_aim_point(const Projectile& projectile, const Target& target) const override;
|
||||||
|
|
||||||
|
[[nodiscard]] std::optional<AimAngles>
|
||||||
|
maybe_calculate_aim_angles(const Projectile& projectile, const Target& target) const override;
|
||||||
|
|
||||||
ProjPredEngineAvx2(float gravity_constant, float simulation_time_step, float maximum_simulation_time);
|
ProjPredEngineAvx2(float gravity_constant, float simulation_time_step, float maximum_simulation_time);
|
||||||
~ProjPredEngineAvx2() override = default;
|
~ProjPredEngineAvx2() override = default;
|
||||||
|
|
||||||
|
|||||||
@@ -54,6 +54,36 @@ namespace omath::projectile_prediction
|
|||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
std::optional<Vector3<float>> maybe_calculate_aim_point(const Projectile& projectile,
|
std::optional<Vector3<float>> maybe_calculate_aim_point(const Projectile& projectile,
|
||||||
const Target& target) const override
|
const Target& target) const override
|
||||||
|
{
|
||||||
|
const auto solution = find_solution(projectile, target);
|
||||||
|
if (!solution)
|
||||||
|
return std::nullopt;
|
||||||
|
|
||||||
|
return EngineTrait::calc_viewpoint_from_angles(projectile, solution->predicted_target_position,
|
||||||
|
solution->pitch);
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
std::optional<AimAngles> maybe_calculate_aim_angles(const Projectile& projectile,
|
||||||
|
const Target& target) const override
|
||||||
|
{
|
||||||
|
const auto solution = find_solution(projectile, target);
|
||||||
|
if (!solution)
|
||||||
|
return std::nullopt;
|
||||||
|
|
||||||
|
const auto yaw = EngineTrait::calc_direct_yaw_angle(projectile.m_origin + projectile.m_launch_offset, solution->predicted_target_position);
|
||||||
|
return AimAngles{solution->pitch, yaw};
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct Solution
|
||||||
|
{
|
||||||
|
Vector3<float> predicted_target_position;
|
||||||
|
float pitch;
|
||||||
|
};
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
std::optional<Solution> find_solution(const Projectile& projectile, const Target& target) const
|
||||||
{
|
{
|
||||||
for (float time = 0.f; time < m_maximum_simulation_time; time += m_simulation_time_step)
|
for (float time = 0.f; time < m_maximum_simulation_time; time += m_simulation_time_step)
|
||||||
{
|
{
|
||||||
@@ -70,12 +100,11 @@ namespace omath::projectile_prediction
|
|||||||
time))
|
time))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
return EngineTrait::calc_viewpoint_from_angles(projectile, predicted_target_position, projectile_pitch);
|
return Solution{predicted_target_position, projectile_pitch.value()};
|
||||||
}
|
}
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
const float m_gravity_constant;
|
const float m_gravity_constant;
|
||||||
const float m_simulation_time_step;
|
const float m_simulation_time_step;
|
||||||
const float m_maximum_simulation_time;
|
const float m_maximum_simulation_time;
|
||||||
@@ -100,10 +129,12 @@ namespace omath::projectile_prediction
|
|||||||
{
|
{
|
||||||
const auto bullet_gravity = m_gravity_constant * projectile.m_gravity_scale;
|
const auto bullet_gravity = m_gravity_constant * projectile.m_gravity_scale;
|
||||||
|
|
||||||
if (bullet_gravity == 0.f)
|
const auto launch_origin = projectile.m_origin + projectile.m_launch_offset;
|
||||||
return EngineTrait::calc_direct_pitch_angle(projectile.m_origin, target_position);
|
|
||||||
|
|
||||||
const auto delta = target_position - projectile.m_origin;
|
if (bullet_gravity == 0.f)
|
||||||
|
return EngineTrait::calc_direct_pitch_angle(launch_origin, target_position);
|
||||||
|
|
||||||
|
const auto delta = target_position - launch_origin;
|
||||||
|
|
||||||
const auto distance2d = EngineTrait::calc_vector_2d_distance(delta);
|
const auto distance2d = EngineTrait::calc_vector_2d_distance(delta);
|
||||||
const auto distance2d_sqr = distance2d * distance2d;
|
const auto distance2d_sqr = distance2d * distance2d;
|
||||||
@@ -126,7 +157,7 @@ namespace omath::projectile_prediction
|
|||||||
bool is_projectile_reached_target(const Vector3<float>& target_position, const Projectile& projectile,
|
bool is_projectile_reached_target(const Vector3<float>& target_position, const Projectile& projectile,
|
||||||
const float pitch, const float time) const noexcept
|
const float pitch, const float time) const noexcept
|
||||||
{
|
{
|
||||||
const auto yaw = EngineTrait::calc_direct_yaw_angle(projectile.m_origin, target_position);
|
const auto yaw = EngineTrait::calc_direct_yaw_angle(projectile.m_origin + projectile.m_launch_offset, target_position);
|
||||||
const auto projectile_position =
|
const auto projectile_position =
|
||||||
EngineTrait::predict_projectile_position(projectile, pitch, yaw, time, m_gravity_constant);
|
EngineTrait::predict_projectile_position(projectile, pitch, yaw, time, m_gravity_constant);
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ namespace omath::projectile_prediction
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Vector3<float> m_origin;
|
Vector3<float> m_origin;
|
||||||
|
Vector3<float> m_launch_offset{0.f, 0.f, 0.f};
|
||||||
float m_launch_speed{};
|
float m_launch_speed{};
|
||||||
float m_gravity_scale{};
|
float m_gravity_scale{};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,11 +3,43 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include <cassert>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include "omath/utility/pe_pattern_scan.hpp"
|
||||||
|
#include <windows.h>
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
#include "omath/utility/macho_pattern_scan.hpp"
|
||||||
|
#include <mach-o/dyld.h>
|
||||||
|
#else
|
||||||
|
#include "omath/utility/elf_pattern_scan.hpp"
|
||||||
|
#include <link.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace omath::rev_eng
|
namespace omath::rev_eng
|
||||||
{
|
{
|
||||||
|
template<std::size_t N>
|
||||||
|
struct FixedString final
|
||||||
|
{
|
||||||
|
char data[N]{};
|
||||||
|
// ReSharper disable once CppNonExplicitConvertingConstructor
|
||||||
|
constexpr FixedString(const char (&str)[N]) noexcept // NOLINT(*-explicit-constructor)
|
||||||
|
{
|
||||||
|
for (std::size_t i = 0; i < N; ++i)
|
||||||
|
data[i] = str[i];
|
||||||
|
}
|
||||||
|
// ReSharper disable once CppNonExplicitConversionOperator
|
||||||
|
constexpr operator std::string_view() const noexcept // NOLINT(*-explicit-constructor)
|
||||||
|
{
|
||||||
|
return {data, N - 1};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
template<std::size_t N>
|
||||||
|
FixedString(const char (&)[N]) -> FixedString<N>;
|
||||||
|
|
||||||
class InternalReverseEngineeredObject
|
class InternalReverseEngineeredObject
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
@@ -23,26 +55,123 @@ namespace omath::rev_eng
|
|||||||
return *reinterpret_cast<Type*>(reinterpret_cast<std::uintptr_t>(this) + offset);
|
return *reinterpret_cast<Type*>(reinterpret_cast<std::uintptr_t>(this) + offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<std::size_t id, class ReturnType>
|
template<class ReturnType>
|
||||||
|
ReturnType call_method(const void* ptr, auto... arg_list)
|
||||||
|
{
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
using MethodType = ReturnType(__thiscall*)(void*, decltype(arg_list)...);
|
||||||
|
#else
|
||||||
|
using MethodType = ReturnType (*)(void*, decltype(arg_list)...);
|
||||||
|
#endif
|
||||||
|
return reinterpret_cast<MethodType>(const_cast<void*>(ptr))(this, arg_list...);
|
||||||
|
}
|
||||||
|
template<class ReturnType>
|
||||||
|
ReturnType call_method(const void* ptr, auto... arg_list) const
|
||||||
|
{
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
using MethodType = ReturnType(__thiscall*)(const void*, decltype(arg_list)...);
|
||||||
|
#else
|
||||||
|
using MethodType = ReturnType (*)(const void*, decltype(arg_list)...);
|
||||||
|
#endif
|
||||||
|
return reinterpret_cast<MethodType>(const_cast<void*>(ptr))(this, arg_list...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<FixedString ModuleName, FixedString Pattern, class ReturnType>
|
||||||
|
ReturnType call_method(auto... arg_list)
|
||||||
|
{
|
||||||
|
static const auto* address = resolve_pattern(ModuleName, Pattern);
|
||||||
|
return call_method<ReturnType>(address, arg_list...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<FixedString ModuleName, FixedString Pattern, class ReturnType>
|
||||||
|
ReturnType call_method(auto... arg_list) const
|
||||||
|
{
|
||||||
|
static const auto* address = resolve_pattern(ModuleName, Pattern);
|
||||||
|
return call_method<ReturnType>(address, arg_list...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class ReturnType>
|
||||||
|
ReturnType call_method(const std::string_view& module_name,const std::string_view& pattern, auto... arg_list)
|
||||||
|
{
|
||||||
|
static const auto* address = resolve_pattern(module_name, pattern);
|
||||||
|
return call_method<ReturnType>(address, arg_list...);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class ReturnType>
|
||||||
|
ReturnType call_method(const std::string_view& module_name,const std::string_view& pattern, auto... arg_list) const
|
||||||
|
{
|
||||||
|
static const auto* address = resolve_pattern(module_name, pattern);
|
||||||
|
return call_method<ReturnType>(address, arg_list...);
|
||||||
|
}
|
||||||
|
template<std::size_t Id, class ReturnType>
|
||||||
ReturnType call_virtual_method(auto... arg_list)
|
ReturnType call_virtual_method(auto... arg_list)
|
||||||
{
|
{
|
||||||
#ifdef _MSC_VER
|
const auto vtable = *reinterpret_cast<void***>(this);
|
||||||
using VirtualMethodType = ReturnType(__thiscall*)(void*, decltype(arg_list)...);
|
return call_method<ReturnType>(vtable[Id], arg_list...);
|
||||||
#else
|
|
||||||
using VirtualMethodType = ReturnType (*)(void*, decltype(arg_list)...);
|
|
||||||
#endif
|
|
||||||
return (*reinterpret_cast<VirtualMethodType**>(this))[id](this, arg_list...);
|
|
||||||
}
|
}
|
||||||
template<std::size_t id, class ReturnType>
|
template<std::size_t Id, class ReturnType>
|
||||||
ReturnType call_virtual_method(auto... arg_list) const
|
ReturnType call_virtual_method(auto... arg_list) const
|
||||||
{
|
{
|
||||||
#ifdef _MSC_VER
|
const auto vtable = *reinterpret_cast<void* const* const*>(this);
|
||||||
using VirtualMethodType = ReturnType(__thiscall*)(void*, decltype(arg_list)...);
|
return call_method<ReturnType>(vtable[Id], arg_list...);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
[[nodiscard]]
|
||||||
|
static const void* resolve_pattern(const std::string_view module_name, const std::string_view pattern)
|
||||||
|
{
|
||||||
|
const auto* base = get_module_base(module_name);
|
||||||
|
assert(base && "Failed to find module");
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
const auto result = PePatternScanner::scan_for_pattern_in_loaded_module(base, pattern);
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
const auto result = MachOPatternScanner::scan_for_pattern_in_loaded_module(base, pattern);
|
||||||
#else
|
#else
|
||||||
using VirtualMethodType = ReturnType (*)(void*, decltype(arg_list)...);
|
const auto result = ElfPatternScanner::scan_for_pattern_in_loaded_module(base, pattern);
|
||||||
|
#endif
|
||||||
|
assert(result.has_value() && "Pattern scan failed");
|
||||||
|
return reinterpret_cast<const void*>(*result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
static const void* get_module_base(const std::string_view module_name)
|
||||||
|
{
|
||||||
|
#ifdef _WIN32
|
||||||
|
return GetModuleHandleA(module_name.data());
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
// On macOS, iterate loaded images to find the module by name
|
||||||
|
const auto count = _dyld_image_count();
|
||||||
|
for (std::uint32_t i = 0; i < count; ++i)
|
||||||
|
{
|
||||||
|
const auto* name = _dyld_get_image_name(i);
|
||||||
|
if (name && std::string_view{name}.find(module_name) != std::string_view::npos)
|
||||||
|
return static_cast<const void*>(_dyld_get_image_header(i));
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
#else
|
||||||
|
// On Linux, use dl_iterate_phdr to find loaded module by name
|
||||||
|
struct CallbackData
|
||||||
|
{
|
||||||
|
std::string_view name;
|
||||||
|
const void* base;
|
||||||
|
} cb_data{module_name, nullptr};
|
||||||
|
|
||||||
|
dl_iterate_phdr(
|
||||||
|
[](dl_phdr_info* info, std::size_t, void* data) -> int
|
||||||
|
{
|
||||||
|
auto* cb = static_cast<CallbackData*>(data);
|
||||||
|
if (info->dlpi_name
|
||||||
|
&& std::string_view{info->dlpi_name}.find(cb->name) != std::string_view::npos)
|
||||||
|
{
|
||||||
|
cb->base = reinterpret_cast<const void*>(info->dlpi_addr);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
},
|
||||||
|
&cb_data);
|
||||||
|
return cb_data.base;
|
||||||
#endif
|
#endif
|
||||||
return (*static_cast<VirtualMethodType**>((void*)(this)))[id](
|
|
||||||
const_cast<void*>(static_cast<const void*>(this)), arg_list...);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace omath::rev_eng
|
} // namespace omath::rev_eng
|
||||||
|
|||||||
@@ -457,85 +457,414 @@ namespace omath::hud
|
|||||||
m_text_cursor_left(m_canvas.top_left_corner), m_renderer(renderer)
|
m_text_cursor_left(m_canvas.top_left_corner), m_renderer(renderer)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
// ── Spacers ─────────────────────────────────────────────────────────────────
|
||||||
|
EntityOverlay& EntityOverlay::add_right_space_vertical(const float size)
|
||||||
|
{
|
||||||
|
m_text_cursor_right.y += size;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
EntityOverlay& EntityOverlay::add_right_space_horizontal(const float size)
|
||||||
|
{
|
||||||
|
m_text_cursor_right.x += size;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
EntityOverlay& EntityOverlay::add_left_space_vertical(const float size)
|
||||||
|
{
|
||||||
|
m_text_cursor_left.y += size;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
EntityOverlay& EntityOverlay::add_left_space_horizontal(const float size)
|
||||||
|
{
|
||||||
|
m_text_cursor_left.x -= size;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
EntityOverlay& EntityOverlay::add_top_space_vertical(const float size)
|
||||||
|
{
|
||||||
|
m_text_cursor_top.y -= size;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
EntityOverlay& EntityOverlay::add_top_space_horizontal(const float size)
|
||||||
|
{
|
||||||
|
m_text_cursor_top.x += size;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
EntityOverlay& EntityOverlay::add_bottom_space_vertical(const float size)
|
||||||
|
{
|
||||||
|
m_text_cursor_bottom.y += size;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
EntityOverlay& EntityOverlay::add_bottom_space_horizontal(const float size)
|
||||||
|
{
|
||||||
|
m_text_cursor_bottom.x += size;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Progress rings ──────────────────────────────────────────────────────────
|
||||||
|
EntityOverlay& EntityOverlay::add_right_progress_ring(const Color& color, const Color& bg, const float radius,
|
||||||
|
const float ratio, const float thickness, const float offset,
|
||||||
|
const int segments)
|
||||||
|
{
|
||||||
|
const auto cx = m_text_cursor_right.x + offset + radius;
|
||||||
|
const auto cy = m_text_cursor_right.y + radius;
|
||||||
|
draw_progress_ring({cx, cy}, widget::ProgressRing{color, bg, radius, ratio, thickness, offset, segments});
|
||||||
|
m_text_cursor_right.y += radius * 2.f;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
EntityOverlay& EntityOverlay::add_left_progress_ring(const Color& color, const Color& bg, const float radius,
|
||||||
|
const float ratio, const float thickness, const float offset,
|
||||||
|
const int segments)
|
||||||
|
{
|
||||||
|
const auto cx = m_text_cursor_left.x - offset - radius;
|
||||||
|
const auto cy = m_text_cursor_left.y + radius;
|
||||||
|
draw_progress_ring({cx, cy}, widget::ProgressRing{color, bg, radius, ratio, thickness, offset, segments});
|
||||||
|
m_text_cursor_left.y += radius * 2.f;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
EntityOverlay& EntityOverlay::add_top_progress_ring(const Color& color, const Color& bg, const float radius,
|
||||||
|
const float ratio, const float thickness, const float offset,
|
||||||
|
const int segments)
|
||||||
|
{
|
||||||
|
m_text_cursor_top.y -= radius * 2.f;
|
||||||
|
const auto cx = m_text_cursor_top.x + radius;
|
||||||
|
const auto cy = m_text_cursor_top.y - offset + radius;
|
||||||
|
draw_progress_ring({cx, cy}, widget::ProgressRing{color, bg, radius, ratio, thickness, offset, segments});
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
EntityOverlay& EntityOverlay::add_bottom_progress_ring(const Color& color, const Color& bg, const float radius,
|
||||||
|
const float ratio, const float thickness, const float offset,
|
||||||
|
const int segments)
|
||||||
|
{
|
||||||
|
const auto cx = m_text_cursor_bottom.x + radius;
|
||||||
|
const auto cy = m_text_cursor_bottom.y + offset + radius;
|
||||||
|
draw_progress_ring({cx, cy}, widget::ProgressRing{color, bg, radius, ratio, thickness, offset, segments});
|
||||||
|
m_text_cursor_bottom.y += radius * 2.f;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Icons ────────────────────────────────────────────────────────────────────
|
||||||
|
EntityOverlay& EntityOverlay::add_right_icon(const std::any& texture_id, const float width, const float height,
|
||||||
|
const Color& tint, const float offset)
|
||||||
|
{
|
||||||
|
const auto pos = m_text_cursor_right + Vector2<float>{offset, 0.f};
|
||||||
|
m_renderer->add_image(texture_id, pos, pos + Vector2<float>{width, height}, tint);
|
||||||
|
m_text_cursor_right.y += height;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
EntityOverlay& EntityOverlay::add_left_icon(const std::any& texture_id, const float width, const float height,
|
||||||
|
const Color& tint, const float offset)
|
||||||
|
{
|
||||||
|
const auto pos = m_text_cursor_left + Vector2<float>{-(offset + width), 0.f};
|
||||||
|
m_renderer->add_image(texture_id, pos, pos + Vector2<float>{width, height}, tint);
|
||||||
|
m_text_cursor_left.y += height;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
EntityOverlay& EntityOverlay::add_top_icon(const std::any& texture_id, const float width, const float height,
|
||||||
|
const Color& tint, const float offset)
|
||||||
|
{
|
||||||
|
m_text_cursor_top.y -= height;
|
||||||
|
const auto pos = m_text_cursor_top + Vector2<float>{0.f, -offset};
|
||||||
|
m_renderer->add_image(texture_id, pos, pos + Vector2<float>{width, height}, tint);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
EntityOverlay& EntityOverlay::add_bottom_icon(const std::any& texture_id, const float width, const float height,
|
||||||
|
const Color& tint, const float offset)
|
||||||
|
{
|
||||||
|
const auto pos = m_text_cursor_bottom + Vector2<float>{0.f, offset};
|
||||||
|
m_renderer->add_image(texture_id, pos, pos + Vector2<float>{width, height}, tint);
|
||||||
|
m_text_cursor_bottom.y += height;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
// ── widget dispatch ───────────────────────────────────────────────────────
|
// ── widget dispatch ───────────────────────────────────────────────────────
|
||||||
void EntityOverlay::dispatch(const widget::Box& w)
|
void EntityOverlay::dispatch(const widget::Box& box)
|
||||||
{ add_2d_box(w.color, w.fill, w.thickness); }
|
{
|
||||||
|
add_2d_box(box.color, box.fill, box.thickness);
|
||||||
|
}
|
||||||
|
|
||||||
void EntityOverlay::dispatch(const widget::CorneredBox& w)
|
void EntityOverlay::dispatch(const widget::CorneredBox& cornered_box)
|
||||||
{ add_cornered_2d_box(w.color, w.fill, w.corner_ratio, w.thickness); }
|
{
|
||||||
|
add_cornered_2d_box(cornered_box.color, cornered_box.fill, cornered_box.corner_ratio, cornered_box.thickness);
|
||||||
|
}
|
||||||
|
|
||||||
void EntityOverlay::dispatch(const widget::DashedBox& w)
|
void EntityOverlay::dispatch(const widget::DashedBox& dashed_box)
|
||||||
{ add_dashed_box(w.color, w.dash_len, w.gap_len, w.thickness); }
|
{
|
||||||
|
add_dashed_box(dashed_box.color, dashed_box.dash_len, dashed_box.gap_len, dashed_box.thickness);
|
||||||
|
}
|
||||||
|
|
||||||
void EntityOverlay::dispatch(const widget::Skeleton& w)
|
void EntityOverlay::dispatch(const widget::Skeleton& skeleton)
|
||||||
{ add_skeleton(w.color, w.thickness); }
|
{
|
||||||
|
add_skeleton(skeleton.color, skeleton.thickness);
|
||||||
|
}
|
||||||
|
|
||||||
void EntityOverlay::dispatch(const widget::SnapLine& w)
|
void EntityOverlay::dispatch(const widget::SnapLine& snap_line)
|
||||||
{ add_snap_line(w.start, w.color, w.width); }
|
{
|
||||||
|
add_snap_line(snap_line.start, snap_line.color, snap_line.width);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityOverlay::dispatch(const widget::ScanMarker& scan_marker)
|
||||||
|
{
|
||||||
|
const auto box_width = std::abs(m_canvas.top_right_corner.x - m_canvas.top_left_corner.x);
|
||||||
|
const auto box_height = std::abs(m_canvas.bottom_left_corner.y - m_canvas.top_left_corner.y);
|
||||||
|
|
||||||
|
const auto center_x = (m_canvas.top_left_corner.x + m_canvas.top_right_corner.x) / 2.f;
|
||||||
|
const auto center_y = m_canvas.top_left_corner.y + box_height * 0.44f;
|
||||||
|
|
||||||
|
const auto side = std::min(box_width, box_height) * 0.5f;
|
||||||
|
const auto h = side * std::sqrt(3.f) / 2.f;
|
||||||
|
|
||||||
|
const std::array<Vector2<float>, 3> tri = {
|
||||||
|
Vector2<float>{center_x, center_y - h * 2.f / 3.f},
|
||||||
|
Vector2<float>{center_x - side / 2.f, center_y + h / 3.f},
|
||||||
|
Vector2<float>{center_x + side / 2.f, center_y + h / 3.f},
|
||||||
|
};
|
||||||
|
|
||||||
|
m_renderer->add_filled_polyline({tri.data(), tri.size()}, scan_marker.color);
|
||||||
|
|
||||||
|
if (scan_marker.outline.value().w > 0.f)
|
||||||
|
m_renderer->add_polyline({tri.data(), tri.size()}, scan_marker.outline, scan_marker.outline_thickness);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityOverlay::dispatch(const widget::AimDot& aim_dot)
|
||||||
|
{
|
||||||
|
m_renderer->add_filled_circle(aim_dot.position, aim_dot.radius, aim_dot.color);
|
||||||
|
}
|
||||||
|
void EntityOverlay::dispatch(const widget::ProjectileAim& proj_widget)
|
||||||
|
{
|
||||||
|
const auto box_width = std::abs(m_canvas.top_right_corner.x - m_canvas.top_left_corner.x);
|
||||||
|
const auto box_height = std::abs(m_canvas.bottom_left_corner.y - m_canvas.top_left_corner.y);
|
||||||
|
|
||||||
|
const auto box_center = m_canvas.top_left_corner + Vector2{box_width, box_height} / 2.f;
|
||||||
|
|
||||||
|
m_renderer->add_line(box_center, proj_widget.position, proj_widget.color, proj_widget.line_size);
|
||||||
|
|
||||||
|
if (proj_widget.figure == widget::ProjectileAim::Figure::CIRCLE)
|
||||||
|
{
|
||||||
|
m_renderer->add_filled_circle(proj_widget.position, proj_widget.size, proj_widget.color);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (proj_widget.figure == widget::ProjectileAim::Figure::SQUARE)
|
||||||
|
{
|
||||||
|
const auto box_min = proj_widget.position - Vector2{proj_widget.size, proj_widget.size} / 2.f;
|
||||||
|
const auto box_max = proj_widget.position + Vector2{proj_widget.size, proj_widget.size} / 2.f;
|
||||||
|
m_renderer->add_filled_rectangle(box_min, box_max, proj_widget.color);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unreachable();
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityOverlay::draw_progress_ring(const Vector2<float>& center, const widget::ProgressRing& ring)
|
||||||
|
{
|
||||||
|
constexpr auto pi = std::numbers::pi_v<float>;
|
||||||
|
const float ratio = std::clamp(ring.ratio, 0.f, 1.f);
|
||||||
|
|
||||||
|
m_renderer->add_circle(center, ring.radius, ring.bg, ring.thickness, ring.segments);
|
||||||
|
|
||||||
|
if (ratio > 0.f)
|
||||||
|
{
|
||||||
|
const float a_min = -pi / 2.f;
|
||||||
|
const float a_max = a_min + ratio * 2.f * pi;
|
||||||
|
m_renderer->add_arc(center, ring.radius, a_min, a_max, ring.color, ring.thickness, ring.segments);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ── Side container dispatch ───────────────────────────────────────────────
|
// ── Side container dispatch ───────────────────────────────────────────────
|
||||||
void EntityOverlay::dispatch(const widget::RightSide& s)
|
void EntityOverlay::dispatch(const widget::RightSide& right_side)
|
||||||
{
|
{
|
||||||
for (const auto& child : s.children)
|
for (const auto& child : right_side.children)
|
||||||
std::visit(widget::Overloaded{
|
std::visit(
|
||||||
[](const widget::None&) {},
|
widget::Overloaded{
|
||||||
[this](const widget::Bar& w)
|
[](const widget::None&)
|
||||||
{ add_right_bar(w.color, w.outline, w.bg, w.size, w.ratio, w.offset); },
|
{
|
||||||
[this](const widget::DashedBar& w)
|
},
|
||||||
{ add_right_dashed_bar(w.color, w.outline, w.bg, w.size, w.ratio, w.dash_len, w.gap_len, w.offset); },
|
[this](const widget::Bar& w)
|
||||||
[this](const widget::Label& w)
|
{
|
||||||
{ add_right_label(w.color, w.offset, w.outlined, w.text); },
|
add_right_bar(w.color, w.outline, w.bg, w.size, w.ratio, w.offset);
|
||||||
[this](const widget::Centered<widget::Label>& w)
|
},
|
||||||
{ add_right_label(w.child.color, w.child.offset, w.child.outlined, w.child.text); },
|
[this](const widget::DashedBar& w)
|
||||||
}, child);
|
{
|
||||||
|
add_right_dashed_bar(w.color, w.outline, w.bg, w.size, w.ratio, w.dash_len, w.gap_len,
|
||||||
|
w.offset);
|
||||||
|
},
|
||||||
|
[this](const widget::Label& w)
|
||||||
|
{
|
||||||
|
add_right_label(w.color, w.offset, w.outlined, w.text);
|
||||||
|
},
|
||||||
|
[this](const widget::Centered<widget::Label>& w)
|
||||||
|
{
|
||||||
|
add_right_label(w.child.color, w.child.offset, w.child.outlined, w.child.text);
|
||||||
|
},
|
||||||
|
[this](const widget::SpaceVertical& w)
|
||||||
|
{
|
||||||
|
add_right_space_vertical(w.size);
|
||||||
|
},
|
||||||
|
[this](const widget::SpaceHorizontal& w)
|
||||||
|
{
|
||||||
|
add_right_space_horizontal(w.size);
|
||||||
|
},
|
||||||
|
[this](const widget::ProgressRing& w)
|
||||||
|
{
|
||||||
|
add_right_progress_ring(w.color, w.bg, w.radius, w.ratio, w.thickness, w.offset,
|
||||||
|
w.segments);
|
||||||
|
},
|
||||||
|
[this](const widget::Icon& w)
|
||||||
|
{
|
||||||
|
add_right_icon(w.texture_id, w.width, w.height, w.tint, w.offset);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
child);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityOverlay::dispatch(const widget::LeftSide& s)
|
void EntityOverlay::dispatch(const widget::LeftSide& left_side)
|
||||||
{
|
{
|
||||||
for (const auto& child : s.children)
|
for (const auto& child : left_side.children)
|
||||||
std::visit(widget::Overloaded{
|
std::visit(
|
||||||
[](const widget::None&) {},
|
widget::Overloaded{
|
||||||
[this](const widget::Bar& w)
|
[](const widget::None&)
|
||||||
{ add_left_bar(w.color, w.outline, w.bg, w.size, w.ratio, w.offset); },
|
{
|
||||||
[this](const widget::DashedBar& w)
|
},
|
||||||
{ add_left_dashed_bar(w.color, w.outline, w.bg, w.size, w.ratio, w.dash_len, w.gap_len, w.offset); },
|
[this](const widget::Bar& w)
|
||||||
[this](const widget::Label& w)
|
{
|
||||||
{ add_left_label(w.color, w.offset, w.outlined, w.text); },
|
add_left_bar(w.color, w.outline, w.bg, w.size, w.ratio, w.offset);
|
||||||
[this](const widget::Centered<widget::Label>& w)
|
},
|
||||||
{ add_left_label(w.child.color, w.child.offset, w.child.outlined, w.child.text); },
|
[this](const widget::DashedBar& w)
|
||||||
}, child);
|
{
|
||||||
|
add_left_dashed_bar(w.color, w.outline, w.bg, w.size, w.ratio, w.dash_len, w.gap_len,
|
||||||
|
w.offset);
|
||||||
|
},
|
||||||
|
[this](const widget::Label& w)
|
||||||
|
{
|
||||||
|
add_left_label(w.color, w.offset, w.outlined, w.text);
|
||||||
|
},
|
||||||
|
[this](const widget::Centered<widget::Label>& w)
|
||||||
|
{
|
||||||
|
add_left_label(w.child.color, w.child.offset, w.child.outlined, w.child.text);
|
||||||
|
},
|
||||||
|
[this](const widget::SpaceVertical& w)
|
||||||
|
{
|
||||||
|
add_left_space_vertical(w.size);
|
||||||
|
},
|
||||||
|
[this](const widget::SpaceHorizontal& w)
|
||||||
|
{
|
||||||
|
add_left_space_horizontal(w.size);
|
||||||
|
},
|
||||||
|
[this](const widget::ProgressRing& w)
|
||||||
|
{
|
||||||
|
add_left_progress_ring(w.color, w.bg, w.radius, w.ratio, w.thickness, w.offset,
|
||||||
|
w.segments);
|
||||||
|
},
|
||||||
|
[this](const widget::Icon& w)
|
||||||
|
{
|
||||||
|
add_left_icon(w.texture_id, w.width, w.height, w.tint, w.offset);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
child);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityOverlay::dispatch(const widget::TopSide& s)
|
void EntityOverlay::dispatch(const widget::TopSide& top_side)
|
||||||
{
|
{
|
||||||
for (const auto& child : s.children)
|
for (const auto& child : top_side.children)
|
||||||
std::visit(widget::Overloaded{
|
std::visit(
|
||||||
[](const widget::None&) {},
|
widget::Overloaded{
|
||||||
[this](const widget::Bar& w)
|
[](const widget::None&)
|
||||||
{ add_top_bar(w.color, w.outline, w.bg, w.size, w.ratio, w.offset); },
|
{
|
||||||
[this](const widget::DashedBar& w)
|
},
|
||||||
{ add_top_dashed_bar(w.color, w.outline, w.bg, w.size, w.ratio, w.dash_len, w.gap_len, w.offset); },
|
[this](const widget::Bar& w)
|
||||||
[this](const widget::Label& w)
|
{
|
||||||
{ add_top_label(w.color, w.offset, w.outlined, w.text); },
|
add_top_bar(w.color, w.outline, w.bg, w.size, w.ratio, w.offset);
|
||||||
[this](const widget::Centered<widget::Label>& w)
|
},
|
||||||
{ add_centered_top_label(w.child.color, w.child.offset, w.child.outlined, w.child.text); },
|
[this](const widget::DashedBar& w)
|
||||||
}, child);
|
{
|
||||||
|
add_top_dashed_bar(w.color, w.outline, w.bg, w.size, w.ratio, w.dash_len, w.gap_len,
|
||||||
|
w.offset);
|
||||||
|
},
|
||||||
|
[this](const widget::Label& w)
|
||||||
|
{
|
||||||
|
add_top_label(w.color, w.offset, w.outlined, w.text);
|
||||||
|
},
|
||||||
|
[this](const widget::Centered<widget::Label>& w)
|
||||||
|
{
|
||||||
|
add_centered_top_label(w.child.color, w.child.offset, w.child.outlined, w.child.text);
|
||||||
|
},
|
||||||
|
[this](const widget::SpaceVertical& w)
|
||||||
|
{
|
||||||
|
add_top_space_vertical(w.size);
|
||||||
|
},
|
||||||
|
[this](const widget::SpaceHorizontal& w)
|
||||||
|
{
|
||||||
|
add_top_space_horizontal(w.size);
|
||||||
|
},
|
||||||
|
[this](const widget::ProgressRing& w)
|
||||||
|
{
|
||||||
|
add_top_progress_ring(w.color, w.bg, w.radius, w.ratio, w.thickness, w.offset,
|
||||||
|
w.segments);
|
||||||
|
},
|
||||||
|
[this](const widget::Icon& w)
|
||||||
|
{
|
||||||
|
add_top_icon(w.texture_id, w.width, w.height, w.tint, w.offset);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
child);
|
||||||
}
|
}
|
||||||
|
void EntityOverlay::dispatch(const widget::BottomSide& bottom_side)
|
||||||
void EntityOverlay::dispatch(const widget::BottomSide& s)
|
|
||||||
{
|
{
|
||||||
for (const auto& child : s.children)
|
for (const auto& child : bottom_side.children)
|
||||||
std::visit(widget::Overloaded{
|
std::visit(
|
||||||
[](const widget::None&) {},
|
widget::Overloaded{
|
||||||
[this](const widget::Bar& w)
|
[](const widget::None&)
|
||||||
{ add_bottom_bar(w.color, w.outline, w.bg, w.size, w.ratio, w.offset); },
|
{
|
||||||
[this](const widget::DashedBar& w)
|
},
|
||||||
{ add_bottom_dashed_bar(w.color, w.outline, w.bg, w.size, w.ratio, w.dash_len, w.gap_len, w.offset); },
|
[this](const widget::Bar& w)
|
||||||
[this](const widget::Label& w)
|
{
|
||||||
{ add_bottom_label(w.color, w.offset, w.outlined, w.text); },
|
add_bottom_bar(w.color, w.outline, w.bg, w.size, w.ratio, w.offset);
|
||||||
[this](const widget::Centered<widget::Label>& w)
|
},
|
||||||
{ add_centered_bottom_label(w.child.color, w.child.offset, w.child.outlined, w.child.text); },
|
[this](const widget::DashedBar& w)
|
||||||
}, child);
|
{
|
||||||
|
add_bottom_dashed_bar(w.color, w.outline, w.bg, w.size, w.ratio, w.dash_len, w.gap_len,
|
||||||
|
w.offset);
|
||||||
|
},
|
||||||
|
[this](const widget::Label& w)
|
||||||
|
{
|
||||||
|
add_bottom_label(w.color, w.offset, w.outlined, w.text);
|
||||||
|
},
|
||||||
|
[this](const widget::Centered<widget::Label>& w)
|
||||||
|
{
|
||||||
|
add_centered_bottom_label(w.child.color, w.child.offset, w.child.outlined,
|
||||||
|
w.child.text);
|
||||||
|
},
|
||||||
|
[this](const widget::SpaceVertical& w)
|
||||||
|
{
|
||||||
|
add_bottom_space_vertical(w.size);
|
||||||
|
},
|
||||||
|
[this](const widget::SpaceHorizontal& w)
|
||||||
|
{
|
||||||
|
add_bottom_space_horizontal(w.size);
|
||||||
|
},
|
||||||
|
[this](const widget::ProgressRing& w)
|
||||||
|
{
|
||||||
|
add_bottom_progress_ring(w.color, w.bg, w.radius, w.ratio, w.thickness, w.offset,
|
||||||
|
w.segments);
|
||||||
|
},
|
||||||
|
[this](const widget::Icon& w)
|
||||||
|
{
|
||||||
|
add_bottom_icon(w.texture_id, w.width, w.height, w.tint, w.offset);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
child);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace omath::hud
|
} // namespace omath::hud
|
||||||
@@ -42,6 +42,32 @@ namespace omath::hud
|
|||||||
ImGui::GetBackgroundDrawList()->AddRectFilled(min.to_im_vec2(), max.to_im_vec2(), color.to_im_color());
|
ImGui::GetBackgroundDrawList()->AddRectFilled(min.to_im_vec2(), max.to_im_vec2(), color.to_im_color());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ImguiHudRenderer::add_circle(const Vector2<float>& center, const float radius, const Color& color,
|
||||||
|
const float thickness, const int segments)
|
||||||
|
{
|
||||||
|
ImGui::GetBackgroundDrawList()->AddCircle(center.to_im_vec2(), radius, color.to_im_color(), segments, thickness);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImguiHudRenderer::add_filled_circle(const Vector2<float>& center, const float radius, const Color& color,
|
||||||
|
const int segments)
|
||||||
|
{
|
||||||
|
ImGui::GetBackgroundDrawList()->AddCircleFilled(center.to_im_vec2(), radius, color.to_im_color(), segments);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImguiHudRenderer::add_arc(const Vector2<float>& center, const float radius, const float a_min, const float a_max,
|
||||||
|
const Color& color, const float thickness, const int segments)
|
||||||
|
{
|
||||||
|
ImGui::GetBackgroundDrawList()->PathArcTo(center.to_im_vec2(), radius, a_min, a_max, segments);
|
||||||
|
ImGui::GetBackgroundDrawList()->PathStroke(color.to_im_color(), ImDrawFlags_None, thickness);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImguiHudRenderer::add_image(const std::any& texture_id, const Vector2<float>& min, const Vector2<float>& max,
|
||||||
|
const Color& tint)
|
||||||
|
{
|
||||||
|
ImGui::GetBackgroundDrawList()->AddImage(std::any_cast<ImTextureID>(texture_id), min.to_im_vec2(),
|
||||||
|
max.to_im_vec2(), {0, 0}, {1, 1}, tint.to_im_color());
|
||||||
|
}
|
||||||
|
|
||||||
void ImguiHudRenderer::add_text(const Vector2<float>& position, const Color& color, const std::string_view& text)
|
void ImguiHudRenderer::add_text(const Vector2<float>& position, const Color& color, const std::string_view& text)
|
||||||
{
|
{
|
||||||
ImGui::GetBackgroundDrawList()->AddText(position.to_im_vec2(), color.to_im_color(), text.data(),
|
ImGui::GetBackgroundDrawList()->AddText(position.to_im_vec2(), color.to_im_color(), text.data(),
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ namespace omath::projectile_prediction
|
|||||||
const float bullet_gravity = m_gravity_constant * projectile.m_gravity_scale;
|
const float bullet_gravity = m_gravity_constant * projectile.m_gravity_scale;
|
||||||
const float v0 = projectile.m_launch_speed;
|
const float v0 = projectile.m_launch_speed;
|
||||||
const float v0_sqr = v0 * v0;
|
const float v0_sqr = v0 * v0;
|
||||||
const Vector3 proj_origin = projectile.m_origin;
|
const Vector3 proj_origin = projectile.m_origin + projectile.m_launch_offset;
|
||||||
|
|
||||||
constexpr int SIMD_FACTOR = 8;
|
constexpr int SIMD_FACTOR = 8;
|
||||||
float current_time = m_simulation_time_step;
|
float current_time = m_simulation_time_step;
|
||||||
@@ -124,6 +124,110 @@ namespace omath::projectile_prediction
|
|||||||
std::format("{} AVX2 feature is not enabled!", std::source_location::current().function_name()));
|
std::format("{} AVX2 feature is not enabled!", std::source_location::current().function_name()));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
std::optional<AimAngles>
|
||||||
|
ProjPredEngineAvx2::maybe_calculate_aim_angles([[maybe_unused]] const Projectile& projectile,
|
||||||
|
[[maybe_unused]] const Target& target) const
|
||||||
|
{
|
||||||
|
#if defined(OMATH_USE_AVX2) && defined(__i386__) && defined(__x86_64__)
|
||||||
|
const float bullet_gravity = m_gravity_constant * projectile.m_gravity_scale;
|
||||||
|
const float v0 = projectile.m_launch_speed;
|
||||||
|
const Vector3 proj_origin = projectile.m_origin + projectile.m_launch_offset;
|
||||||
|
|
||||||
|
constexpr int SIMD_FACTOR = 8;
|
||||||
|
float current_time = m_simulation_time_step;
|
||||||
|
|
||||||
|
for (; current_time <= m_maximum_simulation_time; current_time += m_simulation_time_step * SIMD_FACTOR)
|
||||||
|
{
|
||||||
|
const __m256 times
|
||||||
|
= _mm256_setr_ps(current_time, current_time + m_simulation_time_step,
|
||||||
|
current_time + m_simulation_time_step * 2, current_time + m_simulation_time_step * 3,
|
||||||
|
current_time + m_simulation_time_step * 4, current_time + m_simulation_time_step * 5,
|
||||||
|
current_time + m_simulation_time_step * 6, current_time + m_simulation_time_step * 7);
|
||||||
|
|
||||||
|
const __m256 target_x
|
||||||
|
= _mm256_fmadd_ps(_mm256_set1_ps(target.m_velocity.x), times, _mm256_set1_ps(target.m_origin.x));
|
||||||
|
const __m256 target_y
|
||||||
|
= _mm256_fmadd_ps(_mm256_set1_ps(target.m_velocity.y), times, _mm256_set1_ps(target.m_origin.y));
|
||||||
|
const __m256 times_sq = _mm256_mul_ps(times, times);
|
||||||
|
const __m256 target_z = _mm256_fmadd_ps(_mm256_set1_ps(target.m_velocity.z), times,
|
||||||
|
_mm256_fnmadd_ps(_mm256_set1_ps(0.5f * m_gravity_constant), times_sq,
|
||||||
|
_mm256_set1_ps(target.m_origin.z)));
|
||||||
|
|
||||||
|
const __m256 delta_x = _mm256_sub_ps(target_x, _mm256_set1_ps(proj_origin.x));
|
||||||
|
const __m256 delta_y = _mm256_sub_ps(target_y, _mm256_set1_ps(proj_origin.y));
|
||||||
|
|
||||||
|
const __m256 d_sqr = _mm256_add_ps(_mm256_mul_ps(delta_x, delta_x), _mm256_mul_ps(delta_y, delta_y));
|
||||||
|
const __m256 delta_z = _mm256_sub_ps(target_z, _mm256_set1_ps(proj_origin.z));
|
||||||
|
|
||||||
|
const __m256 bg_times_sq = _mm256_mul_ps(_mm256_set1_ps(bullet_gravity), times_sq);
|
||||||
|
const __m256 term = _mm256_add_ps(delta_z, _mm256_mul_ps(_mm256_set1_ps(0.5f), bg_times_sq));
|
||||||
|
const __m256 term_sq = _mm256_mul_ps(term, term);
|
||||||
|
const __m256 numerator = _mm256_add_ps(d_sqr, term_sq);
|
||||||
|
const __m256 denominator = _mm256_add_ps(times_sq, _mm256_set1_ps(1e-8f));
|
||||||
|
const __m256 required_v0_sqr = _mm256_div_ps(numerator, denominator);
|
||||||
|
|
||||||
|
const __m256 v0_sqr_vec = _mm256_set1_ps(v0 * v0 + 1e-3f);
|
||||||
|
const __m256 mask = _mm256_cmp_ps(required_v0_sqr, v0_sqr_vec, _CMP_LE_OQ);
|
||||||
|
|
||||||
|
const unsigned valid_mask = _mm256_movemask_ps(mask);
|
||||||
|
if (!valid_mask)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
alignas(32) float valid_times[SIMD_FACTOR];
|
||||||
|
_mm256_store_ps(valid_times, times);
|
||||||
|
|
||||||
|
for (int i = 0; i < SIMD_FACTOR; ++i)
|
||||||
|
{
|
||||||
|
if (!(valid_mask & (1 << i)))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const float candidate_time = valid_times[i];
|
||||||
|
if (candidate_time > m_maximum_simulation_time)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
for (float fine_time = candidate_time - m_simulation_time_step * 2;
|
||||||
|
fine_time <= candidate_time + m_simulation_time_step * 2; fine_time += m_simulation_time_step)
|
||||||
|
{
|
||||||
|
if (fine_time < 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
Vector3 target_pos = target.m_origin + target.m_velocity * fine_time;
|
||||||
|
if (target.m_is_airborne)
|
||||||
|
target_pos.z -= 0.5f * m_gravity_constant * fine_time * fine_time;
|
||||||
|
|
||||||
|
const auto pitch = calculate_pitch(proj_origin, target_pos, bullet_gravity, v0, fine_time);
|
||||||
|
if (!pitch)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const Vector3 delta = target_pos - projectile.m_origin;
|
||||||
|
const float yaw = angles::radians_to_degrees(std::atan2(delta.y, delta.x));
|
||||||
|
return AimAngles{*pitch, yaw};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (; current_time <= m_maximum_simulation_time; current_time += m_simulation_time_step)
|
||||||
|
{
|
||||||
|
Vector3 target_pos = target.m_origin + target.m_velocity * current_time;
|
||||||
|
if (target.m_is_airborne)
|
||||||
|
target_pos.z -= 0.5f * m_gravity_constant * current_time * current_time;
|
||||||
|
|
||||||
|
const auto pitch = calculate_pitch(proj_origin, target_pos, bullet_gravity, v0, current_time);
|
||||||
|
if (!pitch)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const Vector3 delta = target_pos - projectile.m_origin;
|
||||||
|
const float yaw = angles::radians_to_degrees(std::atan2(delta.y, delta.x));
|
||||||
|
return AimAngles{*pitch, yaw};
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::nullopt;
|
||||||
|
#else
|
||||||
|
throw std::runtime_error(
|
||||||
|
std::format("{} AVX2 feature is not enabled!", std::source_location::current().function_name()));
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
ProjPredEngineAvx2::ProjPredEngineAvx2(const float gravity_constant, const float simulation_time_step,
|
ProjPredEngineAvx2::ProjPredEngineAvx2(const float gravity_constant, const float simulation_time_step,
|
||||||
const float maximum_simulation_time)
|
const float maximum_simulation_time)
|
||||||
: m_gravity_constant(gravity_constant), m_simulation_time_step(simulation_time_step),
|
: m_gravity_constant(gravity_constant), m_simulation_time_step(simulation_time_step),
|
||||||
|
|||||||
@@ -20,6 +20,8 @@
|
|||||||
#include <omath/engines/unreal_engine/traits/mesh_trait.hpp>
|
#include <omath/engines/unreal_engine/traits/mesh_trait.hpp>
|
||||||
#include <omath/engines/unreal_engine/traits/camera_trait.hpp>
|
#include <omath/engines/unreal_engine/traits/camera_trait.hpp>
|
||||||
|
|
||||||
|
#include <omath/engines/source_engine/traits/pred_engine_trait.hpp>
|
||||||
|
|
||||||
#include <omath/projectile_prediction/projectile.hpp>
|
#include <omath/projectile_prediction/projectile.hpp>
|
||||||
#include <omath/projectile_prediction/target.hpp>
|
#include <omath/projectile_prediction/target.hpp>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
@@ -35,6 +37,132 @@ static void expect_matrix_near(const MatT& a, const MatT& b, float eps = 1e-5f)
|
|||||||
EXPECT_NEAR(a.at(r, c), b.at(r, c), eps);
|
EXPECT_NEAR(a.at(r, c), b.at(r, c), eps);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ── Launch offset tests for all engines ──────────────────────────────────────
|
||||||
|
#include <omath/engines/cry_engine/traits/pred_engine_trait.hpp>
|
||||||
|
|
||||||
|
// Helper: verify that zero offset matches default-initialized offset behavior
|
||||||
|
template<typename Trait>
|
||||||
|
static void verify_launch_offset_at_time_zero(const Vector3<float>& origin, const Vector3<float>& offset)
|
||||||
|
{
|
||||||
|
projectile_prediction::Projectile p;
|
||||||
|
p.m_origin = origin;
|
||||||
|
p.m_launch_offset = offset;
|
||||||
|
p.m_launch_speed = 100.f;
|
||||||
|
p.m_gravity_scale = 1.f;
|
||||||
|
|
||||||
|
const auto pos = Trait::predict_projectile_position(p, 0.f, 0.f, 0.f, 9.81f);
|
||||||
|
const auto expected = origin + offset;
|
||||||
|
EXPECT_NEAR(pos.x, expected.x, 1e-4f);
|
||||||
|
EXPECT_NEAR(pos.y, expected.y, 1e-4f);
|
||||||
|
EXPECT_NEAR(pos.z, expected.z, 1e-4f);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename Trait>
|
||||||
|
static void verify_zero_offset_matches_default()
|
||||||
|
{
|
||||||
|
projectile_prediction::Projectile p;
|
||||||
|
p.m_origin = {10.f, 20.f, 30.f};
|
||||||
|
p.m_launch_offset = {0.f, 0.f, 0.f};
|
||||||
|
p.m_launch_speed = 50.f;
|
||||||
|
p.m_gravity_scale = 1.f;
|
||||||
|
|
||||||
|
projectile_prediction::Projectile p2;
|
||||||
|
p2.m_origin = {10.f, 20.f, 30.f};
|
||||||
|
p2.m_launch_speed = 50.f;
|
||||||
|
p2.m_gravity_scale = 1.f;
|
||||||
|
|
||||||
|
const auto pos1 = Trait::predict_projectile_position(p, 15.f, 30.f, 1.f, 9.81f);
|
||||||
|
const auto pos2 = Trait::predict_projectile_position(p2, 15.f, 30.f, 1.f, 9.81f);
|
||||||
|
#if defined(__x86_64__) || defined(_M_X64) || defined(__aarch64__) || defined(_M_ARM64)
|
||||||
|
constexpr float tol = 1e-6f;
|
||||||
|
#else
|
||||||
|
constexpr float tol = 1e-4f;
|
||||||
|
#endif
|
||||||
|
EXPECT_NEAR(pos1.x, pos2.x, tol);
|
||||||
|
EXPECT_NEAR(pos1.y, pos2.y, tol);
|
||||||
|
EXPECT_NEAR(pos1.z, pos2.z, tol);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(LaunchOffsetTests, Source_OffsetAtTimeZero)
|
||||||
|
{
|
||||||
|
verify_launch_offset_at_time_zero<source_engine::PredEngineTrait>({0, 0, 0}, {5, 3, -2});
|
||||||
|
}
|
||||||
|
TEST(LaunchOffsetTests, Source_ZeroOffsetMatchesDefault)
|
||||||
|
{
|
||||||
|
verify_zero_offset_matches_default<source_engine::PredEngineTrait>();
|
||||||
|
}
|
||||||
|
TEST(LaunchOffsetTests, Frostbite_OffsetAtTimeZero)
|
||||||
|
{
|
||||||
|
verify_launch_offset_at_time_zero<frostbite_engine::PredEngineTrait>({0, 0, 0}, {5, 3, -2});
|
||||||
|
}
|
||||||
|
TEST(LaunchOffsetTests, Frostbite_ZeroOffsetMatchesDefault)
|
||||||
|
{
|
||||||
|
verify_zero_offset_matches_default<frostbite_engine::PredEngineTrait>();
|
||||||
|
}
|
||||||
|
TEST(LaunchOffsetTests, IW_OffsetAtTimeZero)
|
||||||
|
{
|
||||||
|
verify_launch_offset_at_time_zero<iw_engine::PredEngineTrait>({0, 0, 0}, {5, 3, -2});
|
||||||
|
}
|
||||||
|
TEST(LaunchOffsetTests, IW_ZeroOffsetMatchesDefault)
|
||||||
|
{
|
||||||
|
verify_zero_offset_matches_default<iw_engine::PredEngineTrait>();
|
||||||
|
}
|
||||||
|
TEST(LaunchOffsetTests, OpenGL_OffsetAtTimeZero)
|
||||||
|
{
|
||||||
|
verify_launch_offset_at_time_zero<opengl_engine::PredEngineTrait>({0, 0, 0}, {5, 3, -2});
|
||||||
|
}
|
||||||
|
TEST(LaunchOffsetTests, OpenGL_ZeroOffsetMatchesDefault)
|
||||||
|
{
|
||||||
|
verify_zero_offset_matches_default<opengl_engine::PredEngineTrait>();
|
||||||
|
}
|
||||||
|
TEST(LaunchOffsetTests, Unity_OffsetAtTimeZero)
|
||||||
|
{
|
||||||
|
verify_launch_offset_at_time_zero<unity_engine::PredEngineTrait>({0, 0, 0}, {5, 3, -2});
|
||||||
|
}
|
||||||
|
TEST(LaunchOffsetTests, Unity_ZeroOffsetMatchesDefault)
|
||||||
|
{
|
||||||
|
verify_zero_offset_matches_default<unity_engine::PredEngineTrait>();
|
||||||
|
}
|
||||||
|
TEST(LaunchOffsetTests, Unreal_OffsetAtTimeZero)
|
||||||
|
{
|
||||||
|
verify_launch_offset_at_time_zero<unreal_engine::PredEngineTrait>({0, 0, 0}, {5, 3, -2});
|
||||||
|
}
|
||||||
|
TEST(LaunchOffsetTests, Unreal_ZeroOffsetMatchesDefault)
|
||||||
|
{
|
||||||
|
verify_zero_offset_matches_default<unreal_engine::PredEngineTrait>();
|
||||||
|
}
|
||||||
|
TEST(LaunchOffsetTests, CryEngine_OffsetAtTimeZero)
|
||||||
|
{
|
||||||
|
verify_launch_offset_at_time_zero<cry_engine::PredEngineTrait>({0, 0, 0}, {5, 3, -2});
|
||||||
|
}
|
||||||
|
TEST(LaunchOffsetTests, CryEngine_ZeroOffsetMatchesDefault)
|
||||||
|
{
|
||||||
|
verify_zero_offset_matches_default<cry_engine::PredEngineTrait>();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test that offset shifts the projectile position at t>0 as well
|
||||||
|
TEST(LaunchOffsetTests, OffsetShiftsTrajectory)
|
||||||
|
{
|
||||||
|
projectile_prediction::Projectile p_no_offset;
|
||||||
|
p_no_offset.m_origin = {0.f, 0.f, 0.f};
|
||||||
|
p_no_offset.m_launch_speed = 100.f;
|
||||||
|
p_no_offset.m_gravity_scale = 1.f;
|
||||||
|
|
||||||
|
projectile_prediction::Projectile p_with_offset;
|
||||||
|
p_with_offset.m_origin = {0.f, 0.f, 0.f};
|
||||||
|
p_with_offset.m_launch_offset = {10.f, 5.f, -3.f};
|
||||||
|
p_with_offset.m_launch_speed = 100.f;
|
||||||
|
p_with_offset.m_gravity_scale = 1.f;
|
||||||
|
|
||||||
|
const auto pos1 = source_engine::PredEngineTrait::predict_projectile_position(p_no_offset, 20.f, 45.f, 2.f, 9.81f);
|
||||||
|
const auto pos2 = source_engine::PredEngineTrait::predict_projectile_position(p_with_offset, 20.f, 45.f, 2.f, 9.81f);
|
||||||
|
|
||||||
|
// The difference should be exactly the launch offset
|
||||||
|
EXPECT_NEAR(pos2.x - pos1.x, 10.f, 1e-4f);
|
||||||
|
EXPECT_NEAR(pos2.y - pos1.y, 5.f, 1e-4f);
|
||||||
|
EXPECT_NEAR(pos2.z - pos1.z, -3.f, 1e-4f);
|
||||||
|
}
|
||||||
|
|
||||||
// Generic tests for PredEngineTrait behaviour across engines
|
// Generic tests for PredEngineTrait behaviour across engines
|
||||||
TEST(TraitTests, Frostbite_Pred_And_Mesh_And_Camera)
|
TEST(TraitTests, Frostbite_Pred_And_Mesh_And_Camera)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -53,6 +53,47 @@ TEST(PredEngineTrait, CalcViewpointFromAngles)
|
|||||||
EXPECT_NEAR(vp.z, 10.f, 1e-6f);
|
EXPECT_NEAR(vp.z, 10.f, 1e-6f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(PredEngineTrait, PredictProjectilePositionWithLaunchOffset)
|
||||||
|
{
|
||||||
|
projectile_prediction::Projectile p;
|
||||||
|
p.m_origin = {0.f, 0.f, 0.f};
|
||||||
|
p.m_launch_offset = {5.f, 3.f, -2.f};
|
||||||
|
p.m_launch_speed = 10.f;
|
||||||
|
p.m_gravity_scale = 1.f;
|
||||||
|
|
||||||
|
// At time=0, projectile should be at launch_pos = origin + offset
|
||||||
|
const auto pos_t0 = PredEngineTrait::predict_projectile_position(p, 0.f, 0.f, 0.f, 9.81f);
|
||||||
|
EXPECT_NEAR(pos_t0.x, 5.f, 1e-4f);
|
||||||
|
EXPECT_NEAR(pos_t0.y, 3.f, 1e-4f);
|
||||||
|
EXPECT_NEAR(pos_t0.z, -2.f, 1e-4f);
|
||||||
|
|
||||||
|
// At time=1 with zero pitch/yaw, should travel along X from the offset position
|
||||||
|
const auto pos_t1 = PredEngineTrait::predict_projectile_position(p, 0.f, 0.f, 1.f, 9.81f);
|
||||||
|
EXPECT_NEAR(pos_t1.x, 5.f + 10.f, 1e-3f);
|
||||||
|
EXPECT_NEAR(pos_t1.y, 3.f, 1e-3f);
|
||||||
|
EXPECT_NEAR(pos_t1.z, -2.f - 9.81f * 0.5f, 1e-3f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(PredEngineTrait, ZeroLaunchOffsetMatchesOriginalBehavior)
|
||||||
|
{
|
||||||
|
projectile_prediction::Projectile p;
|
||||||
|
p.m_origin = {10.f, 20.f, 30.f};
|
||||||
|
p.m_launch_offset = {0.f, 0.f, 0.f};
|
||||||
|
p.m_launch_speed = 15.f;
|
||||||
|
p.m_gravity_scale = 0.5f;
|
||||||
|
|
||||||
|
projectile_prediction::Projectile p_no_offset;
|
||||||
|
p_no_offset.m_origin = {10.f, 20.f, 30.f};
|
||||||
|
p_no_offset.m_launch_speed = 15.f;
|
||||||
|
p_no_offset.m_gravity_scale = 0.5f;
|
||||||
|
|
||||||
|
const auto pos1 = PredEngineTrait::predict_projectile_position(p, 30.f, 45.f, 2.f, 9.81f);
|
||||||
|
const auto pos2 = PredEngineTrait::predict_projectile_position(p_no_offset, 30.f, 45.f, 2.f, 9.81f);
|
||||||
|
EXPECT_NEAR(pos1.x, pos2.x, 1e-6f);
|
||||||
|
EXPECT_NEAR(pos1.y, pos2.y, 1e-6f);
|
||||||
|
EXPECT_NEAR(pos1.z, pos2.z, 1e-6f);
|
||||||
|
}
|
||||||
|
|
||||||
TEST(PredEngineTrait, DirectAngles)
|
TEST(PredEngineTrait, DirectAngles)
|
||||||
{
|
{
|
||||||
constexpr Vector3<float> origin{0.f, 0.f, 0.f};
|
constexpr Vector3<float> origin{0.f, 0.f, 0.f};
|
||||||
|
|||||||
@@ -16,3 +16,280 @@ TEST(UnitTestPrediction, PredictionTest)
|
|||||||
EXPECT_NEAR(-42.547142, pitch.as_degrees(), 0.01f);
|
EXPECT_NEAR(-42.547142, pitch.as_degrees(), 0.01f);
|
||||||
EXPECT_NEAR(-1.181189, yaw.as_degrees(), 0.01f);
|
EXPECT_NEAR(-1.181189, yaw.as_degrees(), 0.01f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper: verify aim_angles match angles derived from aim_point via CameraTrait
|
||||||
|
static void expect_angles_match_aim_point(const omath::projectile_prediction::Projectile& proj,
|
||||||
|
const omath::projectile_prediction::Target& target,
|
||||||
|
float gravity, float step, float max_time, float tolerance,
|
||||||
|
float angle_eps = 0.01f)
|
||||||
|
{
|
||||||
|
const omath::projectile_prediction::ProjPredEngineLegacy engine(gravity, step, max_time, tolerance);
|
||||||
|
|
||||||
|
const auto aim_point = engine.maybe_calculate_aim_point(proj, target);
|
||||||
|
const auto aim_angles = engine.maybe_calculate_aim_angles(proj, target);
|
||||||
|
|
||||||
|
ASSERT_TRUE(aim_point.has_value()) << "aim_point should have a solution";
|
||||||
|
ASSERT_TRUE(aim_angles.has_value()) << "aim_angles should have a solution";
|
||||||
|
|
||||||
|
// Source engine CameraTrait: pitch = -asin(dir.z), yaw = atan2(dir.y, dir.x)
|
||||||
|
// PredEngineTrait: pitch = asin(delta.z / dist), yaw = atan2(delta.y, delta.x)
|
||||||
|
// So aim_angles.pitch == -camera_pitch, aim_angles.yaw == camera_yaw
|
||||||
|
const auto [cam_pitch, cam_yaw, cam_roll] =
|
||||||
|
omath::source_engine::CameraTrait::calc_look_at_angle(proj.m_origin, aim_point.value());
|
||||||
|
|
||||||
|
EXPECT_NEAR(aim_angles->pitch, -cam_pitch.as_degrees(), angle_eps)
|
||||||
|
<< "pitch from aim_angles must match pitch derived from aim_point";
|
||||||
|
EXPECT_NEAR(aim_angles->yaw, cam_yaw.as_degrees(), angle_eps)
|
||||||
|
<< "yaw from aim_angles must match yaw derived from aim_point";
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(UnitTestPrediction, AimAnglesMatchAimPoint_StaticTarget)
|
||||||
|
{
|
||||||
|
constexpr omath::projectile_prediction::Target target{
|
||||||
|
.m_origin = {100, 0, 90}, .m_velocity = {0, 0, 0}, .m_is_airborne = false};
|
||||||
|
constexpr omath::projectile_prediction::Projectile proj = {
|
||||||
|
.m_origin = {3, 2, 1}, .m_launch_speed = 5000, .m_gravity_scale = 0.4};
|
||||||
|
|
||||||
|
expect_angles_match_aim_point(proj, target, 400, 1.f / 1000.f, 50, 5.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(UnitTestPrediction, AimAnglesMatchAimPoint_MovingTarget)
|
||||||
|
{
|
||||||
|
constexpr omath::projectile_prediction::Target target{
|
||||||
|
.m_origin = {500, 100, 0}, .m_velocity = {-50, 20, 0}, .m_is_airborne = false};
|
||||||
|
constexpr omath::projectile_prediction::Projectile proj = {
|
||||||
|
.m_origin = {0, 0, 0}, .m_launch_speed = 3000, .m_gravity_scale = 1.0};
|
||||||
|
|
||||||
|
expect_angles_match_aim_point(proj, target, 800, 1.f / 500.f, 30, 10.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(UnitTestPrediction, AimAnglesMatchAimPoint_AirborneTarget)
|
||||||
|
{
|
||||||
|
constexpr omath::projectile_prediction::Target target{
|
||||||
|
.m_origin = {200, 50, 300}, .m_velocity = {10, -5, -20}, .m_is_airborne = true};
|
||||||
|
constexpr omath::projectile_prediction::Projectile proj = {
|
||||||
|
.m_origin = {0, 0, 0}, .m_launch_speed = 4000, .m_gravity_scale = 0.5};
|
||||||
|
|
||||||
|
expect_angles_match_aim_point(proj, target, 400, 1.f / 1000.f, 50, 10.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(UnitTestPrediction, AimAnglesMatchAimPoint_HighArc)
|
||||||
|
{
|
||||||
|
// Target nearly directly above — high pitch angle
|
||||||
|
constexpr omath::projectile_prediction::Target target{
|
||||||
|
.m_origin = {10, 0, 500}, .m_velocity = {0, 0, 0}, .m_is_airborne = false};
|
||||||
|
constexpr omath::projectile_prediction::Projectile proj = {
|
||||||
|
.m_origin = {0, 0, 0}, .m_launch_speed = 5000, .m_gravity_scale = 0.3};
|
||||||
|
|
||||||
|
expect_angles_match_aim_point(proj, target, 400, 1.f / 1000.f, 50, 5.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(UnitTestPrediction, AimAnglesMatchAimPoint_NegativeYaw)
|
||||||
|
{
|
||||||
|
// Target behind and to the left — negative yaw quadrant
|
||||||
|
constexpr omath::projectile_prediction::Target target{
|
||||||
|
.m_origin = {-200, -150, 10}, .m_velocity = {0, 0, 0}, .m_is_airborne = false};
|
||||||
|
constexpr omath::projectile_prediction::Projectile proj = {
|
||||||
|
.m_origin = {0, 0, 0}, .m_launch_speed = 5000, .m_gravity_scale = 0.4};
|
||||||
|
|
||||||
|
expect_angles_match_aim_point(proj, target, 400, 1.f / 1000.f, 50, 5.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(UnitTestPrediction, AimAnglesMatchAimPoint_WithLaunchOffset)
|
||||||
|
{
|
||||||
|
constexpr omath::projectile_prediction::Target target{
|
||||||
|
.m_origin = {200, 0, 50}, .m_velocity = {0, 0, 0}, .m_is_airborne = false};
|
||||||
|
const omath::projectile_prediction::Projectile proj = {
|
||||||
|
.m_origin = {0, 0, 0}, .m_launch_offset = {5, 0, -3}, .m_launch_speed = 5000, .m_gravity_scale = 0.4};
|
||||||
|
|
||||||
|
expect_angles_match_aim_point(proj, target, 400, 1.f / 1000.f, 50, 5.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Helper: simulate projectile flight using aim_angles and verify it reaches the target.
|
||||||
|
// Steps the projectile forward in small increments, simultaneously predicts target position,
|
||||||
|
// and checks that the minimum distance is within hit_tolerance.
|
||||||
|
static void expect_projectile_hits_target(const omath::projectile_prediction::Projectile& proj,
|
||||||
|
const omath::projectile_prediction::Target& target,
|
||||||
|
float gravity, float engine_step, float max_time, float engine_tolerance,
|
||||||
|
float hit_tolerance, float sim_step = 1.f / 2000.f)
|
||||||
|
{
|
||||||
|
using Trait = omath::source_engine::PredEngineTrait;
|
||||||
|
const omath::projectile_prediction::ProjPredEngineLegacy engine(gravity, engine_step, max_time, engine_tolerance);
|
||||||
|
|
||||||
|
const auto aim_angles = engine.maybe_calculate_aim_angles(proj, target);
|
||||||
|
ASSERT_TRUE(aim_angles.has_value()) << "engine must find a solution";
|
||||||
|
|
||||||
|
float min_dist = std::numeric_limits<float>::max();
|
||||||
|
float best_time = 0.f;
|
||||||
|
|
||||||
|
for (float t = 0.f; t <= max_time; t += sim_step)
|
||||||
|
{
|
||||||
|
const auto proj_pos = Trait::predict_projectile_position(proj, aim_angles->pitch, aim_angles->yaw, t, gravity);
|
||||||
|
const auto tgt_pos = Trait::predict_target_position(target, t, gravity);
|
||||||
|
const float dist = proj_pos.distance_to(tgt_pos);
|
||||||
|
|
||||||
|
if (dist < min_dist)
|
||||||
|
{
|
||||||
|
min_dist = dist;
|
||||||
|
best_time = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Early exit once distance starts increasing significantly after approaching
|
||||||
|
if (dist > min_dist + hit_tolerance * 10.f && min_dist < hit_tolerance * 100.f)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
EXPECT_LE(min_dist, hit_tolerance)
|
||||||
|
<< "Projectile must reach target. Closest approach: " << min_dist
|
||||||
|
<< " at t=" << best_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Simulation hit tests: no launch offset ─────────────────────────────────
|
||||||
|
|
||||||
|
TEST(ProjectileSimulation, HitsStaticTarget_NoOffset)
|
||||||
|
{
|
||||||
|
constexpr omath::projectile_prediction::Target target{
|
||||||
|
.m_origin = {100, 0, 90}, .m_velocity = {0, 0, 0}, .m_is_airborne = false};
|
||||||
|
constexpr omath::projectile_prediction::Projectile proj = {
|
||||||
|
.m_origin = {3, 2, 1}, .m_launch_speed = 5000, .m_gravity_scale = 0.4};
|
||||||
|
|
||||||
|
expect_projectile_hits_target(proj, target, 400, 1.f / 1000.f, 50, 5.f, 10.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(ProjectileSimulation, HitsMovingTarget_NoOffset)
|
||||||
|
{
|
||||||
|
constexpr omath::projectile_prediction::Target target{
|
||||||
|
.m_origin = {500, 100, 0}, .m_velocity = {-50, 20, 0}, .m_is_airborne = false};
|
||||||
|
constexpr omath::projectile_prediction::Projectile proj = {
|
||||||
|
.m_origin = {0, 0, 0}, .m_launch_speed = 3000, .m_gravity_scale = 1.0};
|
||||||
|
|
||||||
|
expect_projectile_hits_target(proj, target, 800, 1.f / 500.f, 30, 10.f, 15.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(ProjectileSimulation, HitsAirborneTarget_NoOffset)
|
||||||
|
{
|
||||||
|
constexpr omath::projectile_prediction::Target target{
|
||||||
|
.m_origin = {200, 50, 300}, .m_velocity = {10, -5, -20}, .m_is_airborne = true};
|
||||||
|
constexpr omath::projectile_prediction::Projectile proj = {
|
||||||
|
.m_origin = {0, 0, 0}, .m_launch_speed = 4000, .m_gravity_scale = 0.5};
|
||||||
|
|
||||||
|
expect_projectile_hits_target(proj, target, 400, 1.f / 1000.f, 50, 10.f, 15.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(ProjectileSimulation, HitsHighTarget_NoOffset)
|
||||||
|
{
|
||||||
|
constexpr omath::projectile_prediction::Target target{
|
||||||
|
.m_origin = {10, 0, 500}, .m_velocity = {0, 0, 0}, .m_is_airborne = false};
|
||||||
|
constexpr omath::projectile_prediction::Projectile proj = {
|
||||||
|
.m_origin = {0, 0, 0}, .m_launch_speed = 5000, .m_gravity_scale = 0.3};
|
||||||
|
|
||||||
|
expect_projectile_hits_target(proj, target, 400, 1.f / 1000.f, 50, 5.f, 10.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(ProjectileSimulation, HitsNegativeYawTarget_NoOffset)
|
||||||
|
{
|
||||||
|
constexpr omath::projectile_prediction::Target target{
|
||||||
|
.m_origin = {-200, -150, 10}, .m_velocity = {0, 0, 0}, .m_is_airborne = false};
|
||||||
|
constexpr omath::projectile_prediction::Projectile proj = {
|
||||||
|
.m_origin = {0, 0, 0}, .m_launch_speed = 5000, .m_gravity_scale = 0.4};
|
||||||
|
|
||||||
|
expect_projectile_hits_target(proj, target, 400, 1.f / 1000.f, 50, 5.f, 10.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Simulation hit tests: with launch offset ────────────────────────────────
|
||||||
|
|
||||||
|
TEST(ProjectileSimulation, HitsStaticTarget_SmallOffset)
|
||||||
|
{
|
||||||
|
constexpr omath::projectile_prediction::Target target{
|
||||||
|
.m_origin = {200, 0, 50}, .m_velocity = {0, 0, 0}, .m_is_airborne = false};
|
||||||
|
const omath::projectile_prediction::Projectile proj = {
|
||||||
|
.m_origin = {0, 0, 0}, .m_launch_offset = {5, 0, -3}, .m_launch_speed = 5000, .m_gravity_scale = 0.4};
|
||||||
|
|
||||||
|
expect_projectile_hits_target(proj, target, 400, 1.f / 1000.f, 50, 5.f, 10.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(ProjectileSimulation, HitsStaticTarget_LargeXOffset)
|
||||||
|
{
|
||||||
|
constexpr omath::projectile_prediction::Target target{
|
||||||
|
.m_origin = {300, 100, 0}, .m_velocity = {0, 0, 0}, .m_is_airborne = false};
|
||||||
|
const omath::projectile_prediction::Projectile proj = {
|
||||||
|
.m_origin = {0, 0, 0}, .m_launch_offset = {20, 0, 0}, .m_launch_speed = 5000, .m_gravity_scale = 0.4};
|
||||||
|
|
||||||
|
expect_projectile_hits_target(proj, target, 400, 1.f / 1000.f, 50, 5.f, 10.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(ProjectileSimulation, HitsStaticTarget_LargeYOffset)
|
||||||
|
{
|
||||||
|
constexpr omath::projectile_prediction::Target target{
|
||||||
|
.m_origin = {150, -200, 30}, .m_velocity = {0, 0, 0}, .m_is_airborne = false};
|
||||||
|
const omath::projectile_prediction::Projectile proj = {
|
||||||
|
.m_origin = {0, 0, 0}, .m_launch_offset = {0, 15, 0}, .m_launch_speed = 5000, .m_gravity_scale = 0.4};
|
||||||
|
|
||||||
|
expect_projectile_hits_target(proj, target, 400, 1.f / 1000.f, 50, 5.f, 10.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(ProjectileSimulation, HitsStaticTarget_LargeZOffset)
|
||||||
|
{
|
||||||
|
constexpr omath::projectile_prediction::Target target{
|
||||||
|
.m_origin = {100, 0, 200}, .m_velocity = {0, 0, 0}, .m_is_airborne = false};
|
||||||
|
const omath::projectile_prediction::Projectile proj = {
|
||||||
|
.m_origin = {0, 0, 0}, .m_launch_offset = {0, 0, -10}, .m_launch_speed = 5000, .m_gravity_scale = 0.4};
|
||||||
|
|
||||||
|
expect_projectile_hits_target(proj, target, 400, 1.f / 1000.f, 50, 5.f, 10.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(ProjectileSimulation, HitsStaticTarget_AllAxesOffset)
|
||||||
|
{
|
||||||
|
constexpr omath::projectile_prediction::Target target{
|
||||||
|
.m_origin = {250, 80, 60}, .m_velocity = {0, 0, 0}, .m_is_airborne = false};
|
||||||
|
const omath::projectile_prediction::Projectile proj = {
|
||||||
|
.m_origin = {10, 5, 20}, .m_launch_offset = {8, -4, -6}, .m_launch_speed = 5000, .m_gravity_scale = 0.4};
|
||||||
|
|
||||||
|
expect_projectile_hits_target(proj, target, 400, 1.f / 1000.f, 50, 5.f, 10.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(ProjectileSimulation, HitsMovingTarget_WithOffset)
|
||||||
|
{
|
||||||
|
constexpr omath::projectile_prediction::Target target{
|
||||||
|
.m_origin = {400, 0, 50}, .m_velocity = {-30, 10, 5}, .m_is_airborne = false};
|
||||||
|
const omath::projectile_prediction::Projectile proj = {
|
||||||
|
.m_origin = {0, 0, 0}, .m_launch_offset = {10, -5, 2}, .m_launch_speed = 3000, .m_gravity_scale = 0.8};
|
||||||
|
|
||||||
|
expect_projectile_hits_target(proj, target, 800, 1.f / 500.f, 30, 10.f, 15.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(ProjectileSimulation, HitsAirborneTarget_WithOffset)
|
||||||
|
{
|
||||||
|
constexpr omath::projectile_prediction::Target target{
|
||||||
|
.m_origin = {150, 80, 250}, .m_velocity = {5, -10, -30}, .m_is_airborne = true};
|
||||||
|
const omath::projectile_prediction::Projectile proj = {
|
||||||
|
.m_origin = {0, 0, 50}, .m_launch_offset = {3, 7, -5}, .m_launch_speed = 4000, .m_gravity_scale = 0.5};
|
||||||
|
|
||||||
|
expect_projectile_hits_target(proj, target, 400, 1.f / 1000.f, 50, 10.f, 15.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(ProjectileSimulation, HitsNegativeYawTarget_WithOffset)
|
||||||
|
{
|
||||||
|
constexpr omath::projectile_prediction::Target target{
|
||||||
|
.m_origin = {-200, -150, 10}, .m_velocity = {0, 0, 0}, .m_is_airborne = false};
|
||||||
|
const omath::projectile_prediction::Projectile proj = {
|
||||||
|
.m_origin = {0, 0, 0}, .m_launch_offset = {-5, 3, 2}, .m_launch_speed = 5000, .m_gravity_scale = 0.4};
|
||||||
|
|
||||||
|
expect_projectile_hits_target(proj, target, 400, 1.f / 1000.f, 50, 5.f, 10.f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(UnitTestPrediction, AimAnglesReturnsNulloptWhenNoSolution)
|
||||||
|
{
|
||||||
|
constexpr omath::projectile_prediction::Target target{
|
||||||
|
.m_origin = {100000, 0, 0}, .m_velocity = {0, 0, 0}, .m_is_airborne = false};
|
||||||
|
constexpr omath::projectile_prediction::Projectile proj = {
|
||||||
|
.m_origin = {0, 0, 0}, .m_launch_speed = 1, .m_gravity_scale = 1};
|
||||||
|
|
||||||
|
const omath::projectile_prediction::ProjPredEngineLegacy engine(9.81f, 0.1f, 2.f, 5.f);
|
||||||
|
|
||||||
|
const auto aim_point = engine.maybe_calculate_aim_point(proj, target);
|
||||||
|
const auto aim_angles = engine.maybe_calculate_aim_angles(proj, target);
|
||||||
|
|
||||||
|
EXPECT_FALSE(aim_point.has_value());
|
||||||
|
EXPECT_FALSE(aim_angles.has_value());
|
||||||
|
}
|
||||||
|
|||||||
@@ -46,6 +46,22 @@ TEST(ProjPredLegacyMore, ZeroGravityUsesDirectPitchAndReturnsViewpoint)
|
|||||||
EXPECT_NEAR(v.z, 3.f, 1e-6f);
|
EXPECT_NEAR(v.z, 3.f, 1e-6f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(ProjPredLegacyMore, ZeroGravityAimAnglesReturnsPitchAndYaw)
|
||||||
|
{
|
||||||
|
constexpr Projectile proj{ .m_origin = {0.f, 0.f, 0.f}, .m_launch_speed = 10.f, .m_gravity_scale = 0.f };
|
||||||
|
constexpr Target target{ .m_origin = {100.f, 0.f, 0.f}, .m_velocity = {0.f,0.f,0.f}, .m_is_airborne = false };
|
||||||
|
|
||||||
|
using Engine = omath::projectile_prediction::ProjPredEngineLegacy<FakeEngineZeroGravity>;
|
||||||
|
const Engine engine(9.8f, 0.1f, 5.f, 1e-3f);
|
||||||
|
|
||||||
|
const auto res = engine.maybe_calculate_aim_angles(proj, target);
|
||||||
|
ASSERT_TRUE(res.has_value());
|
||||||
|
// FakeEngineZeroGravity::calc_direct_pitch_angle returns 12.5f
|
||||||
|
EXPECT_NEAR(res->pitch, 12.5f, 1e-6f);
|
||||||
|
// FakeEngineZeroGravity::calc_direct_yaw_angle returns 0.f
|
||||||
|
EXPECT_NEAR(res->yaw, 0.f, 1e-6f);
|
||||||
|
}
|
||||||
|
|
||||||
// Fake trait producing no valid launch angle (root < 0)
|
// Fake trait producing no valid launch angle (root < 0)
|
||||||
struct FakeEngineNoSolution
|
struct FakeEngineNoSolution
|
||||||
{
|
{
|
||||||
@@ -69,6 +85,9 @@ TEST(ProjPredLegacyMore, NoSolutionRootReturnsNullopt)
|
|||||||
|
|
||||||
const auto res = engine.maybe_calculate_aim_point(proj, target);
|
const auto res = engine.maybe_calculate_aim_point(proj, target);
|
||||||
EXPECT_FALSE(res.has_value());
|
EXPECT_FALSE(res.has_value());
|
||||||
|
|
||||||
|
const auto angles_res = engine.maybe_calculate_aim_angles(proj, target);
|
||||||
|
EXPECT_FALSE(angles_res.has_value());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fake trait where an angle exists but the projectile does not reach target (miss)
|
// Fake trait where an angle exists but the projectile does not reach target (miss)
|
||||||
|
|||||||
@@ -20,6 +20,13 @@ public:
|
|||||||
int m_health{123};
|
int m_health{123};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Extract a raw function pointer from an object's vtable
|
||||||
|
inline const void* get_vtable_entry(const void* obj, const std::size_t index)
|
||||||
|
{
|
||||||
|
const auto vtable = *static_cast<void* const* const*>(obj);
|
||||||
|
return vtable[index];
|
||||||
|
}
|
||||||
|
|
||||||
class RevPlayer final : omath::rev_eng::InternalReverseEngineeredObject
|
class RevPlayer final : omath::rev_eng::InternalReverseEngineeredObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -51,6 +58,17 @@ public:
|
|||||||
{
|
{
|
||||||
return call_virtual_method<1, int>();
|
return call_virtual_method<1, int>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wrappers exposing call_method for testing — use vtable entries as known-good function pointers
|
||||||
|
int call_foo_via_ptr(const void* fn_ptr) const
|
||||||
|
{
|
||||||
|
return call_method<int>(fn_ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
int call_bar_via_ptr(const void* fn_ptr) const
|
||||||
|
{
|
||||||
|
return call_method<int>(fn_ptr);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST(unit_test_reverse_enineering, read_test)
|
TEST(unit_test_reverse_enineering, read_test)
|
||||||
@@ -64,4 +82,39 @@ TEST(unit_test_reverse_enineering, read_test)
|
|||||||
EXPECT_EQ(player_original.bar(), player_reversed->rev_bar());
|
EXPECT_EQ(player_original.bar(), player_reversed->rev_bar());
|
||||||
EXPECT_EQ(player_original.foo(), player_reversed->rev_foo());
|
EXPECT_EQ(player_original.foo(), player_reversed->rev_foo());
|
||||||
EXPECT_EQ(player_original.bar(), player_reversed->rev_bar_const());
|
EXPECT_EQ(player_original.bar(), player_reversed->rev_bar_const());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(unit_test_reverse_enineering, call_method_with_vtable_ptr)
|
||||||
|
{
|
||||||
|
// Extract raw function pointers from Player's vtable, then call them via call_method
|
||||||
|
Player player;
|
||||||
|
const auto* rev = reinterpret_cast<const RevPlayer*>(&player);
|
||||||
|
|
||||||
|
const auto* foo_ptr = get_vtable_entry(&player, 0);
|
||||||
|
const auto* bar_ptr = get_vtable_entry(&player, 1);
|
||||||
|
|
||||||
|
EXPECT_EQ(player.foo(), rev->call_foo_via_ptr(foo_ptr));
|
||||||
|
EXPECT_EQ(player.bar(), rev->call_bar_via_ptr(bar_ptr));
|
||||||
|
EXPECT_EQ(1, rev->call_foo_via_ptr(foo_ptr));
|
||||||
|
EXPECT_EQ(2, rev->call_bar_via_ptr(bar_ptr));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(unit_test_reverse_enineering, call_method_same_result_as_virtual)
|
||||||
|
{
|
||||||
|
// call_virtual_method delegates to call_method — both paths must agree
|
||||||
|
Player player;
|
||||||
|
const auto* rev = reinterpret_cast<const RevPlayer*>(&player);
|
||||||
|
|
||||||
|
EXPECT_EQ(rev->rev_foo(), rev->call_foo_via_ptr(get_vtable_entry(&player, 0)));
|
||||||
|
EXPECT_EQ(rev->rev_bar(), rev->call_bar_via_ptr(get_vtable_entry(&player, 1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(unit_test_reverse_enineering, call_virtual_method_delegates_to_call_method)
|
||||||
|
{
|
||||||
|
Player player;
|
||||||
|
auto* rev = reinterpret_cast<RevPlayer*>(&player);
|
||||||
|
|
||||||
|
EXPECT_EQ(1, rev->rev_foo());
|
||||||
|
EXPECT_EQ(2, rev->rev_bar());
|
||||||
|
EXPECT_EQ(2, rev->rev_bar_const());
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user