From 06b2a531133ffc1bbc080dd28f8d91692e46c532 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 11 Jul 2018 11:29:47 +0300 Subject: [PATCH] cubic bezier interpolation --- include/cglm/bezier.h | 36 ++++++++++++++++++++++++++++++++++++ include/cglm/cglm.h | 1 + 2 files changed, 37 insertions(+) create mode 100644 include/cglm/bezier.h diff --git a/include/cglm/bezier.h b/include/cglm/bezier.h new file mode 100644 index 0000000..4e8ae27 --- /dev/null +++ b/include/cglm/bezier.h @@ -0,0 +1,36 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_bezier_h +#define cglm_bezier_h + +#include "common.h" + +/*! + * @brief cubic bezier interpolation + * + * @param[in] t time between 0 and 1 + * @param[in] p0 begin point + * @param[in] c0 control point 1 + * @param[in] c1 control point 2 + * @param[in] p1 end point + * + * @return B(s) + */ +CGLM_INLINE +float +glm_bezier_cubic(float t, float p0, float c0, float c1, float p1) { + float s, ss, tt; + + s = 1.0f - t; + ss = s * s; + tt = t * t; + + return p0 * ss * s + 3.0f * c0 * t * ss + 3.0f * c1 * tt * s + p1 * tt * t; +} + +#endif /* cglm_bezier_h */ diff --git a/include/cglm/cglm.h b/include/cglm/cglm.h index 8b37162..87feb0f 100644 --- a/include/cglm/cglm.h +++ b/include/cglm/cglm.h @@ -26,5 +26,6 @@ #include "project.h" #include "sphere.h" #include "ease.h" +#include "bezier.h" #endif /* cglm_h */