summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorraysan5 <[email protected]>2017-03-14 00:22:53 +0100
committerraysan5 <[email protected]>2017-03-14 00:22:53 +0100
commit3813722f170066c3113d4a3ef6a21ec53af71034 (patch)
tree175e98a2332565bf42a09596650646a70ad63f2b /src
parent63c65f8cc5d3173fedb74164ed2b89b9e2b776ea (diff)
downloadraylib-3813722f170066c3113d4a3ef6a21ec53af71034.tar.gz
raylib-3813722f170066c3113d4a3ef6a21ec53af71034.zip
Added function: DrawLineBezier()
Diffstat (limited to 'src')
-rw-r--r--src/raylib.h1
-rw-r--r--src/shapes.c42
2 files changed, 42 insertions, 1 deletions
diff --git a/src/raylib.h b/src/raylib.h
index b0f03bbe..85689378 100644
--- a/src/raylib.h
+++ b/src/raylib.h
@@ -764,6 +764,7 @@ RLAPI void DrawPixelV(Vector2 position, Color color);
RLAPI void DrawLine(int startPosX, int startPosY, int endPosX, int endPosY, Color color); // Draw a line
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 DrawLineBezier(Vector2 startPos, Vector2 endPos, float thick, Color color); // Draw a line using cubic-bezier curves in-out
RLAPI void DrawCircle(int centerX, int centerY, float radius, Color color); // Draw a color-filled circle
RLAPI void DrawCircleGradient(int centerX, int centerY, float radius, Color color1, Color color2); // Draw a gradient-filled circle
RLAPI void DrawCircleV(Vector2 center, float radius, Color color); // Draw a color-filled circle (Vector version)
diff --git a/src/shapes.c b/src/shapes.c
index 9cbe1da4..5ed633f6 100644
--- a/src/shapes.c
+++ b/src/shapes.c
@@ -57,7 +57,7 @@
//----------------------------------------------------------------------------------
// Module specific Functions Declaration
//----------------------------------------------------------------------------------
-// No private (static) functions in this module (.c file)
+static float EaseCubicInOut(float t, float b, float c, float d); // Cubic easing
//----------------------------------------------------------------------------------
// Module Functions Definition
@@ -106,6 +106,13 @@ 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 tempPos = startPos;
+ startPos = endPos;
+ endPos = tempPos;
+ }
+
float dx = endPos.x - startPos.x;
float dy = endPos.y - startPos.y;
@@ -133,6 +140,27 @@ void DrawLineEx(Vector2 startPos, Vector2 endPos, float thick, Color color)
rlDisableTexture();
}
+// Draw line using cubic-bezier curves in-out
+void DrawLineBezier(Vector2 startPos, Vector2 endPos, float thick, Color color)
+{
+ #define LINE_DIVISIONS 24 // Bezier line divisions
+
+ Vector2 previous = startPos;
+ Vector2 current;
+
+ for (int i = 1; i <= LINE_DIVISIONS; i++)
+ {
+ // Cubic easing in-out
+ // NOTE: Easing is calcutated only for y position value
+ current.y = EaseCubicInOut(i, startPos.y, endPos.y - startPos.y, LINE_DIVISIONS);
+ current.x = previous.x + (endPos.x - startPos.x)/LINE_DIVISIONS;
+
+ DrawLineEx(previous, current, thick, color);
+
+ previous = current;
+ }
+}
+
// Draw a color-filled circle
void DrawCircle(int centerX, int centerY, float radius, Color color)
{
@@ -590,3 +618,15 @@ Rectangle GetCollisionRec(Rectangle rec1, Rectangle rec2)
return retRec;
}
+
+//----------------------------------------------------------------------------------
+// Module specific Functions Definition
+//----------------------------------------------------------------------------------
+
+// Cubic easing in-out
+// NOTE: Required for DrawLineBezier()
+static float EaseCubicInOut(float t, float b, float c, float d)
+{
+ if ((t/=d/2) < 1) return (c/2*t*t*t + b);
+ return (c/2*((t-=2)*t*t + 2) + b);
+} \ No newline at end of file