matrix: Add a init_translation() constructor

This allows people to initialize a matrix with a translation
transformation. The options to do it at the moment were:

* init_from_array() but it give cogl no information about the type of
  matrix.
* init_indentity() and then translate() but it means doing a lot of
  computations for no reason.

Reviewed-by: Robert Bragg <robert@linux.intel.com>

(cherry picked from commit 068b3b59221e405dc288d434b0008464684a7c12)
This commit is contained in:
Damien Lespiau 2012-05-03 12:26:11 +01:00 committed by Robert Bragg
parent 68a6e82828
commit 7ff0b52d78
3 changed files with 59 additions and 0 deletions

View File

@ -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.

View File

@ -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

View File

@ -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