Add 3D line painting
This commit is contained in:
parent
dbc429eaa7
commit
e73da04a31
2 changed files with 22 additions and 0 deletions
|
|
@ -60,6 +60,7 @@ namespace psemek::gfx
|
|||
// 3D
|
||||
void axes(geom::point<float, 3> const & p, float length, float width);
|
||||
void sphere(geom::point<float, 3> const & p, float radius, color const & c, int quality = 6);
|
||||
void line3d(geom::point<float, 3> const & p0, geom::point<float, 3> const & p1, float width, color const & c);
|
||||
void text3d(geom::point<float, 3> const & p, std::string_view str, text_options const & opts, geom::matrix<float, 3, 3> const & transform);
|
||||
|
||||
// Should be called on each frame
|
||||
|
|
|
|||
|
|
@ -356,6 +356,27 @@ namespace psemek::gfx
|
|||
}
|
||||
}
|
||||
|
||||
void painter::line3d(geom::point<float, 3> const & p0, geom::point<float, 3> 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<float, 3> 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<float, 3> const & p, std::string_view str, text_options const & opts, geom::matrix<float, 3, 3> const & t)
|
||||
{
|
||||
auto const size = text_size(str, opts.f, opts.scale);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue