[cogl/wip/rib/cogl-1.12: 101/101] quaternions: Allow multiplication into 'a' arg



commit e3138921d4319bded722307b28d5b8ac41e68ca5
Author: Robert Bragg <robert linux intel com>
Date:   Mon Jul 9 17:55:58 2012 +0100

    quaternions: Allow multiplication into 'a' arg
    
    When multiplying two quaternions, we now implicitly copy the components
    of the 'a' argument so that the result can be reliably written back to
    the 'a' argument quaternion without conflicting with the multiplication
    itself. This is consistent with the cogl_matrix_multiply() api which
    allows the 'result' and 'a' arguments to point to the same matrix. In
    debug builds Cogl will assert that the 'b' and 'result' arguments don't
    point to the same quaternion.
    
    Reviewed-by: Neil Roberts <neil linux intel com>
    
    (cherry picked from commit 207527313a8957789390069e84189254cf41e88f)

 cogl/cogl-quaternion.c |   15 +++++++++++----
 cogl/cogl-quaternion.h |    3 +++
 2 files changed, 14 insertions(+), 4 deletions(-)
---
diff --git a/cogl/cogl-quaternion.c b/cogl/cogl-quaternion.c
index a6a275a..70cfe3e 100644
--- a/cogl/cogl-quaternion.c
+++ b/cogl/cogl-quaternion.c
@@ -434,11 +434,18 @@ cogl_quaternion_multiply (CoglQuaternion *result,
                           const CoglQuaternion *a,
                           const CoglQuaternion *b)
 {
-  result->w = a->w * b->w - a->x * b->x - a->y * b->y - a->z * b->z;
+  float w = a->w;
+  float x = a->x;
+  float y = a->y;
+  float z = a->z;
 
-  result->x = a->w * b->x + a->x * b->w + a->y * b->z - a->z * b->y;
-  result->y = a->w * b->y + a->y * b->w + a->z * b->x - a->x * b->z;
-  result->z = a->w * b->z + a->z * b->w + a->x * b->y - a->y * b->x;
+  _COGL_RETURN_IF_FAIL (b != result);
+
+  result->w = w * b->w - x * b->x - y * b->y - z * b->z;
+
+  result->x = w * b->x + x * b->w + y * b->z - z * b->y;
+  result->y = w * b->y + y * b->w + z * b->x - x * b->z;
+  result->z = w * b->z + z * b->w + x * b->y - y * b->x;
 }
 
 void
diff --git a/cogl/cogl-quaternion.h b/cogl/cogl-quaternion.h
index 6501603..a1b3cfb 100644
--- a/cogl/cogl-quaternion.h
+++ b/cogl/cogl-quaternion.h
@@ -394,6 +394,9 @@ cogl_quaternion_invert (CoglQuaternion *quaternion);
  * so the rotations are applied @right to @left. This is similar to the
  * combining of matrices.
  *
+ * <note>It is possible to multiply the @a quaternion in-place, so
+ * @result can be equal to @a but can't be equal to @b.</note>
+ *
  * Since: 2.0
  */
 void



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