示例#1
0
static void
quaternion_operators_equal (mutest_spec_t *spec)
{
  graphene_quaternion_t q1, q2, q3;

  graphene_quaternion_init (&q1, 1.f, 1.f, 1.f, 1.f);
  graphene_quaternion_init (&q2, 1.f, 2.f, 3.f, 1.f);
  graphene_quaternion_invert (&q1, &q3);

  mutest_expect ("a quaternion to be equal to itself",
                 mutest_bool_value (graphene_quaternion_equal (&q1, &q1)),
                 mutest_to_be_true,
                 NULL);
  mutest_expect ("a quaternion not to be equal to null",
                 mutest_bool_value (graphene_quaternion_equal (&q1, NULL)),
                 mutest_not, mutest_to_be_true,
                 NULL);
  mutest_expect ("null not to be equal to a quaternion",
                 mutest_bool_value (graphene_quaternion_equal (NULL, &q1)),
                 mutest_not, mutest_to_be_true,
                 NULL);
  mutest_expect ("two different quaternions not to be equal",
                 mutest_bool_value (graphene_quaternion_equal (&q1, &q2)),
                 mutest_not, mutest_to_be_true,
                 NULL);
  mutest_expect ("a quaternion to be equal to its invert",
                 mutest_bool_value (graphene_quaternion_equal (&q1, &q3)),
                 mutest_to_be_true,
                 NULL);
}
示例#2
0
static void
quaternion_operators_invert (mutest_spec_t *spec)
{
  graphene_quaternion_t q1, q2, tmp;

  graphene_quaternion_init_identity (&q1);
  graphene_quaternion_invert (&q1, &q2);
  mutest_expect ("inverting identity gives back an identity",
                 mutest_bool_value (graphene_quaternion_equal (&q1, &q2)),
                 mutest_to_be_true,
                 NULL);

  graphene_quaternion_init (&q1, 1.f, 1.f, 1.f, 1.f);
  graphene_quaternion_invert (&q1, &q2);
  mutest_expect ("inverting a quaternion flips the sign of the first three fields",
                 mutest_bool_value (graphene_quaternion_equal (&q2, graphene_quaternion_init (&tmp, -1.f, -1.f, -1.f, 1.f))),
                 mutest_to_be_true,
                 NULL);
}
示例#3
0
static void
quaternion_matrix_to_from (mutest_spec_t *spec)
{
  graphene_quaternion_t *q1, *q2;
  graphene_matrix_t *m;

  m = graphene_matrix_init_identity (graphene_matrix_alloc ());

  q1 = graphene_quaternion_init_from_matrix (graphene_quaternion_alloc (), m);
  q2 = graphene_quaternion_init_identity (graphene_quaternion_alloc ());
  mutest_expect ("initializing from an identity matrix yields an identity quaternion",
                 mutest_bool_value (graphene_quaternion_equal (q1, q2)),
                 mutest_to_be_true,
                 NULL);

  graphene_matrix_rotate_x (m, 30.f);
  graphene_matrix_rotate_y (m, 45.f);
  graphene_matrix_rotate_z (m, -135.f);
  graphene_quaternion_init_from_matrix (q1, m);
  mutest_expect ("initializing from a rotation matrix does not yield an identity quaternion",
                 mutest_bool_value (graphene_quaternion_equal (q1, q2)),
                 mutest_to_be_false,
                 NULL);

  graphene_matrix_init_identity (m);
  graphene_matrix_rotate_quaternion (m, q1);
  graphene_quaternion_init_from_matrix (q2, m);
  mutest_expect ("rotating a matrix with a quaternion yields the same quaternion",
                 mutest_bool_value (graphene_quaternion_equal (q1, q2)),
                 mutest_to_be_true,
                 NULL);

  graphene_quaternion_free (q2);
  graphene_quaternion_free (q1);

  graphene_matrix_free (m);
}
示例#4
0
static void
quaternion_init (mutest_spec_t *spec)
{
  graphene_quaternion_t q1, q2;

  graphene_quaternion_init (&q1, 0.f, 0.f, 0.f, 1.f);
  graphene_quaternion_init_identity (&q2);
  mutest_expect ("identity to set (0, 0, 0, 1)",
                 mutest_bool_value (graphene_quaternion_equal (&q1, &q2)),
                 mutest_to_be_true,
                 NULL);

  graphene_quaternion_init (&q1, 1.f, 1.f, 1.f, 1.f);
  mutest_expect ("initialization sets all fields",
                 mutest_bool_value (graphene_quaternion_equal (&q1, &q2)),
                 mutest_not, mutest_to_be_true,
                 NULL);

  graphene_quaternion_init_from_quaternion (&q2, &q1);
  mutest_expect ("initialization from quaternion makes a copy",
                 mutest_bool_value (graphene_quaternion_equal (&q1, &q2)),
                 mutest_to_be_true,
                 NULL);
}
示例#5
0
static void
quaternion_slerp (mutest_spec_t *spec)
{
  graphene_quaternion_t q1, q2, q3;

  graphene_quaternion_init (&q1, 0.0f, 0.0f, 0.0f, 1.0f);
  graphene_quaternion_init (&q2, 0.2f, 0.3f, 0.4f, 0.5f);
  mutest_expect ("initial and final states are different",
                 mutest_bool_value (graphene_quaternion_equal (&q1, &q2)),
                 mutest_to_be_false,
                 NULL);

  graphene_quaternion_slerp (&q1, &q2, 0.33f, &q3);
  mutest_expect ("interpolated result is different from the initial state",
                 mutest_bool_value (graphene_quaternion_equal (&q1, &q3)),
                 mutest_to_be_false,
                 NULL);

  graphene_quaternion_slerp (&q1, &q2, 0.66f, &q3);
  mutest_expect ("interpolated result is different from the final state",
                 mutest_bool_value (graphene_quaternion_equal (&q2, &q3)),
                 mutest_to_be_false,
                 NULL);
}
示例#6
0
GRAPHENE_TEST_UNIT_END

GRAPHENE_TEST_UNIT_BEGIN (euler_quaternion_roundtrip)
{
  graphene_euler_t values[3];
  unsigned int i;

  graphene_euler_init_with_order (&values[0], 0.f, 0.f, 0.f, GRAPHENE_EULER_ORDER_XYZ);
  graphene_euler_init_with_order (&values[1], 1.f, 0.f, 0.f, GRAPHENE_EULER_ORDER_XYZ);
  graphene_euler_init_with_order (&values[2], 0.f, 1.f, 0.f, GRAPHENE_EULER_ORDER_ZYX);

  for (i = 0; i < G_N_ELEMENTS (values); i++)
    {
      graphene_quaternion_t q, check;
      graphene_euler_t e;

      graphene_quaternion_init_from_euler (&q, &values[i]);

      graphene_euler_init_from_quaternion (&e, &q, graphene_euler_get_order (&values[i]));
      graphene_quaternion_init_from_euler (&check, &e);

      g_assert_true (graphene_quaternion_equal (&q, &check));
    }
}