Browse Source

Fixed DrawLineEx (#1598)

* Fixed DrawLineEx

Corrected the issue https://github.com/raysan5/raylib/issues/1596

* Removed raymath dependency for DrawLineEx
Paul Jurczak 4 years ago
parent
commit
82cdd88ffe
1 changed files with 10 additions and 37 deletions
  1. 10 37
      src/shapes.c

+ 10 - 37
src/shapes.c

@@ -116,45 +116,18 @@ 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 tempPos = startPos;
-        startPos = endPos;
-        endPos = tempPos;
-    }
-
-    float dx = endPos.x - startPos.x;
-    float dy = endPos.y - startPos.y;
-
-    float d = sqrtf(dx*dx + dy*dy);
-    float angle = asinf(dy/d);
+    Vector2 delta = {endPos.x-startPos.x, endPos.y-startPos.y};
+    float   length = sqrtf(delta.x*delta.x + delta.y*delta.y);
 
-    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();
+    if (length > 0  &&  thick > 0) 
+    {
+        float   scale = thick/(2*length);
+        Vector2 radius = {-scale*delta.y, scale*delta.x};
+        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}};
 
-    rlDisableTexture();
+        DrawTriangleStrip(strip, 4, color);
+    }
 }
 
 // Draw line using cubic-bezier curves in-out