Update C sources
This commit is contained in:
parent
e08c4cd054
commit
3327fcaf9f
22 changed files with 14167 additions and 10920 deletions
|
@ -25,7 +25,7 @@
|
|||
*
|
||||
* LICENSE: zlib/libpng
|
||||
*
|
||||
* Copyright (c) 2013-2024 Ramon Santamaria (@raysan5)
|
||||
* Copyright (c) 2013-2025 Ramon Santamaria (@raysan5)
|
||||
*
|
||||
* This software is provided "as-is", without any express or implied warranty. In no event
|
||||
* will the authors be held liable for any damages arising from the use of this software.
|
||||
|
@ -285,6 +285,7 @@ void DrawCircleV(Vector2 center, float radius, Color color)
|
|||
// Draw a piece of a circle
|
||||
void DrawCircleSector(Vector2 center, float radius, float startAngle, float endAngle, int segments, Color color)
|
||||
{
|
||||
if (startAngle == endAngle) return;
|
||||
if (radius <= 0.0f) radius = 0.1f; // Avoid div by zero
|
||||
|
||||
// Function expects (endAngle > startAngle)
|
||||
|
@ -376,6 +377,7 @@ void DrawCircleSector(Vector2 center, float radius, float startAngle, float endA
|
|||
// Draw a piece of a circle outlines
|
||||
void DrawCircleSectorLines(Vector2 center, float radius, float startAngle, float endAngle, int segments, Color color)
|
||||
{
|
||||
if (startAngle == endAngle) return;
|
||||
if (radius <= 0.0f) radius = 0.1f; // Avoid div by zero issue
|
||||
|
||||
// Function expects (endAngle > startAngle)
|
||||
|
@ -468,27 +470,39 @@ void DrawCircleLinesV(Vector2 center, float radius, Color color)
|
|||
|
||||
// Draw ellipse
|
||||
void DrawEllipse(int centerX, int centerY, float radiusH, float radiusV, Color color)
|
||||
{
|
||||
DrawEllipseV((Vector2){ (float)centerX, (float)centerY }, radiusH, radiusV, color);
|
||||
}
|
||||
|
||||
// Draw ellipse (Vector version)
|
||||
void DrawEllipseV(Vector2 center, float radiusH, float radiusV, Color color)
|
||||
{
|
||||
rlBegin(RL_TRIANGLES);
|
||||
for (int i = 0; i < 360; i += 10)
|
||||
{
|
||||
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||
rlVertex2f((float)centerX, (float)centerY);
|
||||
rlVertex2f((float)centerX + cosf(DEG2RAD*(i + 10))*radiusH, (float)centerY + sinf(DEG2RAD*(i + 10))*radiusV);
|
||||
rlVertex2f((float)centerX + cosf(DEG2RAD*i)*radiusH, (float)centerY + sinf(DEG2RAD*i)*radiusV);
|
||||
rlVertex2f(center.x, center.y);
|
||||
rlVertex2f(center.x + cosf(DEG2RAD*(i + 10))*radiusH, center.y + sinf(DEG2RAD*(i + 10))*radiusV);
|
||||
rlVertex2f(center.x + cosf(DEG2RAD*i)*radiusH, center.y + sinf(DEG2RAD*i)*radiusV);
|
||||
}
|
||||
rlEnd();
|
||||
}
|
||||
|
||||
// Draw ellipse outline
|
||||
void DrawEllipseLines(int centerX, int centerY, float radiusH, float radiusV, Color color)
|
||||
{
|
||||
DrawEllipseLinesV((Vector2){ (float)centerX, (float)centerY }, radiusH, radiusV, color);
|
||||
}
|
||||
|
||||
// Draw ellipse outline
|
||||
void DrawEllipseLinesV(Vector2 center, float radiusH, float radiusV, Color color)
|
||||
{
|
||||
rlBegin(RL_LINES);
|
||||
for (int i = 0; i < 360; i += 10)
|
||||
{
|
||||
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||
rlVertex2f(centerX + cosf(DEG2RAD*(i + 10))*radiusH, centerY + sinf(DEG2RAD*(i + 10))*radiusV);
|
||||
rlVertex2f(centerX + cosf(DEG2RAD*i)*radiusH, centerY + sinf(DEG2RAD*i)*radiusV);
|
||||
rlVertex2f(center.x + cosf(DEG2RAD*(i + 10))*radiusH, center.y + sinf(DEG2RAD*(i + 10))*radiusV);
|
||||
rlVertex2f(center.x + cosf(DEG2RAD*i)*radiusH, center.y + sinf(DEG2RAD*i)*radiusV);
|
||||
}
|
||||
rlEnd();
|
||||
}
|
||||
|
@ -772,7 +786,7 @@ void DrawRectangleGradientH(int posX, int posY, int width, int height, Color lef
|
|||
}
|
||||
|
||||
// Draw a gradient-filled rectangle
|
||||
void DrawRectangleGradientEx(Rectangle rec, Color topLeft, Color bottomLeft, Color topRight, Color bottomRight)
|
||||
void DrawRectangleGradientEx(Rectangle rec, Color topLeft, Color bottomLeft, Color bottomRight, Color topRight)
|
||||
{
|
||||
rlSetTexture(GetShapesTexture().id);
|
||||
Rectangle shapeRect = GetShapesTextureRectangle();
|
||||
|
@ -789,11 +803,11 @@ void DrawRectangleGradientEx(Rectangle rec, Color topLeft, Color bottomLeft, Col
|
|||
rlTexCoord2f(shapeRect.x/texShapes.width, (shapeRect.y + shapeRect.height)/texShapes.height);
|
||||
rlVertex2f(rec.x, rec.y + rec.height);
|
||||
|
||||
rlColor4ub(topRight.r, topRight.g, topRight.b, topRight.a);
|
||||
rlColor4ub(bottomRight.r, bottomRight.g, bottomRight.b, bottomRight.a);
|
||||
rlTexCoord2f((shapeRect.x + shapeRect.width)/texShapes.width, (shapeRect.y + shapeRect.height)/texShapes.height);
|
||||
rlVertex2f(rec.x + rec.width, rec.y + rec.height);
|
||||
|
||||
rlColor4ub(bottomRight.r, bottomRight.g, bottomRight.b, bottomRight.a);
|
||||
rlColor4ub(topRight.r, topRight.g, topRight.b, topRight.a);
|
||||
rlTexCoord2f((shapeRect.x + shapeRect.width)/texShapes.width, shapeRect.y/texShapes.height);
|
||||
rlVertex2f(rec.x + rec.width, rec.y);
|
||||
rlEnd();
|
||||
|
@ -807,22 +821,25 @@ void DrawRectangleGradientEx(Rectangle rec, Color topLeft, Color bottomLeft, Col
|
|||
// but it solves another issue: https://github.com/raysan5/raylib/issues/3884
|
||||
void DrawRectangleLines(int posX, int posY, int width, int height, Color color)
|
||||
{
|
||||
Matrix mat = rlGetMatrixModelview();
|
||||
float zoomFactor = 0.5f/mat.m0;
|
||||
Matrix mat = rlGetMatrixTransform();
|
||||
float xOffset = 0.5f/mat.m0;
|
||||
float yOffset = 0.5f/mat.m5;
|
||||
|
||||
rlBegin(RL_LINES);
|
||||
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||
rlVertex2f((float)posX - zoomFactor, (float)posY);
|
||||
rlVertex2f((float)posX + (float)width + zoomFactor, (float)posY);
|
||||
rlVertex2f((float)posX + xOffset, (float)posY + yOffset);
|
||||
rlVertex2f((float)posX + (float)width - xOffset, (float)posY + yOffset);
|
||||
|
||||
rlVertex2f((float)posX + (float)width, (float)posY - zoomFactor);
|
||||
rlVertex2f((float)posX + (float)width, (float)posY + (float)height + zoomFactor);
|
||||
rlVertex2f((float)posX + (float)width - xOffset, (float)posY + yOffset);
|
||||
rlVertex2f((float)posX + (float)width - xOffset, (float)posY + (float)height - yOffset);
|
||||
|
||||
rlVertex2f((float)posX + (float)width + zoomFactor, (float)posY + (float)height);
|
||||
rlVertex2f((float)posX - zoomFactor, (float)posY + (float)height);
|
||||
rlVertex2f((float)posX + (float)width - xOffset, (float)posY + (float)height - yOffset);
|
||||
rlVertex2f((float)posX + xOffset, (float)posY + (float)height - yOffset);
|
||||
|
||||
rlVertex2f((float)posX, (float)posY + (float)height + zoomFactor);
|
||||
rlVertex2f((float)posX, (float)posY - zoomFactor);
|
||||
rlVertex2f((float)posX + xOffset, (float)posY + (float)height - yOffset);
|
||||
rlVertex2f((float)posX + xOffset, (float)posY + yOffset);
|
||||
rlEnd();
|
||||
|
||||
/*
|
||||
// Previous implementation, it has issues... but it does not require view matrix...
|
||||
#if defined(SUPPORT_QUADS_DRAW_MODE)
|
||||
|
@ -845,7 +862,7 @@ void DrawRectangleLines(int posX, int posY, int width, int height, Color color)
|
|||
rlVertex2f((float)posX + 1, (float)posY + (float)height);
|
||||
rlVertex2f((float)posX + 1, (float)posY + 1);
|
||||
rlEnd();
|
||||
//#endif
|
||||
#endif
|
||||
*/
|
||||
}
|
||||
|
||||
|
@ -884,7 +901,7 @@ void DrawRectangleLinesEx(Rectangle rec, float lineThick, Color color)
|
|||
void DrawRectangleRounded(Rectangle rec, float roundness, int segments, Color color)
|
||||
{
|
||||
// Not a rounded rectangle
|
||||
if ((roundness <= 0.0f) || (rec.width < 1) || (rec.height < 1 ))
|
||||
if (roundness <= 0.0f)
|
||||
{
|
||||
DrawRectangleRec(rec, color);
|
||||
return;
|
||||
|
@ -1160,18 +1177,29 @@ void DrawRectangleRoundedLinesEx(Rectangle rec, float roundness, int segments, f
|
|||
P5 ================== P4
|
||||
*/
|
||||
const Vector2 point[16] = {
|
||||
{(float)rec.x + innerRadius, rec.y - lineThick}, {(float)(rec.x + rec.width) - innerRadius, rec.y - lineThick}, { rec.x + rec.width + lineThick, (float)rec.y + innerRadius }, // PO, P1, P2
|
||||
{rec.x + rec.width + lineThick, (float)(rec.y + rec.height) - innerRadius}, {(float)(rec.x + rec.width) - innerRadius, rec.y + rec.height + lineThick}, // P3, P4
|
||||
{(float)rec.x + innerRadius, rec.y + rec.height + lineThick}, { rec.x - lineThick, (float)(rec.y + rec.height) - innerRadius}, {rec.x - lineThick, (float)rec.y + innerRadius}, // P5, P6, P7
|
||||
{(float)rec.x + innerRadius, rec.y}, {(float)(rec.x + rec.width) - innerRadius, rec.y}, // P8, P9
|
||||
{ rec.x + rec.width, (float)rec.y + innerRadius }, {rec.x + rec.width, (float)(rec.y + rec.height) - innerRadius}, // P10, P11
|
||||
{(float)(rec.x + rec.width) - innerRadius, rec.y + rec.height}, {(float)rec.x + innerRadius, rec.y + rec.height}, // P12, P13
|
||||
{ rec.x, (float)(rec.y + rec.height) - innerRadius}, {rec.x, (float)rec.y + innerRadius} // P14, P15
|
||||
{(float)rec.x + innerRadius + 0.5f, rec.y - lineThick + 0.5f},
|
||||
{(float)(rec.x + rec.width) - innerRadius - 0.5f, rec.y - lineThick + 0.5f},
|
||||
{rec.x + rec.width + lineThick - 0.5f, (float)rec.y + innerRadius + 0.5f}, // PO, P1, P2
|
||||
{rec.x + rec.width + lineThick - 0.5f, (float)(rec.y + rec.height) - innerRadius - 0.5f},
|
||||
{(float)(rec.x + rec.width) - innerRadius - 0.5f, rec.y + rec.height + lineThick - 0.5f}, // P3, P4
|
||||
{(float)rec.x + innerRadius + 0.5f, rec.y + rec.height + lineThick - 0.5f},
|
||||
{rec.x - lineThick + 0.5f, (float)(rec.y + rec.height) - innerRadius - 0.5f},
|
||||
{rec.x - lineThick + 0.5f, (float)rec.y + innerRadius + 0.5f}, // P5, P6, P7
|
||||
{(float)rec.x + innerRadius + 0.5f, rec.y + 0.5f},
|
||||
{(float)(rec.x + rec.width) - innerRadius - 0.5f, rec.y + 0.5f}, // P8, P9
|
||||
{rec.x + rec.width - 0.5f, (float)rec.y + innerRadius + 0.5f},
|
||||
{rec.x + rec.width - 0.5f, (float)(rec.y + rec.height) - innerRadius - 0.5f}, // P10, P11
|
||||
{(float)(rec.x + rec.width) - innerRadius - 0.5f, rec.y + rec.height - 0.5f},
|
||||
{(float)rec.x + innerRadius + 0.5f, rec.y + rec.height - 0.5f}, // P12, P13
|
||||
{rec.x + 0.5f, (float)(rec.y + rec.height) - innerRadius - 0.5f},
|
||||
{rec.x + 0.5f, (float)rec.y + innerRadius + 0.5f} // P14, P15
|
||||
};
|
||||
|
||||
const Vector2 centers[4] = {
|
||||
{(float)rec.x + innerRadius, (float)rec.y + innerRadius}, {(float)(rec.x + rec.width) - innerRadius, (float)rec.y + innerRadius}, // P16, P17
|
||||
{(float)(rec.x + rec.width) - innerRadius, (float)(rec.y + rec.height) - innerRadius}, {(float)rec.x + innerRadius, (float)(rec.y + rec.height) - innerRadius} // P18, P19
|
||||
{(float)rec.x + innerRadius + 0.5f, (float)rec.y + innerRadius + 0.5f},
|
||||
{(float)(rec.x + rec.width) - innerRadius - 0.5f, (float)rec.y + innerRadius + 0.5f}, // P16, P17
|
||||
{(float)(rec.x + rec.width) - innerRadius - 0.5f, (float)(rec.y + rec.height) - innerRadius - 0.5f},
|
||||
{(float)rec.x + innerRadius + 0.5f, (float)(rec.y + rec.height) - innerRadius - 0.5f} // P18, P19
|
||||
};
|
||||
|
||||
const float angles[4] = { 180.0f, 270.0f, 0.0f, 90.0f };
|
||||
|
@ -2223,7 +2251,7 @@ bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Vector2
|
|||
// NOTE: Based on http://jeffreythompson.org/collision-detection/poly-point.php
|
||||
bool CheckCollisionPointPoly(Vector2 point, const Vector2 *points, int pointCount)
|
||||
{
|
||||
bool inside = false;
|
||||
bool collision = false;
|
||||
|
||||
if (pointCount > 2)
|
||||
{
|
||||
|
@ -2232,12 +2260,12 @@ bool CheckCollisionPointPoly(Vector2 point, const Vector2 *points, int pointCoun
|
|||
if ((points[i].y > point.y) != (points[j].y > point.y) &&
|
||||
(point.x < (points[j].x - points[i].x)*(point.y - points[i].y)/(points[j].y - points[i].y) + points[i].x))
|
||||
{
|
||||
inside = !inside;
|
||||
collision = !collision;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return inside;
|
||||
return collision;
|
||||
}
|
||||
|
||||
// Check collision between two rectangles
|
||||
|
@ -2342,7 +2370,7 @@ bool CheckCollisionPointLine(Vector2 point, Vector2 p1, Vector2 p2, int threshol
|
|||
return collision;
|
||||
}
|
||||
|
||||
// Check if circle collides with a line created betweeen two points [p1] and [p2]
|
||||
// Check if circle collides with a line created between two points [p1] and [p2]
|
||||
RLAPI bool CheckCollisionCircleLine(Vector2 center, float radius, Vector2 p1, Vector2 p2)
|
||||
{
|
||||
float dx = p1.x - p2.x;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue