diff dmlib.h @ 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 93fbce0e6591
children c36e0316de9f
line wrap: on
line diff
--- 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,