Skip to content
Snippets Groups Projects
Commit 89f75b27 authored by Joseph Walton-Rivers's avatar Joseph Walton-Rivers
Browse files

added some arc-generation code for use as progress bars

parent df9139fb
No related branches found
No related tags found
No related merge requests found
......@@ -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);
}
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment