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); }
GRAPHENE_TEST_UNIT_END GRAPHENE_TEST_UNIT_BEGIN (ray_matrix_transform) { graphene_ray_t r, res; graphene_matrix_t m; if (g_test_verbose ()) g_test_message ("Identity matrix..."); graphene_ray_init (&r, &one3, graphene_vec3_z_axis ()); graphene_matrix_init_identity (&m); graphene_matrix_transform_ray (&m, &r, &res); g_assert_true (graphene_ray_equal (&r, &res)); if (g_test_verbose ()) g_test_message ("Rotation matrix: rotateZ(90deg)"); graphene_ray_init (&r, &zero3, graphene_vec3_z_axis ()); graphene_matrix_init_rotate (&m, 90, graphene_vec3_z_axis ()); graphene_matrix_transform_ray (&m, &r, &res); g_assert_true (graphene_ray_equal (&r, &res)); }
void ops_finish (RenderOpBuilder *builder) { if (builder->mv_stack) g_array_free (builder->mv_stack, TRUE); builder->mv_stack = NULL; if (builder->clip_stack) g_array_free (builder->clip_stack, TRUE); builder->clip_stack = NULL; builder->buffer_size = 0; builder->dx = 0; builder->dy = 0; builder->current_modelview = NULL; builder->current_clip = NULL; builder->current_render_target = 0; builder->current_texture = 0; builder->current_program = NULL; builder->current_program_state = NULL; graphene_matrix_init_identity (&builder->current_projection); builder->current_viewport = GRAPHENE_RECT_INIT (0, 0, 0, 0); }
/** * graphene_euler_to_matrix: * @e: a #graphene_euler_t * @res: (out caller-allocates): return location for a #graphene_matrix_t * * Converts a #graphene_euler_t into a transformation matrix expressing * the extrinsic composition of rotations described by the Euler angles. * * The rotations are applied over the reference frame axes in the order * associated with the #graphene_euler_t; for instance, if the order * used to initialize @e is %GRAPHENE_EULER_ORDER_XYZ: * * * the first rotation moves the body around the X axis with * an angle φ * * the second rotation moves the body around the Y axis with * an angle of ϑ * * the third rotation moves the body around the Z axis with * an angle of ψ * * The rotation sign convention is left-handed, to preserve compatibility * between Euler-based, quaternion-based, and angle-axis-based rotations. * * Since: 1.2 */ void graphene_euler_to_matrix (const graphene_euler_t *e, graphene_matrix_t *res) { graphene_euler_order_t order = graphene_euler_get_order (e); const float x = graphene_vec3_get_x (&e->angles); const float y = graphene_vec3_get_y (&e->angles); const float z = graphene_vec3_get_z (&e->angles); float c1, s1, c2, s2, c3, s3; float c3c2, s3c1, c3s2s1, s3s1; float c3s2c1, s3c2, c3c1, s3s2s1; float c3s1, s3s2c1, c2s1, c2c1; graphene_sincos (x, &c1, &s1); graphene_sincos (y, &c2, &s2); graphene_sincos (z, &c3, &s3); c3c2 = c3 * c2; s3c1 = s3 * c1; c3s2s1 = c3 * s2 * s1; s3s1 = s3 * s1; c3s2c1 = c3 * s2 * c1; s3c2 = s3 * c2; c3c1 = c3 * c1; s3s2s1 = s3 * s2 * s1; c3s1 = c3 * s1; s3s2c1 = s3 * s2 * c1; c2s1 = c2 * s1; c2c1 = c2 * c1; switch (order) { case GRAPHENE_EULER_ORDER_XYZ: { /* ⎡ c3 s3 0 ⎤ ⎡ c2 0 -s2 ⎤ ⎡ 1 0 0 ⎤ * ⎢ -s3 c3 0 ⎥ ⎢ 0 1 0 ⎥ ⎢ 0 c1 s1 ⎥ * ⎣ 0 0 1 ⎦ ⎣ s2 0 c2 ⎦ ⎣ 0 -s1 c1 ⎦ */ res->value.x = graphene_simd4f_init ( c3c2, s3c1 + c3s2s1, s3s1 - c3s2c1, 0.f); res->value.y = graphene_simd4f_init (-s3c2, c3c1 - s3s2s1, c3s1 + s3s2c1, 0.f); res->value.z = graphene_simd4f_init ( s2, -c2s1, c2c1, 0.f); res->value.w = graphene_simd4f_init ( 0.f, 0.f, 0.f, 1.f); } break; case GRAPHENE_EULER_ORDER_YXZ: { /* ⎡ c3 s3 0 ⎤ ⎡ 1 0 0 ⎤ ⎡ c1 0 -s1 ⎤ * ⎢ -s2 c3 0 ⎥ ⎢ 0 c2 s2 ⎥ ⎢ 0 1 0 ⎥ * ⎣ 0 0 1 ⎦ ⎣ 0 -s2 c2 ⎦ ⎣ s1 0 c1 ⎦ */ res->value.x = graphene_simd4f_init ( c3c1 + s3s2s1, s3c2, -c3s1 + s3s2c1, 0.f); res->value.y = graphene_simd4f_init (-s3c1 + c3s2s1, c3c2, s3s1 + c3s2c1, 0.f); res->value.z = graphene_simd4f_init ( c2s1, -s2, c2c1, 0.f); res->value.w = graphene_simd4f_init ( 0.f, 0.f, 0.f, 1.f); } break; case GRAPHENE_EULER_ORDER_ZXY: { /* ⎡ 1 0 0 ⎤ ⎡ c2 0 -s2 ⎤ ⎡ c1 s1 0 ⎤ * ⎢ 0 c3 s3 ⎥ ⎢ 0 1 0 ⎥ ⎢ -s1 c1 0 ⎥ * ⎣ 0 -s3 c3 ⎦ ⎣ s2 0 c2 ⎦ ⎣ 0 0 1 ⎦ */ res->value.x = graphene_simd4f_init (c3c1 - s3s2s1, c3s1 + s3s2c1, -s3c2, 0.f); res->value.y = graphene_simd4f_init ( -c2s1, c2c1, s2, 0.f); res->value.z = graphene_simd4f_init (s3c1 + c3s2s1, s3s1 - c3s2c1, c3c2, 0.f); res->value.w = graphene_simd4f_init ( 0.f, 0.f, 0.f, 1.f); } break; case GRAPHENE_EULER_ORDER_ZYX: { /* ⎡ 1 0 0 ⎤ ⎡ c2 0 -s2 ⎤ ⎡ c1 s1 0 ⎤ * ⎢ 0 c3 s3 ⎥ ⎢ 0 1 0 ⎥ ⎢ -s1 c1 0 ⎥ * ⎣ 0 -s3 c3 ⎦ ⎣ s2 0 c2 ⎦ ⎣ 0 0 1 ⎦ */ res->value.x = graphene_simd4f_init ( c2c1, c2s1, -s2, 0.f); res->value.y = graphene_simd4f_init (s3s2c1 - c3s1, s3s2s1 + c3c1, s3c2, 0.f); res->value.z = graphene_simd4f_init (c3s2c1 + s3s1, c3s2s1 - s3c1, c3c2, 0.f); res->value.w = graphene_simd4f_init ( 0.f, 0.f, 0.f, 1.f); } break; case GRAPHENE_EULER_ORDER_YZX: { /* ⎡ 1 0 0 ⎤ ⎡ c2 s2 0 ⎤ ⎡ c1 0 -s1 ⎤ * ⎢ 0 c3 s3 ⎥ ⎢ -s2 c2 0 ⎥ ⎢ 0 1 0 ⎥ * ⎣ 0 -s3 c3 ⎦ ⎣ 0 0 1 ⎦ ⎣ s1 0 c1 ⎦ */ res->value.x = graphene_simd4f_init ( c2c1, s2, -c2s1, 0.f); res->value.y = graphene_simd4f_init (-c3s2c1 + s3s1, c3c2, c3s2s1 + s3c1, 0.f); res->value.z = graphene_simd4f_init ( s3s2c1 + c3s1, -s3c2, -s3s2s1 + c3c1, 0.f); res->value.w = graphene_simd4f_init ( 0.f, 0.f, 0.f, 1.f); } break; case GRAPHENE_EULER_ORDER_XZY: { /* ⎡ c3 0 -s3 ⎤ ⎡ c2 s2 0 ⎤ ⎡ 1 0 0 ⎤ * ⎢ 0 1 0 ⎥ ⎢ -s2 c2 0 ⎥ ⎢ 0 c1 s1 ⎥ * ⎣ s3 0 c3 ⎦ ⎣ 0 0 1 ⎦ ⎣ 0 -s1 c1 ⎦ */ res->value.x = graphene_simd4f_init (c3c2, c3s2c1 + s3s1, c3s2s1 - s3c1, 0.f); res->value.y = graphene_simd4f_init ( -s2, c2c1, c2s1, 0.f); res->value.z = graphene_simd4f_init (s3c2, s3s2c1 - c3s1, s3s2s1 + c3c1, 0.f); res->value.w = graphene_simd4f_init ( 0.f, 0.f, 0.f, 1.f); } break; default: graphene_matrix_init_identity (res); break; } }