diff --git a/docs/source/affine-mat.rst b/docs/source/affine-mat.rst index 0c0fcaa..43740cf 100644 --- a/docs/source/affine-mat.rst +++ b/docs/source/affine-mat.rst @@ -33,6 +33,7 @@ Table of contents (click func go): Functions: 1. :c:func:`glm_mul` +#. :c:func:`glm_mul_rot` #. :c:func:`glm_inv_tr` Functions documentation @@ -59,6 +60,27 @@ Functions documentation | *[in]* **m2** affine matrix 2 | *[out]* **dest** result matrix +.. c:function:: void glm_mul_rot(mat4 m1, mat4 m2, mat4 dest) + + | this is similar to glm_mat4_mul but specialized to rotation matrix + + Right Matrix format should be (left is free): + + .. code-block:: text + + R R R 0 + R R R 0 + R R R 0 + 0 0 0 1 + + this reduces some multiplications. It should be faster than mat4_mul. + if you are not sure about matrix format then DON'T use this! use mat4_mul + + Parameters: + | *[in]* **m1** affine matrix 1 + | *[in]* **m2** affine matrix 2 + | *[out]* **dest** result matrix + .. c:function:: void glm_inv_tr(mat4 mat) | inverse orthonormal rotation + translation matrix (ridig-body) diff --git a/docs/source/affine.rst b/docs/source/affine.rst index 8eaf01c..8ded38d 100644 --- a/docs/source/affine.rst +++ b/docs/source/affine.rst @@ -36,6 +36,15 @@ If you want to rotate model around arbibtrary point follow these steps: **glm_rotate_at**, **glm_quat_rotate_at** and their helper functions works that way. +The implementation would be: + +.. code-block:: c + :linenos: + + glm_translate(m, pivot); + glm_rotate(m, angle, axis); + glm_translate(m, pivotInv); /* pivotInv = -pivot */ + Transforms Order ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -68,7 +77,7 @@ because you call it first, do you? Result will be **`transform = transform * translate1`** -2. Then you call translate using `translate2` and you expect it will be second transform, really? +2. Then you call translate using `translate2` and you expect it will be second transform? Result will be **`transform = transform * translate2`**. Now lets expand transform, it was `transform * translate1` before second call. @@ -86,6 +95,8 @@ It is all about matrix multiplication order. It is similar to MVP matrix: **Confused?** +In the end the last function call applied first in shaders. + As alternative way, you can create transform matrices individually then combine manually, but don't forget that `glm_translate`, `glm_rotate`, `glm_scale`... are optimized and should be faster (an smaller assembly output) than manual multiplication @@ -121,14 +132,11 @@ Functions: #. :c:func:`glm_scale_to` #. :c:func:`glm_scale_make` #. :c:func:`glm_scale` -#. :c:func:`glm_scale1` #. :c:func:`glm_scale_uni` #. :c:func:`glm_rotate_x` #. :c:func:`glm_rotate_y` #. :c:func:`glm_rotate_z` -#. :c:func:`glm_rotate_ndc_make` #. :c:func:`glm_rotate_make` -#. :c:func:`glm_rotate_ndc` #. :c:func:`glm_rotate` #. :c:func:`glm_rotate_at` #. :c:func:`glm_rotate_atm` @@ -216,10 +224,6 @@ Functions documentation | *[in, out]* **m** affine transfrom | *[in]* **v** scale vector [x, y, z] -.. c:function:: void glm_scale1(mat4 m, float s) - - DEPRECATED! Use glm_scale_uni - .. c:function:: void glm_scale_uni(mat4 m, float s) applies uniform scale to existing transform matrix v = [s, s, s] @@ -259,16 +263,6 @@ Functions documentation | *[in]* **angle** angle (radians) | *[out]* **dest** rotated matrix -.. c:function:: void glm_rotate_ndc_make(mat4 m, float angle, vec3 axis_ndc) - - creates NEW rotation matrix by angle and axis - this name may change in the future. axis must be is normalized - - Parameters: - | *[out]* **m** affine transfrom - | *[in]* **angle** angle (radians) - | *[in]* **axis_ndc** normalized axis - .. c:function:: void glm_rotate_make(mat4 m, float angle, vec3 axis) creates NEW rotation matrix by angle and axis, @@ -279,16 +273,6 @@ Functions documentation | *[in]* **axis** angle (radians) | *[in]* **axis** axis -.. c:function:: void glm_rotate_ndc(mat4 m, float angle, vec3 axis_ndc) - - rotate existing transform matrix around Z axis by angle and axis - this name may change in the future, axis must be normalized. - - Parameters: - | *[out]* **m** affine transfrom - | *[in]* **angle** angle (radians) - | *[in]* **axis_ndc** normalized axis - .. c:function:: void glm_rotate(mat4 m, float angle, vec3 axis) rotate existing transform matrix around Z axis by angle and axis diff --git a/include/cglm/affine.h b/include/cglm/affine.h index 953b31c..95d60b7 100644 --- a/include/cglm/affine.h +++ b/include/cglm/affine.h @@ -16,7 +16,6 @@ CGLM_INLINE void glm_scale_to(mat4 m, vec3 v, mat4 dest); CGLM_INLINE void glm_scale_make(mat4 m, vec3 v); CGLM_INLINE void glm_scale(mat4 m, vec3 v); - CGLM_INLINE void glm_scale1(mat4 m, float s); CGLM_INLINE void glm_scale_uni(mat4 m, float s); CGLM_INLINE void glm_rotate_x(mat4 m, float angle, mat4 dest); CGLM_INLINE void glm_rotate_y(mat4 m, float angle, mat4 dest); @@ -242,16 +241,6 @@ glm_scale(mat4 m, vec3 v) { glm_scale_to(m, v, m); } -/*! - * @brief DEPRECATED! Use glm_scale_uni - */ -CGLM_INLINE -void -glm_scale1(mat4 m, float s) { - vec3 v = { s, s, s }; - glm_scale_to(m, v, m); -} - /*! * @brief applies uniform scale to existing transform matrix v = [s, s, s] * and stores result in same matrix diff --git a/include/cglm/call/affine.h b/include/cglm/call/affine.h index 4e30fff..4d3834b 100644 --- a/include/cglm/call/affine.h +++ b/include/cglm/call/affine.h @@ -49,10 +49,6 @@ CGLM_EXPORT void glmc_scale(mat4 m, vec3 v); -CGLM_EXPORT -void -glmc_scale1(mat4 m, float s); - CGLM_EXPORT void glmc_scale_uni(mat4 m, float s); diff --git a/src/affine.c b/src/affine.c index 0c028ba..a271f9f 100644 --- a/src/affine.c +++ b/src/affine.c @@ -62,12 +62,6 @@ glmc_scale(mat4 m, vec3 v) { glm_scale(m, v); } -CGLM_EXPORT -void -glmc_scale1(mat4 m, float s) { - glm_scale1(m, s); -} - CGLM_EXPORT void glmc_scale_uni(mat4 m, float s) {