static void gst_gl_transformation_build_mvp (GstGLTransformation * transformation) { graphene_point3d_t translation_vector = GRAPHENE_POINT3D_INIT (transformation->xtranslation * 2.0 * transformation->aspect, transformation->ytranslation * 2.0, transformation->ztranslation * 2.0); graphene_matrix_t model_matrix; graphene_matrix_t projection_matrix; graphene_matrix_t view_matrix; graphene_matrix_t vp_matrix; graphene_vec3_t eye; graphene_vec3_t center; graphene_vec3_t up; graphene_vec3_init (&eye, 0.f, 0.f, 1.f); graphene_vec3_init (¢er, 0.f, 0.f, 0.f); graphene_vec3_init (&up, 0.f, 1.f, 0.f); graphene_matrix_init_scale (&model_matrix, transformation->xscale, transformation->yscale, 1.0f); graphene_matrix_rotate (&model_matrix, transformation->xrotation, graphene_vec3_x_axis ()); graphene_matrix_rotate (&model_matrix, transformation->yrotation, graphene_vec3_y_axis ()); graphene_matrix_rotate (&model_matrix, transformation->zrotation, graphene_vec3_z_axis ()); graphene_matrix_translate (&model_matrix, &translation_vector); if (transformation->ortho) { graphene_matrix_init_ortho (&projection_matrix, -transformation->aspect, transformation->aspect, -1, 1, transformation->znear, transformation->zfar); } else { graphene_matrix_init_perspective (&projection_matrix, transformation->fov, transformation->aspect, transformation->znear, transformation->zfar); } graphene_matrix_init_look_at (&view_matrix, &eye, ¢er, &up); graphene_matrix_multiply (&view_matrix, &projection_matrix, &vp_matrix); graphene_matrix_multiply (&model_matrix, &vp_matrix, &transformation->mvp_matrix); }
/* This sets the given modelview to the one we get when multiplying * the given modelview with the current one. */ void ops_push_modelview (RenderOpBuilder *builder, const graphene_matrix_t *mv, GskTransformCategory mv_category) { float scale = ops_get_scale (builder); MatrixStackEntry *entry; if (G_UNLIKELY (builder->mv_stack == NULL)) builder->mv_stack = g_array_new (FALSE, TRUE, sizeof (MatrixStackEntry)); g_assert (builder->mv_stack != NULL); g_array_set_size (builder->mv_stack, builder->mv_stack->len + 1); entry = &g_array_index (builder->mv_stack, MatrixStackEntry, builder->mv_stack->len - 1); if (G_LIKELY (builder->mv_stack->len >= 2)) { const MatrixStackEntry *cur; cur = &g_array_index (builder->mv_stack, MatrixStackEntry, builder->mv_stack->len - 2); /* Multiply given matrix with current modelview */ graphene_matrix_multiply (mv, &cur->matrix, &entry->matrix); graphene_matrix_translate (&entry->matrix, &(graphene_point3d_t) { builder->dx * scale, builder->dy * scale, 0}); entry->metadata.category = MIN (mv_category, cur->metadata.category); } else { entry->matrix = *mv; entry->metadata.category = mv_category; } entry->metadata.dx_before = builder->dx; entry->metadata.dy_before = builder->dy; extract_matrix_metadata (mv, &entry->metadata); builder->dx = 0; builder->dy = 0; builder->current_modelview = &entry->matrix; ops_set_modelview_internal (builder, &entry->matrix); }
/** * graphene_matrix_interpolate: * @a: ... * @b: ... * @factor: ... * @res: (out caller-allocates): ... * * ... * * Since: 1.0 */ void graphene_matrix_interpolate (const graphene_matrix_t *a, const graphene_matrix_t *b, double factor, graphene_matrix_t *res) { graphene_point3d_t scale_a = { 1.f, 1.f, 1.f }, translate_a; graphene_vec4_t perspective_a; graphene_quaternion_t rotate_a; float shear_a[3] = { 0.f, 0.f, 0.f }; graphene_point3d_t scale_b = { 1.f, 1.f, 1.f }, translate_b; graphene_vec4_t perspective_b; graphene_quaternion_t rotate_b; float shear_b[3] = { 0.f, 0.f, 0.f }; graphene_point3d_t scale_r = { 1.f, 1.f, 1.f }, translate_r; graphene_quaternion_t rotate_r; graphene_matrix_t tmp; float shear; g_return_if_fail (a != NULL && b != NULL); g_return_if_fail (res != NULL); if (graphene_matrix_is_2d (a) && graphene_matrix_is_2d (b)) { graphene_vec4_init (&perspective_a, 0.f, 0.f, 0.f, 1.f); graphene_vec4_init (&perspective_b, 0.f, 0.f, 0.f, 1.f); matrix_decompose_2d (a, &scale_a, shear_a, &rotate_a, &translate_a); matrix_decompose_2d (b, &scale_b, shear_b, &rotate_b, &translate_b); } else { matrix_decompose_3d (a, &scale_a, shear_a, &rotate_a, &translate_a, &perspective_a); matrix_decompose_3d (b, &scale_b, shear_b, &rotate_b, &translate_b, &perspective_b); } res->value.w = graphene_simd4f_interpolate (perspective_a.value, perspective_b.value, factor); graphene_point3d_interpolate (&translate_a, &translate_b, factor, &translate_r); graphene_matrix_translate (res, &translate_r); graphene_quaternion_slerp (&rotate_a, &rotate_b, factor, &rotate_r); graphene_quaternion_to_matrix (&rotate_r, &tmp); if (!graphene_matrix_is_identity (&tmp)) graphene_matrix_multiply (&tmp, res, res); shear = shear_a[YZ_SHEAR] + (shear_b[YZ_SHEAR] - shear_a[YZ_SHEAR]) * factor; if (shear != 0.f) graphene_matrix_skew_yz (res, shear); shear = shear_a[XZ_SHEAR] + (shear_b[XZ_SHEAR] - shear_a[XZ_SHEAR]) * factor; if (shear != 0.f) graphene_matrix_skew_xz (res, shear); shear = shear_a[XY_SHEAR] + (shear_b[XY_SHEAR] - shear_a[XY_SHEAR]) * factor; if (shear != 0.f) graphene_matrix_skew_xy (res, shear); graphene_point3d_interpolate (&scale_a, &scale_b, factor, &scale_r); if (scale_r.x != 1.f && scale_r.y != 1.f && scale_r.z != 0.f) graphene_matrix_scale (res, scale_r.x, scale_r.y, scale_r.z); }