mirror of
https://github.com/orange-cpp/omath.git
synced 2026-04-18 17:03:27 +00:00
added skeleton
This commit is contained in:
@@ -71,6 +71,11 @@ namespace imgui_desktop::gui
|
||||
float dash_len = 8.f, dash_gap = 5.f, dash_thickness = 1.f;
|
||||
bool show_dashed_box = false;
|
||||
|
||||
// Skeleton
|
||||
omath::Color skel_color = omath::Color::from_rgba(255, 255, 255, 200);
|
||||
float skel_thickness = 1.f;
|
||||
bool show_skeleton = false;
|
||||
|
||||
// Snap line
|
||||
omath::Color snap_color = omath::Color::from_rgba(255, 50, 50, 255);
|
||||
float snap_width = 1.5f;
|
||||
@@ -145,6 +150,13 @@ namespace imgui_desktop::gui
|
||||
ImGui::Checkbox("Centered bot##lbl", &show_centered_bottom);
|
||||
}
|
||||
|
||||
if (ImGui::CollapsingHeader("Skeleton"))
|
||||
{
|
||||
ImGui::Checkbox("Show##skel", &show_skeleton);
|
||||
ImGui::ColorEdit4("Color##skel", reinterpret_cast<float*>(&skel_color), ImGuiColorEditFlags_NoInputs);
|
||||
ImGui::SliderFloat("Thickness##skel", &skel_thickness, 0.5f, 5.f);
|
||||
}
|
||||
|
||||
if (ImGui::CollapsingHeader("Snap Line"))
|
||||
{
|
||||
ImGui::Checkbox("Show##snap", &show_snap);
|
||||
@@ -199,6 +211,9 @@ namespace imgui_desktop::gui
|
||||
if (show_bottom_labels)
|
||||
ent.add_bottom_label(omath::Color::from_rgba(200, 200, 0, 255), label_offset, outlined, "42m");
|
||||
|
||||
if (show_skeleton)
|
||||
ent.add_skeleton(skel_color, skel_thickness);
|
||||
|
||||
if (show_snap)
|
||||
ent.add_snap_line({viewport->Size.x / 2.f, viewport->Size.y}, snap_color, snap_width);
|
||||
|
||||
|
||||
@@ -58,6 +58,8 @@ namespace omath::hud
|
||||
void add_dashed_box(const Color& color, float dash_len = 8.f, float gap_len = 5.f,
|
||||
float thickness = 1.f) const;
|
||||
|
||||
void add_skeleton(const Color& color, float thickness = 1.f) const;
|
||||
|
||||
void add_bottom_bar(const Color& color, const Color& outline_color, const Color& bg_color, float height,
|
||||
float ratio, float offset = 5.f);
|
||||
|
||||
|
||||
@@ -122,6 +122,46 @@ namespace omath::hud
|
||||
+ Vector2<float>{m_canvas.bottom_right_corner.x - m_canvas.bottom_left_corner.x, 0.f} / 2;
|
||||
m_renderer->add_line(start_pos, line_end, color, width);
|
||||
}
|
||||
void EntityOverlay::add_skeleton(const Color& color, const float thickness) const
|
||||
{
|
||||
// Maps normalized (rx in [0,1], ry in [0,1]) to canvas screen position
|
||||
const auto joint = [&](const float rx, const float ry) -> Vector2<float>
|
||||
{
|
||||
const auto top = m_canvas.top_left_corner
|
||||
+ (m_canvas.top_right_corner - m_canvas.top_left_corner) * rx;
|
||||
const auto bot = m_canvas.bottom_left_corner
|
||||
+ (m_canvas.bottom_right_corner - m_canvas.bottom_left_corner) * rx;
|
||||
return top + (bot - top) * ry;
|
||||
};
|
||||
|
||||
using B = std::pair<std::pair<float,float>, std::pair<float,float>>;
|
||||
static constexpr std::array<B, 15> k_bones{{
|
||||
// Spine
|
||||
{{0.50f, 0.13f}, {0.50f, 0.22f}}, // head → neck
|
||||
{{0.50f, 0.22f}, {0.50f, 0.38f}}, // neck → chest
|
||||
{{0.50f, 0.38f}, {0.50f, 0.55f}}, // chest → pelvis
|
||||
// Left arm
|
||||
{{0.50f, 0.22f}, {0.25f, 0.25f}}, // neck → L shoulder
|
||||
{{0.25f, 0.25f}, {0.13f, 0.42f}}, // L shoulder → L elbow
|
||||
{{0.13f, 0.42f}, {0.08f, 0.56f}}, // L elbow → L hand
|
||||
// Right arm
|
||||
{{0.50f, 0.22f}, {0.75f, 0.25f}}, // neck → R shoulder
|
||||
{{0.75f, 0.25f}, {0.87f, 0.42f}}, // R shoulder → R elbow
|
||||
{{0.87f, 0.42f}, {0.92f, 0.56f}}, // R elbow → R hand
|
||||
// Left leg
|
||||
{{0.50f, 0.55f}, {0.36f, 0.58f}}, // pelvis → L hip
|
||||
{{0.36f, 0.58f}, {0.32f, 0.77f}}, // L hip → L knee
|
||||
{{0.32f, 0.77f}, {0.27f, 0.97f}}, // L knee → L foot
|
||||
// Right leg
|
||||
{{0.50f, 0.55f}, {0.64f, 0.58f}}, // pelvis → R hip
|
||||
{{0.64f, 0.58f}, {0.68f, 0.77f}}, // R hip → R knee
|
||||
{{0.68f, 0.77f}, {0.73f, 0.97f}}, // R knee → R foot
|
||||
}};
|
||||
|
||||
for (const auto& [a, b] : k_bones)
|
||||
m_renderer->add_line(joint(a.first, a.second), joint(b.first, b.second), color, thickness);
|
||||
}
|
||||
|
||||
void EntityOverlay::draw_dashed_line(const Vector2<float>& from, const Vector2<float>& to, const Color& color,
|
||||
const float dash_len, const float gap_len, const float thickness) const
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user