diff --git a/README.md b/README.md index dffa54c..d03a03f 100644 --- a/README.md +++ b/README.md @@ -82,7 +82,11 @@ Currently *cglm* uses default clip space configuration (-1, 1) for camera functi - inline or pre-compiled function call - frustum (extract view frustum planes, corners...) - bounding box (AABB in Frustum (culling), crop, merge...) +- bounding sphere - project, unproject +- easing functions +- curves +- curve interpolation helpers (S*M*C, deCasteljau...) - and other...
diff --git a/docs/source/api.rst b/docs/source/api.rst index c7f74a5..408eae7 100644 --- a/docs/source/api.rst +++ b/docs/source/api.rst @@ -47,3 +47,4 @@ Follow the :doc:`build` documentation for this call sphere curve + bezier diff --git a/docs/source/bezier.rst b/docs/source/bezier.rst new file mode 100644 index 0000000..8b29751 --- /dev/null +++ b/docs/source/bezier.rst @@ -0,0 +1,89 @@ +.. default-domain:: C + +Bezier +================================================================================ + +Header: cglm/bezier.h + +Common helpers for cubic bezier and similar curves. + +Table of contents (click to go): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Functions: + +1. :c:func:`glm_bezier` +2. :c:func:`glm_hermite` +3. :c:func:`glm_decasteljau` + +Functions documentation +~~~~~~~~~~~~~~~~~~~~~~~ + +.. c:function:: float glm_bezier(float s, float p0, float c0, float c1, float p1) + + | cubic bezier interpolation + | formula: + + .. code-block:: text + + B(s) = P0*(1-s)^3 + 3*C0*s*(1-s)^2 + 3*C1*s^2*(1-s) + P1*s^3 + + | similar result using matrix: + + .. code-block:: text + + B(s) = glm_smc(t, GLM_BEZIER_MAT, (vec4){p0, c0, c1, p1}) + + | glm_eq(glm_smc(...), glm_bezier(...)) should return TRUE + + Parameters: + | *[in]* **s** parameter between 0 and 1 + | *[in]* **p0** begin point + | *[in]* **c0** control point 1 + | *[in]* **c1** control point 2 + | *[in]* **p1** end point + + Returns: + B(s) + +.. c:function:: float glm_hermite(float s, float p0, float t0, float t1, float p1) + + | cubic hermite interpolation + | formula: + + .. code-block:: text + + H(s) = P0*(2*s^3 - 3*s^2 + 1) + T0*(s^3 - 2*s^2 + s) + P1*(-2*s^3 + 3*s^2) + T1*(s^3 - s^2) + + | similar result using matrix: + + .. code-block:: text + + H(s) = glm_smc(t, GLM_HERMITE_MAT, (vec4){p0, p1, c0, c1}) + + | glm_eq(glm_smc(...), glm_hermite(...)) should return TRUE + + + Parameters: + | *[in]* **s** parameter between 0 and 1 + | *[in]* **p0** begin point + | *[in]* **t0** tangent 1 + | *[in]* **t1** tangent 2 + | *[in]* **p1** end point + + Returns: + B(s) + +.. c:function:: float glm_decasteljau(float prm, float p0, float c0, float c1, float p1) + + | iterative way to solve cubic equation + + Parameters: + | *[in]* **prm** parameter between 0 and 1 + | *[in]* **p0** begin point + | *[in]* **c0** control point 1 + | *[in]* **c1** control point 2 + | *[in]* **p1** end point + + Returns: + parameter to use in cubic equation diff --git a/include/cglm/bezier.h b/include/cglm/bezier.h index 8b1ee6e..1d194f5 100644 --- a/include/cglm/bezier.h +++ b/include/cglm/bezier.h @@ -75,7 +75,7 @@ glm_bezier(float s, float p0, float c0, float c1, float p1) { * @param[in] t1 tangent 2 * @param[in] p1 end point * - * @return B(s) + * @return H(s) */ CGLM_INLINE float