Removed raymath dependency for DrawLineEx

This commit is contained in:
Paul Jurczak 2021-02-20 13:47:25 -07:00 committed by GitHub
parent 27d325e5c9
commit ea70e6ba66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -116,14 +116,15 @@ void DrawLineV(Vector2 startPos, Vector2 endPos, Color color)
// Draw a line defining thickness // Draw a line defining thickness
void DrawLineEx(Vector2 startPos, Vector2 endPos, float thick, Color color) void DrawLineEx(Vector2 startPos, Vector2 endPos, float thick, Color color)
{ {
Vector2 delta = Vector2Subtract(endPos, startPos); Vector2 delta = {endPos.x-startPos.x, endPos.y-startPos.y};
float length = Vector2Length(delta); float length = sqrtf(delta.x*delta.x + delta.y*delta.y);
if (length > 0 && thick > 0) if (length > 0 && thick > 0)
{ {
float scale = thick/(2*length); float scale = thick/(2*length);
Vector2 radius = {-scale*delta.y, scale*delta.x}; Vector2 radius = {-scale*delta.y, scale*delta.x};
Vector2 strip[] = {Vector2Subtract(startPos, radius), Vector2Add(startPos, radius), Vector2Subtract(endPos, radius), Vector2Add(endPos, radius)}; Vector2 strip[] = {{startPos.x-radius.x, startPos.y-radius.y}, {startPos.x+radius.x, startPos.y+radius.y},
{endPos.x-radius.x, endPos.y-radius.y}, {endPos.x+radius.x, endPos.y+radius.y}};
DrawTriangleStrip(strip, 4, color); DrawTriangleStrip(strip, 4, color);
} }