ADDED: DrawCircleSector()
This commit is contained in:
parent
e46c23128e
commit
297dd641e8
2 changed files with 49 additions and 39 deletions
|
@ -1033,6 +1033,7 @@ RLAPI void DrawLineV(Vector2 startPos, Vector2 endPos, Color color);
|
||||||
RLAPI void DrawLineEx(Vector2 startPos, Vector2 endPos, float thick, Color color); // Draw a line defining thickness
|
RLAPI void DrawLineEx(Vector2 startPos, Vector2 endPos, float thick, Color color); // Draw a line defining thickness
|
||||||
RLAPI void DrawLineBezier(Vector2 startPos, Vector2 endPos, float thick, Color color); // Draw a line using cubic-bezier curves in-out
|
RLAPI void DrawLineBezier(Vector2 startPos, Vector2 endPos, float thick, Color color); // Draw a line using cubic-bezier curves in-out
|
||||||
RLAPI void DrawCircle(int centerX, int centerY, float radius, Color color); // Draw a color-filled circle
|
RLAPI void DrawCircle(int centerX, int centerY, float radius, Color color); // Draw a color-filled circle
|
||||||
|
RLAPI void DrawCircleSector(Vector2 center, float radius, int startAngle, int endAngle, Color color); // Draw a piece of a circle
|
||||||
RLAPI void DrawCircleGradient(int centerX, int centerY, float radius, Color color1, Color color2); // Draw a gradient-filled circle
|
RLAPI void DrawCircleGradient(int centerX, int centerY, float radius, Color color1, Color color2); // Draw a gradient-filled circle
|
||||||
RLAPI void DrawCircleV(Vector2 center, float radius, Color color); // Draw a color-filled circle (Vector version)
|
RLAPI void DrawCircleV(Vector2 center, float radius, Color color); // Draw a color-filled circle (Vector version)
|
||||||
RLAPI void DrawCircleLines(int centerX, int centerY, float radius, Color color); // Draw circle outline
|
RLAPI void DrawCircleLines(int centerX, int centerY, float radius, Color color); // Draw circle outline
|
||||||
|
|
87
src/shapes.c
87
src/shapes.c
|
@ -182,6 +182,53 @@ void DrawCircle(int centerX, int centerY, float radius, Color color)
|
||||||
DrawCircleV((Vector2){ (float)centerX, (float)centerY }, radius, color);
|
DrawCircleV((Vector2){ (float)centerX, (float)centerY }, radius, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw a piece of a circle
|
||||||
|
// TODO: Support better angle resolution (now limited to CIRCLE_SECTOR_LENGTH)
|
||||||
|
void DrawCircleSector(Vector2 center, float radius, int startAngle, int endAngle, Color color)
|
||||||
|
{
|
||||||
|
#define CIRCLE_SECTOR_LENGTH 10
|
||||||
|
|
||||||
|
#if defined(SUPPORT_QUADS_DRAW_MODE)
|
||||||
|
if (rlCheckBufferLimit(4*((360/CIRCLE_SECTOR_LENGTH)/2))) rlglDraw();
|
||||||
|
|
||||||
|
rlEnableTexture(GetShapesTexture().id);
|
||||||
|
|
||||||
|
rlBegin(RL_QUADS);
|
||||||
|
for (int i = startAngle; i < endAngle; i += CIRCLE_SECTOR_LENGTH*2)
|
||||||
|
{
|
||||||
|
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||||
|
|
||||||
|
rlTexCoord2f(recTexShapes.x/texShapes.width, recTexShapes.y/texShapes.height);
|
||||||
|
rlVertex2f(center.x, center.y);
|
||||||
|
|
||||||
|
rlTexCoord2f(recTexShapes.x/texShapes.width, (recTexShapes.y + recTexShapes.height)/texShapes.height);
|
||||||
|
rlVertex2f(center.x + sinf(DEG2RAD*i)*radius, center.y + cosf(DEG2RAD*i)*radius);
|
||||||
|
|
||||||
|
rlTexCoord2f((recTexShapes.x + recTexShapes.width)/texShapes.width, (recTexShapes.y + recTexShapes.height)/texShapes.height);
|
||||||
|
rlVertex2f(center.x + sinf(DEG2RAD*(i + CIRCLE_SECTOR_LENGTH))*radius, center.y + cosf(DEG2RAD*(i + CIRCLE_SECTOR_LENGTH))*radius);
|
||||||
|
|
||||||
|
rlTexCoord2f((recTexShapes.x + recTexShapes.width)/texShapes.width, recTexShapes.y/texShapes.height);
|
||||||
|
rlVertex2f(center.x + sinf(DEG2RAD*(i + CIRCLE_SECTOR_LENGTH*2))*radius, center.y + cosf(DEG2RAD*(i + CIRCLE_SECTOR_LENGTH*2))*radius);
|
||||||
|
}
|
||||||
|
rlEnd();
|
||||||
|
|
||||||
|
rlDisableTexture();
|
||||||
|
#else
|
||||||
|
if (rlCheckBufferLimit(3*((360/CIRCLE_SECTOR_LENGTH)/2))) rlglDraw();
|
||||||
|
|
||||||
|
rlBegin(RL_TRIANGLES);
|
||||||
|
for (int i = startAngle; i < endAngle; i += CIRCLE_SECTOR_LENGTH)
|
||||||
|
{
|
||||||
|
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||||
|
|
||||||
|
rlVertex2f(center.x, center.y);
|
||||||
|
rlVertex2f(center.x + sinf(DEG2RAD*i)*radius, center.y + cosf(DEG2RAD*i)*radius);
|
||||||
|
rlVertex2f(center.x + sinf(DEG2RAD*(i + CIRCLE_SECTOR_LENGTH))*radius, center.y + cosf(DEG2RAD*(i + CIRCLE_SECTOR_LENGTH))*radius);
|
||||||
|
}
|
||||||
|
rlEnd();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// Draw a gradient-filled circle
|
// Draw a gradient-filled circle
|
||||||
// NOTE: Gradient goes from center (color1) to border (color2)
|
// NOTE: Gradient goes from center (color1) to border (color2)
|
||||||
void DrawCircleGradient(int centerX, int centerY, float radius, Color color1, Color color2)
|
void DrawCircleGradient(int centerX, int centerY, float radius, Color color1, Color color2)
|
||||||
|
@ -205,45 +252,7 @@ void DrawCircleGradient(int centerX, int centerY, float radius, Color color1, Co
|
||||||
// NOTE: On OpenGL 3.3 and ES2 we use QUADS to avoid drawing order issues (view rlglDraw)
|
// NOTE: On OpenGL 3.3 and ES2 we use QUADS to avoid drawing order issues (view rlglDraw)
|
||||||
void DrawCircleV(Vector2 center, float radius, Color color)
|
void DrawCircleV(Vector2 center, float radius, Color color)
|
||||||
{
|
{
|
||||||
#if defined(SUPPORT_QUADS_DRAW_MODE)
|
DrawCircleSector(center, radius, 0, 360, color);
|
||||||
if (rlCheckBufferLimit(4*(36/2))) rlglDraw();
|
|
||||||
|
|
||||||
rlEnableTexture(GetShapesTexture().id);
|
|
||||||
|
|
||||||
rlBegin(RL_QUADS);
|
|
||||||
for (int i = 0; i < 360; i += 20)
|
|
||||||
{
|
|
||||||
rlColor4ub(color.r, color.g, color.b, color.a);
|
|
||||||
|
|
||||||
rlTexCoord2f(recTexShapes.x/texShapes.width, recTexShapes.y/texShapes.height);
|
|
||||||
rlVertex2f(center.x, center.y);
|
|
||||||
|
|
||||||
rlTexCoord2f(recTexShapes.x/texShapes.width, (recTexShapes.y + recTexShapes.height)/texShapes.height);
|
|
||||||
rlVertex2f(center.x + sinf(DEG2RAD*i)*radius, center.y + cosf(DEG2RAD*i)*radius);
|
|
||||||
|
|
||||||
rlTexCoord2f((recTexShapes.x + recTexShapes.width)/texShapes.width, (recTexShapes.y + recTexShapes.height)/texShapes.height);
|
|
||||||
rlVertex2f(center.x + sinf(DEG2RAD*(i + 10))*radius, center.y + cosf(DEG2RAD*(i + 10))*radius);
|
|
||||||
|
|
||||||
rlTexCoord2f((recTexShapes.x + recTexShapes.width)/texShapes.width, recTexShapes.y/texShapes.height);
|
|
||||||
rlVertex2f(center.x + sinf(DEG2RAD*(i + 20))*radius, center.y + cosf(DEG2RAD*(i + 20))*radius);
|
|
||||||
}
|
|
||||||
rlEnd();
|
|
||||||
|
|
||||||
rlDisableTexture();
|
|
||||||
#else
|
|
||||||
if (rlCheckBufferLimit(3*(36/2))) rlglDraw();
|
|
||||||
|
|
||||||
rlBegin(RL_TRIANGLES);
|
|
||||||
for (int i = 0; i < 360; i += 10)
|
|
||||||
{
|
|
||||||
rlColor4ub(color.r, color.g, color.b, color.a);
|
|
||||||
|
|
||||||
rlVertex2f(center.x, center.y);
|
|
||||||
rlVertex2f(center.x + sinf(DEG2RAD*i)*radius, center.y + cosf(DEG2RAD*i)*radius);
|
|
||||||
rlVertex2f(center.x + sinf(DEG2RAD*(i + 10))*radius, center.y + cosf(DEG2RAD*(i + 10))*radius);
|
|
||||||
}
|
|
||||||
rlEnd();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw circle outline
|
// Draw circle outline
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue