/** * graphene_quaternion_to_angles: * @q: a #graphene_quaternion_t * @deg_x: (out) (optional): return location for the rotation angle on * the X axis (yaw), in degress * @deg_y: (out) (optional): return location for the rotation angle on * the Y axis (pitch), in degrees * @deg_z: (out) (optional): return location for the rotation angle on * the Z axis (roll), in degrees * * Converts a #graphene_quaternion_t to its corresponding rotations * on the [Euler angles](http://en.wikipedia.org/wiki/Euler_angles) * on each axis. * * Since: 1.2 */ void graphene_quaternion_to_angles (const graphene_quaternion_t *q, float *deg_x, float *deg_y, float *deg_z) { graphene_vec4_t v; graphene_vec4_t sq; float qx, qy, qz, qw, sqx, sqy, sqz, sqw; graphene_quaternion_to_vec4 (q, &v); graphene_vec4_multiply (&v, &v, &sq); qx = graphene_vec4_get_x (&v); qy = graphene_vec4_get_y (&v); qz = graphene_vec4_get_z (&v); qw = graphene_vec4_get_w (&v); sqx = graphene_vec4_get_x (&sq); sqy = graphene_vec4_get_y (&sq); sqz = graphene_vec4_get_z (&sq); sqw = graphene_vec4_get_w (&sq); if (deg_x != NULL) { float res = atan2f (2 * (qx * qw - qy * qz), (sqw - sqx - sqy + sqz)); *deg_x = GRAPHENE_RAD_TO_DEG (res); } if (deg_y != NULL) { float res = asinf (CLAMP (2 * ( qx * qz + qy * qw), -1, 1)); *deg_y = GRAPHENE_RAD_TO_DEG (res); } if (deg_z != NULL) { float res = atan2f (2 * (qz * qw - qx * qy), (sqw + sqx - sqy - sqz)); *deg_z = GRAPHENE_RAD_TO_DEG (res); } }
static gboolean _set_uniform (GQuark field_id, const GValue * value, gpointer user_data) { GstGLShader *shader = user_data; const gchar *field_name = g_quark_to_string (field_id); if (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_INT)) { gst_gl_shader_set_uniform_1i (shader, field_name, g_value_get_int (value)); } else if (G_TYPE_CHECK_VALUE_TYPE ((value), G_TYPE_FLOAT)) { gst_gl_shader_set_uniform_1f (shader, field_name, g_value_get_float (value)); #ifdef HAVE_GRAPHENE } else if (G_TYPE_CHECK_VALUE_TYPE ((value), GRAPHENE_TYPE_VEC2)) { graphene_vec2_t *vec2 = g_value_get_boxed (value); float x = graphene_vec2_get_x (vec2); float y = graphene_vec2_get_y (vec2); gst_gl_shader_set_uniform_2f (shader, field_name, x, y); } else if (G_TYPE_CHECK_VALUE_TYPE ((value), GRAPHENE_TYPE_VEC3)) { graphene_vec3_t *vec3 = g_value_get_boxed (value); float x = graphene_vec3_get_x (vec3); float y = graphene_vec3_get_y (vec3); float z = graphene_vec3_get_z (vec3); gst_gl_shader_set_uniform_3f (shader, field_name, x, y, z); } else if (G_TYPE_CHECK_VALUE_TYPE ((value), GRAPHENE_TYPE_VEC4)) { graphene_vec4_t *vec4 = g_value_get_boxed (value); float x = graphene_vec4_get_x (vec4); float y = graphene_vec4_get_y (vec4); float z = graphene_vec4_get_z (vec4); float w = graphene_vec4_get_w (vec4); gst_gl_shader_set_uniform_4f (shader, field_name, x, y, z, w); } else if (G_TYPE_CHECK_VALUE_TYPE ((value), GRAPHENE_TYPE_MATRIX)) { graphene_matrix_t *matrix = g_value_get_boxed (value); float matrix_f[16]; graphene_matrix_to_float (matrix, matrix_f); gst_gl_shader_set_uniform_matrix_4fv (shader, field_name, 1, FALSE, matrix_f); #endif } else { /* FIXME: Add support for unsigned ints, non 4x4 matrices, etc */ GST_FIXME ("Don't know how to set the \'%s\' paramater. Unknown type", field_name); return TRUE; } return TRUE; }