Update C sources
This commit is contained in:
parent
22ca1484d1
commit
781c207678
27 changed files with 13963 additions and 4637 deletions
|
@ -26,7 +26,7 @@
|
|||
*
|
||||
* LICENSE: zlib/libpng
|
||||
*
|
||||
* Copyright (c) 2013-2022 Ramon Santamaria (@raysan5)
|
||||
* Copyright (c) 2013-2023 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.
|
||||
|
@ -58,6 +58,7 @@
|
|||
|
||||
#include <math.h> // Required for: sinf(), asinf(), cosf(), acosf(), sqrtf(), fabsf()
|
||||
#include <float.h> // Required for: FLT_EPSILON
|
||||
#include <stdlib.h> // Required for: RL_FREE
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
// Defines and Macros
|
||||
|
@ -104,7 +105,7 @@ void SetShapesTexture(Texture2D texture, Rectangle source)
|
|||
// Draw a pixel
|
||||
void DrawPixel(int posX, int posY, Color color)
|
||||
{
|
||||
DrawPixelV((Vector2){ posX, posY }, color);
|
||||
DrawPixelV((Vector2){ (float)posX, (float)posY }, color);
|
||||
}
|
||||
|
||||
// Draw a pixel (Vector version)
|
||||
|
@ -155,8 +156,8 @@ void DrawLine(int startPosX, int startPosY, int endPosX, int endPosY, Color colo
|
|||
{
|
||||
rlBegin(RL_LINES);
|
||||
rlColor4ub(color.r, color.g, color.b, color.a);
|
||||
rlVertex2f(startPosX, startPosY);
|
||||
rlVertex2f(endPosX, endPosY);
|
||||
rlVertex2f((float)startPosX, (float)startPosY);
|
||||
rlVertex2f((float)endPosX, (float)endPosY);
|
||||
rlEnd();
|
||||
}
|
||||
|
||||
|
@ -197,6 +198,8 @@ void DrawLineBezier(Vector2 startPos, Vector2 endPos, float thick, Color color)
|
|||
Vector2 previous = startPos;
|
||||
Vector2 current = { 0 };
|
||||
|
||||
Vector2 points[2*BEZIER_LINE_DIVISIONS + 2] = { 0 };
|
||||
|
||||
for (int i = 1; i <= BEZIER_LINE_DIVISIONS; i++)
|
||||
{
|
||||
// Cubic easing in-out
|
||||
|
@ -204,12 +207,27 @@ void DrawLineBezier(Vector2 startPos, Vector2 endPos, float thick, Color color)
|
|||
current.y = EaseCubicInOut((float)i, startPos.y, endPos.y - startPos.y, (float)BEZIER_LINE_DIVISIONS);
|
||||
current.x = previous.x + (endPos.x - startPos.x)/ (float)BEZIER_LINE_DIVISIONS;
|
||||
|
||||
// TODO: Avoid drawing the line by pieces, it generates gaps for big thicks,
|
||||
// Custom "triangle-strip" implementation should be used, check DrawTriangleStrip() for reference
|
||||
DrawLineEx(previous, current, thick, color);
|
||||
float dy = current.y-previous.y;
|
||||
float dx = current.x-previous.x;
|
||||
float size = 0.5f*thick/sqrtf(dx*dx+dy*dy);
|
||||
|
||||
if (i==1)
|
||||
{
|
||||
points[0].x = previous.x+dy*size;
|
||||
points[0].y = previous.y-dx*size;
|
||||
points[1].x = previous.x-dy*size;
|
||||
points[1].y = previous.y+dx*size;
|
||||
}
|
||||
|
||||
points[2*i+1].x = current.x-dy*size;
|
||||
points[2*i+1].y = current.y+dx*size;
|
||||
points[2*i].x = current.x+dy*size;
|
||||
points[2*i].y = current.y-dx*size;
|
||||
|
||||
previous = current;
|
||||
}
|
||||
|
||||
DrawTriangleStrip(points, 2*BEZIER_LINE_DIVISIONS+2, color);
|
||||
}
|
||||
|
||||
// Draw line using quadratic bezier curves with a control point
|
||||
|
@ -221,6 +239,8 @@ void DrawLineBezierQuad(Vector2 startPos, Vector2 endPos, Vector2 controlPos, fl
|
|||
Vector2 current = { 0 };
|
||||
float t = 0.0f;
|
||||
|
||||
Vector2 points[2*BEZIER_LINE_DIVISIONS + 2] = { 0 };
|
||||
|
||||
for (int i = 0; i <= BEZIER_LINE_DIVISIONS; i++)
|
||||
{
|
||||
t = step*i;
|
||||
|
@ -232,12 +252,27 @@ void DrawLineBezierQuad(Vector2 startPos, Vector2 endPos, Vector2 controlPos, fl
|
|||
current.y = a*startPos.y + b*controlPos.y + c*endPos.y;
|
||||
current.x = a*startPos.x + b*controlPos.x + c*endPos.x;
|
||||
|
||||
// TODO: Avoid drawing the line by pieces, it generates gaps for big thicks,
|
||||
// Custom "triangle-strip" implementation should be used, check DrawTriangleStrip() for reference
|
||||
DrawLineEx(previous, current, thick, color);
|
||||
float dy = current.y-previous.y;
|
||||
float dx = current.x-previous.x;
|
||||
float size = 0.5f*thick/sqrtf(dx*dx+dy*dy);
|
||||
|
||||
if (i==1)
|
||||
{
|
||||
points[0].x = previous.x+dy*size;
|
||||
points[0].y = previous.y-dx*size;
|
||||
points[1].x = previous.x-dy*size;
|
||||
points[1].y = previous.y+dx*size;
|
||||
}
|
||||
|
||||
points[2*i+1].x = current.x-dy*size;
|
||||
points[2*i+1].y = current.y+dx*size;
|
||||
points[2*i].x = current.x+dy*size;
|
||||
points[2*i].y = current.y-dx*size;
|
||||
|
||||
previous = current;
|
||||
}
|
||||
|
||||
DrawTriangleStrip(points, 2*BEZIER_LINE_DIVISIONS+2, color);
|
||||
}
|
||||
|
||||
// Draw line using cubic bezier curves with 2 control points
|
||||
|
@ -249,6 +284,8 @@ void DrawLineBezierCubic(Vector2 startPos, Vector2 endPos, Vector2 startControlP
|
|||
Vector2 current = { 0 };
|
||||
float t = 0.0f;
|
||||
|
||||
Vector2 points[2*BEZIER_LINE_DIVISIONS + 2] = { 0 };
|
||||
|
||||
for (int i = 0; i <= BEZIER_LINE_DIVISIONS; i++)
|
||||
{
|
||||
t = step*i;
|
||||
|
@ -260,12 +297,27 @@ void DrawLineBezierCubic(Vector2 startPos, Vector2 endPos, Vector2 startControlP
|
|||
current.y = a*startPos.y + b*startControlPos.y + c*endControlPos.y + d*endPos.y;
|
||||
current.x = a*startPos.x + b*startControlPos.x + c*endControlPos.x + d*endPos.x;
|
||||
|
||||
// TODO: Avoid drawing the line by pieces, it generates gaps for big thicks,
|
||||
// Custom "triangle-strip" implementation should be used, check DrawTriangleStrip() for reference
|
||||
DrawLineEx(previous, current, thick, color);
|
||||
float dy = current.y-previous.y;
|
||||
float dx = current.x-previous.x;
|
||||
float size = 0.5f*thick/sqrtf(dx*dx+dy*dy);
|
||||
|
||||
if (i==1)
|
||||
{
|
||||
points[0].x = previous.x+dy*size;
|
||||
points[0].y = previous.y-dx*size;
|
||||
points[1].x = previous.x-dy*size;
|
||||
points[1].y = previous.y+dx*size;
|
||||
}
|
||||
|
||||
points[2*i+1].x = current.x-dy*size;
|
||||
points[2*i+1].y = current.y+dx*size;
|
||||
points[2*i].x = current.x+dy*size;
|
||||
points[2*i].y = current.y-dx*size;
|
||||
|
||||
previous = current;
|
||||
}
|
||||
|
||||
DrawTriangleStrip(points, 2*BEZIER_LINE_DIVISIONS+2, color);
|
||||
}
|
||||
|
||||
// Draw lines sequence
|
||||
|
@ -926,7 +978,7 @@ void DrawRectangleRounded(Rectangle rec, float roundness, int segments, Color co
|
|||
rlSetTexture(texShapes.id);
|
||||
|
||||
rlBegin(RL_QUADS);
|
||||
// Draw all of the 4 corners: [1] Upper Left Corner, [3] Upper Right Corner, [5] Lower Right Corner, [7] Lower Left Corner
|
||||
// Draw all the 4 corners: [1] Upper Left Corner, [3] Upper Right Corner, [5] Lower Right Corner, [7] Lower Left Corner
|
||||
for (int k = 0; k < 4; ++k) // Hope the compiler is smart enough to unroll this loop
|
||||
{
|
||||
float angle = angles[k];
|
||||
|
@ -1155,7 +1207,7 @@ void DrawRectangleRoundedLines(Rectangle rec, float roundness, int segments, flo
|
|||
|
||||
rlBegin(RL_QUADS);
|
||||
|
||||
// Draw all of the 4 corners first: Upper Left Corner, Upper Right Corner, Lower Right Corner, Lower Left Corner
|
||||
// Draw all the 4 corners first: Upper Left Corner, Upper Right Corner, Lower Right Corner, Lower Left Corner
|
||||
for (int k = 0; k < 4; ++k) // Hope the compiler is smart enough to unroll this loop
|
||||
{
|
||||
float angle = angles[k];
|
||||
|
@ -1290,7 +1342,7 @@ void DrawRectangleRoundedLines(Rectangle rec, float roundness, int segments, flo
|
|||
// Use LINES to draw the outline
|
||||
rlBegin(RL_LINES);
|
||||
|
||||
// Draw all of the 4 corners first: Upper Left Corner, Upper Right Corner, Lower Right Corner, Lower Left Corner
|
||||
// Draw all the 4 corners first: Upper Left Corner, Upper Right Corner, Lower Right Corner, Lower Left Corner
|
||||
for (int k = 0; k < 4; ++k) // Hope the compiler is smart enough to unroll this loop
|
||||
{
|
||||
float angle = angles[k];
|
||||
|
@ -1587,19 +1639,19 @@ bool CheckCollisionPointTriangle(Vector2 point, Vector2 p1, Vector2 p2, Vector2
|
|||
bool CheckCollisionPointPoly(Vector2 point, Vector2 *points, int pointCount)
|
||||
{
|
||||
bool collision = false;
|
||||
|
||||
|
||||
if (pointCount > 2)
|
||||
{
|
||||
for (int i = 0; i < pointCount - 1; i++)
|
||||
{
|
||||
Vector2 vc = points[i];
|
||||
Vector2 vn = points[i + 1];
|
||||
|
||||
|
||||
if ((((vc.y >= point.y) && (vn.y < point.y)) || ((vc.y < point.y) && (vn.y >= point.y))) &&
|
||||
(point.x < ((vn.x - vc.x)*(point.y - vc.y)/(vn.y - vc.y) + vc.x))) collision = !collision;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return collision;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue