diff --git a/cogl/cogl-matrix.c b/cogl/cogl-matrix.c index 142cd65d8..51665496c 100644 --- a/cogl/cogl-matrix.c +++ b/cogl/cogl-matrix.c @@ -1603,6 +1603,40 @@ cogl_matrix_init_identity (CoglMatrix *matrix) _COGL_MATRIX_DEBUG_PRINT (matrix); } +/* + * Set a matrix to the (tx, ty, tz) translation matrix. + * + * @matix matrix. + * @tx x coordinate of the translation vector + * @ty y coordinate of the translation vector + * @tz z coordinate of the translation vector + */ +static void +_cogl_matrix_init_translation (CoglMatrix *matrix, + float tx, + float ty, + float tz) +{ + memcpy (matrix, identity, 16 * sizeof (float)); + + matrix->xw = tx; + matrix->yw = ty; + matrix->yw = tz; + + matrix->type = COGL_MATRIX_TYPE_3D; + matrix->flags = MAT_FLAG_TRANSLATION | MAT_DIRTY_INVERSE; +} + +void +cogl_matrix_init_translation (CoglMatrix *matrix, + float tx, + float ty, + float tz) +{ + _cogl_matrix_init_translation (matrix, tx, ty, tz); + _COGL_MATRIX_DEBUG_PRINT (matrix); +} + #if 0 /* * Test if the given matrix preserves vector lengths. diff --git a/cogl/cogl-matrix.h b/cogl/cogl-matrix.h index b5b5fc3b6..3f0709a73 100644 --- a/cogl/cogl-matrix.h +++ b/cogl/cogl-matrix.h @@ -126,6 +126,30 @@ COGL_STRUCT_SIZE_ASSERT (CoglMatrix, 128 + sizeof (unsigned long) * 3); void cogl_matrix_init_identity (CoglMatrix *matrix); +/** + * cogl_matrix_init_translation: + * @matrix: A 4x4 transformation matrix + * @tx x coordinate of the translation vector + * @ty y coordinate of the translation vector + * @tz z coordinate of the translation vector + * + * Resets matrix to the (tx, ty, tz) translation matrix: + * + * |[ + * .xx=1; .xy=0; .xz=0; .xw=tx; + * .yx=0; .yy=1; .yz=0; .yw=ty; + * .zx=0; .zy=0; .zz=1; .zw=tz; + * .wx=0; .wy=0; .wz=0; .ww=1; + * ]| + * + * Since: 2.0 + */ +void +cogl_matrix_init_translation (CoglMatrix *matrix, + float tx, + float ty, + float tz); + /** * cogl_matrix_multiply: * @result: The address of a 4x4 matrix to store the result in 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 3bfed9580..3f09cab05 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 @@ -545,6 +545,7 @@ cogl_color_equal CoglMatrix cogl_matrix_init_identity cogl_matrix_init_from_array +cogl_matrix_init_translation cogl_matrix_copy cogl_matrix_equal cogl_matrix_free