exspline(3)

πŸ“¦ version 4.4.3.1, in fedora 43, fedora 44

πŸ’– exspline(3) πŸ’–

okay bestie, welcome to exspline, a lil page from the Allegro manual ✨ (yes it's the Allegro game programming library, the whole vibe).


πŸ¦‹ NAME πŸ¦‹

exspline β€” constructing smooth movement paths from spline curves. Allegro game programming library. πŸ’…


🌸 SYNOPSIS 🌸

#include <allegro.h>

Example exspline

✨ DESCRIPTION ✨

so this program is literally a demo of how you use spline curves to build smooth paths that connect a bunch of node points πŸŽ€. it's giving realistic motion, it's giving animations, it's giving everything you ever wanted for your little guy sliding across the screen 🫢.

the technique, bestie, is this: you connect the series of guide points p1..p(n) with spline curves from p1-p2, p2-p3, etc. πŸ“ˆ each spline has to pass through both of its guide points, so those guide points get used as the first and fourth of the spline control points. and now the fun bit 😭: you have to come up with sensible values for the second and third spline control points so the spline segments have equal gradients where they meet. the author came up with this solution:

for each guide point p(n), calculate the desired tangent to the curve at that point 🌈. they took it to be the vector p(n-1) -> p(n+1), which is easy to calculate with the inverse tangent function, and it gives decent looking results ngl. one implication tho (and it's a real one): you need two dummy guide points at each end of the curve πŸ™ˆ. those get used in the tangent calculations but they are not connected to the set of splines. periodt.

having got those tangents, calculating the spline control points becomes fairly easy πŸ’…. for a spline between guide points p(a) and p(b):

  • the second control point should lie along the positive tangent from p(a)
  • the third control point should lie along the negative tangent from p(b)

how far they're placed along those tangents controls the shape of the curve πŸ‘‘. and what did they find works well? applying a 'curviness' scaling factor to the distance between p(a) and p(b). slay.

⚠️ one thing to note about splines: the generated points are not all equidistant. they tend to bunch up nearer to the ends of the spline 😭, which means you will need to apply some fudges to get an object moving at a constant speed. (fr fr, budget for the fudges.)

but lowkey? in situations where the curve has a noticeable change of direction at each guide point, the effect can be quite nice 🌿 because it makes the object slow down for the curve. main character motion, honestly πŸ’œ.


πŸŽ€ SEE ALSO πŸŽ€


okay that's the whole page bestie, go make something move real smooth πŸ’–βœ¨

Allegro Β· version 4.4.3 Β· exspline(3) β€” mwah, that's a wrap πŸŽ€πŸ¦‹πŸ’…

πŸ“¦ where this page comes from