Mercurial > hg > dmlib
changeset 108:72813cece1ba
Move some lerp functions to the header as static inline functions.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 03 Oct 2012 09:39:15 +0300 |
parents | 1c2ff205fa0e |
children | 3de6301dcfe1 |
files | dmlerp.c dmlib.h |
diffstat | 2 files changed, 44 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/dmlerp.c Wed Oct 03 09:29:29 2012 +0300 +++ b/dmlerp.c Wed Oct 03 09:39:15 2012 +0300 @@ -8,22 +8,7 @@ } -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); -} - - -DMFloat dmLerp1(DMLerpContext *ctx, const DMFloat step) -{ - const DMFloat v = step / ctx->nsteps; - return DMM_LERP(v, ctx->start, ctx->end); -} - - -DMFloat dmCatmull_Rom(const DMFloat t, const DMFloat p0, const DMFloat p1, const DMFloat p2, const DMFloat p3) +DMFloat dmCatmullRom(const DMFloat t, const DMFloat p0, const DMFloat p1, const DMFloat p2, const DMFloat p3) { const DMFloat q = t * t; return (
--- a/dmlib.h Wed Oct 03 09:29:29 2012 +0300 +++ b/dmlib.h Wed Oct 03 09:39:15 2012 +0300 @@ -206,9 +206,49 @@ void dmLerpInit(DMLerpContext *ctx, DMFloat start, DMFloat end, DMFloat nsteps); -DMFloat dmLerpSCurve(DMLerpContext *ctx, const DMFloat step); -DMFloat dmLerp1(DMLerpContext *ctx, const DMFloat step); -DMFloat dmCatmull_Rom(const DMFloat t, const DMFloat p0, const DMFloat p1, const DMFloat p2, const DMFloat p3); +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 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); +} /* Perlin noise @@ -278,12 +318,6 @@ #endif -static inline DMFloat dmClip10(const DMFloat a) -{ - return (a < 0.0f ? 0.0f : (a > 1.0f ? 1.0f : a)); -} - - /* Global variables */ extern char *dmProgName,