summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--examples/shapes/shapes_splines_drawing.c21
-rw-r--r--src/rshapes.c14
2 files changed, 27 insertions, 8 deletions
diff --git a/examples/shapes/shapes_splines_drawing.c b/examples/shapes/shapes_splines_drawing.c
index 8df5f09f..0d5693eb 100644
--- a/examples/shapes/shapes_splines_drawing.c
+++ b/examples/shapes/shapes_splines_drawing.c
@@ -63,7 +63,7 @@ int main(void)
Vector2 *focusedControlPoint = NULL;
// Cubic Bezier control points initialization
- ControlPoint control[MAX_SPLINE_POINTS] = { 0 };
+ ControlPoint control[MAX_SPLINE_POINTS-1] = { 0 };
for (int i = 0; i < pointCount - 1; i++)
{
control[i].start = (Vector2){ points[i].x + 50, points[i].y };
@@ -88,6 +88,9 @@ int main(void)
if (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON) && (pointCount < MAX_SPLINE_POINTS))
{
points[pointCount] = GetMousePosition();
+ int i = pointCount - 1;
+ control[i].start = (Vector2){ points[i].x + 50, points[i].y };
+ control[i].end = (Vector2){ points[i + 1].x - 50, points[i + 1].y };
pointCount++;
}
@@ -114,7 +117,7 @@ int main(void)
if ((splineTypeActive == SPLINE_BEZIER) && (focusedPoint == -1))
{
// Spline control point focus and selection logic
- for (int i = 0; i < pointCount; i++)
+ for (int i = 0; i < pointCount - 1; i++)
{
if (CheckCollisionPointCircle(GetMousePosition(), control[i].start, 6.0f))
{
@@ -186,10 +189,20 @@ int main(void)
else if (splineTypeActive == SPLINE_BEZIER)
{
// Draw spline: cubic-bezier (with control points)
+
+ Vector2 fullPoints[3*(MAX_SPLINE_POINTS-1)+1] = {0};
+ for (int i = 0; i < pointCount-1; i++) {
+ fullPoints[3*i] = points[i];
+ fullPoints[3*i+1] = control[i].start;
+ fullPoints[3*i+2] = control[i].end;
+ }
+ fullPoints[3*(pointCount-1)] = points[pointCount-1],
+ DrawSplineBezierCubic(fullPoints, 3*(pointCount-1)+1, splineThickness, RED);
+
for (int i = 0; i < pointCount - 1; i++)
{
// Drawing individual segments, not considering thickness connection compensation
- DrawSplineSegmentBezierCubic(points[i], control[i].start, control[i].end, points[i + 1], splineThickness, RED);
+ // DrawSplineSegmentBezierCubic(points[i], control[i].start, control[i].end, points[i + 1], splineThickness, RED);
// Every cubic bezier point should have two control points
DrawCircleV(control[i].start, 6, GOLD);
@@ -244,4 +257,4 @@ int main(void)
//--------------------------------------------------------------------------------------
return 0;
-} \ No newline at end of file
+}
diff --git a/src/rshapes.c b/src/rshapes.c
index e9a84834..2c4a57d3 100644
--- a/src/rshapes.c
+++ b/src/rshapes.c
@@ -1832,8 +1832,11 @@ void DrawSplineCatmullRom(const Vector2 *points, int pointCount, float thick, Co
void DrawSplineBezierQuadratic(const Vector2 *points, int pointCount, float thick, Color color)
{
if (pointCount < 3) return;
-
- for (int i = 0; i < pointCount - 2; i++)
+ for (int i = 2; i < pointCount - 2; i += 2)
+ {
+ DrawCircleV(points[i], thick/2.0f, color);
+ }
+ for (int i = 0; i < pointCount - 2; i += 2)
{
DrawSplineSegmentBezierQuadratic(points[i], points[i + 1], points[i + 2], thick, color);
}
@@ -1843,8 +1846,11 @@ void DrawSplineBezierQuadratic(const Vector2 *points, int pointCount, float thic
void DrawSplineBezierCubic(const Vector2 *points, int pointCount, float thick, Color color)
{
if (pointCount < 4) return;
-
- for (int i = 0; i < pointCount - 3; i++)
+ for (int i = 3; i < pointCount - 3; i += 3)
+ {
+ DrawCircleV(points[i], thick/2.0f, color);
+ }
+ for (int i = 0; i < pointCount - 3; i += 3)
{
DrawSplineSegmentBezierCubic(points[i], points[i + 1], points[i + 2], points[i + 3], thick, color);
}