Mercurial > hg > dmlib
diff src/dmlib.h @ 976:1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
etc and the LERP functions. Move LERP functions from dmlib.h to dmcurves.h.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 27 Feb 2015 16:16:59 +0200 |
parents | f654435df15e |
children | 43594ac98f91 |
line wrap: on
line diff
--- a/src/dmlib.h Fri Feb 27 14:49:02 2015 +0200 +++ b/src/dmlib.h Fri Feb 27 16:16:59 2015 +0200 @@ -206,69 +206,6 @@ } -/* Generic parameter interpolation - */ -#define DMM_S_CURVE(t) ((t) * (t) * (3.0f - 2.0f * (t))) -#define DMM_LERP(t, a, b) ((a) + (t) * ((b) - (a))) - -typedef struct -{ - DMFloat start, end, nsteps; -} DMLerpContext; - - -void dmLerpInit(DMLerpContext *ctx, DMFloat start, DMFloat end, DMFloat nsteps); -DMFloat dmCatmullRom(const DMFloat t, const DMFloat p0, const DMFloat p1, const DMFloat p2, const DMFloat p3); - - -static inline DMFloat dmClamp10(const DMFloat a) -{ - return (a < 0.0f ? 0.0f : (a > 1.0f ? 1.0f : a)); -} - - -static inline int dmClamp(const int v, const int min, const int max) -{ - return (v < min ? min : (v > max ? max : v)); -} - - -static inline DMFloat dmLerpSCurve(DMLerpContext *ctx, const DMFloat step) -{ - const DMFloat n = step / ctx->nsteps; - const DMFloat v = DMM_S_CURVE(n); - return DMM_LERP(v, ctx->start, ctx->end); -} - - -static inline DMFloat dmLerpSCurveClamp(DMLerpContext *ctx, const DMFloat step) -{ - const DMFloat n = dmClamp10(step / ctx->nsteps); - const DMFloat v = DMM_S_CURVE(n); - return DMM_LERP(v, ctx->start, ctx->end); -} - - -static inline DMFloat dmLerp1(DMLerpContext *ctx, const DMFloat step) -{ - const DMFloat v = step / ctx->nsteps; - return DMM_LERP(v, ctx->start, ctx->end); -} - - -static inline DMFloat dmLerp1Clamp(DMLerpContext *ctx, const DMFloat step) -{ - const DMFloat v = dmClamp10(step / ctx->nsteps); - return DMM_LERP(v, ctx->start, ctx->end); -} - - -static inline DMFloat dmCatmullRomClamp(const DMFloat t, const DMFloat p0, const DMFloat p1, const DMFloat p2, const DMFloat p3) -{ - return dmCatmullRom(dmClamp10(t), p0, p1, p2, p3); -} - - /* Arbitrary line drawing */ #ifdef DM_GFX_LINES