added obround might need to optomize or add rotation in the futrue

This commit is contained in:
herbglitch 2023-06-25 16:17:04 -06:00
parent 092908819d
commit c3361f640c
5 changed files with 91 additions and 0 deletions

View file

@ -0,0 +1,46 @@
#ifdef ARC_SDL
#include "arc/graphics/obround.h"
#include "arc/graphics/sdl/renderer.h"
#include <stdlib.h>
//Modified from https://stackoverflow.com/questions/38334081/how-to-draw-circles-arcs-and-vector-graphics-in-sdl
void ARC_Obround_Render(ARC_Obround *obround, ARC_Renderer *renderer, ARC_Color *color){
SDL_SetRenderDrawColor((SDL_Renderer *)renderer, color->r, color->g, color->b, color->a);
int32_t diameter = (obround->r * 2);
int32_t x = (obround->r - 1);
int32_t y = 0;
int32_t tx = 1;
int32_t ty = 1;
int32_t error = (tx - diameter);
SDL_RenderDrawLine((SDL_Renderer *)renderer, obround->x - obround->r, obround->y - (obround->h / 2), obround->x - obround->r, obround->y + (obround->h / 2));
SDL_RenderDrawLine((SDL_Renderer *)renderer, obround->x + obround->r, obround->y - (obround->h / 2), obround->x + obround->r, obround->y + (obround->h / 2));
while(x >= y){
// Each of the following renders an octant of the circle
SDL_RenderDrawPoint((SDL_Renderer *)renderer, obround->x + x, obround->y - y - (obround->h / 2));
SDL_RenderDrawPoint((SDL_Renderer *)renderer, obround->x + x, obround->y + y + (obround->h / 2));
SDL_RenderDrawPoint((SDL_Renderer *)renderer, obround->x - x, obround->y - y - (obround->h / 2));
SDL_RenderDrawPoint((SDL_Renderer *)renderer, obround->x - x, obround->y + y + (obround->h / 2));
SDL_RenderDrawPoint((SDL_Renderer *)renderer, obround->x + y, obround->y - x - (obround->h / 2));
SDL_RenderDrawPoint((SDL_Renderer *)renderer, obround->x + y, obround->y + x + (obround->h / 2));
SDL_RenderDrawPoint((SDL_Renderer *)renderer, obround->x - y, obround->y - x - (obround->h / 2));
SDL_RenderDrawPoint((SDL_Renderer *)renderer, obround->x - y, obround->y + x + (obround->h / 2));
if(error <= 0){
++y;
error += ty;
ty += 2;
}
if(error > 0){
--x;
tx += 2;
error += (tx - diameter);
}
}
}
#endif // ARC_SDL