1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
|
.. default-domain:: C
mat4
====
Header: cglm/mat4.h
Important: :c:func:`glm_mat4_scale` multiplies mat4 with scalar, if you need to
apply scale transform use :c:func:`glm_scale` functions.
Table of contents (click to go):
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Macros:
1. GLM_MAT4_IDENTITY_INIT
#. GLM_MAT4_ZERO_INIT
#. GLM_MAT4_IDENTITY
#. GLM_MAT4_ZERO
#. glm_mat4_udup(mat, dest)
#. glm_mat4_dup(mat, dest)
Functions:
1. :c:func:`glm_mat4_ucopy`
#. :c:func:`glm_mat4_copy`
#. :c:func:`glm_mat4_identity`
#. :c:func:`glm_mat4_identity_array`
#. :c:func:`glm_mat4_zero`
#. :c:func:`glm_mat4_pick3`
#. :c:func:`glm_mat4_pick3t`
#. :c:func:`glm_mat4_ins3`
#. :c:func:`glm_mat4_mul`
#. :c:func:`glm_mat4_mulN`
#. :c:func:`glm_mat4_mulv`
#. :c:func:`glm_mat4_mulv3`
#. :c:func:`glm_mat4_trace`
#. :c:func:`glm_mat4_trace3`
#. :c:func:`glm_mat4_quat`
#. :c:func:`glm_mat4_transpose_to`
#. :c:func:`glm_mat4_transpose`
#. :c:func:`glm_mat4_scale_p`
#. :c:func:`glm_mat4_scale`
#. :c:func:`glm_mat4_det`
#. :c:func:`glm_mat4_inv`
#. :c:func:`glm_mat4_inv_fast`
#. :c:func:`glm_mat4_swap_col`
#. :c:func:`glm_mat4_swap_row`
#. :c:func:`glm_mat4_rmc`
#. :c:func:`glm_mat4_make`
Functions documentation
~~~~~~~~~~~~~~~~~~~~~~~
.. c:function:: void glm_mat4_ucopy(mat4 mat, mat4 dest)
copy mat4 to another one (dest). u means align is not required for dest
Parameters:
| *[in]* **mat** source
| *[out]* **dest** destination
.. c:function:: void glm_mat4_copy(mat4 mat, mat4 dest)
copy mat4 to another one (dest).
Parameters:
| *[in]* **mat** source
| *[out]* **dest** destination
.. c:function:: void glm_mat4_identity(mat4 mat)
copy identity mat4 to mat, or makes mat to identity
Parameters:
| *[out]* **mat** matrix
.. c:function:: void glm_mat4_identity_array(mat4 * __restrict mat, size_t count)
make given matrix array's each element identity matrix
Parameters:
| *[in,out]* **mat** matrix array (must be aligned (16/32) if alignment is not disabled)
| *[in]* **count** count of matrices
.. c:function:: void glm_mat4_zero(mat4 mat)
make given matrix zero
Parameters:
| *[in,out]* **mat** matrix to
.. c:function:: void glm_mat4_pick3(mat4 mat, mat3 dest)
copy upper-left of mat4 to mat3
Parameters:
| *[in]* **mat** source
| *[out]* **dest** destination
.. c:function:: void glm_mat4_pick3t(mat4 mat, mat4 dest)
copy upper-left of mat4 to mat3 (transposed)
the postfix t stands for transpose
Parameters:
| *[in]* **mat** source
| *[out]* **dest** destination
.. c:function:: void glm_mat4_ins3(mat3 mat, mat4 dest)
copy mat3 to mat4's upper-left. this function does not fill mat4's other
elements. To do that use glm_mat4.
Parameters:
| *[in]* **mat** source
| *[out]* **dest** destination
.. c:function:: void glm_mat4_mul(mat4 m1, mat4 m2, mat4 dest)
multiply m1 and m2 to dest
m1, m2 and dest matrices can be same matrix, it is possible to write this:
.. code-block:: c
mat4 m = GLM_MAT4_IDENTITY_INIT;
glm_mat4_mul(m, m, m);
Parameters:
| *[in]* **m1** left matrix
| *[in]* **m2** right matrix
| *[out]* **dest** destination matrix
.. c:function:: void glm_mat4_mulN(mat4 * __restrict matrices[], int len, mat4 dest)
mupliply N mat4 matrices and store result in dest
| this function lets you multiply multiple (more than two or more...)
| matrices
| multiplication will be done in loop, this may reduce instructions
| size but if **len** is too small then compiler may unroll whole loop
.. code-block:: c
mat m1, m2, m3, m4, res;
glm_mat4_mulN((mat4 *[]){&m1, &m2, &m3, &m4}, 4, res);
Parameters:
| *[in]* **matrices** array of mat4
| *[in]* **len** matrices count
| *[out]* **dest** destination matrix
.. c:function:: void glm_mat4_mulv(mat4 m, vec4 v, vec4 dest)
multiply mat4 with vec4 (column vector) and store in dest vector
Parameters:
| *[in]* **m** mat4 (left)
| *[in]* **v** vec4 (right, column vector)
| *[out]* **dest** vec4 (result, column vector)
.. c:function:: void glm_mat4_mulv3(mat4 m, vec3 v, float last, vec3 dest)
| multiply **vec3** with **mat4** and get **vec3** as result
|
| actually the result is **vec4**, after multiplication,
the last component is trimmed, if you need the result's last component
then don't use this function and consider to use **glm_mat4_mulv()**
Parameters:
| *[in]* **m** mat4(affine transform)
| *[in]* **v** vec3
| *[in]* **last** 4th item to make it vec4
| *[out]* **dest** result vector (vec3)
.. c:function:: void glm_mat4_trace(mat4 m)
| sum of the elements on the main diagonal from upper left to the lower right
Parameters:
| *[in]* **m** matrix
Returns:
trace of matrix
.. c:function:: void glm_mat4_trace3(mat4 m)
| trace of matrix (rotation part)
| sum of the elements on the main diagonal from upper left to the lower right
Parameters:
| *[in]* **m** matrix
Returns:
trace of matrix
.. c:function:: void glm_mat4_quat(mat4 m, versor dest)
convert mat4's rotation part to quaternion
Parameters:
| *[in]* **m** affine matrix
| *[out]* **dest** destination quaternion
.. c:function:: void glm_mat4_transpose_to(mat4 m, mat4 dest)
transpose mat4 and store in dest
source matrix will not be transposed unless dest is m
Parameters:
| *[in]* **m** matrix
| *[out]* **dest** destination matrix
.. c:function:: void glm_mat4_transpose(mat4 m)
transpose mat4 and store result in same matrix
Parameters:
| *[in]* **m** source
| *[out]* **dest** destination matrix
.. c:function:: void glm_mat4_scale_p(mat4 m, float s)
scale (multiply with scalar) matrix without simd optimization
Parameters:
| *[in, out]* **m** matrix
| *[in]* **s** scalar
.. c:function:: void glm_mat4_scale(mat4 m, float s)
scale (multiply with scalar) matrix
THIS IS NOT SCALE TRANSFORM, use glm_scale for that.
Parameters:
| *[in, out]* **m** matrix
| *[in]* **s** scalar
.. c:function:: float glm_mat4_det(mat4 mat)
mat4 determinant
Parameters:
| *[in]* **mat** matrix
Return:
| determinant
.. c:function:: void glm_mat4_inv(mat4 mat, mat4 dest)
inverse mat4 and store in dest
Parameters:
| *[in]* **mat** source
| *[out]* **dest** destination matrix (inverse matrix)
.. c:function:: void glm_mat4_inv_fast(mat4 mat, mat4 dest)
inverse mat4 and store in dest
| this func uses reciprocal approximation without extra corrections
| e.g Newton-Raphson. this should work faster than normal,
| to get more precise use glm_mat4_inv version.
.. note:: You will lose precision, glm_mat4_inv is more accurate
Parameters:
| *[in]* **mat** source
| *[out]* **dest** destination
.. c:function:: void glm_mat4_swap_col(mat4 mat, int col1, int col2)
swap two matrix columns
Parameters:
| *[in, out]* **mat** matrix
| *[in]* **col1** col1
| *[in]* **col2** col2
.. c:function:: void glm_mat4_swap_row(mat4 mat, int row1, int row2)
swap two matrix rows
Parameters:
| *[in, out]* **mat** matrix
| *[in]* **row1** row1
| *[in]* **row2** row2
.. c:function:: float glm_mat4_rmc(vec4 r, mat4 m, vec4 c)
| **rmc** stands for **Row** * **Matrix** * **Column**
| helper for R (row vector) * M (matrix) * C (column vector)
| the result is scalar because R * M = Matrix1x4 (row vector),
| then Matrix1x4 * Vec4 (column vector) = Matrix1x1 (Scalar)
Parameters:
| *[in]* **r** row vector or matrix1x4
| *[in]* **m** matrix4x4
| *[in]* **c** column vector or matrix4x1
Returns:
scalar value e.g. Matrix1x1
.. c:function:: void glm_mat4_make(const float * __restrict src, mat4 dest)
Create mat4 matrix from pointer
.. note:: **@src** must contain at least 16 elements.
Parameters:
| *[in]* **src** pointer to an array of floats
| *[out]* **dest** destination matrix4x4
|