Mercurial > hg > dmlib
view src/dmcurves.h @ 2379:7011e11dad9a
Comments.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 08 Jan 2020 13:08:06 +0200 |
parents | 67f5c9d60c72 |
children |
line wrap: on
line source
/* * DMLib * -- Curve and spline functions * Programmed and designed by Matti 'ccr' Hamalainen * (C) Copyright 2015 Tecnic Software productions (TNSP) */ #ifndef DMCURVES_H #define DMCURVES_H #include "dmlib.h" #include "dmvecmat.h" #ifdef __cplusplus extern "C" { #endif /* 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 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); } static inline int dmBSplineGetNPoints(const int npoints, const int slod) { return npoints * slod; } int dmBSplineGenerateAlloc(DMVector **dst, int *ndst, const DMVector *points, const int npoints, const int slod); int dmBSplineGenerateArray(DMVector *dst, const int ndst, const DMVector *points, const int npoints, const int slod); int dmBSplineGenerate(const DMVector *points, const int npoints, const int slod, int (*callback)(void *data, const int ndst, const int nc, float x, float y, float z), void *data, const int ndst); #ifdef __cplusplus } #endif #endif // DMCURVES_H