Mercurial > hg > dmlib
annotate src/dmcurves.h @ 2256:fe974f670d1d
Rename a variable.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 15 Jun 2019 22:53:25 +0300 |
parents | 67f5c9d60c72 |
children |
rev | line source |
---|---|
976
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 /* |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2 * DMLib |
1084
67f5c9d60c72
The module header description was incorrect (due to copypaste), fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
1081
diff
changeset
|
3 * -- Curve and spline functions |
976
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
4 * Programmed and designed by Matti 'ccr' Hamalainen |
1084
67f5c9d60c72
The module header description was incorrect (due to copypaste), fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
1081
diff
changeset
|
5 * (C) Copyright 2015 Tecnic Software productions (TNSP) |
976
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
6 */ |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 #ifndef DMCURVES_H |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
8 #define DMCURVES_H |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
9 |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
10 #include "dmlib.h" |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
11 #include "dmvecmat.h" |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
12 |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
13 #ifdef __cplusplus |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
14 extern "C" { |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
15 #endif |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
16 |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 /* Generic parameter interpolation |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
18 */ |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
19 #define DMM_S_CURVE(t) ((t) * (t) * (3.0f - 2.0f * (t))) |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
20 #define DMM_LERP(t, a, b) ((a) + (t) * ((b) - (a))) |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
21 |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
22 typedef struct |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
23 { |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
24 DMFloat start, end, nsteps; |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
25 } DMLerpContext; |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
26 |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
27 |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
28 void dmLerpInit(DMLerpContext *ctx, DMFloat start, DMFloat end, DMFloat nsteps); |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
29 DMFloat dmCatmullRom(const DMFloat t, const DMFloat p0, const DMFloat p1, const DMFloat p2, const DMFloat p3); |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
30 |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
31 |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
32 static inline DMFloat dmLerpSCurve(DMLerpContext *ctx, const DMFloat step) |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
33 { |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
34 const DMFloat n = step / ctx->nsteps; |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
35 const DMFloat v = DMM_S_CURVE(n); |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
36 return DMM_LERP(v, ctx->start, ctx->end); |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
37 } |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
38 |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
39 |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
40 static inline DMFloat dmLerpSCurveClamp(DMLerpContext *ctx, const DMFloat step) |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
41 { |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
42 const DMFloat n = dmClamp10(step / ctx->nsteps); |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
43 const DMFloat v = DMM_S_CURVE(n); |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
44 return DMM_LERP(v, ctx->start, ctx->end); |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
45 } |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
46 |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
47 |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
48 static inline DMFloat dmLerp1(DMLerpContext *ctx, const DMFloat step) |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
49 { |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
50 const DMFloat v = step / ctx->nsteps; |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
51 return DMM_LERP(v, ctx->start, ctx->end); |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
52 } |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
53 |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
54 |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
55 static inline DMFloat dmLerp1Clamp(DMLerpContext *ctx, const DMFloat step) |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
56 { |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
57 const DMFloat v = dmClamp10(step / ctx->nsteps); |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
58 return DMM_LERP(v, ctx->start, ctx->end); |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
59 } |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
60 |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
61 |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
62 static inline DMFloat dmCatmullRomClamp(const DMFloat t, const DMFloat p0, const DMFloat p1, const DMFloat p2, const DMFloat p3) |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
63 { |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
64 return dmCatmullRom(dmClamp10(t), p0, p1, p2, p3); |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
65 } |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
66 |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
67 |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
68 static inline int dmBSplineGetNPoints(const int npoints, const int slod) |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
69 { |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
70 return npoints * slod; |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
71 } |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
72 |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
73 int dmBSplineGenerateAlloc(DMVector **dst, int *ndst, const DMVector *points, const int npoints, const int slod); |
1081
7df95aefb9c6
Make bspline functions more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
980
diff
changeset
|
74 int dmBSplineGenerateArray(DMVector *dst, const int ndst, const DMVector *points, const int npoints, const int slod); |
7df95aefb9c6
Make bspline functions more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
980
diff
changeset
|
75 |
7df95aefb9c6
Make bspline functions more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
980
diff
changeset
|
76 int dmBSplineGenerate(const DMVector *points, const int npoints, const int slod, |
7df95aefb9c6
Make bspline functions more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
980
diff
changeset
|
77 int (*callback)(void *data, const int ndst, const int nc, float x, float y, float z), |
7df95aefb9c6
Make bspline functions more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
980
diff
changeset
|
78 void *data, const int ndst); |
976
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
79 |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
80 |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
81 #ifdef __cplusplus |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
82 } |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
83 #endif |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
84 |
1b439304ff3c
Add new module dmcurves, that will contain functions for spline generation
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
85 #endif // DMCURVES_H |