Skip to content
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

[rshapes] More spline functions #4809

Open
AmityWilder opened this issue Mar 4, 2025 · 3 comments
Open

[rshapes] More spline functions #4809

AmityWilder opened this issue Mar 4, 2025 · 3 comments

Comments

@AmityWilder
Copy link
Contributor

Description

It would be helpful to have spline functions for velocity--to sample a curve's direction--and calculating bounds--for collision/rendering optimization. I think these would fit in nicely alongside the GetSplinePoint_ functions.

GetSplineVelocityLinear
GetSplineVelocityBezierQuad
GetSplineVelocityBezierCubic
GetSplineAccelerationBezierQuad
GetSplineAccelerationBezierCubic
GetSplineJoltBezierCubic

GetSplineBoundsBezierLinear
GetSplineBoundsBezierQuad
GetSplineBoundsBezierCubic

GetSplineCurvatureBezierCubic
GetSplineNearestTLinear

It might also be nice to have spline drawing with variable thickness along the curve, since this can't currently be accomplished without some pretty advanced trickery.

I have already written the code for these as part of my Raylib vector art program and thought they might be valuable for others as a contribution to Raylib.
The variable thickness one needs a little work because it doesn't translate 1:1 from object-oriented Rust directly into C (I will continue to work on that further), but it is already working pretty well as a basic calligraphic effect.

Image

@AmityWilder AmityWilder changed the title [rcore] More spline functions [rshapes] More spline functions Mar 4, 2025
@AmityWilder
Copy link
Contributor Author

Variable thickness sampling is now working as intended, as of commit 1e6332e

Image

https://www.desmos.com/calculator/hswsmzuflh

Image

@raysan5
Copy link
Owner

raysan5 commented Mar 4, 2025

@AmityWilder Those improvements are really nice but I'm afraid they are growing considerably, maybe they should be moved to a separate library... let me review them carefully...

@AmityWilder
Copy link
Contributor Author

AmityWilder commented Mar 4, 2025

@raysan5 If you think it would be better, I could split this issue into two separate ones: one for the math functions and one for the draw functions. Alternatively, I could split the draw functions off entirely and move them to raylib-extras, or create my own entirely separate library for them.

I believe the math functions (GetSpline_) are pretty much complete (I just need to make sure the bounds functions translated over accurately from Rust, since my original implementation used Rust iterator methods, and in the Raylib version I inlined certain functions I don't think would be used frequently enough to put into Raylib), but the variable-width draw functions may need a bit more work before they're ready for merging, since my Rust implementation of the variable width was reliant on a special data structure,

// amyvec::bezier::cubic

/// A cubic Bezier slice built from a [`curve::Slices`] iterator
pub struct Cubic {
  pub p0:    Vector2,
  pub c_in:  Vector2,
  pub c_out: Vector2,
  pub p1:    Vector2,
}

which I don't think makes sense to port into Raylib. I'm in the process of rewriting the functions to use an array [p0, c1, c2, p3, c4, c5, p6, ...] instead.

I will say however, in case it influences your decision, I'm thinking of further modifying the variable width draw functions so that Raylib users can specify the t-values of each thickness (e.g. [t0, thick0, t1, thick1, ...]), rather than simply having them evenly spaced along the spline.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants