diff options
| author | raysan5 <[email protected]> | 2020-12-26 13:09:34 +0100 |
|---|---|---|
| committer | raysan5 <[email protected]> | 2020-12-26 13:09:34 +0100 |
| commit | 521ed1cef0c0dbc752cb79f70c21bb4fc3bf70d4 (patch) | |
| tree | 1ed941e228c766bff6a6132a3f7d2efb4b797edf /src/shapes.c | |
| parent | de13fca3b1da643c74be37d16df5e30cd7198457 (diff) | |
| download | raylib-521ed1cef0c0dbc752cb79f70c21bb4fc3bf70d4.tar.gz raylib-521ed1cef0c0dbc752cb79f70c21bb4fc3bf70d4.zip | |
Review DrawLineBezierQuad(), formating and aprameters order
Diffstat (limited to 'src/shapes.c')
| -rw-r--r-- | src/shapes.c | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/src/shapes.c b/src/shapes.c index 829d54cb..3cb30eb0 100644 --- a/src/shapes.c +++ b/src/shapes.c @@ -179,29 +179,33 @@ void DrawLineBezier(Vector2 startPos, Vector2 endPos, float thick, Color color) previous = current; } } + // Draw line using quadratic bezier curves with a control point -void DrawLineBezierQuad(Vector2 startPos, Vector2 controlPos, Vector2 endPos,float thick,Color color) +void DrawLineBezierQuad(Vector2 startPos, Vector2 endPos, Vector2 controlPos, float thick, Color color) { - Vector2 previous = startPos; - Vector2 current; - float t=0; const float step = 1.0f/BEZIER_LINE_DIVISIONS; + + Vector2 previous = startPos; + Vector2 current = { 0 }; + float t = 0.0f; + for (int i = 0; i <= BEZIER_LINE_DIVISIONS; i++) { - t=step*i; - float a = powf(1-t,2); - float b = 2*(1-t)*t; - float c = powf(t,2); - //The easing functions aren't suitable here because they don't take a control point - current.y=a*startPos.y+b*controlPos.y+c*endPos.y; - current.x=a*startPos.x+b*controlPos.x+c*endPos.x; + t = step*i; + float a = powf(1 - t, 2); + float b = 2*(1 - t)*t; + float c = powf(t, 2); - DrawLineEx(previous,current,thick,color); + // NOTE: The easing functions aren't suitable here because they don't take a control point + current.y = a*startPos.y + b*controlPos.y + c*endPos.y; + current.x = a*startPos.x + b*controlPos.x + c*endPos.x; - previous=current; + DrawLineEx(previous,current,thick,color); + previous = current; } } + // Draw lines sequence void DrawLineStrip(Vector2 *points, int pointsCount, Color color) { |
