diff --git a/demo/demo/grid.cpp b/demo/demo/grid.cpp index 7f7d99b24efd6047f31b021934761fcfefbd0ac1..f600861913cd0b5973f38f1dc33bfe92d29cc2ec 100644 --- a/demo/demo/grid.cpp +++ b/demo/demo/grid.cpp @@ -55,6 +55,7 @@ namespace demo { } } + float progress = 0.0f; void GridScene::render(fggl::gfx::Graphics &gfx) { Game::render(gfx); @@ -67,6 +68,22 @@ namespace demo { paint.fill(hexTest); } + // draw test arcs + for (int sides = 0; sides < 12; ++sides) { + float endAngle = progress * (M_PI * 2); + + float startAngle = sides/12.0F * (M_PI * 2); + float endAngle2 = endAngle + startAngle; + + auto hexTest = fggl::gfx::make_arc(fggl::math::vec2{sides + 3, 7} * DRAW_SIZE, DRAW_HALF, startAngle, endAngle2, fggl::gfx::colours::CYAN); + paint.fill(hexTest); + } + + progress += 0.01F; + if ( progress > 1.0F) { + progress = 0.0F; + } + gfx.draw2D(paint); } diff --git a/include/fggl/gfx/paint.hpp b/include/fggl/gfx/paint.hpp index 06d10ba493bdd9de5f884b8a3bfa2850ab7405b8..4a9b27a5ec05cdf817d5825da6294d9f7890b3f9 100644 --- a/include/fggl/gfx/paint.hpp +++ b/include/fggl/gfx/paint.hpp @@ -97,7 +97,7 @@ namespace fggl::gfx { bool sinFirst = true; }; - inline Path2D make_shape(math::vec2 center, float radius, int sides, math::vec3 colour = {1.0f, 1.0f, 1.0f}, ShapeOpts opts = {}) { + inline Path2D make_shape(math::vec2 center, float radius, int sides, math::vec3 colour = colours::WHITE, ShapeOpts opts = {}) { double angle = (M_PI * 2.0) / sides; fggl::gfx::Path2D tileGfx(center); @@ -119,6 +119,31 @@ namespace fggl::gfx { return tileGfx; } + inline Path2D make_arc(math::vec2 center, float radius, float start, float end, math::vec3 colour = colours::WHITE, int slices = 25) { + const float angle = (M_PI * 2.0) / slices; + fggl::gfx::Path2D tileGfx(center); + + tileGfx.colour(colour); + tileGfx.moveTo(center); + for (float totalAngle = start; totalAngle < end; totalAngle += angle) { // NOLINT(cert-flp30-c) + float xPos = (float)(sinf(totalAngle) * radius) + center.x; + float yPos = (float)(cosf(totalAngle) * radius) + center.y; + tileGfx.pathTo({xPos, yPos}); + if ( (totalAngle + angle) > end) { + break; + } + } + + { + float xPos = (float) (sinf(end) * radius) + center.x; + float yPos = (float) (cosf(end) * radius) + center.y; + tileGfx.pathTo( {xPos, yPos} ); + } + + tileGfx.close(); + return tileGfx; + } + enum class PaintType { FILL, STROKE