calc_spline(3)

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

πŸ’– calc_spline β€” the Allegro manual, but make it make sense ✨

okay bestie, so this is a page from the Allegro manual (that's the manual name, yes, we're fancy like that πŸ’…) and today's main character is calc_spline(3). Buckle up, it's giving math but make it cute. πŸŽ€


🌸 NAME 🌸

calc_spline β€” calculates a series of values along a Bezier spline. πŸ¦‹

(Also: it lives in the Allegro game programming library, so like, it's a whole vibe.) πŸ’œ


✨ SYNOPSIS ✨

#include <allegro.h>

void calc_spline(const int points[8], int npts, int *x, int *y);

yes that's the whole thing, she's compact, she's iconic, she's not gonna waste your time. πŸ‘‘


🫢 DESCRIPTION 🫢

So what she does: she calculates a series of npts values along a Bezier spline, and stores them in the output x and y arrays. Boom. Done. Slay. πŸ’…

The Bezier curve itself is specified by the four x/y control points in the points array, and the way it's laid out is:

  • points[0] and points[1] contain the coordinates of the first control point
  • points[2] and points[3] are the second point
  • points[4] and points[5] are the third point
  • points[6] and points[7] are the fourth point

(etc., you get the pattern, it just keeps going like that 🧚)

Control points 0 and 3 are the ends of the spline. Control points 1 and 2 are just guides. Important: the curve probably won't pass through points 1 and 2, but bestie they absolutely affect the shape of the curve between points 0 and 3 β€” because the lines p0-p1 and p2-p3 are tangents</> to the spline. πŸŒ€

The easiest way to think of it (and honestly the only way my brain will accept it) is:

the curve starts at p0, heading in the direction of p1, but curves round so that it arrives at p3 from the direction of p2. 🌈

Not me explaining tangents like it's gossip. 😭 Anyway.

And like, in addition to their role as graphics primitives, spline curves can be useful for constructing smooth paths around a series of control points β€” as in exspline.c. So if you wanna see this in the wild, that's your girl. πŸ“


πŸ‘€ SEE ALSO πŸ‘€


okay that's the whole page, you ate that, go build something smooth and gorgeous with it πŸ¦‹βœ¨

this little love letter came to you from Allegro, version 4.4.3 β€” mwah, periodt πŸ’–πŸ‘‘πŸŽ€

πŸ“¦ where this page comes from