diff --git a/src/shapes.c b/src/shapes.c index fc4bddc02..51ff7a375 100644 --- a/src/shapes.c +++ b/src/shapes.c @@ -116,45 +116,17 @@ void DrawLineV(Vector2 startPos, Vector2 endPos, Color color) // Draw a line defining thickness void DrawLineEx(Vector2 startPos, Vector2 endPos, float thick, Color color) { - if (startPos.x > endPos.x) + Vector2 delta = Vector2Subtract(endPos, startPos); + float length = Vector2Length(delta); + + if (length > 0 && thick > 0) { - Vector2 tempPos = startPos; - startPos = endPos; - endPos = tempPos; + float scale = thick/(2*length); + Vector2 radius = {-scale*delta.y, scale*delta.x}; + Vector2 strip[] = {Vector2Subtract(startPos, radius), Vector2Add(startPos, radius), Vector2Subtract(endPos, radius), Vector2Add(endPos, radius)}; + + DrawTriangleStrip(strip, 4, color); } - - float dx = endPos.x - startPos.x; - float dy = endPos.y - startPos.y; - - float d = sqrtf(dx*dx + dy*dy); - float angle = asinf(dy/d); - - rlEnableTexture(GetShapesTexture().id); - - rlPushMatrix(); - rlTranslatef((float)startPos.x, (float)startPos.y, 0.0f); - rlRotatef(RAD2DEG*angle, 0.0f, 0.0f, 1.0f); - rlTranslatef(0, (thick > 1.0f)? -thick/2.0f : -1.0f, 0.0f); - - rlBegin(RL_QUADS); - rlColor4ub(color.r, color.g, color.b, color.a); - rlNormal3f(0.0f, 0.0f, 1.0f); - - rlTexCoord2f(GetShapesTextureRec().x/GetShapesTexture().width, GetShapesTextureRec().y/GetShapesTexture().height); - rlVertex2f(0.0f, 0.0f); - - rlTexCoord2f(GetShapesTextureRec().x/GetShapesTexture().width, (GetShapesTextureRec().y + GetShapesTextureRec().height)/GetShapesTexture().height); - rlVertex2f(0.0f, thick); - - rlTexCoord2f((GetShapesTextureRec().x + GetShapesTextureRec().width)/GetShapesTexture().width, (GetShapesTextureRec().y + GetShapesTextureRec().height)/GetShapesTexture().height); - rlVertex2f(d, thick); - - rlTexCoord2f((GetShapesTextureRec().x + GetShapesTextureRec().width)/GetShapesTexture().width, GetShapesTextureRec().y/GetShapesTexture().height); - rlVertex2f(d, 0.0f); - rlEnd(); - rlPopMatrix(); - - rlDisableTexture(); } // Draw line using cubic-bezier curves in-out