浏览代码

Add Quadratic Bezier drawing (#1468)

* Add quadratic bezier to shapes.c

* Add DrawLineBezierQuad to header
pull/1473/head
Violet White 4 年前
committed by GitHub
父节点
当前提交
de13fca3b1
找不到此签名对应的密钥 GPG 密钥 ID: 4AEE18F83AFDEB23
共有 2 个文件被更改,包括 24 次插入1 次删除
  1. +1
    -0
      src/raylib.h
  2. +23
    -1
      src/shapes.c

+ 1
- 0
src/raylib.h 查看文件

@ -1090,6 +1090,7 @@ RLAPI void DrawLine(int startPosX, int startPosY, int endPosX, int endPosY, Colo
RLAPI void DrawLineV(Vector2 startPos, Vector2 endPos, Color color); // Draw a line (Vector version) RLAPI void DrawLineV(Vector2 startPos, Vector2 endPos, Color color); // Draw a line (Vector version)
RLAPI void DrawLineEx(Vector2 startPos, Vector2 endPos, float thick, Color color); // Draw a line defining thickness RLAPI void DrawLineEx(Vector2 startPos, Vector2 endPos, float thick, Color color); // Draw a line defining thickness
RLAPI void DrawLineBezier(Vector2 startPos, Vector2 endPos, float thick, Color color); // Draw a line using cubic-bezier curves in-out RLAPI void DrawLineBezier(Vector2 startPos, Vector2 endPos, float thick, Color color); // Draw a line using cubic-bezier curves in-out
RLAPI void DrawLineBezierQuad(Vector2 startPos,Vector2 controlPos,Vector2 endPos, float thick, Color color);//Draw line using quadratic bezier curves with a control point
RLAPI void DrawLineStrip(Vector2 *points, int pointsCount, Color color); // Draw lines sequence RLAPI void DrawLineStrip(Vector2 *points, int pointsCount, Color color); // Draw lines sequence
RLAPI void DrawCircle(int centerX, int centerY, float radius, Color color); // Draw a color-filled circle RLAPI void DrawCircle(int centerX, int centerY, float radius, Color color); // Draw a color-filled circle
RLAPI void DrawCircleSector(Vector2 center, float radius, int startAngle, int endAngle, int segments, Color color); // Draw a piece of a circle RLAPI void DrawCircleSector(Vector2 center, float radius, int startAngle, int endAngle, int segments, Color color); // Draw a piece of a circle

+ 23
- 1
src/shapes.c 查看文件

@ -179,7 +179,29 @@ void DrawLineBezier(Vector2 startPos, Vector2 endPos, float thick, Color color)
previous = current; 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 // Draw lines sequence
void DrawLineStrip(Vector2 *points, int pointsCount, Color color) void DrawLineStrip(Vector2 *points, int pointsCount, Color color)
{ {

正在加载...
取消
保存