/** [quaternion conjugate example] */ static char * test_quaternion_conjugate() { quaternion qA; quaternion qB; quaternion_set_from_axis_anglef3(&qA, 1.0f, 1.0f, 1.0f, HYP_TAU / 4.0f); quaternion_set_from_axis_anglef3(&qB, -1.0f, -1.0f, -1.0f, HYP_TAU / 4.0f); quaternion_conjugate(&qB); test_assert(quaternion_equals(&qA, &qB)); return 0; }
/** [quaternion inverse example] */ static char * test_quaternion_inverse() { quaternion qA; quaternion qInverse; quaternion qIdentity; quaternion_set_from_axis_anglef3(&qA, 1.0f, 1.0f, 1.0f, HYP_TAU / 4.0f); quaternion_set(&qInverse, &qA); quaternion_inverse(&qInverse); quaternion_multiply(&qA, &qInverse); quaternion_normalize(&qA); quaternion_identity(&qIdentity); test_assert(quaternion_equals(&qA, &qIdentity)); return 0; }
static char *test_quaternion_get_eulers_create_quaternion_ZYX_aa(void) { struct quaternion q1, q2; HYP_FLOAT anglex, angley, anglez; /* making the original quaternion out of an arbitrary axis angle */ quaternion_set_from_axis_anglef3(&q1, 0.4f, 0.232f, 0.543f, HYP_TAU / 1.45f); /* get the angles */ quaternion_get_euler_anglesf3_ZYX_EXP(&q1, &anglex, &angley, &anglez); /* compose new quaternions with the eulers */ quaternion_set_from_euler_anglesf3_ZYX_EXP(&q2, anglex, angley, anglez); /* same */ test_assert(quaternion_equals(&q1, &q2)); return 0; }
/** * @ingroup quaternion * @brief Sets the values in the quaternion, in place, based on the axis and angle. * * @param self the quaternion that will become initialized with the values of the axis and angle * @param axis the reference axis * @param angle the angle is in radians * */ HYPAPI quaternion * quaternion_set_from_axis_anglev3(quaternion *self, const vector3 *axis, float angle) { return quaternion_set_from_axis_anglef3(self, axis->x, axis->y, axis->z, angle); }