Fixed DrawLineEx
Corrected the issue https://github.com/raysan5/raylib/issues/1596
This commit is contained in:
parent
d96b422809
commit
27d325e5c9
46
src/shapes.c
46
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
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user