[cogl/wip/rib/cogl-1.12: 73/142] matrix: Add a init_translation() constructor



commit f4b1af741aae5cf4f17fae4fbeb004386baf0bd8
Author: Damien Lespiau <damien lespiau intel com>
Date:   Thu May 3 12:26:11 2012 +0100

    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)

 cogl/cogl-matrix.c                                 |   34 ++++++++++++++++++++
 cogl/cogl-matrix.h                                 |   24 ++++++++++++++
 .../cogl-2.0-experimental-sections.txt             |    1 +
 3 files changed, 59 insertions(+), 0 deletions(-)
---
diff --git a/cogl/cogl-matrix.c b/cogl/cogl-matrix.c
index 142cd65..5166549 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 b5b5fc3..3f0709a 100644
--- a/cogl/cogl-matrix.h
+++ b/cogl/cogl-matrix.h
@@ -127,6 +127,30 @@ 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
  * @a: A 4x4 transformation matrix
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 3bfed95..3f09cab 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



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]