diff options
| author | Violet White <[email protected]> | 2020-12-26 06:04:38 -0600 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-12-26 13:04:38 +0100 |
| commit | de13fca3b1da643c74be37d16df5e30cd7198457 (patch) | |
| tree | b77046b5b5e6b916a8b885ef67a880b863a87e99 /src/shapes.c | |
| parent | b59ca95a160db14a3c7b54d139723b03a1147cf9 (diff) | |
| download | raylib-de13fca3b1da643c74be37d16df5e30cd7198457.tar.gz raylib-de13fca3b1da643c74be37d16df5e30cd7198457.zip | |
Add Quadratic Bezier drawing (#1468)
* Add quadratic bezier to shapes.c
* Add DrawLineBezierQuad to header
Diffstat (limited to 'src/shapes.c')
| -rw-r--r-- | src/shapes.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/shapes.c b/src/shapes.c index 56de3a7a..829d54cb 100644 --- a/src/shapes.c +++ b/src/shapes.c @@ -179,7 +179,29 @@ 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) +{ + Vector2 previous = startPos; + Vector2 current; + float t=0; + const float step = 1.0f/BEZIER_LINE_DIVISIONS; + 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; + + DrawLineEx(previous,current,thick,color); + + previous=current; + + } +} // Draw lines sequence void DrawLineStrip(Vector2 *points, int pointsCount, Color color) { |
