matrix: trace of matrix

This commit is contained in:
Recep Aslantas
2018-12-06 18:17:02 +03:00
parent 2ef9c23a6c
commit 21834b4ffb
8 changed files with 105 additions and 0 deletions

View File

@@ -29,6 +29,7 @@ Functions:
#. :c:func:`glm_mat3_scale` #. :c:func:`glm_mat3_scale`
#. :c:func:`glm_mat3_det` #. :c:func:`glm_mat3_det`
#. :c:func:`glm_mat3_inv` #. :c:func:`glm_mat3_inv`
#. :c:func:`glm_mat3_trace`
#. :c:func:`glm_mat3_swap_col` #. :c:func:`glm_mat3_swap_col`
#. :c:func:`glm_mat3_swap_row` #. :c:func:`glm_mat3_swap_row`
@@ -133,6 +134,16 @@ Functions documentation
| *[in]* **mat** matrix | *[in]* **mat** matrix
| *[out]* **dest** destination (inverse matrix) | *[out]* **dest** destination (inverse matrix)
.. c:function:: void glm_mat3_trace(mat3 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_mat3_swap_col(mat3 mat, int col1, int col2) .. c:function:: void glm_mat3_swap_col(mat3 mat, int col1, int col2)
swap two matrix columns swap two matrix columns

View File

@@ -33,6 +33,8 @@ Functions:
#. :c:func:`glm_mat4_mulN` #. :c:func:`glm_mat4_mulN`
#. :c:func:`glm_mat4_mulv` #. :c:func:`glm_mat4_mulv`
#. :c:func:`glm_mat4_mulv3` #. :c:func:`glm_mat4_mulv3`
#. :c:func:`glm_mat3_trace`
#. :c:func:`glm_mat3_trace3`
#. :c:func:`glm_mat4_quat` #. :c:func:`glm_mat4_quat`
#. :c:func:`glm_mat4_transpose_to` #. :c:func:`glm_mat4_transpose_to`
#. :c:func:`glm_mat4_transpose` #. :c:func:`glm_mat4_transpose`
@@ -156,6 +158,27 @@ Functions documentation
| *[in]* **v** vec3 (right, column vector) | *[in]* **v** vec3 (right, column vector)
| *[out]* **dest** vec3 (result, column vector) | *[out]* **dest** vec3 (result, column vector)
.. 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) .. c:function:: void glm_mat4_quat(mat4 m, versor dest)
convert mat4's rotation part to quaternion convert mat4's rotation part to quaternion

View File

@@ -44,6 +44,10 @@ CGLM_EXPORT
void void
glmc_mat3_mulv(mat3 m, vec3 v, vec3 dest); glmc_mat3_mulv(mat3 m, vec3 v, vec3 dest);
CGLM_EXPORT
float
glmc_mat3_trace(mat3 m);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_mat3_quat(mat3 m, versor dest); glmc_mat3_quat(mat3 m, versor dest);

View File

@@ -61,6 +61,14 @@ CGLM_EXPORT
void void
glmc_mat4_mulv3(mat4 m, vec3 v, float last, vec3 dest); glmc_mat4_mulv3(mat4 m, vec3 v, float last, vec3 dest);
CGLM_EXPORT
float
glmc_mat4_trace(mat4 m);
CGLM_EXPORT
float
glmc_mat4_trace3(mat4 m);
CGLM_EXPORT CGLM_EXPORT
void void
glmc_mat4_quat(mat4 m, versor dest); glmc_mat4_quat(mat4 m, versor dest);

View File

@@ -21,6 +21,7 @@
CGLM_INLINE void glm_mat3_transpose_to(mat3 m, mat3 dest); CGLM_INLINE void glm_mat3_transpose_to(mat3 m, mat3 dest);
CGLM_INLINE void glm_mat3_transpose(mat3 m); CGLM_INLINE void glm_mat3_transpose(mat3 m);
CGLM_INLINE void glm_mat3_mulv(mat3 m, vec3 v, vec3 dest); CGLM_INLINE void glm_mat3_mulv(mat3 m, vec3 v, vec3 dest);
CGLM_INLINE float glm_mat3_trace(mat3 m);
CGLM_INLINE void glm_mat3_scale(mat3 m, float s); CGLM_INLINE void glm_mat3_scale(mat3 m, float s);
CGLM_INLINE float glm_mat3_det(mat3 mat); CGLM_INLINE float glm_mat3_det(mat3 mat);
CGLM_INLINE void glm_mat3_inv(mat3 mat, mat3 dest); CGLM_INLINE void glm_mat3_inv(mat3 mat, mat3 dest);
@@ -207,6 +208,18 @@ glm_mat3_mulv(mat3 m, vec3 v, vec3 dest) {
dest[2] = m[0][2] * v[0] + m[1][2] * v[1] + m[2][2] * v[2]; dest[2] = m[0][2] * v[0] + m[1][2] * v[1] + m[2][2] * v[2];
} }
/*!
* @brief trace of matrix
*
* sum of the elements on the main diagonal from upper left to the lower right
*
* @param[in] m matrix
*/
CGLM_INLINE
float
glm_mat3_trace(mat3 m) {
return m[0][0] + m[1][1] + m[2][2];
}
/*! /*!
* @brief convert mat3 to quaternion * @brief convert mat3 to quaternion

View File

@@ -29,6 +29,8 @@
CGLM_INLINE void glm_mat4_mulN(mat4 *matrices[], int len, mat4 dest); CGLM_INLINE void glm_mat4_mulN(mat4 *matrices[], int len, mat4 dest);
CGLM_INLINE void glm_mat4_mulv(mat4 m, vec4 v, vec4 dest); CGLM_INLINE void glm_mat4_mulv(mat4 m, vec4 v, vec4 dest);
CGLM_INLINE void glm_mat4_mulv3(mat4 m, vec3 v, vec3 dest); CGLM_INLINE void glm_mat4_mulv3(mat4 m, vec3 v, vec3 dest);
CGLM_INLINE float glm_mat4_trace(mat4 m);
CGLM_INLINE float glm_mat4_trace3(mat4 m);
CGLM_INLINE void glm_mat4_transpose_to(mat4 m, mat4 dest); CGLM_INLINE void glm_mat4_transpose_to(mat4 m, mat4 dest);
CGLM_INLINE void glm_mat4_transpose(mat4 m); CGLM_INLINE void glm_mat4_transpose(mat4 m);
CGLM_INLINE void glm_mat4_scale_p(mat4 m, float s); CGLM_INLINE void glm_mat4_scale_p(mat4 m, float s);
@@ -338,6 +340,32 @@ glm_mat4_mulv(mat4 m, vec4 v, vec4 dest) {
#endif #endif
} }
/*!
* @brief trace of matrix
*
* sum of the elements on the main diagonal from upper left to the lower right
*
* @param[in] m matrix
*/
CGLM_INLINE
float
glm_mat4_trace(mat4 m) {
return m[0][0] + m[1][1] + m[2][2] + m[3][3];
}
/*!
* @brief trace of matrix (rotation part)
*
* sum of the elements on the main diagonal from upper left to the lower right
*
* @param[in] m matrix
*/
CGLM_INLINE
float
glm_mat4_trace3(mat4 m) {
return m[0][0] + m[1][1] + m[2][2];
}
/*! /*!
* @brief convert mat4's rotation part to quaternion * @brief convert mat4's rotation part to quaternion
* *

View File

@@ -50,6 +50,12 @@ glmc_mat3_mulv(mat3 m, vec3 v, vec3 dest) {
glm_mat3_mulv(m, v, dest); glm_mat3_mulv(m, v, dest);
} }
CGLM_EXPORT
float
glmc_mat3_trace(mat3 m) {
return glm_mat3_trace(m);
}
CGLM_EXPORT CGLM_EXPORT
void void
glmc_mat3_quat(mat3 m, versor dest) { glmc_mat3_quat(mat3 m, versor dest) {

View File

@@ -74,6 +74,18 @@ glmc_mat4_mulv3(mat4 m, vec3 v, float last, vec3 dest) {
glm_mat4_mulv3(m, v, last, dest); glm_mat4_mulv3(m, v, last, dest);
} }
CGLM_EXPORT
float
glmc_mat4_trace(mat4 m) {
return glm_mat4_trace(m);
}
CGLM_EXPORT
float
glmc_mat4_trace3(mat4 m) {
return glm_mat4_trace3(m);
}
CGLM_EXPORT CGLM_EXPORT
void void
glmc_mat4_quat(mat4 m, versor dest) { glmc_mat4_quat(mat4 m, versor dest) {