Fixed DrawLineEx (#1598)
* Fixed DrawLineEx Corrected the issue https://github.com/raysan5/raylib/issues/1596 * Removed raymath dependency for DrawLineEx
This commit is contained in:
parent
0726491ef8
commit
82cdd88ffe
1 changed files with 10 additions and 37 deletions
47
src/shapes.c
47
src/shapes.c
|
@ -116,45 +116,18 @@ 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)
|
||||||
{
|
{
|
||||||
if (startPos.x > endPos.x)
|
Vector2 delta = {endPos.x-startPos.x, endPos.y-startPos.y};
|
||||||
|
float length = sqrtf(delta.x*delta.x + delta.y*delta.y);
|
||||||
|
|
||||||
|
if (length > 0 && thick > 0)
|
||||||
{
|
{
|
||||||
Vector2 tempPos = startPos;
|
float scale = thick/(2*length);
|
||||||
startPos = endPos;
|
Vector2 radius = {-scale*delta.y, scale*delta.x};
|
||||||
endPos = tempPos;
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
// Draw line using cubic-bezier curves in-out
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue