Skip to content

[rshapes] More spline functions #4810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -179,6 +179,19 @@ WIP: Last update with commit from 02-Nov-2024
[rshapes] REVIEWED: `CheckCollisionCircleRec()` (#3584) by @ubkp
[rshapes] REVIEWED: Add more detail to function comment (#4344) by @Jeffery Myers
[rshapes] REVIEWED: Functions that draw point arrays take them as const (#4051) by @Jeffery Myers
[rshapes] ADDED: `DrawSplineSegmentBezierCubicVar()` (#4809) by @AmityWilder
[rshapes] ADDED: `GetSplineVelocityLinear()` (#4809) by @AmityWilder
[rshapes] ADDED: `GetSplineVelocityBezierQuad()` (#4809) by @AmityWilder
[rshapes] ADDED: `GetSplineVelocityBezierCubic()` (#4809) by @AmityWilder
[rshapes] ADDED: `GetSplineAccelerationBezierQuad()` (#4809) by @AmityWilder
[rshapes] ADDED: `GetSplineAccelerationBezierCubic()` (#4809) by @AmityWilder
[rshapes] ADDED: `GetSplineJoltBezierCubic()` (#4809) by @AmityWilder
[rshapes] ADDED: `GetSplineBoundsBezierLinear()` (#4809) by @AmityWilder
[rshapes] ADDED: `GetSplineBoundsBezierQuad()` (#4809) by @AmityWilder
[rshapes] ADDED: `GetSplineBoundsBezierCubic()` (#4809) by @AmityWilder
[rshapes] ADDED: `GetSplineCurvatureBezierCubic()` (#4809) by @AmityWilder
[rshapes] ADDED: `GetSplineNearestTLinear()` (#4809) by @AmityWilder
[rshapes] ADDED: Example of `DrawSplineSegmentBezierCubicVar` in splines drawing example (#4809) by @AmityWilder
[rtextures] ADDED: `ColorIsEqual()` by @Ray
[rtextures] ADDED: `ColorLerp()`, to mix 2 colors together (#4310) by @SusgUY446
[rtextures] ADDED: `LoadImageAnimFromMemory()` (#3681) by @IoIxD
58 changes: 54 additions & 4 deletions examples/shapes/shapes_splines_drawing.c
Original file line number Diff line number Diff line change
@@ -34,7 +34,9 @@ typedef enum {
SPLINE_LINEAR = 0, // Linear
SPLINE_BASIS, // B-Spline
SPLINE_CATMULLROM, // Catmull-Rom
SPLINE_BEZIER // Cubic Bezier
SPLINE_BEZIER, // Cubic Bezier
SPLINE_LINEAR_VAR, // Linear, variable thickness
SPLINE_BEZIER_VAR // Cubic Bezier, variable thickness
} SplineType;

//------------------------------------------------------------------------------------
@@ -78,7 +80,7 @@ int main(void)

// Spline config variables
float splineThickness = 8.0f;
int splineTypeActive = SPLINE_LINEAR; // 0-Linear, 1-BSpline, 2-CatmullRom, 3-Bezier
int splineTypeActive = SPLINE_LINEAR; // 0-Linear, 1-BSpline, 2-CatmullRom, 3-Bezier, 4-LinearVar, 5-BezierVar
bool splineTypeEditMode = false;
bool splineHelpersActive = true;

@@ -120,7 +122,7 @@ int main(void)
}

// Cubic Bezier spline control points logic
if ((splineTypeActive == SPLINE_BEZIER) && (focusedPoint == -1))
if (((splineTypeActive == SPLINE_BEZIER) || (splineTypeActive == SPLINE_BEZIER_VAR)) && (focusedPoint == -1))
{
// Spline control point focus and selection logic
for (int i = 0; i < pointCount - 1; i++)
@@ -153,6 +155,8 @@ int main(void)
else if (IsKeyPressed(KEY_TWO)) splineTypeActive = 1;
else if (IsKeyPressed(KEY_THREE)) splineTypeActive = 2;
else if (IsKeyPressed(KEY_FOUR)) splineTypeActive = 3;
else if (IsKeyPressed(KEY_FIVE)) splineTypeActive = 4;
else if (IsKeyPressed(KEY_SIX)) splineTypeActive = 5;
//----------------------------------------------------------------------------------

// Draw
@@ -215,7 +219,51 @@ int main(void)
DrawSplineSegmentBezierCubic(pointsInterleaved[i], pointsInterleaved[i + 1], pointsInterleaved[i + 2], pointsInterleaved[i + 3], splineThickness, MAROON);
}
*/
}
else if (splineTypeActive == SPLINE_LINEAR_VAR)
{
float thicks[] = {
0.0f,
splineThickness,
-splineThickness,
splineThickness,
};

// Draw spline: variable-width linear
for (int i = 0; i < pointCount - 1; ++i)
{
DrawSplineSegmentLinearVar(points[i], points[i+1], thicks, 4, RED);
}
}
else if (splineTypeActive == SPLINE_BEZIER_VAR)
{
float thicks[] = {
0.0f,
splineThickness,
splineThickness,
0.0f,
};

// NOTE: Cubic-bezier spline requires the 2 control points of each segnment to be
// provided interleaved with the start and end point of every segment
for (int i = 0; i < (pointCount - 1); i++)
{
pointsInterleaved[3*i] = points[i];
pointsInterleaved[3*i + 1] = control[i].start;
pointsInterleaved[3*i + 2] = control[i].end;
}

pointsInterleaved[3*(pointCount - 1)] = points[pointCount - 1];

// Draw spline: variable-width cubic-bezier (with control points)
for (int i = 0; i < pointCount - 1; ++i)
{
DrawSplineSegmentBezierCubicVar(points[i], control[i].start, control[i].end, points[i+1], thicks, 4, RED);
}
}

if ((splineTypeActive == SPLINE_BEZIER) || (splineTypeActive == SPLINE_BEZIER_VAR))
{
// Draw spline control points
for (int i = 0; i < pointCount - 1; i++)
{
@@ -241,7 +289,9 @@ int main(void)
{
DrawCircleLinesV(points[i], (focusedPoint == i)? 12.0f : 8.0f, (focusedPoint == i)? BLUE: DARKBLUE);
if ((splineTypeActive != SPLINE_LINEAR) &&
(splineTypeActive != SPLINE_LINEAR_VAR) &&
(splineTypeActive != SPLINE_BEZIER) &&
(splineTypeActive != SPLINE_BEZIER_VAR) &&
(i < pointCount - 1)) DrawLineV(points[i], points[i + 1], GRAY);

DrawText(TextFormat("[%.0f, %.0f]", points[i].x, points[i].y), (int)points[i].x, (int)points[i].y + 10, 10, BLACK);
@@ -260,7 +310,7 @@ int main(void)
GuiUnlock();

GuiLabel((Rectangle){ 12, 10, 140, 24 }, "Spline type:");
if (GuiDropdownBox((Rectangle){ 12, 8 + 24, 140, 28 }, "LINEAR;BSPLINE;CATMULLROM;BEZIER", &splineTypeActive, splineTypeEditMode)) splineTypeEditMode = !splineTypeEditMode;
if (GuiDropdownBox((Rectangle){ 12, 8 + 24, 140, 28 }, "LINEAR;BSPLINE;CATMULLROM;BEZIER;LINEAR VARIABLE;BEZIER VARIABLE", &splineTypeActive, splineTypeEditMode)) splineTypeEditMode = !splineTypeEditMode;

EndDrawing();
//----------------------------------------------------------------------------------
Loading