diff --git a/libs/gfx/include/psemek/gfx/painter.hpp b/libs/gfx/include/psemek/gfx/painter.hpp index 02c86d22..52f1ce4b 100644 --- a/libs/gfx/include/psemek/gfx/painter.hpp +++ b/libs/gfx/include/psemek/gfx/painter.hpp @@ -60,6 +60,7 @@ namespace psemek::gfx // 3D void axes(geom::point const & p, float length, float width); void sphere(geom::point const & p, float radius, color const & c, int quality = 6); + void line3d(geom::point const & p0, geom::point const & p1, float width, color const & c); void text3d(geom::point const & p, std::string_view str, text_options const & opts, geom::matrix const & transform); // Should be called on each frame diff --git a/libs/gfx/source/painter.cpp b/libs/gfx/source/painter.cpp index 350593c3..5a67ff13 100644 --- a/libs/gfx/source/painter.cpp +++ b/libs/gfx/source/painter.cpp @@ -356,6 +356,27 @@ namespace psemek::gfx } } + void painter::line3d(geom::point const & p0, geom::point const & p1, float width, color const & c) + { + std::uint32_t const base = impl().vertices.size(); + float const r = width / 2.f; + + auto const d = geom::normalized(p1 - p0); + geom::vector const o { -d[1], d[0], 0.f }; + + impl().vertices.push_back({{p0[0] + r * o[0], p0[1] + r * o[1], p0[2]}, c}); + impl().vertices.push_back({{p0[0] - r * o[0], p0[1] - r * o[1], p0[2]}, c}); + impl().vertices.push_back({{p1[0] + r * o[0], p1[1] + r * o[1], p1[2]}, c}); + impl().vertices.push_back({{p1[0] - r * o[0], p1[1] - r * o[1], p1[2]}, c}); + + impl().indices.push_back(base + 0); + impl().indices.push_back(base + 1); + impl().indices.push_back(base + 3); + impl().indices.push_back(base + 0); + impl().indices.push_back(base + 3); + impl().indices.push_back(base + 2); + } + void painter::text3d(geom::point const & p, std::string_view str, text_options const & opts, geom::matrix const & t) { auto const size = text_size(str, opts.f, opts.scale);