Skip to content
modkitv0.2

math/spline.h

#include <modkit/math/spline.h>5 functions

Spline evaluation (Bezier, Catmull-Rom, Hermite).

Pure evaluation helpers given control points and a parameter t, return the point (or tangent) on the curve. These are the math behind mk_draw3d_bezier / mk_draw3d_catmull_rom, exposed so you can move objects along a path, not just draw it. Header-only, like math/mat4.h.

Functions

mk_spline_bezierfunction

mk_vec3 mk_spline_bezier(mk_vec3 p0, mk_vec3 p1, mk_vec3 p2, mk_vec3 p3, float t)

Point on a cubic Bezier defined by p0..p3 at t in [0,1].

ParameterTypeDescription
p0mk_vec3Value for p0.
p1mk_vec3Value for p1.
p2mk_vec3Value for p2.
p3mk_vec3Value for p3.
tfloatValue for t.

Returns The resulting value.

mk_spline_bezier_tangentfunction

mk_vec3 mk_spline_bezier_tangent(mk_vec3 p0, mk_vec3 p1, mk_vec3 p2, mk_vec3 p3, float t)

Unnormalized tangent (derivative) of a cubic Bezier at t.

ParameterTypeDescription
p0mk_vec3Value for p0.
p1mk_vec3Value for p1.
p2mk_vec3Value for p2.
p3mk_vec3Value for p3.
tfloatValue for t.

Returns The resulting value.

mk_spline_catmull_romfunction

mk_vec3 mk_spline_catmull_rom(mk_vec3 p0, mk_vec3 p1, mk_vec3 p2, mk_vec3 p3, float t)

Point on the Catmull-Rom segment between p1 and p2 at t in [0,1].

ParameterTypeDescription
p0mk_vec3Value for p0.
p1mk_vec3Value for p1.
p2mk_vec3Value for p2.
p3mk_vec3Value for p3.
tfloatValue for t.

Returns The resulting value.

mk_spline_catmull_rom_pathfunction

mk_vec3 mk_spline_catmull_rom_path(const mk_vec3 *pts, int count, float u)

Evaluate a Catmull-Rom spline through an array of control points.

Needs at least 4 points; u in [0,1] maps across all interior segments (the first and last points act as tangent anchors).

ParameterTypeDescription
ptsconst mk_vec3 *Value for pts.
countintNumber of entries.
ufloatValue for u.

Returns The resulting value.

mk_spline_hermitefunction

mk_vec3 mk_spline_hermite(mk_vec3 p0, mk_vec3 m0, mk_vec3 p1, mk_vec3 m1, float t)

Point on a cubic Hermite curve at t in [0,1].

ParameterTypeDescription
p0mk_vec3Value for p0.
m0mk_vec3Value for m0.
p1mk_vec3Value for p1.
m1mk_vec3Value for m1.
tfloatValue for t.

Returns The resulting value.