comparison src/dmcurves.c @ 978:fecf3967abee

Move lerp functions from dmlerp.c to dmcurves.c, too.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 27 Feb 2015 16:20:24 +0200
parents 1b439304ff3c
children 0ba1ec9b8608
comparison
equal deleted inserted replaced
977:4a6dece98cb2 978:fecf3967abee
3 * -- Curve and spline functions 3 * -- Curve and spline functions
4 * Programmed and designed by Matti 'ccr' Hamalainen 4 * Programmed and designed by Matti 'ccr' Hamalainen
5 * (C) Copyright 2015 Tecnic Software productions (TNSP) 5 * (C) Copyright 2015 Tecnic Software productions (TNSP)
6 */ 6 */
7 #include "dmcurves.h" 7 #include "dmcurves.h"
8
9
10 void dmLerpInit(DMLerpContext *ctx, DMFloat start, DMFloat end, DMFloat nsteps)
11 {
12 ctx->start = start;
13 ctx->end = end;
14 ctx->nsteps = nsteps;
15 }
16
17
18 DMFloat dmCatmullRom(const DMFloat t, const DMFloat p0, const DMFloat p1, const DMFloat p2, const DMFloat p3)
19 {
20 const DMFloat q = t * t;
21 return (
22 (2 * p1) +
23 (-p0 + p2) * t +
24 (2 * p0 - 5 * p1 + 4 * p2 - p3) * q +
25 ( -p0 + 3 * p1 - 3 * p2 + p3) * q * t
26 ) * 0.5f;
27 }
8 28
9 29
10 static inline const DMVector *dmSplineGetPoint(const DMVector *points, const int npoints, const int n) 30 static inline const DMVector *dmSplineGetPoint(const DMVector *points, const int npoints, const int n)
11 { 31 {
12 return (n < 0) ? &points[0] : ((n < npoints) ? &points[n] : &points[npoints - 1]); 32 return (n < 0) ? &points[0] : ((n < npoints) ? &points[n] : &points[npoints - 1]);