Changed DrawRing and DrawCircleSector angle params from int to float to allow greater accuracy. (#1656)
Co-authored-by: Simon <simon@frithrah.com>
This commit is contained in:
parent
7a566a07ea
commit
2f367a905e
4 changed files with 26 additions and 26 deletions
|
@ -28,8 +28,8 @@ int main(void)
|
||||||
Vector2 center = {(GetScreenWidth() - 300)/2, GetScreenHeight()/2 };
|
Vector2 center = {(GetScreenWidth() - 300)/2, GetScreenHeight()/2 };
|
||||||
|
|
||||||
float outerRadius = 180.0f;
|
float outerRadius = 180.0f;
|
||||||
int startAngle = 0;
|
float startAngle = 0.0f;
|
||||||
int endAngle = 180;
|
float endAngle = 180.0f;
|
||||||
int segments = 0;
|
int segments = 0;
|
||||||
|
|
||||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||||
|
|
|
@ -30,8 +30,8 @@ int main(void)
|
||||||
float innerRadius = 80.0f;
|
float innerRadius = 80.0f;
|
||||||
float outerRadius = 190.0f;
|
float outerRadius = 190.0f;
|
||||||
|
|
||||||
int startAngle = 0;
|
float startAngle = 0.0f;
|
||||||
int endAngle = 360;
|
float endAngle = 360.0f;
|
||||||
int segments = 0;
|
int segments = 0;
|
||||||
|
|
||||||
bool drawRing = true;
|
bool drawRing = true;
|
||||||
|
|
|
@ -1098,15 +1098,15 @@ RLAPI void DrawLineBezier(Vector2 startPos, Vector2 endPos, float thick, Color c
|
||||||
RLAPI void DrawLineBezierQuad(Vector2 startPos, Vector2 endPos, Vector2 controlPos, float thick, Color color); //Draw line using quadratic bezier curves with a control point
|
RLAPI void DrawLineBezierQuad(Vector2 startPos, Vector2 endPos, Vector2 controlPos, float thick, Color color); //Draw line using quadratic bezier curves with a control point
|
||||||
RLAPI void DrawLineStrip(Vector2 *points, int pointsCount, Color color); // Draw lines sequence
|
RLAPI void DrawLineStrip(Vector2 *points, int pointsCount, Color color); // Draw lines sequence
|
||||||
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, int segments, Color color); // Draw a piece of a circle
|
RLAPI void DrawCircleSector(Vector2 center, float radius, float startAngle, float endAngle, int segments, Color color); // Draw a piece of a circle
|
||||||
RLAPI void DrawCircleSectorLines(Vector2 center, float radius, int startAngle, int endAngle, int segments, Color color); // Draw circle sector outline
|
RLAPI void DrawCircleSectorLines(Vector2 center, float radius, float startAngle, float endAngle, int segments, Color color); // Draw circle sector outline
|
||||||
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
|
||||||
RLAPI void DrawEllipse(int centerX, int centerY, float radiusH, float radiusV, Color color); // Draw ellipse
|
RLAPI void DrawEllipse(int centerX, int centerY, float radiusH, float radiusV, Color color); // Draw ellipse
|
||||||
RLAPI void DrawEllipseLines(int centerX, int centerY, float radiusH, float radiusV, Color color); // Draw ellipse outline
|
RLAPI void DrawEllipseLines(int centerX, int centerY, float radiusH, float radiusV, Color color); // Draw ellipse outline
|
||||||
RLAPI void DrawRing(Vector2 center, float innerRadius, float outerRadius, int startAngle, int endAngle, int segments, Color color); // Draw ring
|
RLAPI void DrawRing(Vector2 center, float innerRadius, float outerRadius, float startAngle, float endAngle, int segments, Color color); // Draw ring
|
||||||
RLAPI void DrawRingLines(Vector2 center, float innerRadius, float outerRadius, int startAngle, int endAngle, int segments, Color color); // Draw ring outline
|
RLAPI void DrawRingLines(Vector2 center, float innerRadius, float outerRadius, float startAngle, float endAngle, int segments, Color color); // Draw ring outline
|
||||||
RLAPI void DrawRectangle(int posX, int posY, int width, int height, Color color); // Draw a color-filled rectangle
|
RLAPI void DrawRectangle(int posX, int posY, int width, int height, Color color); // Draw a color-filled rectangle
|
||||||
RLAPI void DrawRectangleV(Vector2 position, Vector2 size, Color color); // Draw a color-filled rectangle (Vector version)
|
RLAPI void DrawRectangleV(Vector2 position, Vector2 size, Color color); // Draw a color-filled rectangle (Vector version)
|
||||||
RLAPI void DrawRectangleRec(Rectangle rec, Color color); // Draw a color-filled rectangle
|
RLAPI void DrawRectangleRec(Rectangle rec, Color color); // Draw a color-filled rectangle
|
||||||
|
|
36
src/shapes.c
36
src/shapes.c
|
@ -205,7 +205,7 @@ void DrawCircle(int centerX, int centerY, float radius, Color color)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw a piece of a circle
|
// Draw a piece of a circle
|
||||||
void DrawCircleSector(Vector2 center, float radius, int startAngle, int endAngle, int segments, Color color)
|
void DrawCircleSector(Vector2 center, float radius, float startAngle, float endAngle, int segments, Color color)
|
||||||
{
|
{
|
||||||
if (radius <= 0.0f) radius = 0.1f; // Avoid div by zero
|
if (radius <= 0.0f) radius = 0.1f; // Avoid div by zero
|
||||||
|
|
||||||
|
@ -213,7 +213,7 @@ void DrawCircleSector(Vector2 center, float radius, int startAngle, int endAngle
|
||||||
if (endAngle < startAngle)
|
if (endAngle < startAngle)
|
||||||
{
|
{
|
||||||
// Swap values
|
// Swap values
|
||||||
int tmp = startAngle;
|
float tmp = startAngle;
|
||||||
startAngle = endAngle;
|
startAngle = endAngle;
|
||||||
endAngle = tmp;
|
endAngle = tmp;
|
||||||
}
|
}
|
||||||
|
@ -227,8 +227,8 @@ void DrawCircleSector(Vector2 center, float radius, int startAngle, int endAngle
|
||||||
if (segments <= 0) segments = 4;
|
if (segments <= 0) segments = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
float stepLength = (float)(endAngle - startAngle)/(float)segments;
|
float stepLength = (endAngle - startAngle)/(float)segments;
|
||||||
float angle = (float)startAngle;
|
float angle = startAngle;
|
||||||
|
|
||||||
#if defined(SUPPORT_QUADS_DRAW_MODE)
|
#if defined(SUPPORT_QUADS_DRAW_MODE)
|
||||||
if (rlCheckBufferLimit(4*segments/2)) rlglDraw();
|
if (rlCheckBufferLimit(4*segments/2)) rlglDraw();
|
||||||
|
@ -294,7 +294,7 @@ void DrawCircleSector(Vector2 center, float radius, int startAngle, int endAngle
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawCircleSectorLines(Vector2 center, float radius, int startAngle, int endAngle, int segments, Color color)
|
void DrawCircleSectorLines(Vector2 center, float radius, float startAngle, float endAngle, int segments, Color color)
|
||||||
{
|
{
|
||||||
if (radius <= 0.0f) radius = 0.1f; // Avoid div by zero issue
|
if (radius <= 0.0f) radius = 0.1f; // Avoid div by zero issue
|
||||||
|
|
||||||
|
@ -302,7 +302,7 @@ void DrawCircleSectorLines(Vector2 center, float radius, int startAngle, int end
|
||||||
if (endAngle < startAngle)
|
if (endAngle < startAngle)
|
||||||
{
|
{
|
||||||
// Swap values
|
// Swap values
|
||||||
int tmp = startAngle;
|
float tmp = startAngle;
|
||||||
startAngle = endAngle;
|
startAngle = endAngle;
|
||||||
endAngle = tmp;
|
endAngle = tmp;
|
||||||
}
|
}
|
||||||
|
@ -316,13 +316,13 @@ void DrawCircleSectorLines(Vector2 center, float radius, int startAngle, int end
|
||||||
if (segments <= 0) segments = 4;
|
if (segments <= 0) segments = 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
float stepLength = (float)(endAngle - startAngle)/(float)segments;
|
float stepLength = (endAngle - startAngle)/(float)segments;
|
||||||
float angle = (float)startAngle;
|
float angle = startAngle;
|
||||||
|
|
||||||
// Hide the cap lines when the circle is full
|
// Hide the cap lines when the circle is full
|
||||||
bool showCapLines = true;
|
bool showCapLines = true;
|
||||||
int limit = 2*(segments + 2);
|
int limit = 2*(segments + 2);
|
||||||
if ((endAngle - startAngle)%360 == 0) { limit = 2*segments; showCapLines = false; }
|
if ((int)(endAngle - startAngle)%360 == 0) { limit = 2*segments; showCapLines = false; }
|
||||||
|
|
||||||
if (rlCheckBufferLimit(limit)) rlglDraw();
|
if (rlCheckBufferLimit(limit)) rlglDraw();
|
||||||
|
|
||||||
|
@ -427,7 +427,7 @@ void DrawEllipseLines(int centerX, int centerY, float radiusH, float radiusV, Co
|
||||||
rlEnd();
|
rlEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawRing(Vector2 center, float innerRadius, float outerRadius, int startAngle, int endAngle, int segments, Color color)
|
void DrawRing(Vector2 center, float innerRadius, float outerRadius, float startAngle, float endAngle, int segments, Color color)
|
||||||
{
|
{
|
||||||
if (startAngle == endAngle) return;
|
if (startAngle == endAngle) return;
|
||||||
|
|
||||||
|
@ -445,7 +445,7 @@ void DrawRing(Vector2 center, float innerRadius, float outerRadius, int startAng
|
||||||
if (endAngle < startAngle)
|
if (endAngle < startAngle)
|
||||||
{
|
{
|
||||||
// Swap values
|
// Swap values
|
||||||
int tmp = startAngle;
|
float tmp = startAngle;
|
||||||
startAngle = endAngle;
|
startAngle = endAngle;
|
||||||
endAngle = tmp;
|
endAngle = tmp;
|
||||||
}
|
}
|
||||||
|
@ -466,8 +466,8 @@ void DrawRing(Vector2 center, float innerRadius, float outerRadius, int startAng
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
float stepLength = (float)(endAngle - startAngle)/(float)segments;
|
float stepLength = (endAngle - startAngle)/(float)segments;
|
||||||
float angle = (float)startAngle;
|
float angle = startAngle;
|
||||||
|
|
||||||
#if defined(SUPPORT_QUADS_DRAW_MODE)
|
#if defined(SUPPORT_QUADS_DRAW_MODE)
|
||||||
if (rlCheckBufferLimit(4*segments)) rlglDraw();
|
if (rlCheckBufferLimit(4*segments)) rlglDraw();
|
||||||
|
@ -518,7 +518,7 @@ void DrawRing(Vector2 center, float innerRadius, float outerRadius, int startAng
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawRingLines(Vector2 center, float innerRadius, float outerRadius, int startAngle, int endAngle, int segments, Color color)
|
void DrawRingLines(Vector2 center, float innerRadius, float outerRadius, float startAngle, float endAngle, int segments, Color color)
|
||||||
{
|
{
|
||||||
if (startAngle == endAngle) return;
|
if (startAngle == endAngle) return;
|
||||||
|
|
||||||
|
@ -536,7 +536,7 @@ void DrawRingLines(Vector2 center, float innerRadius, float outerRadius, int sta
|
||||||
if (endAngle < startAngle)
|
if (endAngle < startAngle)
|
||||||
{
|
{
|
||||||
// Swap values
|
// Swap values
|
||||||
int tmp = startAngle;
|
float tmp = startAngle;
|
||||||
startAngle = endAngle;
|
startAngle = endAngle;
|
||||||
endAngle = tmp;
|
endAngle = tmp;
|
||||||
}
|
}
|
||||||
|
@ -556,12 +556,12 @@ void DrawRingLines(Vector2 center, float innerRadius, float outerRadius, int sta
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
float stepLength = (float)(endAngle - startAngle)/(float)segments;
|
float stepLength = (endAngle - startAngle)/(float)segments;
|
||||||
float angle = (float)startAngle;
|
float angle = startAngle;
|
||||||
|
|
||||||
bool showCapLines = true;
|
bool showCapLines = true;
|
||||||
int limit = 4*(segments + 1);
|
int limit = 4*(segments + 1);
|
||||||
if ((endAngle - startAngle)%360 == 0) { limit = 4*segments; showCapLines = false; }
|
if ((int)(endAngle - startAngle)%360 == 0) { limit = 4*segments; showCapLines = false; }
|
||||||
|
|
||||||
if (rlCheckBufferLimit(limit)) rlglDraw();
|
if (rlCheckBufferLimit(limit)) rlglDraw();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue