[cogl/wip/rib/cogl-1.12: 104/142] Add a basic conformance test for eulers and quaternions



commit 6dbb346a7ed3f17d7e06cca94d8ade97c84d631e
Author: Neil Roberts <neil linux intel com>
Date:   Thu May 17 22:30:37 2012 +0100

    Add a basic conformance test for eulers and quaternions
    
    This adds some preliminary testing for eulers and quaternions. It
    mostly just tests the cogl_matrix_init_from_{quaternion,euler}
    functions as well as applying a euler or quaternion transformation to
    a framebuffer's modelview matrix.
    
    Reviewed-by: Robert Bragg <robert linux intel com>
    
    (cherry picked from commit a32eb76e16d7d76af2fe8a6ba9151d8826b58864)

 tests/conform/Makefile.am             |    1 +
 tests/conform/test-conform-main.c     |    2 +
 tests/conform/test-euler-quaternion.c |   81 +++++++++++++++++++++++++++++++++
 3 files changed, 84 insertions(+), 0 deletions(-)
---
diff --git a/tests/conform/Makefile.am b/tests/conform/Makefile.am
index cfd8a8c..8d8ebfa 100644
--- a/tests/conform/Makefile.am
+++ b/tests/conform/Makefile.am
@@ -55,6 +55,7 @@ test_sources = \
 	test-no-gl-header.c \
 	test-version.c \
 	test-gles2-context.c \
+	test-euler-quaternion.c \
 	$(NULL)
 
 test_conformance_SOURCES = $(common_sources) $(test_sources)
diff --git a/tests/conform/test-conform-main.c b/tests/conform/test-conform-main.c
index 5b38aa1..e611ff9 100644
--- a/tests/conform/test-conform-main.c
+++ b/tests/conform/test-conform-main.c
@@ -101,6 +101,8 @@ main (int argc, char **argv)
 
   ADD_TEST (test_gles2_context, TEST_REQUIREMENT_GLES2_CONTEXT);
 
+  ADD_TEST (test_euler_quaternion, 0);
+
   g_printerr ("Unknown test name \"%s\"\n", argv[1]);
 
   return 1;
diff --git a/tests/conform/test-euler-quaternion.c b/tests/conform/test-euler-quaternion.c
new file mode 100644
index 0000000..d271544
--- /dev/null
+++ b/tests/conform/test-euler-quaternion.c
@@ -0,0 +1,81 @@
+#include <cogl/cogl.h>
+#include <math.h>
+#include <string.h>
+
+#include "test-utils.h"
+
+/* Macros are used here instead of functions so that the
+ * g_assert_cmpfloat will give a more interesting message when it
+ * fails */
+
+#define COMPARE_FLOATS(a, b)                    \
+  do {                                          \
+    if (fabsf ((a) - (b)) >= 0.0001f)           \
+      g_assert_cmpfloat ((a), ==, (b));         \
+  } while (0)
+
+#define COMPARE_MATRICES(a, b) \
+  do {                                          \
+    COMPARE_FLOATS ((a)->xx, (b)->xx);          \
+    COMPARE_FLOATS ((a)->yx, (b)->yx);          \
+    COMPARE_FLOATS ((a)->zx, (b)->zx);          \
+    COMPARE_FLOATS ((a)->wx, (b)->wx);          \
+    COMPARE_FLOATS ((a)->xy, (b)->xy);          \
+    COMPARE_FLOATS ((a)->yy, (b)->yy);          \
+    COMPARE_FLOATS ((a)->zy, (b)->zy);          \
+    COMPARE_FLOATS ((a)->wy, (b)->wy);          \
+    COMPARE_FLOATS ((a)->xz, (b)->xz);          \
+    COMPARE_FLOATS ((a)->yz, (b)->yz);          \
+    COMPARE_FLOATS ((a)->zz, (b)->zz);          \
+    COMPARE_FLOATS ((a)->wz, (b)->wz);          \
+    COMPARE_FLOATS ((a)->xw, (b)->xw);          \
+    COMPARE_FLOATS ((a)->yw, (b)->yw);          \
+    COMPARE_FLOATS ((a)->zw, (b)->zw);          \
+    COMPARE_FLOATS ((a)->ww, (b)->ww);          \
+  } while (0)
+
+void
+test_euler_quaternion (void)
+{
+  CoglEuler euler;
+  CoglQuaternion quaternion;
+  CoglMatrix matrix_a, matrix_b;
+
+  /* Try doing the rotation with three separate rotations */
+  cogl_matrix_init_identity (&matrix_a);
+  cogl_matrix_rotate (&matrix_a, -30.0f, 0.0f, 1.0f, 0.0f);
+  cogl_matrix_rotate (&matrix_a, 40.0f, 1.0f, 0.0f, 0.0f);
+  cogl_matrix_rotate (&matrix_a, 50.0f, 0.0f, 0.0f, 1.0f);
+
+  /* And try the same rotation with a euler */
+  cogl_euler_init (&euler, -30, 40, 50);
+  cogl_matrix_init_from_euler (&matrix_b, &euler);
+
+  /* Verify that the matrices are approximately the same */
+  COMPARE_MATRICES (&matrix_a, &matrix_b);
+
+  /* Try converting the euler to a matrix via a quaternion */
+  cogl_quaternion_init_from_euler (&quaternion, &euler);
+  memset (&matrix_b, 0, sizeof (matrix_b));
+  cogl_matrix_init_from_quaternion (&matrix_b, &quaternion);
+  COMPARE_MATRICES (&matrix_a, &matrix_b);
+
+  /* Try applying the rotation from a euler to a framebuffer */
+  cogl_framebuffer_identity_matrix (fb);
+  cogl_framebuffer_rotate_euler (fb, &euler);
+  memset (&matrix_b, 0, sizeof (matrix_b));
+  cogl_framebuffer_get_modelview_matrix (fb, &matrix_b);
+  COMPARE_MATRICES (&matrix_a, &matrix_b);
+
+  /* And again with a quaternion */
+  cogl_framebuffer_identity_matrix (fb);
+  cogl_framebuffer_rotate_quaternion (fb, &quaternion);
+  memset (&matrix_b, 0, sizeof (matrix_b));
+  cogl_framebuffer_get_modelview_matrix (fb, &matrix_b);
+  COMPARE_MATRICES (&matrix_a, &matrix_b);
+
+  /* FIXME: This needs a lot more tests! */
+
+  if (cogl_test_verbose ())
+    g_print ("OK\n");
+}



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