Skip to content

Instantly share code, notes, and snippets.

@SpexGuy
Created September 4, 2023 13:49
Show Gist options
  • Save SpexGuy/12b6f0d9c4b97592d40f251af5c04695 to your computer and use it in GitHub Desktop.
Save SpexGuy/12b6f0d9c4b97592d40f251af5c04695 to your computer and use it in GitHub Desktop.
DrawCircle with quads, saving previous corner position
rlBegin(RL_QUADS);
float lastCornerX = center.x + cosf(DEG2RAD*angle)*radius;
float lastCornerY = center.y + sinf(DEG2RAD*angle)*radius;
// NOTE: Every QUAD actually represents two segments
for (int i = 0; i < segments/2; i++)
{
float nextAngle = angle + stepLength*2.0f;
float nextCornerX = center.x + cosf(DEG2RAD*(nextAngle))*radius;
float nextCornerY = center.y + sinf(DEG2RAD*(nextAngle))*radius;
rlColor4ub(color.r, color.g, color.b, color.a);
rlTexCoord2f(texShapesRec.x/texShapes.width, texShapesRec.y/texShapes.height);
rlVertex2f(center.x, center.y);
rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, texShapesRec.y/texShapes.height);
rlVertex2f(nextCornerX, nextCornerY);
rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height);
rlVertex2f(center.x + cosf(DEG2RAD*(angle + stepLength))*radius, center.y + sinf(DEG2RAD*(angle + stepLength))*radius);
rlTexCoord2f(texShapesRec.x/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height);
rlVertex2f(lastCornerX, lastCornerY);
lastCornerX = nextCornerX;
lastCornerY = nextCornerY;
angle = nextAngle;
}
// NOTE: In case number of segments is odd, we add one last piece to the cake
if ((segments%2) == 1)
{
rlColor4ub(color.r, color.g, color.b, color.a);
rlTexCoord2f(texShapesRec.x/texShapes.width, texShapesRec.y/texShapes.height);
rlVertex2f(center.x, center.y);
rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height);
rlVertex2f(center.x + cosf(DEG2RAD*(angle + stepLength))*radius, center.y + sinf(DEG2RAD*(angle + stepLength))*radius);
rlTexCoord2f(texShapesRec.x/texShapes.width, (texShapesRec.y + texShapesRec.height)/texShapes.height);
rlVertex2f(lastCornerX, lastCornerY);
rlTexCoord2f((texShapesRec.x + texShapesRec.width)/texShapes.width, texShapesRec.y/texShapes.height);
rlVertex2f(center.x, center.y);
}
rlEnd();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment