diff --git a/cogl/cogl-matrix.c b/cogl/cogl-matrix.c index abb0a9267..396017c5e 100644 --- a/cogl/cogl-matrix.c +++ b/cogl/cogl-matrix.c @@ -1689,7 +1689,6 @@ cogl_matrix_init_from_quaternion (CoglMatrix *matrix, _cogl_matrix_init_from_quaternion (matrix, quaternion); } -#if 0 /* * Transpose a float matrix. */ @@ -1713,7 +1712,6 @@ _cogl_matrix_util_transposef (float to[16], const float from[16]) to[14] = from[11]; to[15] = from[15]; } -#endif void cogl_matrix_view_2d_in_frustum (CoglMatrix *matrix, @@ -2122,3 +2120,18 @@ cogl_matrix_look_at (CoglMatrix *matrix, cogl_matrix_multiply (matrix, matrix, &tmp); } + +void +cogl_matrix_transpose (CoglMatrix *matrix) +{ + float new_values[16]; + + /* We don't need to do anything if the matrix is the identity matrix */ + if (!(matrix->flags & MAT_DIRTY_TYPE) && + matrix->type == COGL_MATRIX_TYPE_IDENTITY) + return; + + _cogl_matrix_util_transposef (new_values, cogl_matrix_get_array (matrix)); + + cogl_matrix_init_from_array (matrix, new_values); +} diff --git a/cogl/cogl-matrix.h b/cogl/cogl-matrix.h index 14e92a3bd..0bb3e75e8 100644 --- a/cogl/cogl-matrix.h +++ b/cogl/cogl-matrix.h @@ -653,6 +653,18 @@ cogl_matrix_project_points (const CoglMatrix *matrix, gboolean cogl_matrix_is_identity (const CoglMatrix *matrix); +/** + * cogl_matrix_transpose: + * @matrix: A #CoglMatrix + * + * Replaces @matrix with its transpose. Ie, every element (i,j) in the + * new matrix is taken from element (j,i) in the old matrix. + * + * Since: 1.10 + */ +void +cogl_matrix_transpose (CoglMatrix *matrix); + #ifdef _COGL_SUPPORTS_GTYPE_INTEGRATION #define COGL_GTYPE_TYPE_MATRIX (cogl_gtype_matrix_get_type ()) diff --git a/doc/reference/cogl-2.0-experimental/cogl-2.0-experimental-sections.txt b/doc/reference/cogl-2.0-experimental/cogl-2.0-experimental-sections.txt index 0073408ef..b0b8ae7aa 100644 --- a/doc/reference/cogl-2.0-experimental/cogl-2.0-experimental-sections.txt +++ b/doc/reference/cogl-2.0-experimental/cogl-2.0-experimental-sections.txt @@ -486,6 +486,7 @@ cogl_matrix_multiply cogl_matrix_rotate cogl_matrix_translate cogl_matrix_scale +cogl_matrix_transpose cogl_matrix_get_array cogl_matrix_get_inverse cogl_matrix_transform_point diff --git a/doc/reference/cogl/cogl-sections.txt b/doc/reference/cogl/cogl-sections.txt index 1bbb50b08..77240494b 100644 --- a/doc/reference/cogl/cogl-sections.txt +++ b/doc/reference/cogl/cogl-sections.txt @@ -463,6 +463,7 @@ cogl_matrix_multiply cogl_matrix_rotate cogl_matrix_translate cogl_matrix_scale +cogl_matrix_transpose cogl_matrix_init_from_array cogl_matrix_get_array cogl_matrix_get_inverse