From b8e61f49fa651e8051a6f46a46b888fd872b57a9 Mon Sep 17 00:00:00 2001 From: orange Date: Tue, 17 Mar 2026 19:36:35 +0300 Subject: [PATCH] add projectile --- examples/example_hud/gui/main_window.cpp | 12 +++++++++ examples/example_hud/gui/main_window.hpp | 8 ++++++ include/omath/hud/entity_overlay.hpp | 1 + include/omath/hud/entity_overlay_widgets.hpp | 14 ++++++++++ source/hud/entity_overlay.cpp | 28 +++++++++++++++++--- 5 files changed, 59 insertions(+), 4 deletions(-) diff --git a/examples/example_hud/gui/main_window.cpp b/examples/example_hud/gui/main_window.cpp index 4a71f0c4..7b12ffb0 100644 --- a/examples/example_hud/gui/main_window.cpp +++ b/examples/example_hud/gui/main_window.cpp @@ -164,6 +164,17 @@ namespace imgui_desktop::gui 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(&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")) { ImGui::Checkbox("Show##snap", &m_show_snap); @@ -235,6 +246,7 @@ namespace imgui_desktop::gui 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_proj, ProjectileAim{{m_proj_pos_x, m_proj_pos_y}, m_proj_color, m_proj_size, m_proj_line_width, static_cast(m_proj_figure)}), when(m_show_snap, SnapLine{{vp->Size.x / 2.f, vp->Size.y}, m_snap_color, m_snap_width})); } diff --git a/examples/example_hud/gui/main_window.hpp b/examples/example_hud/gui/main_window.hpp index 8b622bf2..cef9ee0f 100644 --- a/examples/example_hud/gui/main_window.hpp +++ b/examples/example_hud/gui/main_window.hpp @@ -82,5 +82,13 @@ namespace imgui_desktop::gui omath::Color m_snap_color = omath::Color::from_rgba(255, 50, 50, 255); float m_snap_width = 1.5f; 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 diff --git a/include/omath/hud/entity_overlay.hpp b/include/omath/hud/entity_overlay.hpp index 94d076c5..4aa2e96e 100644 --- a/include/omath/hud/entity_overlay.hpp +++ b/include/omath/hud/entity_overlay.hpp @@ -183,6 +183,7 @@ namespace omath::hud 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& center, const widget::ProgressRing& ring); void draw_outlined_text(const Vector2& position, const Color& color, const std::string_view& text); void draw_dashed_line(const Vector2& from, const Vector2& to, const Color& color, float dash_len, diff --git a/include/omath/hud/entity_overlay_widgets.hpp b/include/omath/hud/entity_overlay_widgets.hpp index 52757bab..a895494a 100644 --- a/include/omath/hud/entity_overlay_widgets.hpp +++ b/include/omath/hud/entity_overlay_widgets.hpp @@ -71,6 +71,20 @@ namespace omath::hud::widget Color color; float radius = 3.f; }; + struct ProjectileAim + { + enum class Figure + { + CIRCLE, + SQUARE, + }; + Vector2 position; + Color color; + float size = 3.f; + float line_size = 1.f; + Figure figure = Figure::SQUARE; + }; + // ── Side-agnostic widgets (used inside XxxSide containers) ──────────────── diff --git a/source/hud/entity_overlay.cpp b/source/hud/entity_overlay.cpp index c866427f..9181df47 100644 --- a/source/hud/entity_overlay.cpp +++ b/source/hud/entity_overlay.cpp @@ -553,7 +553,7 @@ namespace omath::hud // ── Icons ──────────────────────────────────────────────────────────────────── EntityOverlay& EntityOverlay::add_right_icon(const std::any& texture_id, const float width, const float height, - const Color& tint, const float offset) + const Color& tint, const float offset) { const auto pos = m_text_cursor_right + Vector2{offset, 0.f}; m_renderer->add_image(texture_id, pos, pos + Vector2{width, height}, tint); @@ -562,7 +562,7 @@ namespace omath::hud } EntityOverlay& EntityOverlay::add_left_icon(const std::any& texture_id, const float width, const float height, - const Color& tint, const float offset) + const Color& tint, const float offset) { const auto pos = m_text_cursor_left + Vector2{-(offset + width), 0.f}; m_renderer->add_image(texture_id, pos, pos + Vector2{width, height}, tint); @@ -571,7 +571,7 @@ namespace omath::hud } EntityOverlay& EntityOverlay::add_top_icon(const std::any& texture_id, const float width, const float height, - const Color& tint, const float offset) + const Color& tint, const float offset) { m_text_cursor_top.y -= height; const auto pos = m_text_cursor_top + Vector2{0.f, -offset}; @@ -580,7 +580,7 @@ namespace omath::hud } EntityOverlay& EntityOverlay::add_bottom_icon(const std::any& texture_id, const float width, const float height, - const Color& tint, const float offset) + const Color& tint, const float offset) { const auto pos = m_text_cursor_bottom + Vector2{0.f, offset}; m_renderer->add_image(texture_id, pos, pos + Vector2{width, height}, tint); @@ -641,6 +641,26 @@ namespace omath::hud { 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); + } + else 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); + } + } void EntityOverlay::draw_progress_ring(const Vector2& center, const widget::ProgressRing& ring) {